Complete specification for rewriting Swarmops v5 as using.cash v6: - Proposal: scope buckets (Working Rewrite / First Beyond Working / Maybe), non-goals (governance, geography, memberships permanently cut) - Design: 18 architectural decisions including preserved patterns (Basic/Logic, stored procs, credential split), new patterns (repository classes, chain abstraction, rate providers), and operational concerns (Galera awareness, continuation transactions, VAT booking, OOD denormalization) - Specs: 17 capability specifications with SHALL/MUST requirements and WHEN/THEN scenarios, covering accounting core, AP/AR, crypto treasury, exchange rates, organizations, users/auth, documents, comms, dashboard, end-of-month, backend worker, event bus, data migration, API layer, frontend app, and CI/packaging - Tasks: 145 implementation tasks grouped by subsystem, ordered by dependency (migration gates API/frontend work) Two rounds of adversarial review incorporated. Made-with: Cursor
13 KiB
ADDED Requirements
Requirement: Double-entry ledger engine
The system SHALL maintain a double-entry bookkeeping ledger where every financial transaction consists of two or more rows that sum to zero (debits equal credits). Transaction rows reference financial accounts. A transaction with rows that do not sum to zero SHALL be flagged as unbalanced.
Scenario: Balanced transaction
- WHEN a transaction is created with rows summing to zero across all referenced accounts
- THEN the transaction is stored and reflected in account balances
Scenario: Unbalanced transaction detection
- WHEN a transaction exists whose rows do not sum to zero
- THEN the system SHALL flag it as unbalanced and surface it in the end-of-month workflow
Requirement: Chart of accounts
The system SHALL maintain a chart of accounts per organization. Each account has a type (Asset, Debt, Income, Cost), a name, an optional parent account (for hierarchical display), and an open/closed status. Result accounts (Income, Cost) SHALL have their signs reversed for display (positive means credit).
Scenario: Create account
- WHEN an authorized user creates a new financial account with a name, type, and optional parent
- THEN the account appears in the chart of accounts for that organization
Scenario: Close account
- WHEN an authorized user closes a financial account
- THEN the account no longer accepts new transaction rows but remains visible in historical ledger views
Scenario: Rename account in open period
- WHEN an authorized user renames an account whose first activity year is in an open fiscal period
- THEN the account name is updated
Scenario: Reject rename in closed period
- WHEN an authorized user attempts to rename an account whose first activity year falls within a closed fiscal period
- THEN the system SHALL reject the rename
Requirement: Financial transaction tags
The system SHALL support multi-dimensional tagging of financial transactions. Tag sets define categories (e.g., project, department). Each transaction can have one tag per tag set. Tag types within a set have open/closed years controlling their availability.
Scenario: Tag a transaction
- WHEN a user assigns a tag from an active tag type to a transaction
- THEN the tag is stored and the transaction appears in filtered views for that tag
Scenario: Closed tag type
- WHEN a tag type's closed year has passed
- THEN it SHALL NOT be available for new tagging but remains visible on historical transactions
Requirement: Budget tracking
The system SHALL support annual and monthly budget amounts per financial account. Budget vs actual reporting compares budgeted amounts against actual transaction row totals for the same account and period.
Scenario: Set annual budget
- WHEN an authorized user sets a budget amount for an account for a given year
- THEN the budget appears in budget-vs-actual reports for that year
Scenario: Budget vs actual report
- WHEN a user views the budget-vs-actual report for a year
- THEN the system displays each budgeted account with its budget amount, actual total from transaction rows, and the variance
Requirement: Balance sheet reporting
The system SHALL generate a balance sheet showing all Asset and Debt accounts with their cumulative balances as of a specified date. The balance sheet MUST balance (total assets equals total debts plus equity).
Scenario: View balance sheet
- WHEN a user requests a balance sheet for a given date
- THEN the system displays Asset accounts, Debt accounts, and equity with their cumulative balances from the dawn of the organization through the specified date
Requirement: Profit and loss reporting
The system SHALL generate a profit and loss statement showing all Income and Cost accounts with their totals for a specified period (typically a fiscal year).
Scenario: View P&L for fiscal year
- WHEN a user requests a P&L report for a given year
- THEN the system displays all Income and Cost accounts with totals for transactions dated within that year
Requirement: Ledger inspection
The system SHALL allow users to view all transaction rows for a given account within a date range, with links to the parent transactions.
Scenario: Inspect account ledger
- WHEN a user selects an account and date range
- THEN the system displays all transaction rows for that account within the range, showing date, description, amount, running balance, and a link to the full transaction
Requirement: Period closing
The system SHALL support closing fiscal years per organization. Closing a year requires: (1) no unbalanced transactions in that year, (2) balance sheet identity holds (asset/debt deltas equal negative P&L totals), (3) a closing journal entry is created on Dec 31 transferring P&L results to equity. Once closed, the ClosedThroughYear for the organization advances.
Scenario: Close fiscal year
- WHEN an authorized user initiates year-end closing for a year where all preconditions are met
- THEN a closing journal is created, and the organization's closed-through-year advances
Scenario: Reject close with unbalanced transactions
- WHEN an authorized user attempts to close a year that contains unbalanced transactions
- THEN the system SHALL reject the close and list the unbalanced transactions
Scenario: Reject direct modification in closed period
- WHEN any operation attempts to directly insert, update, or delete a transaction row where the transaction date falls within a closed fiscal period without going through the continuation mechanism
- THEN the system SHALL reject the operation at both the application layer and the database layer (SQL trigger)
Requirement: Continuation transactions
When AddRow is called on a transaction whose date year falls within a closed fiscal period, the system SHALL NOT reject the operation. Instead, it SHALL create (or reuse) a continuation transaction dated at the current time in the open period, post the rows there, and link the continuation to the original via a dependency record of type FinancialTransaction. RecalculateTransaction SHALL aggregate balances across the entire continuation chain before computing deltas.
Scenario: AddRow on closed-period transaction
- WHEN a row is added to a transaction whose date is in a closed fiscal year
- THEN a continuation transaction is created (or reused) in the current open period, the row is posted there, and the continuation is linked to the original via a dependency
Scenario: Recursive continuation chain
- WHEN a continuation transaction itself falls in a newly closed period (due to books being closed since it was created)
- THEN the system recurses and creates another continuation in the current open period
Scenario: Recalculation across chain
- WHEN
RecalculateTransactionis called on a transaction that has continuations - THEN it aggregates balances from the root transaction and all continuations before computing adjustment deltas
Requirement: Sequential journal numbering
The system SHALL assign a per-organization sequential number (OrganizationSequenceId) to each financial transaction. These numbers MUST be gap-free within an organization for legal compliance. Migration MUST preserve existing sequence numbers.
Scenario: New transaction gets sequence number
- WHEN a financial transaction is created for an organization
- THEN it receives the next sequential OrganizationSequenceId for that organization
Scenario: Sequence preserved in migration
- WHEN v5 transactions are migrated to v6
- THEN their OrganizationSequenceId values are preserved exactly
Requirement: Foreign currency amounts on transaction rows
When a transaction row records an amount in a currency different from the organization's presentation currency, the system SHALL store both the presentation-currency amount (in the main row) and the foreign-currency amount and code. This preserves the audit trail for multi-currency operations.
Scenario: BCH deposit in SEK-denominated org
- WHEN a BCH deposit is recorded in an organization that books in SEK
- THEN the transaction row stores the SEK equivalent as the primary amount and the original BCH satoshi amount as the foreign currency amount
Scenario: Foreign amount preserved in migration
- WHEN v5 transaction rows with native currency data are migrated
- THEN the foreign currency code and amount are preserved exactly in v6
Requirement: VAT booking splits
When an expense claim, inbound invoice, or outbound invoice includes a VAT amount and the organization has VAT enabled, the system SHALL create separate transaction rows: the net amount on the budget/income account and the VAT amount on the appropriate VAT account (AssetsVatInboundUnreported for expenses/inbound invoices, DebtsVatOutboundUnreported for outbound invoices). VAT amounts always enter the ledger as absolute cents regardless of how they were determined at the UI layer.
Scenario: Expense claim with VAT
- WHEN a user submits an expense of €125 with €25 VAT in a VAT-enabled org
- THEN the ledger records: DebtsExpenseClaims −12500, Budget +10000, AssetsVatInboundUnreported +2500
Scenario: Outbound invoice with VAT
- WHEN a user creates an outbound invoice for €1200 with €200 VAT
- THEN the ledger records: AssetsOutboundInvoices +120000, Budget −100000, DebtsVatOutboundUnreported −20000
Scenario: VAT disabled org
- WHEN an expense is submitted in an org where VAT is not enabled
- THEN the full amount goes to the budget account with no VAT split
Requirement: VAT amount determination
For inbound documents (expense claims and supplier invoices), the VAT amount SHALL be entered manually in whole currency units (e.g., "25.00" for twenty-five euros) matching the receipt or invoice exactly — even if the counterparty calculated it incorrectly. The system SHALL NOT validate or recompute inbound VAT amounts. The UI-entered amount is converted to the smallest currency unit (cents) at the API boundary for internal storage. For outbound invoices, the system SHALL pre-fill the VAT amount computed from the organization's default VAT rate applied to the net amount, but this pre-filled amount SHALL be editable so the user can adjust it (for cross-border sales, exempt items, different rate classes, or reverse charge).
Scenario: Manual VAT on expense claim
- WHEN a user submits an expense claim and enters "25.00" as the VAT amount
- THEN the system converts this to 2500 cents internally and uses it for the VAT booking split, with no validation against any rate
Scenario: Manual VAT on inbound invoice
- WHEN a user registers a supplier invoice and enters the VAT amount from the invoice
- THEN the entered amount is converted to cents and used exactly, even if it does not match any standard VAT rate applied to the net amount
Scenario: Default VAT on outbound invoice
- WHEN a user creates an outbound invoice in a VAT-enabled org with a default rate of 25%
- THEN the VAT field is pre-filled with 25% of the net amount (displayed in whole units), and the user can accept or override it
Scenario: Override VAT on outbound invoice
- WHEN a user creates an outbound invoice and changes the pre-filled VAT amount (e.g., to 0.00 for a cross-border B2B reverse charge)
- THEN the overridden amount is converted to cents and used for the VAT booking split
Requirement: Organization default VAT rate
A VAT-enabled organization SHALL have a configurable default VAT rate (percentage) representing the standard rate of the organization's home country. This rate is used to pre-fill outbound invoice VAT amounts. It does not affect inbound document VAT entry (which is always manual).
Scenario: Set default VAT rate
- WHEN an administrator sets the organization's default VAT rate to 25%
- THEN new outbound invoices pre-fill VAT at 25% of the net amount
Requirement: Budget owner tracking
Each financial account SHALL have an optional owner (user) who serves as the budget owner for attestation purposes. The owner is stored as a first-class column on the account.
Scenario: Set budget owner
- WHEN an administrator assigns a user as the budget owner of a financial account
- THEN that user receives attestation tasks for expenses and invoices charged to that account
Requirement: Money representation
The system SHALL represent all monetary amounts as Int64 values in the smallest unit of the currency (cents for fiat, satoshis for BTC/BCH). Display formatting SHALL convert to the appropriate decimal representation based on the currency's unit scale (100 for most fiat, 1,000,000 for microbitcoin display).
Scenario: Fiat amount storage
- WHEN an amount of €42.50 is stored
- THEN the internal representation is 4250 (cents) with currency EUR
Scenario: Crypto amount storage
- WHEN an amount of 0.005 BCH is stored
- THEN the internal representation is 500000 (satoshis) with currency BCH
Scenario: Cross-currency display
- WHEN a report displays amounts in multiple currencies
- THEN each amount is formatted according to its currency's decimal convention