This is the tooling, not a wholesale migration. Existing Mermaid diagrams (like the Orchestrator state machines) are untouched; this page demonstrates the new pipeline on one diagram so it's ready for future diagrams to adopt it.
How OFFER-HUB generates offline, token-driven SVG diagrams for the docs site.
Every diagram in these docs has been a Mermaid chart rendered client-side. That is simple, but it means layout happens in the visitor's browser on every page load, and Mermaid's own render pass is the only thing standing between a diagram-heavy page and a flash of unstyled content. This guide covers the alternative: a small Python pipeline that generates polished, optimized SVGs offline, once, at commit time.
This is the tooling, not a wholesale migration. Existing Mermaid diagrams (like the Orchestrator state machines) are untouched; this page demonstrates the new pipeline on one diagram so it's ready for future diagrams to adopt it.
The tool choice is written up as an ADR: docs/adr/0001-python-diagram-pipeline.md. Short version: Graphviz's dot layout engine produces the same output for the same input every time, emits real SVG <g class="node"> / <g class="edge"> elements we can theme with ordinary CSS, and needs no browser or headless renderer in CI — just the dot binary and a thin Python wrapper.
This calls scripts/diagrams/generate_all.py, which runs every diagram module and writes its SVG into public/diagrams/. Nothing here is a build step you run once and forget: CI re-runs it on every pull request and fails if the committed SVGs don't match what the pipeline would produce right now (see CI enforcement below).
scripts/diagrams/your_diagram_name.py. Import the builders from theme.py — new_graph, state_node, terminal_node, transition_edge — rather than calling graphviz.Digraph directly, so your diagram automatically gets the shared layout defaults and theming.render_diagram(g, "your-diagram-name") at the end of a build() function.scripts/diagrams/generate_all.py's DIAGRAM_MODULES list.npm run diagrams and commit the new file under public/diagrams/.<StaticDiagram name="your-diagram-name" caption="..." />.Never hardcode a color in a diagram module. Every fill/stroke must come from a var(--token) reference already defined in src/app/globals.css (see the STYLE_BLOCK in scripts/diagrams/theme.py) so the diagram stays correct in both light and dark mode with zero extra wiring.
theme.py assigns semantic CSS classes (oh-node, oh-node--terminal, oh-edge) to every node and edge instead of literal colors, then injects a single <style> block — built entirely from var(--color-bg-elevated), var(--color-border), var(--shadow-dark), and the rest of the same tokens Mermaid diagrams already use (src/lib/diagram-theme.ts) — right after the opening <svg> tag. StaticDiagram.tsx inlines that SVG directly into the page (not via an <img> tag, which would isolate it from the page's CSS), so those var() references resolve against the real, live tokens: switching the site's theme switches the diagram, with no JavaScript and no second generated file per mode.
The diagram below is generated by scripts/diagrams/order_state_machine.py. Its states and transitions are not guessed: they're copied from ORDER_TRANSITIONS in packages/shared/src/enums/order-status.enum.ts in the orchestrator repository, the same table OrderStateMachine.assertTransition (in packages/shared/src/utils/state-machine.ts) enforces at runtime. Edge labels match the wording already used for this exact state machine in the Orchestrator guide.
CLOSED is the only terminal state; every other state has at least one outgoing transition in the table above.
The diagrams job in .github/workflows/ci.yml installs a pinned Graphviz version (2.42.2-9ubuntu0.1) and the pinned Python requirements, runs npm run diagrams, and then runs git diff --exit-code -- public/diagrams. If regenerating produces a different file than what's committed — a diagram module changed but npm run diagrams wasn't re-run, or the output drifted for any other reason — that diff is non-empty and the job fails. Commit whatever npm run diagrams produces locally; don't hand-edit anything under public/diagrams/.
Graphviz's layout is deterministic for a given version, but not stable across versions. If your local dot -V doesn't report 2.42.2, regenerate inside a container pinned to the same version CI uses rather than trusting a bare local run — see Regenerating against CI's exact environment in the ADR.