1---2name: financial-invariants3description: Audits, designs, and tests financial invariants — monetary precision, ledger balance, account state, reconciliation, regulatory correctness. Use for payments, ledgers, billing, trading, settlement, or any money-exact code.4---56# Financial Invariants78## Workflow9101. **Map the domain**: list financial objects in scope, trace where data enters, and document balance source of truth, lifecycle states, identifiers, rounding rules, and audit records.112. **State the invariants** before editing (e.g. "posted ledger entries are immutable"). Inspect current behavior first; ask the user only when code/tests don't reveal the rule.123. **Test the invariants** through public services/APIs/commands/jobs: normal posting, boundary amounts, currency mismatch, invalid state transitions, reversal/correction, retried operations.134. **Implement defensively**: typed value objects/schemas/DB constraints, checks near the write boundary, DB transactions for multi-record writes, domain errors naming the invariant.1415## Core Invariants1617- Money uses integer minor units, fixed-precision decimal, or an existing money type — never floats.18- Currency is explicit at every boundary and in storage.19- Rounding rules are named and centralized: mode, precision, timing, jurisdiction.20- Ledger records are append-only unless corrections are explicitly allowed.21- Debits and credits balance for every posted journal, transfer, or settlement batch.22- Account/transaction states form an explicit state machine with valid transitions only.23- Reversals, refunds, chargebacks, cancellations, and corrections leave an audit trail.24- External identifiers are preserved for reconciliation and dispute investigation.25- Time-sensitive rules use controlled clocks and explicit effective dates.2627## Guardrails2829- Do not silently change rounding, precision, account state, or balance semantics.30- Do not add derived balance fields without a rebuild/reconcile plan.31- Do not fix historical data in code unless the user asks for a migration/repair script.32- Financial correctness outranks a small reduction in code complexity.