glossary.md 7.2 KB

Glossary

Coming from classical accounting? See accounting-mapping.md for how journals, entries, and ledgers map onto Kuatia's transfers, postings, and books.

Terms

Posting

A signed amount of one asset owned by one account. The fundamental unit of value in the ledger. Postings are immutable once created. A consumed posting leaves the live index but is never deleted from the record.

  • Positive posting: value controlled by the account.
  • Negative posting: an offset position, allowed on any account that permits overdraft (the DEBIT_MUST_NOT_EXCEED_CREDIT flag is not set). It represents issuance, external flow, boundary/system balancing, or an overdraft. An account that forbids overdraft may not hold one.

State: Live (unspent) → Spent (consumed by a committed transfer), derived from live-index membership rather than stored. Balance sums the live postings; there is nothing between the two states, so what an account holds and what it can spend are the same set.

Account

A versioned entity that owns postings. Balance is never stored. It is always the sum of the live postings for a given (account, asset) pair.

Accounts have flags (lifecycle, the DEBIT_MUST_NOT_EXCEED_CREDIT balance constraint, and user-defined bits) and a book assignment.

An account is identified by AccountId { id: i64, sub: i64 }: a base id plus a subaccount. sub = 0 is the main account; a non-zero sub is a subaccount of the same base id, and each (id, sub) is a full account record with its own flags and lifecycle. Balances are reported per subaccount and never summed across them. See the Subaccount entry and adr/0012-subaccounts.md.

Subaccount

A partition of one owner's holdings under a shared base id. AccountId::with_sub(id, sub) names one; AccountId::base() returns the main account of an id. A base account does not roll up its subaccounts, so several independent balances live under one owner, each individually addressable, drained, and closed. Aggregate reads take a base id plus an optional subaccount filter; exact entity operations take the full AccountId. Subaccounts let one account hold many concurrent inflights (a hold is a subaccount of its destination).

AccountId also has an IBAN-style string view via Display / FromStr: a fixed 20 characters, an 18-char base-36 body of the packed legs then two mod-97 check digits (no country code), e.g. FK9RA6QALU15JZ7DZM81 for { id: 5, sub: 7 } (grouped: FK9R A6QA LU15 JZ7D ZM81, five groups of four). Parsing validates the checksum, rejecting mistyped ids. It is a presentation/routing form (the dashboard URLs); storage keeps the two i64 legs. See ADR-0015.

Asset

An identifier (AssetId(u32)) representing a unit of value: a currency, a product, a token. Each asset is an independent conservation boundary: the sum of consumed postings must equal the sum of created postings per asset in every transfer.

Movement

The intent layer's building block: { from, to, asset, amount }. Movements express what should happen. The ledger resolves them into concrete postings.

Transfer

One or more movements to execute atomically. Built via TransferBuilder, committed via ledger.commit(transfer).

Envelope

The resolved, concrete form of a transfer: which postings to consume and which to create. Produced by the resolve step (commit), or built directly and committed via commit_envelope(envelope).

Atomic commit

The design where a whole transfer commits in one store transaction (CommitStore::commit_envelope). The pure core validates first; the transaction re-checks the stateful guards inside it (double-spend, freeze/close, overdraft floor) and applies the effects all-or-nothing. A crash leaves no half-applied state, so there is no write-ahead log and no recovery. See ADR-0023 (superseding ADR-0003). The remaining posting/account write methods stay dumb: each applies one update and returns the number of affected rows, never interpreting it.

Double-spend guard

The concurrency-control mechanism for consumed postings: inside the atomic commit, deleting a consumed live posting is a single atomic conditional update, so two commits cannot both spend it. The loser sees the row gone and is rejected with DoubleSpend. This (not a global validation snapshot) is what prevents double-spend.

Book

A Book is a transfer policy scope: it gates which accounts and assets may participate in a transfer. Note what it is not:

  • It is not the classical accounting journal (the chronological book of entries). That role is played by the append-only transfer log itself.
  • It does not partition balances. Accounts and their balances are global; a Book only gates who can transact with whom in what context.

A book is { id, name, policy }, where the policy (BookPolicy) holds:

  • allowed_assets: if non-empty, only these assets may appear in movements.
  • allowed_flags: if non-empty, accounts with ANY of these flags may participate.
  • allowed_accounts: if non-empty, these specific accounts may participate (in addition to flag matches).

An empty policy (no restrictions) allows any account and any asset.

Conservation

For every transfer, for each asset: sum(consumed) == sum(created). This is the double-entry-style safety invariant (the UTXO-model equivalent of Σ debits = Σ credits), enforced at the type level. No value is created or destroyed. It only moves.

AutoId

Snowflake-inspired i64 identifier: [0 sign bit][40-bit ms timestamp][23-bit counter or CRC32]. The timestamp counts milliseconds since KUATIA_EPOCH_MS (2026-01-01T00:00:00Z), giving ~34.8 years of range going forward. Generated in Rust. The database never assigns IDs.


Usage examples

The worked examples moved to their own section: overdraft, currency exchange, retail point of sale, and the runnable programs.


Book Design

When to use books

  • Always: even if you only have one flow, defining a book documents what assets and accounts are expected.
  • Multiple flows: separate books for sales, payments, inventory, banking. Prevents cross-contamination.
  • Multi-tenant: one book per tenant with allowed_accounts restricting to that tenant's accounts.

Book scoping rules

Field Empty Non-empty
allowed_assets Any asset allowed Only listed assets
allowed_flags Flag check skipped Accounts with ANY matching flag pass
allowed_accounts Account check skipped Listed accounts always pass (even without matching flags)

An account passes the book check if:

  1. It matches allowed_flags (any flag in common), OR
  2. It is explicitly listed in allowed_accounts, OR
  3. Both lists are empty (unrestricted book).

Books do NOT partition balances

An account's balance is the sum of all its non-inactive postings across ALL books. If Alice receives 100 USD via the deposits book and spends 50 USD via the trading book, her balance is 50 USD, not 100 in one book and -50 in another.

This is intentional: books scope access, not state.