cd /news/developer-tools/literate-programming-double-entry-le… · home › topics › developer-tools › article
[ARTICLE · art-158188] src=leanpub.com ↗ pub= topic=developer-tools verified=true sentiment=↑ positive

Literate Programming Double-Entry Ledger in C and SQLite (With AI Bookkeeper)

A new book presents a literate-programming implementation of double-entry bookkeeping in C, building libledger, a library that stores books in a single SQLite file, alongside a ledger command-line tool and an MCP (Model Context Protocol) server that lets an AI assistant keep the books with user approval. The roughly 3,000-line C codebase, which depends only on SQLite and cJSON, uses an 8-table SQLite schema and a 49-account US-style chart of accounts, stores money as 64-bit integers in the smallest currency unit with overflow checks, and validates every entry inside one BEGIN IMMEDIATE transaction. The book's executable chapters are extracted with noweb and their shell sessions run automatically, with output compared character by character against the printed text; the code is on GitHub at github.com/libledger/libledger.

by read3 min views1 publishedOct 26, 2026
Literate Programming Double-Entry Ledger in C and SQLite (With AI Bookkeeper)
Image: Leanpub (auto-discovered)

Double-entry bookkeeping has kept the world's books for more than five centuries. This book explains it from first principles, and builds it in C as you read.

The book is a literate program: the code you read on the page is the code that gets compiled. Chapter by chapter it builds libledger, a small C library that keeps double-entry books in a single SQLite file. On top of the library it builds the ledger command and an MCP server through which an AI assistant can keep the books, but only with your approval.

You need to know some C. You don't need to know any accounting.

You will follow Alex, a freelance graphic designer, through her first week of books: invoicing a client, paying rent, fixing a mistake, getting paid, closing the period. Later you will live one of her days twice, once by hand and once by talking to an assistant, and see the balances come out the same.

Along the way you will learn:

  • Accounting: debits and credits, the accounting equation, a US-style chart of accounts (49 accounts), accrual vs. cash, the trial balance and closing entries.

  • Data modeling: an 8-table SQLite schema, an account tree derived from dotted codes, and cached balances that always agree with their history.

  • Money done right: amounts are 64-bit integers in the smallest unit, with overflow checks. Floating point is never used for money. Every currency balances on its own, and values are converted to USD (mark to market) only when the books are read.

  • Correctness: every entry is validated and written inside one BEGIN IMMEDIATE transaction. Negative balances are rejected, and four consistency checks catch books damaged by hand.

  • Tooling: a single-binary CLI, JSON input and output, and an MCP (Model Context Protocol) server with a ready-to-install skill for the assistant.

The stories in the book are executable chapters. The build extracts their shell sessions, runs them, and compares the output character by character with what the book prints, so the text cannot drift away from the program.

About 3,000 lines of C, with no dependencies beyond SQLite and cJSON. Each technical term, accounting or programming, is defined in a glossary at the end of the book.

A book that tests itself

One distinctive feature of this project is that the book and the software share the same source.

Using noweb, the implementation is extracted from the manuscript and compiled into working programs. Selected chapters go further: their command-line sessions are executed automatically, and their output is compared against the results printed in the book. When the implementation changes, the documentation can be verified against it.

Who is this book for?

This book is intended for programmers who want to understand how financial software works, developers interested in literate programming, and engineers who appreciate small, understandable systems built from first principles.

Readers should have some familiarity with C. No previous accounting knowledge is required.

The result is both an introduction to double-entry bookkeeping and a detailed exploration of how to turn accounting principles into executable, verifiable software.

All the code is on GitHub: https://github.com/libledger/libledger

── more in #developer-tools 4 stories · sorted by recency
── more on @libledger 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/literate-programming…] indexed:0 read:3min 2026-10-26 · —