Skip to content

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:

  1. One chapter registry (tools/docsgen/story.py) defines all 5 acts, 20 chapters, guides, and reference pages. It generates the mkdocs.yml navigation, every page's Previous/Next links, examples/README.md, the Story Map tables, and the landing page cards.
  2. 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.
  3. 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 into examples/__wire__/<slug>.sql.
  4. 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 in tools/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 PostgreSQL editor 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#

  1. Edit the runnable script in examples/ or prose in docs/.
  2. Run uv run --no-sync pytest tests/docs/test_examples.py --update-examples if outputs or SQL changed.
  3. Run uv run --no-sync python examples/_tools.py sync-names so line-count prefixes, embedded code blocks, wire transcripts, and reading times stay in sync.
  4. Run uv run --no-sync python tools/docsgen check and uv run --no-sync --group docs mkdocs build --strict before committing.