{"slug": "literate-programming-double-entry-ledger-in-c-and-sqlite-with-ai-bookkeeper", "title": "Literate Programming Double-Entry Ledger in C and SQLite (With AI Bookkeeper)", "summary": "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.", "body_md": "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.\n\n \n\nThe 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.\n\n \n\n**You need to know some C. You don't need to know any accounting.**\n\n \n\nYou 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.\n\n \n\nAlong the way you will learn:\n\n \n\n- **Accounting**: debits and credits, the accounting equation, a US-style chart of accounts (49 accounts), accrual vs. cash, the trial balance and closing entries.\n\n- **Data modeling**: an 8-table SQLite schema, an account tree derived from dotted codes, and cached balances that always agree with their history.\n\n- **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.\n\n- **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.\n\n- **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.\n\n \n\nThe 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.\n\n \n\nAbout 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.\n\n \n\n**A book that tests itself**\n\nOne distinctive feature of this project is that the book and the software share the same source.\n\nUsing `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.\n\nWhen the implementation changes, the documentation can be verified against it.\n\n \n\n**Who is this book for?**\n\nThis 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.\n\nReaders should have some familiarity with C. No previous accounting knowledge is required.\n\nThe result is both an introduction to double-entry bookkeeping and a detailed exploration of how to turn accounting principles into executable, verifiable software.\n\n \n\nAll the code is on GitHub: https://github.com/libledger/libledger", "url": "https://wpnews.pro/news/literate-programming-double-entry-ledger-in-c-and-sqlite-with-ai-bookkeeper", "canonical_source": "https://leanpub.com/literateledger", "published_at": "2026-10-26 19:23:22+00:00", "updated_at": "2026-10-26 19:41:16.724585+00:00", "lang": "en", "topics": ["developer-tools", "agent-protocols", "ai-agents", "artificial-intelligence"], "entities": ["libledger", "SQLite", "cJSON", "noweb", "Model Context Protocol", "GitHub"], "also_reported_by": [], "alternates": {"html": "https://wpnews.pro/news/literate-programming-double-entry-ledger-in-c-and-sqlite-with-ai-bookkeeper", "markdown": "https://wpnews.pro/news/literate-programming-double-entry-ledger-in-c-and-sqlite-with-ai-bookkeeper.md", "text": "https://wpnews.pro/news/literate-programming-double-entry-ledger-in-c-and-sqlite-with-ai-bookkeeper.txt", "jsonld": "https://wpnews.pro/news/literate-programming-double-entry-ledger-in-c-and-sqlite-with-ai-bookkeeper.jsonld"}}