Decisions
Architecture decision records (ADRs): one page per significant choice, with the context that forced it, the options that lost, and what it costs. Code shows what the system does; these pages explain why it does it that way and what would have to change to decide otherwise.
| # | Decision | In one line |
|---|---|---|
| 0001 | Double-entry ledger with a balance cache | Balances are derived from append-only entries that always sum to zero |
| 0002 | Money as integer cents | bigint in Postgres, safe integers in JS, and a parser that refuses to round |
| 0003 | Explicit SQL with pg, no ORM | Locks, on conflict and unnest are the core of the system; they stay visible |
| 0004 | One transaction per request | TransactionHost carries the client in AsyncLocalStorage; services never connect |
| 0005 | Idempotency inside the same transaction | Key, stored response and ledger entries commit together, or not at all |
| 0006 | Pessimistic row locks in a fixed order | FOR UPDATE sorted by account id: overdrafts fail cleanly, deadlocks can't happen |
| 0007 | Append-only ledger, fixes by reversal | Triggers reject UPDATE/DELETE; mistakes are corrected with new entries |
| 0008 | Serverless on Vercel + Neon | Migrations in the build, transaction-scoped locks, and no top-level await |
| 0009 | Tests against a real Postgres | The behaviour under test is the database's: locks, constraints, triggers |
| 0010 | Docs site with VitePress, served by the API | The markdown in the repo is the single source; one deployment, one origin |
Format
Each record has the same sections:
- Context: the problem and the forces at play.
- Decision: what was chosen, concretely, with pointers into the code.
- Alternatives considered: what was rejected, and why.
- Consequences: what gets easier, what gets harder, and what would make us revisit it.
A decision that changes gets a new record that supersedes the old one; old records are not rewritten.