Philipp Hölke

Systems

Ledger

A small double-entry bookkeeping engine in TypeScript — append-only, deterministic, and designed so the balance is always a function of the history, never a stored number.

Most accounting bugs are the same bug: a balance was stored, then drifted from the transactions that were supposed to produce it. Ledger removes the opportunity. There is no balance column anywhere — a balance is computed by folding the immutable transaction log, every time.

The one rule

Every entry must net to zero across accounts. The type system enforces it before anything touches the database:

function post(tx: Transaction): Result {
  const sum = tx.legs.reduce((n, l) => n + l.amount, 0);
  if (sum !== 0) return err('unbalanced');   // refuse the write
  return append(tx);                          // append-only, never update
}

The whole library is built on the conviction that the safest state is the state you never let yourself corrupt.