Convert LucaSchema from Single-Entry to Double-Entry Accounting (v2.1.0) #57
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This PR converts LucaSchema from a single-entry accounting system to a proper double-entry accounting system, implementing the fundamental principle that every transaction consists of balanced debits and credits. This is a major breaking change requiring version 2.0.0.
What Changed
New Posting Entity
Introduced a new
Postingschema that represents individual debit or credit entries:Transaction Schema Restructuring
Before (v1.x - Single-Entry):
After (v2.0 - Double-Entry):
Key Features
accountIdExample Transactions
Simple Expense:
Income:
Split Transaction:
Breaking Changes
Removed Fields
payorIdfrom Transaction and RecurringTransactionpayeeIdfrom Transaction and RecurringTransactionamountfrom Transaction and RecurringTransaction (replaced by postings array)New Requirements
Migration Guide
Testing
Documentation
Technical Implementation
balancedPostingsenforces sum-zero constraintThis implementation follows established accounting best practices and provides a solid foundation for double-entry bookkeeping in personal finance applications.
Original prompt
This section details on the original issue you should resolve
<issue_title>Convert Schema to Double-Entry</issue_title>
<issue_description># Convert LucaSchema from Single-Entry to Double-Entry Accounting
Summary
Convert LucaSchema from single-entry to double-entry accounting by introducing a Posting entity and restructuring the Transaction model to reference multiple postings where debits and credits balance according to double-entry principles.
Goals
Postinginterface that represents individual debit/credit entries with proper account referencesTransactioninterface to reference postings instead of directpayorId/payeeId/amountfieldsTechnical Considerations
accountIdreferences valid accounts from existing entity system whereentityType="ACCOUNT"Acceptance Criteria
New Schema Components
Postinginterface with fields:id: string (UUID) - optional if postings are embedded in transactionsaccountId: string (UUID reference to entities where entityType="ACCOUNT")amount: integer (signed, in minor units matching current schema)description: string (optional, posting-level description)order: number (for stable ordering within transaction)Transactioninterface to:payorId,payeeId,amountwithpostings: Posting[]id,categoryId,date,description,transactionState,createdAt,updatedAtsrc/schemas/for the newPostingentityRecurringTransactionto follow the same double-entry pattern with template supportValidation Rules
transaction.postings.length >= 2Σ(postings.amount) = 0accountId(must exist in entities where entityType="ACCOUNT")Code Updates
createTestTransactionin test utilities to generate balanced postingscreateTestRecurringTransactionto support posting templates with variablessrc/tests/for new double-entry modellucaValidatorto include posting validation schemasDocumentation & Examples
README.mdwith canonical examples for each transaction type:CHANGELOG.mdmarking as BREAKING change, list removed fieldsTest Coverage
Build & Export
src/index.tsto export newPostingtypesscripts/build.tsincludes new schema files in distributionBreaking Change Notice: This is a major breaking change requiring version 2.0.0. The
payorId,payeeId, andamountfields will be removed from Transaction interface.</issue_description>Comments on the Issue (you are @copilot in this section)
@jwaspin The purpose ...Fixes #47
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.