0035: Diagrams as D2 sources, rendered to committed SVGs¶
Status: accepted
Date: 2026-10-27T16:24:28-03:00
Context¶
The documentation had four inline Mermaid charts: the pipeline in README.md and in
docs/index.md, and the components and the micro-batch sequence in docs/ARCHITECTURE.md.
GitHub and the site render Mermaid in the browser; PyPI does not, so the package page showed
the README's chart as code (the README is the package's long description). The charts shared
no style, gave no control over their layout, and nothing rendered them in CI; as the library
grew they got hard to read and to debug.
The owner's repositories move to one standard: diagrams as code in D2, rendered to SVG in CI,
the same version and style everywhere, with de-lakehouse-pipeline as the pilot.
Decision¶
- Sources in
docs/diagrams/<name>.d2, each starting with...@_styleand a comment naming the files it is grounded in; the rendereddocs/diagrams/<name>.svgcommitted next to it.docs/diagrams/_style.d2(not rendered) holds thed2-config: the ELK layout engine, theme 0 with dark theme 200, padding, and color overrides, and one class per kind of element (process, source, store, actor, external, check;metafor dashed edges). No class sets a fill: the SVG carries both themes and follows the page's color scheme. - D2 v0.9.0, pinned in the
Makefileby version and by the sha256 of its Linux release archive (from the release'sSHA256SUMS).make d2-installinstalls it checksum-checked;make diagramsrenders every diagram withenv -i(noD2_*variable overrides the config) and--scale 1(natural size);make diagrams-checkrenders, then fails on an SVG that is stale, missing or has no source;make diagrams-watch NAME=<name>previews one live. - CI's
diagrams (D2 render check)job runsmake d2-installandmake diagrams-checkand uploads the SVGs as an artifact, even when the check fails.main's branch protection requires it next to the other checks, from the pull request that adds it: the context is added once the job has reported there, before that pull request merges. .gitattributes:*.svg -text(CI compares the bytes D2 writes) anddocs/diagrams/*.svg linguist-generated=true(collapsed in pull request diffs).- The set, each next to the text it explains:
| Diagram | Shows | Where |
|---|---|---|
architecture |
SQL Server CDC, the stream and snapshot readers, the sink, the tables, the consumers | README, home page |
components |
the modules and how they call each other | Architecture |
data-flow |
one micro-batch from an LSN range to rows, with its checks and run metadata | Architecture |
micro-batch |
the same batch call by call, with the T-SQL | Architecture |
data-model |
the CDC tables the source reads and the state it keeps | Architecture |
data-model-tables |
the Delta tables the library writes, keys only | Architecture, Tables |
user-flows-query-lifecycle |
a first run with a bootstrap, then a restart that replays a batch | Streaming into Delta |
user-flows-finalization |
advance, track, silver's verdict and is_final |
Finalization |
- No Mermaid is left: the two pipeline charts are replaced by
architecture, the components chart bycomponentsand the micro-batch sequence bymicro-batch;mkdocs.ymldrops itsmermaidfence.
Where this repository departs from the pilot's setup:
- Paths. The docs pages use relative paths (
diagrams/<name>.svg,../diagrams/...from guides and the reference).docs/diagrams/is insidedocs_dir, so Zensical copies the SVGs and sources into the site and rewrites the paths for directory URLs, and the same paths work on GitHub; the strict build checks them. Each image on a docs page links to its SVG: the site's content column is narrower than most diagrams and has no zoom. The README uses absolute URLs onmaininstead, raw.githubusercontent.com for the image and the GitHub page for the source, as its other links already are: a relative path does not resolve on PyPI. - dagre for one diagram.
data-model-tablessetslayout-engine: dagrein its ownd2-config. In that graph ELK lays thesql_tableshapes out as a staircase over 2,600 px wide (their edges leave from column ports); dagre keeps it at about 1,270 px. dagre draws edges from table to table, so each key column names the column it points at. .gitattributesholds the SVG lines only. The repository has no* text=auto eol=lfrule, and adding one would renormalize files this change does not touch (docs/guides/finalization.mdis stored with CRLF).- No
docs/DECISIONS.md. This repository records decisions as ADRs; the D2 version and the setup are recorded here.
Consequences¶
- Changing a diagram means editing its
.d2, runningmake diagramsand committing both files; CI fails otherwise.make d2-installcovers Linux x86_64 (WSL on Windows); elsewhere, install D2 v0.9.0 and passD2=/path/to/d2. The SVG recordsdata-d2-version, so a D2 upgrade re-renders every diagram, in one change with the new pin. - Tests do not check the diagrams against the code: review does, and each
.d2names the files it is drawn from. A change to what a diagram shows updates it in the same change. - The README's image is
main's: on a branch, and on a release's PyPI page, it shows the diagram asmainhas it, like the README's other links. - In Edge (Chromium), an SVG inside a page follows the page's color scheme, the site's palette toggle included; opened alone, it follows the browser's. raw.githubusercontent.com serves an SVG under a sandboxing Content-Security-Policy: inside the README its fonts and dark theme work, opened alone its text falls back to a serif font.
- Rendered widths stay under about 1,300 px and each diagram under about 25 nodes; the tall ones (the micro-batch sequence, the data flow) are read by scrolling, not by shrinking text.