Chapter 03: Chart of Accounts as Schema
This is an alternate Chapter 03 (for now).
LedgerLoom Chapter 03 — Posting to the Ledger shows how a journal becomes a ledger + trial balance.
This chapter treats the Chart of Accounts (COA) as a schema: metadata + constraints + join keys.
If you’ve ever wished your accounting exports were as well-defined as a database table or an API contract, this chapter is for you.
What you will build
1) A COA schema (metadata + constraints)
You’ll define a schema for account master records:
account type (asset/liability/equity/revenue/expense)
normal balance side (debit/credit)
statement mapping (BS vs IS)
rollups (hierarchical reporting)
segment flags (department/project tracking)
2) An “account master” table
You’ll generate an account master CSV that is designed for:
joins (ledger ↔ accounts ↔ statements)
validation (uniqueness, rollups, conventions)
contributor friendliness (clear columns, stable ordering)
determinism (golden-file tests)
Why this matters
In real life, the COA is often stored in a spreadsheet or a legacy ERP menu. But for modern analytics + automation, we want the COA to be:
Queryable (a table with stable keys)
Validated (constraints + invariants)
Composable (rollups + metadata)
Reproducible (deterministic outputs + hashes)
LedgerLoom treats the COA like a schema contract that future chapters will build on.
Run the chapter
From the repo root:
python -m ledgerloom.chapters.ch03_chart_of_accounts_schema --outdir outputs/ledgerloom --seed 123
Or via Makefile:
make ll-ch03-coa
# (alias)
make ll-ch03AccountsSchema
Artifacts are written under:
outputs/ledgerloom/ch03AccountsSchema/
Artifacts
Core schema + tables
coa_schema.jsonSchema definition (fields + constraints + segment metadata).account_master.csvThe account master table (the join backbone of the system).segment_dimensions.csv+segment_values.csvA minimal segment “dictionary” (Department + Project).
Worked example
income_statement_by_department.csvA tiny statement by segment example to show why segments matter.
WOW / developer artifacts
checks.mdInvariant checks: uniqueness, rollup validity, mapping conventions.tables.mdQuick Markdown tables so you can inspect the COA instantly.diagnostics.mdCanonical hashes and design notes (helps contributors trust the pipeline).lineage.mmdMermaid lineage diagram of artifact dependencies.manifest.jsonInventory of artifacts with byte counts and sha256 hashes.run_meta.jsonRun metadata (seed + module name).summary.mdOne-page “what you built” recap.
How to read the outputs
Start here:
tables.md— instant tour of the COA + segments + example statementaccount_master.csv— the join backbone (codes, types, rollups, segment flags)coa_schema.json— the contract / constraintschecks.md— the invariants you can trust
Exercises (good first contributions)
Add one new account (e.g.,
1350 Prepaid Expenses) and update rollups.Add one new department segment value (e.g.,
FIN Finance).Extend the schema with an
effective_datefield to demonstrate versioning.Add a new golden-file for a new output (determinism is a feature).
Notes for contributors
This chapter is intentionally “schema-first”. Later chapters can rely on the COA as:
a validated table for joins
a source of truth for statement mapping
metadata for segment reporting
Golden-file tests enforce determinism. If you change outputs on purpose,
update the corresponding golden files in tests/golden/ch03AccountsSchema/.