Backstage — How This Book Is Built#
Most technical tutorials rot within three months: an API gets renamed, a SQL output changes, or an example stops compiling, and nobody notices until a reader files an issue. The Elephant Dormitory is built so that drift is a build error.
36 runnable programs · 217 outputs verified on every test run · 3,700 SQL statements captured live from PostgreSQL
Single source of truth#
Every chapter in this book is assembled from four checked-in artifacts that stay locked together by CI:
- One chapter registry (
tools/docsgen/story.py) defines all 5 acts, 20 chapters, guides, and reference pages. It generates themkdocs.ymlnavigation, every page's Previous/Next links,examples/README.md, the Story Map tables, and the landing page cards. - Twenty runnable scripts (
examples/<NNN>_<slug>.py) share one schema (examples/schema.py). Each filename is prefixed with its exact zero-padded line count so the folder sorts naturally by complexity. - Live PostgreSQL verification (
tests/docs/test_examples.py) runs every example script against a real PostgreSQL container, compares stdout line-by-line against every# =>comment, and records every SQL flush that crossed the wire intoexamples/__wire__/<slug>.sql. - Invisible sync regions (
<!-- dorm:... -->) embed exact functions, schema classes, ERDs, reading-time badges, and live wire SQL directly into the Markdown files — so every page reads cleanly on GitLab, GitHub, in IDE previews, and on the MkDocs site!
How docsgen upgrades Markdown for the site#
When you read a chapter on GitLab, it's plain, clean Markdown (comics read as script blockquotes, callouts use native [!TIP] / [!WARNING] alerts, wire transcripts are <details> blocks). When MkDocs builds the site, tools/docsgen/mkdocs_hooks.py upgrades those exact same sources without duplicating a word:
<!-- dorm:comic scene=... -->+ blockquote → illustrated multi-panel comic strips with character avatars generated from code intools/docsgen/art.py(four expressions:neutral,happy,worried,smug) and scene backdrops.> [!WARNING]/> [!TIP]starting with a cast emoji (🐼,🦀,📝,💡,📋,🧪) → branded Material admonitions (with Ferris' basement collapsible by default).# =>output lines inside Python fences → highlighted green with a✓ outputs verified on PostgreSQLeditor badge.docs/assets/art/diagrams/*.svg→ inlined into HTML so dark mode ("the night shift") re-skins every diagram through CSS custom properties.
Voice & cast gradient#
To keep the book approachable for humans without costing tokens or clarity for coding agents and reference readers, the cast fades strictly by section:
- The Story (
docs/story/): Full cast, comics, and branded callouts. - Guides (
docs/guide/): Light tone — Maya tips only, no comic strips. - Benchmarks, Assimilation & Reference (
docs/benchmarks/,docs/assimilation/,schema_reference.md,glossary.md): Literal technical prose, with at most an optional topic-titled🦀 Ferris' basement: <topic>deep dive.
Common commands for contributors#
# 1. Re-run all 20 examples and update `# =>` outputs + `examples/__wire__/*.sql`
uv run --no-sync pytest tests/docs/test_examples.py --update-examples
# 2. Rename <NNN>_<slug>.py prefixes if line counts changed, and sync all Markdown regions + nav
uv run --no-sync python examples/_tools.py sync-names
# 3. Regenerate pure-Rust SVG ERDs from examples/schema.py
uv run --no-sync python examples/_tools.py gen-erds
# 4. Run all docs lints (registry, regions, links, comics, SVGs, freshness)
uv run --no-sync python tools/docsgen check
# 5. Preview the site live in your browser
uv run --no-sync --group docs mkdocs serve
Contributing a chapter or fix#
- Edit the runnable script in
examples/or prose indocs/. - Run
uv run --no-sync pytest tests/docs/test_examples.py --update-examplesif outputs or SQL changed. - Run
uv run --no-sync python examples/_tools.py sync-namesso line-count prefixes, embedded code blocks, wire transcripts, and reading times stay in sync. - Run
uv run --no-sync python tools/docsgen checkanduv run --no-sync --group docs mkdocs build --strictbefore committing.
← PreviousGlossaryDomain Terms & PostgreSQL Wire/ORM Vocabulary