Skip to content

Architecture Decision Records

Documentation · Source: architecture · Step: 1.02

An Architecture Decision Record (ADR) is a short document that records one decision about how Mezgeb is built: the problem, the options that were considered, the choice and what it costs. Decisions are recorded so they are not re-argued every month, and so that any table, crate or rule can be traced back to the reason it exists.

ADR Decision Answers Status
0001 The ledger is a separate service with its own database §5.1 Accepted
0002 Three layers: engine, posting templates, client application §5.2, §5.9 Accepted
0003 Multi-line journal entries that must balance §5.3 Accepted
0004 Holds are real postings to held sub-accounts §4 Accepted
0005 Money is an i64 count of minor units §4 Accepted
0006 Ledger IDs are UUIDv7, generated by the ledger §4 Accepted
0007 READ COMMITTED with row locks taken in account-id order §5.4 Accepted
0008 Idempotency is recorded in the posting transaction §5.5, §5.10 Accepted
0009 The API is REST over HTTP, built with Axum §2 Accepted
0010 Offline payments settle from escrow by signed receipts §5.8 Accepted
0011 History is append-only; corrections are new entries §5.6 Accepted
0012 Balances are stored running totals, proven against the lines §5.7 Accepted
0013 A reversal that would overdraw is refused; the mistake is corrected with an adjustment E13 open question Accepted
0014 Payment channels are metadata; fees are lines in the payment’s own entry E07, E08 open questions Accepted
0015 Refunds name the entry they refund and are capped by it; disputes hold merchant funds in their own sub-account E11, E12 open questions; refund vs reversal Accepted
0016 Accounting periods follow posting order; a close switches periods under a lock Spec §6; INV-10 Accepted
0017 OAuth 2.0 client credentials for opaque tokens; roles grant scopes from a permission matrix; a client touches only its own accounts Spec §13; TM-01, TM-05, TM-07, TM-12, TM-13 Accepted
0018 Entries are hash-chained and signed in the posting transaction; signed checkpoints are published to clients and to a file Spec §7; INV-11, INV-26; TM-11 Accepted
0019 Offline protocol v1: P-256 device signatures, one voucher per device, ordered settlement with a gap timeout, late receipts paid by the payer first Spec §5; TM-17 to TM-21, TM-23 Accepted
0020 Reconciliation matches without guessing, the ledger wins, and money breaks are resolved through suspense entries Architecture §5.9; ADR-0002 Accepted
0021 Callers who have not authenticated are limited globally, optionally by address, and their refusals are audited in summary ADR-0017, ADR-0018; TM-01, TM-03 Accepted

Every question in architecture §5 maps to at least one ADR.

Where each decision implemented in Phase 1 was tested (step 1.16). ADRs 0009 (the REST API) and 0010 (offline escrow) are implemented in Phase 2.

ADR Evidence
0001 1.08: the ledger’s own database and roles; the service role cannot change history
0002 1.02: the crates core, engine, ops and api, each depending only on the layers below
0003 1.06: only a validator builds a BalancedEntry; 1.08: the deferred balance trigger; 1.13: verification
0004 1.14: held sub-accounts, INV-18 under concurrency, the capture and expiry race
0005 1.04: checked i64 arithmetic and parsing, property-tested
0006 1.04: only UUIDv7 accepted
0007 1.10: the schemes compared; 1.16: the lock timeout and serialization retries tested, and the baseline
0008 1.11: one entry per key; 1.15: every fault point, 20 database kills, 1M simulated operations
0011 1.08: triggers and privileges; 1.12: reversals and adjustments
0012 1.09: running totals; 1.13: verification finds every planted corruption
0013 1.12: a reversal that would overdraw is refused
Status Meaning
Proposed Written and under discussion. Not yet binding.
Accepted Binding. Code and docs must follow it.
Superseded by NNNN Replaced by a later ADR. Kept for history, never deleted.

An accepted ADR is not edited to change its decision. To change a decision, write a new ADR that supersedes it, and set the old one’s status to Superseded by NNNN. Typos, links and an Evidence section added later (for example, measurements in step 1.10) are fine to edit in place.

Every ADR must pass this before it is accepted:

  • The context states the problem without assuming the answer.
  • The decision is one clear, testable statement.
  • At least two alternatives are listed, each with reasons for and against.
  • Consequences include the costs, not only the benefits.
  • It names the roadmap steps that implement or test it.
  • It names any part of the spec or code it makes out of date.

Files are named NNNN-short-kebab-title.md. Numbers are never reused.

# NNNN. <Decision as a short statement>
| | |
|---|---|
| Status | Proposed |
| Date | YYYY-MM-DD |
| Answers | <architecture section> |
| Implemented in | <roadmap steps> |
## Context
<The problem and the forces at play. Why a decision is needed now.>
## Decision
<What we will do, in one or two short paragraphs.>
## Alternatives considered
| Option | For | Against |
|---|---|---|
| **<Chosen option>** | | |
| <Alternative> | | |
## Consequences
**Positive:** <what gets easier or safer>
**Negative:** <what it costs, and how that cost is contained>
**Makes out of date:** <spec sections or code that must change>