Building the documentation
This file describes how the kit's documentation is produced, what to edit, and what is generated. For the product docs themselves, start at index.html (searchable landing page) or the engine / Blender indexes. Kit version in prose hubs: engine v0.31.1 · Blender add-on v0.32.0 (from packages/engine/package.json + blender_addon/blender_manifest.toml at build time).
Contributor quick start
Pick the row that matches what you want to change, edit the source file, then run the command. Never hand-edit generated HTML under docs/ (except meta .md files).
| I want to… | Edit this | Then run |
|---|---|---|
| Fix prose chapter text | scripts/docs/prose/content/engine/NN-….html | npm run docs:prose |
| Add a prose chapter | Copy _FRAGMENT-TEMPLATE.html · register in manifest.mjs · PAGE_TOPICS | npm run docs:build |
| Add an engine code trace | scripts/build-trace-docs.mjs → TRACES | npm run docs:trace |
| Add a Blender code trace | scripts/build-blender-docs.mjs → TRACES | npm run docs:blender |
| Edit a subsystem diagram | scripts/docs/engine-areas.mjs or build-blender-docs.mjs → AREA_PAGES | npm run docs:build |
| Change landing search / topics | scripts/docs/topics.mjs · scripts/build-landing.mjs | npm run docs:build |
| Change page layout / typography | docs/_template/prose-shell.html or diagram-shell.html | npm run docs:build |
| Check links + registry before a PR | — | npm run docs:validate · npm run docs:check-links |
Every built prose page footer shows the exact fragment path. Full build (docs:build) runs validate + link check at the end.
Three kinds of documentation
| Kind | Location | How it is maintained |
|---|---|---|
| Interactive HTML | docs/engine/*.html, docs/blender/*.html, docs/index.html | Generated — diagrams and traces from build scripts + data |
| Prose chapters | scripts/docs/prose/content/ → docs/engine/, docs/launcher/ | Hand-authored HTML fragments — assembled by build-prose-docs.mjs |
| Meta markdown | docs/*.md (style guide, test plan, LLM contracts, …) | Hand-authored — stays .md; not indexed on the landing page |
| This guide | scripts/docs/prose/content/meta/BUILDING-DOCS.html → docs/BUILDING-DOCS.html | HTML fragment — same prose build as chapters |
The interactive pages are clickable node graphs and step-by-step code traces that pull live source from packages/engine/ and blender_addon/. Prose chapters are longer-form narrative (architecture, workflow, feature traces in prose) as styled HTML — edit the fragment files directly, not markdown.
Meta markdown (STYLE_GUIDE.md, LLM_*.md, …) is for contributors and tooling; it is listed on the landing footer but not converted to prose HTML. This guide (BUILDING-DOCS.html) is indexed in search under the Contributors topic.
Source map — what to edit for everything
Rule of thumb: never hand-edit generated HTML under docs/ except the short blender/00-INDEX.md redirect stub and hand-edited meta .md files. Edit the source column, then npm run docs:build.
| What you see | Generated output | Edit this (source) | Built by |
|---|---|---|---|
| Landing page — search, topic hub, synonyms | docs/index.html |
scripts/build-landing.mjs (page UI + SYNONYMS) · scripts/docs/topics.mjs (topics, start-here, PAGE_TOPICS) |
build-landing.mjs |
| Engine subsystem diagrams — topic maps (physics, load, input, …) | docs/engine/index.html, load-pipeline.html, physics.html, … |
scripts/docs/engine-areas.mjs → ENGINE_AREA_PAGES |
build-trace-docs.mjs |
| Engine code traces — step walkthroughs + live TS | docs/engine/trace-*.html |
scripts/build-trace-docs.mjs → TRACES · symbols read from packages/engine/, apps/ |
build-trace-docs.mjs |
| Blender subsystem diagrams | docs/blender/index.html, data-model.html, export.html |
scripts/build-blender-docs.mjs → AREA_PAGES |
build-blender-docs.mjs |
| Blender code traces — step walkthroughs + live Python | docs/blender/trace-*.html |
scripts/build-blender-docs.mjs → TRACES · symbols read from blender_addon/ |
build-blender-docs.mjs |
| Prose chapters — architecture, physics, workflow, … | docs/engine/0*.html, docs/blender/00-INDEX.html, docs/launcher/*.html |
scripts/docs/prose/content/ (engine, blender, launcher, meta) · registry: scripts/docs/prose/manifest.mjs |
build-prose-docs.mjs |
| This guide | docs/BUILDING-DOCS.html |
scripts/docs/prose/content/meta/BUILDING-DOCS.html |
build-prose-docs.mjs |
| Diagram viewer — pan/zoom canvas, toolbar, trace code panel | injected into every docs/engine/*.html and docs/blender/*.html diagram/trace page |
docs/_template/diagram-shell.html · assembly: scripts/docs/shared.mjs (EmitDiagramPage, nav, ExtractSymbol / ExtractPySymbol) |
build-trace-docs.mjs · build-blender-docs.mjs |
| Prose page layout — typography, toolbar, mermaid | wrapped around every prose chapter + this guide | docs/_template/prose-shell.html |
build-prose-docs.mjs |
| Engine index hub (prose) | docs/engine/00-INDEX.html |
scripts/docs/prose/content/engine/00-INDEX.html |
build-prose-docs.mjs |
| Blender index hub (prose) | docs/blender/00-INDEX.html |
scripts/docs/prose/content/blender/00-INDEX.html |
build-prose-docs.mjs |
| Blender index redirect (stub) | docs/blender/00-INDEX.md |
same path — short redirect to 00-INDEX.html |
none |
| Kit version placeholder | prose hubs (engine v0.31.1 · Blender add-on v0.32.0) |
scripts/docs/kit-version.mjs · applied in build-prose-docs.mjs |
build-prose-docs.mjs |
| Contributor meta docs — style guide, LLM contracts | docs/*.md (e.g. STYLE_GUIDE.md, LLM_KERNEL.md) |
same paths — hand-edited · list: KEPT_META_MD in scripts/docs/prose-config.mjs |
none · bjs-mcp reads some via tools/bjs-mcp/src/paths.ts |
Orchestrator: scripts/build-docs.mjs runs trace → blender → prose → landing → validate → link check. package.json scripts: docs:build, docs:trace, docs:blender, docs:prose, docs:validate, docs:check-links.
Build commands
All commands run from the repository root.
| Command | What it rebuilds |
|---|---|
npm run docs:build | Everything — engine, Blender, prose, landing page, then validate + link check |
npm run docs:trace | docs/engine/ subsystem diagrams + traces only |
npm run docs:blender | docs/blender/ subsystem diagrams + traces only |
npm run docs:prose | Prose + BUILDING-DOCS.html only |
npm run docs:validate | Registry checks — fragments exist, prev/next chain, PAGE_TOPICS coverage (no HTML regen) |
npm run docs:check-links | Verify internal hrefs in prose fragments + contributor .md (no HTML regen) |
docs:build is the one to use after any doc change. It runs, in order:
scripts/build-trace-docs.mjs→ engine diagrams + tracesscripts/build-blender-docs.mjs→ Blender diagrams + tracesscripts/build-prose-docs.mjs→ prose chaptersscripts/build-landing.mjs→docs/index.html(includesBUILDING-DOCS.htmlin search)scripts/docs/validate-docs.mjs→ fragment registry + topic coveragescripts/check-doc-links.mjs→ internal link validation
The Babylon Launcher can also trigger a build via POST /api/docs/build (see launcher docs).
Architecture
flowchart LR
subgraph sources ["Edit these"]
direction TB
shell["diagram-shell.html"]
proseShell["prose-shell.html"]
shared["shared.mjs"]
engineAreas["engine-areas.mjs"]
engineTraces["engine TRACES"]
blenderAreas["blender AREA_PAGES"]
blenderTraces["blender TRACES"]
proseContent["prose/content/"]
proseManifest["prose/manifest.mjs"]
topics["topics.mjs"]
end
subgraph build ["Build scripts"]
direction TB
buildTrace["build-trace-docs"]
buildBlender["build-blender-docs"]
buildProse["build-prose-docs"]
buildLanding["build-landing"]
end
subgraph generated ["Generated — do not hand-edit"]
direction TB
engineHtml["docs/engine/*.html"]
blenderHtml["docs/blender/*.html"]
launcherHtml["docs/launcher/*.html"]
metaHtml["docs/BUILDING-DOCS.html"]
indexHtml["docs/index.html"]
end
subgraph code ["Read at build time"]
direction TB
engineSrc["packages/engine/"]
blenderSrc["blender_addon/"]
end
shell --> buildTrace
shared --> buildTrace
shared --> buildBlender
engineAreas --> buildTrace
engineTraces --> buildTrace
engineSrc --> buildTrace
blenderAreas --> buildBlender
blenderTraces --> buildBlender
blenderSrc --> buildBlender
proseShell --> buildProse
proseContent --> buildProse
proseManifest --> buildProse
buildTrace --> engineHtml
buildBlender --> blenderHtml
buildProse --> engineHtml
buildProse --> launcherHtml
buildProse --> metaHtml
engineAreas --> buildLanding
engineTraces --> buildLanding
blenderAreas --> buildLanding
blenderTraces --> buildLanding
topics --> buildLanding
buildTrace --> buildLanding
buildBlender --> buildLanding
buildProse --> buildLanding
buildLanding --> indexHtml
Prose chapters (HTML fragments)
Narrative docs (architecture, physics, workflow, launcher guide, …) are HTML body fragments edited directly:
scripts/docs/prose/content/engine/01-ARCHITECTURE.html (etc.)
scripts/build-prose-docs.mjs wraps each fragment in docs/_template/prose-shell.html (toolbar, prev/next nav, typography) and writes docs/engine/01-ARCHITECTURE.html (etc.). Register new chapters in scripts/docs/prose/manifest.mjs (PROSE_CHAPTERS) and scripts/docs/topics.mjs (PAGE_TOPICS).
Fragment files contain only the <article> inner HTML (<h1>, <p>, <table>, <pre>, …). Use <pre class="mermaid"> for diagrams (mermaid.js loads from CDN when present). Link to other chapters with .html paths; contributor meta docs stay .md (STYLE_GUIDE.md, LLM_KERNEL.md, …).
Starter template: copy scripts/docs/prose/content/_FRAGMENT-TEMPLATE.html when adding a chapter.
Prose CSS classes (defined in prose-shell.html)
| Class | Use for |
|---|---|
doc-links | “See also” line linking subsystem diagrams + traces + reference chapters |
trace-feature | Bordered card wrapping one feature in 10-FEATURE-TRACES.html |
trace-summary · trace-interactive | Plain-language intro + link to interactive trace inside a card |
trace-flow | Ordered step list inside a feature card |
step-stage · step-what · step-code | Phase label · plain explanation · code pointer per step |
trace-legend | Five-phase legend at the top of chapter 10 |
Reference chapters: 13 — Feature List (inventory) · 14 — API Guide (behavior author API).
Interactive HTML: the shared shell
Every diagram and trace page is assembled from one template:
docs/_template/diagram-shell.html
The shell contains the viewer UI (pan/zoom canvas, node panel, toolbar, import/export of diagram JSON). Build scripts inject:
DIAGRAM_DATA— JSON for nodes, edges, title<title>— page title- Bottom nav — links to sibling area/trace pages (engine = blue, Blender = amber)
- Body patches — resizable side panel; trace pages add a code block panel
To change viewer behaviour or styling for all diagram pages, edit the shell once and run npm run docs:build.
Assembly lives in scripts/docs/shared.mjs → EmitDiagramPage().
Subsystem diagrams vs code traces
User-facing name: subsystem diagram. Internally the data still lives in ENGINE_AREA_PAGES / AREA_PAGES (historical “area” jargon — not Blender AREA lights). The landing index tags them kind: "diagram" and displays the badge subsystem. On diagram and trace pages, the bottom nav shows breadcrumb links plus a full Traces row listing every code trace on that side (current page highlighted).
Subsystem diagrams
High-level subsystem maps: boxes and arrows, hand-authored content, no source extraction.
| Side | Data file | Output |
|---|---|---|
| Engine | scripts/docs/engine-areas.mjs → ENGINE_AREA_PAGES | docs/engine/index.html, load-pipeline.html, physics.html, … |
| Blender | scripts/build-blender-docs.mjs → AREA_PAGES | docs/blender/index.html, data-model.html, export.html |
Each page entry has:
navLabel(engine only) — short label in the bottom navdiagram/nodes+edges— graph data (id,x,y,w,h,label,sub,desc,metarows)
Blender area pages use helpers N() and E() from shared.mjs for nodes and edges. Engine area pages use plain JSON objects (same shape).
Code traces
Step-by-step walkthroughs along a feature path. Each step is either:
{ file, symbol, note }— build extracts the function/class from disk{ title, code, note }— inline snippet (e.g. manifest JSON); no extraction
| Side | Definition | Source roots |
|---|---|---|
| Engine | TRACES in scripts/build-trace-docs.mjs | packages/engine/, apps/ (for examples) |
| Blender | TRACES in scripts/build-blender-docs.mjs | blender_addon/ |
Output files are named trace-<id>.html (e.g. trace-physics.html).
Trace pages use a wider code panel (CODE_PANEL_PATCH_* in shared.mjs). Clicking a step shows the extracted source and file:line.
Automatic diagram ↔ trace linking
Subsystem diagrams and code traces stay paired at build time — no hand-maintained link lists in the bottom nav or on every node. The single source of truth is PAGE_TOPICS in scripts/docs/topics.mjs (the same map that powers the landing-page topic hub).
How topics choose related pages
Each subsystem diagram and trace page is tagged with one or more topic ids (physics, rendering, export, …). Meta topics start and contributor are ignored when pairing.
- Shared topic — a trace is related to a subsystem diagram when their topic sets overlap (e.g. both include
physics). - Overview fallback —
engine/index.html,engine/architecture.html, andblender/index.htmllist every trace on that side in the bottom nav when they have no content-topic overlap.
Helpers in topics.mjs: TracesForDiagram(href), DiagramsForTrace(href), FilterNavByHrefs().
Bottom nav (page-level)
| Page kind | Behaviour |
|---|---|
| Subsystem diagram | Breadcrumb trail (Docs → Engine/Blender guide → Diagrams → current page). Traces row lists all traces on that side. |
| Code trace | Same breadcrumb + full Traces row (current trace highlighted). |
| Prose chapter | Toolbar + prev/next in prose-shell.html; footer shows the source fragment path. |
Nav HTML is built in scripts/docs/shared.mjs (BuildDiagramBottomNav) and wired in build-trace-docs.mjs / build-blender-docs.mjs.
Node metadata (click a box)
When a subsystem diagram is emitted, scripts/docs/diagram-links.mjs adds Trace rows to each node's meta panel unless the node already has a Trace key (manual entries are preserved).
A trace is attached to a node when:
- It is topic-related to the parent diagram page, and
- Any of the following match a step in that trace:
- Symbol — step
symbolequals the nodelabel, or appears insub - File path — a step
filecontains a token from the node'sFile,Files, orModulemeta value (split on·, commas, spaces) traceIds— optional node field, e.g."traceIds": ["physics", "constraint"], forces those traces when heuristics are not enough
- Symbol — step
On overview diagrams, only symbol matches (and explicit traceIds) are used — file-path matching is disabled so the map does not link every box to every trace.
On code-trace pages, each step node gets Diagram meta rows for every topic-related subsystem diagram (same-side). Cross-side links (e.g. ../engine/input.html from a Blender node) remain manual in the source data. In the viewer, Trace and Diagram meta values render as clickable links (diagram-shell.html → renderMeta).
Adding a new trace or diagram
- Add the page to
PAGE_TOPICSwith the right topic id(s). - Give diagram nodes a
label/sub/Filemeta that overlaps the trace's step symbols or paths — or settraceIdson the node. - Run
npm run docs:build. Nav and node panels update automatically.
To opt a node out of auto traces, add any Trace meta row yourself (even a single manual target); auto-linking skips that node entirely.
Symbol extraction (anti-rot)
Before writing trace HTML, the build reads the real source and embeds it in each step:
- TypeScript —
ExtractSymbol()inshared.mjs(functions, classes,constexports; includes JSDoc above the symbol when present) - Python —
ExtractPySymbol()(function or class body by indentation)
If a symbol is missing or renamed, the build prints MISSING: …, sets exit code 1, and does not write trace pages for that packet. This keeps docs from silently showing stale code.
After changing a traced function's name or file, update the TRACES array and re-run the appropriate docs:* command.
Landing page, topic hub, and search
docs/index.html is fully generated by scripts/build-landing.mjs.
It indexes every subsystem diagram, code trace, prose chapter, and this guide, so search stays in sync with the graphs and narrative docs. Features:
- Topic hub — browse by intent (Physics, Export, Scripting, …) via
scripts/docs/topics.mjs; each topic has curated Start here links - Full-text ranking over titles, summaries, and node/step/chapter text
- Synonym map (
SYNONYMSinbuild-landing.mjs) — e.g. "collision" also matches collider/physics pages; "scale" matchesapplyObjectScale - Suggestion chips under the search box
?topic=and?q=URL parameters for deep links (e.g.?topic=physics&q=scale)
Adding a page to a topic
- Add or update the page's
hrefinPAGE_TOPICSinscripts/docs/topics.mjs(one or more topic ids). - If the page should appear in Start here, add its
hrefto that topic'sstartHerearray (order matters). - Run
npm run docs:build.
New prose chapters require an entry in PROSE_CHAPTERS (manifest.mjs) and topic assignment in PAGE_TOPICS. Contributor markdown under docs/ is listed in KEPT_META_MD (scripts/docs/prose-config.mjs) and linked from the landing footer — not prose HTML.
To improve search for a new concept, add synonyms in SYNONYMS or ensure the page's desc / note fields use words people will search for.
File reference
Quick index of build scripts and templates (see Source map above for edit-vs-output pairing).
| Path | Role |
|---|---|
scripts/docs/prose-config.mjs | KEPT_META_MD — contributor markdown not converted to HTML |
scripts/docs/validate-docs.mjs | Fragment registry, prev/next chain, PAGE_TOPICS coverage |
scripts/check-doc-links.mjs | Internal href validation in prose fragments + meta markdown |
scripts/docs/prose/content/_FRAGMENT-TEMPLATE.html | Copy-paste starter for new prose chapters (not in manifest) |
scripts/build-docs.mjs | Orchestrator — engine, Blender, prose, landing, validate, links |
scripts/build-prose-docs.mjs | Prose chapter assembly; exports BuildProseDocs |
scripts/build-trace-docs.mjs | Engine area + trace pages; exports TRACES, BuildEngineDocs |
scripts/build-blender-docs.mjs | Blender area + trace pages; exports AREA_PAGES, TRACES, BuildBlenderDocs |
scripts/build-landing.mjs | Searchable docs/index.html; exports BuildLandingPage |
scripts/docs/prose/manifest.mjs | Prose chapter registry (output paths, prev/next nav) |
scripts/docs/prose/content/ | Hand-edited HTML body fragments for prose chapters |
scripts/docs/topics.mjs | Topic hub categories, start-here links, page → topic map, diagram ↔ trace pairing |
scripts/docs/diagram-links.mjs | Auto Trace / Diagram meta rows on diagram nodes at build time |
scripts/docs/shared.mjs | Diagram shell read, page emit, nav HTML, symbol extraction |
scripts/docs/engine-areas.mjs | Engine area diagram data only |
docs/_template/diagram-shell.html | Shared interactive viewer (CSS + JS) |
docs/_template/prose-shell.html | Shared prose chapter layout (CSS + toolbar) |
Common tasks
Regenerate after a code change
If you only changed implementation and trace symbols are unchanged:
npm run docs:build
Add an engine code trace
- Append an object to
TRACESinscripts/build-trace-docs.mjs(id,title,intro,steps). - Use
{ file: "packages/engine/…", symbol: "FunctionName", note: "…" }for live extraction. - Run
npm run docs:trace(ordocs:build) and fix anyMISSINGerrors. - Optionally add a prose section in
scripts/docs/prose/content/engine/10-FEATURE-TRACES.html.
The new page appears in the bottom Traces row on every diagram/trace page on that side. The landing page indexes it automatically. Matching diagram nodes gain Trace meta rows when their label/file overlaps trace steps (see node metadata below).
Add a Blender code trace
Same as above, but edit TRACES in scripts/build-blender-docs.mjs and use blender_addon/… paths. Run npm run docs:blender.
Add or edit a subsystem diagram
- Engine: edit
scripts/docs/engine-areas.mjs(ENGINE_AREA_PAGES). - Blender: edit
AREA_PAGESinscripts/build-blender-docs.mjs.
Adjust x/y for layout. Re-run docs:build. Nav labels come from navLabel (engine) or page.title (Blender).
Add a prose chapter
- Copy
scripts/docs/prose/content/_FRAGMENT-TEMPLATE.htmltoengine/NN-MY-TOPIC.html. - Append an entry to
PROSE_CHAPTERSinscripts/docs/prose/manifest.mjs(wireprev/nextinto the chain). - Add
href→ topics inscripts/docs/topics.mjs; link from00-INDEX.html. - Run
npm run docs:validatethennpm run docs:build.
Change diagram viewer UI
Edit docs/_template/diagram-shell.html, then npm run docs:build.
New feature documentation checklist
When shipping a user-facing subsystem or major feature, work through this list (small PRs per bullet are fine):
- Subsystem diagram — add or extend nodes in
ENGINE_AREA_PAGESand/orAREA_PAGES(Blender side when authoring matters). - Code trace(s) — append to
TRACESinbuild-trace-docs.mjsand/orbuild-blender-docs.mjs; fix anyMISSING:symbols. - Prose — chapter section or new fragment under
scripts/docs/prose/content/; register inmanifest.mjs; add a row to10-FEATURE-TRACES.htmlwhen it is a Blender → runtime chain. - Cross-links — prose
doc-linksline pointing at the subsystem diagram + primary trace(s). - Topics —
PAGE_TOPICSand optionalstartHereintopics.mjs(also drives automatic diagram ↔ trace nav and node links). - Search — synonyms in
SYNONYMS(build-landing.mjs) and descriptivedesc/notetext on diagram nodes and trace steps. - Reference — add rows to
13-FEATURE-LIST.htmlwhen shipping user-facing capability; extend14-API-GUIDE.htmlwhen behavior authors get new APIs. - Validate —
npm run docs:validatethennpm run docs:build(runs link check too).
What not to edit
These files are overwritten on every build:
docs/index.htmldocs/engine/*.html(including numbered prose chapters)docs/blender/*.htmldocs/launcher/*.htmldocs/BUILDING-DOCS.html
Edit the sources instead: diagram/trace data in scripts/, prose fragments in scripts/docs/prose/content/. Generated HTML includes a footer pointing at the source fragment.
Viewing locally
Open docs/index.html in a browser (file:// or via a static server). The playground and launcher can serve /docs after a build. Diagram pages are self-contained single HTML files — no bundler required.
Related docs
- Engine index — runtime overview + prose chapter list
- Blender index — add-on overview (prose HTML)
- Feature traces (prose) — scannable Blender → runtime chains
- Feature list — full capability inventory
- API guide — behavior author runtime API
- Style guide — code conventions (separate from this build guide)