Skip to main content

Bank8:Accounting - README

The bank's book of account: a governed chart of accounts, declarative product→GL activity mapping, a replayable double-entry journal projected from committed ledger postings, trial balance and financial statements, period close with retained earnings, and a multi-currency rate catalogue with period-end revaluation - never moving money itself.

Summary​

Bank8:Accounting is a Rust service owning the accounting schema in the bank8 vertical database. It projects committed Bank8:Ledger postings into double-entry journal entries through a declared activity mapping, proves the book balances, serves trial balance, profit & loss, and balance sheet, and closes accounting periods. It is a derived service: the ledger remains the system of record for money movement and atomicity, and Accounting derives the financial interpretation from it.

Motivation​

A ledger records money positions; a bank also needs a book of account that says what those positions mean - assets, liabilities, equity, income, expense - and proves it balances. Finance cannot close a month out of per-account balances, and a controller cannot answer "what is the trial balance" by summing customers.

Accounting is deliberately not in the ledger's transaction. The ledger already guarantees atomicity (posting batch, balances, transactions, journal, audit, and outbox commit together or not at all). Adding accounting to that transaction would couple the money path to the book of account, grow the ledger's owned surface, and lose the property that matters most at audit: the book can be rebuilt from the journal at any time.

Architecture & High-Level Design​

Key Traits and Data Structures​

  • GlAccount - a chart-of-accounts node: code, name, type (asset, liability, equity, income, expense), normal balance, parent, active.
  • MappingRule - binds (product_type, instruction_type) to a debit GL account and a credit GL account, with a specificity priority.
  • JournalEntry / JournalLine - a projected double-entry posting; one entry per ledger posting, balanced per entry.
  • GlPeriod / CloseRun - an accounting period and its close execution; a closed period is immutable.
  • FxRate - an effective-dated, append-only quote for a currency pair.
  • RevaluationRun - a period-end unrealized revaluation, idempotent per (period, account, currency).

Rationale, Trade-offs, and Alternatives​

  • Projection over co-writing. Deriving the book from the ledger's committed, replayable journal keeps the money path free of accounting dependencies, makes the GL rebuildable from genesis, and turns a GL defect into a re-projection instead of a migration.
  • Mapping as data, not code. Which accounts a product books to is a rule row. Launching a product with a new accounting treatment is a configuration change validated at activation - not a service release.
  • Fail closed on a broken book. An unresolvable mapping parks the entry and emits gl:imbalance; the trial balance refuses to serve rather than presenting a plausible wrong number. A visible gap is cheaper than silent skew.
  • Append-only rates. Historical statements must reproduce exactly, so a rate is never rewritten - corrections are new effective-dated rows.

See DESIGN.md for the wire-level detail and BUSINESS.md for the business capabilities.


Architecture & Design: bank8:accounting and its underlying concepts were designed by Hamid Jahanzad.