glossary.md 11 KB

Glossary

Do you come 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. One account owns it. It is the fundamental unit of value in the ledger. A posting is immutable after creation. A consumed posting leaves the live index, but the record keeps it forever.

  • Positive posting: value that the account controls.
  • Negative posting: an offset position. Any account that permits overdraft can hold one, which is an account without the DEBIT_MUST_NOT_EXCEED_CREDIT flag. It represents issuance, an external flow, a boundary or system balance, or an overdraft. An account that forbids overdraft must not hold one.

State: Live (unspent) → Spent (consumed by a committed transfer). The ledger derives the state from live-index membership and does not store it. Balance sums the live postings. There is no state between the two, so the set that an account holds and the set that it can spend are the same.

Account

A versioned entity that owns postings. The ledger never stores a balance. A balance is always the sum of the live postings for one (account, asset) pair.

An account has flags for the lifecycle, for the DEBIT_MUST_NOT_EXCEED_CREDIT balance constraint, and for user-defined bits. It also has a book assignment. An account carries no accounting class, so a class lives in metadata or in a user flag bit: see accounts carry no accounting class.

An AccountId { id: i64, sub: i64 } identifies an account. It is a base id plus a subaccount. sub = 0 is the main account. A non-zero sub is a subaccount of the same base id.

Each (id, sub) is a full account record with its own flags and lifecycle. The ledger reports balances per subaccount and never sums them across subaccounts. 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, and a caller can address, drain and close each one on its own.

An aggregate read takes a base id plus an optional subaccount filter. An exact entity operation takes the full AccountId. Subaccounts let one account hold many concurrent inflights, because a hold is a subaccount of its destination.

AccountId also has an IBAN-style string view through Display and FromStr. It is a fixed 20 characters: an 18-character base-36 body of the packed legs, then two mod-97 check digits. There is no country code.

For { id: 5, sub: 7 } the code is FK9RA6QALU15JZ7DZM81, grouped as FK9R A6QA LU15 JZ7D ZM81 in five groups of four. A parse validates the checksum and rejects a mistyped id. The code is for display and for routes, and the dashboard URLs use it. Storage keeps the two i64 legs. See ADR-0015.

Asset

A unit of value: a currency, a product, a token. Each asset is an independent conservation boundary. In every transfer, the sum of consumed postings must equal the sum of created postings per asset.

A caller names one by its code. ledger.asset("EUR", "\u{20ac}", 2) registers the asset on first sight and returns the handle. The ledger refuses a code that is already registered at another precision (ADR-0030).

AssetId(u32) identifies one asset, and the ledger mints it. An Asset or an Arc<Asset> converts into its id, so a function that takes an asset accepts either form.

Asset { id, code, symbol, decimals } is its registry row. The ledger writes that row once and never updates it. decimals gives the scale for a written amount of the asset. An unregistered asset has no amount. The ledger rejects a transfer in one, and a balance read of one fails, because nothing can say what the number means (ADR-0028).

Amount

A Cent and the asset that denominates it. The type exists so that a caller cannot add two balances in different assets. A Cent on its own compares and adds with any other Cent.

A caller builds an amount only by conversion, in whichever form the caller has. An integer is minor units. A string is the written form at the asset's own scale. So (500, usd) and ("5.00", usd) are the same amount of a two-decimal asset. The ledger refuses ("5.001", usd) and does not round it. The ledger pads a fraction shorter than the scale, so "100.0" of a two-decimal asset is ten thousand minor units.

The value comes first. A person speaks the money in that order. Three spellings reach the same conversion:

  • The handle, (500, usd).
  • A reference to the handle, (500, &usd), which is what a caller with one asset and several movements writes.
  • The asset's own side, usd.amount(500)?, through the Denominate trait. It works on an Asset or an Arc<Asset>, and it must be in scope.

An operation returns the amount itself. Display renders it at its asset's scale. checked_add and the other checked methods refuse two assets. minor_units() gives the plain integer to a caller that formats its own layout. The money type underneath is not public (ADR-0029).

Movement

The fundamental unit of the intent layer: an amount that moves from one account to another. A movement expresses what must happen. The ledger resolves movements into concrete postings.

A caller states one as (from, to, amount), and the stored Movement holds exactly that. A Posting holds the same pair. The asset and the value stay together everywhere above the database columns (ADR-0029).

Transfer

One or more movements to run atomically. TransferBuilder builds one. ledger.commit(transfer) commits it.

Envelope

The resolved, concrete form of a transfer: which postings to consume and which to create. The resolve step inside commit produces one. A caller can also build one directly and commit it with commit_envelope(envelope).

Atomic commit

The design where a whole transfer commits in one store transaction, through CommitStore::commit_envelope. The pure core validates first. The transaction then re-checks the stateful guards inside itself: double-spend, freeze and close, and the overdraft floor. It 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, which supersedes ADR-0003. The other posting and account write methods stay simple. Each one applies one update and returns the number of affected rows. No method interprets that number.

Double-spend guard

The concurrency-control mechanism for consumed postings. Inside the atomic commit, the deletion of a consumed live posting is one atomic conditional update. So two commits cannot both spend it. The second commit sees that the row is gone, and the ledger rejects it with DoubleSpend. This is what prevents a double-spend. A global validation snapshot does not.

Book

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

  • It is not the classical accounting journal, the chronological book of entries. The append-only transfer log has that role.
  • 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, a BookPolicy, holds:

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

An empty policy has no restrictions and 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. The type level enforces it. Nothing creates value and nothing destroys value. Value only moves.

AutoId

A 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). The range is about 34.8 years forward. Rust generates the identifier. The database never assigns an id.


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: a book documents the assets and the accounts that a flow expects. This holds even for one flow.
  • Multiple flows: use separate books for sales, payments, inventory and bank operations. A separate book stops one flow from a mix with another.
  • Multi-tenant: use one book per tenant. Name that tenant's accounts in allowed_accounts. The book records and gates which accounts can transact together. It does not isolate one tenant from another: see books are not a tenancy boundary.

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 live postings across ALL books. Alice can receive 100 USD through the deposits book and spend 50 USD through the trading book. Her balance is then 50 USD. It is not 100 in one book and -50 in another.

This is intentional: books scope access, not state.

Books are not a tenancy boundary

A book gates which accounts and assets can appear in one transfer. It is not an isolation boundary, and the result of that is not obvious from the name:

  • Balances are global, as above.
  • A book restricts no read. TransferQuery::book is a filter that a caller can pass. list_accounts, history and the posting reads take no book at all. So a query can return the rows of another tenant.
  • The gate is per transfer, and the caller picks it. A transfer can name the default book when the store holds no such book. That transfer commits with no policy at all. So a book cannot keep a caller inside a limit.

Isolation is a deployment choice instead. Give each tenant its own Store, which is its own database or its own schema. A ledger over that store needs no cross-tenant check, because the store holds no row of another tenant.