Skip to content

feat(docs): interactive DBML ER diagram for the database schema#545

Merged
aaronsb merged 2 commits into
mainfrom
feat/schema-erd-diagram
Jul 2, 2026
Merged

feat(docs): interactive DBML ER diagram for the database schema#545
aaronsb merged 2 commits into
mainfrom
feat/schema-erd-diagram

Conversation

@aaronsb

@aaronsb aaronsb commented Jul 2, 2026

Copy link
Copy Markdown
Owner

What

Adds a full, navigable ER diagram of all 60 control-plane tables to the Database Schema reference — generated from the same DDL parse the reference already uses. No database, no system Graphviz; runs in CI with Node + Python only.

How

  • generate-schema-docs.py also emits docs/reference/schema.dbml: schema-qualified tables tinted by schema via headercolor (color instead of clusters, so the renderer packs the mostly-disconnected tables into a compact block), types + PK/NOT NULL/UNIQUE flags, comments as notes, FK edges as Refs. Doubles as a portable artifact — paste into dbdiagram.io.
  • render-schema-diagram.mjs renders it to SVG via @softwaretechnik/dbml-renderer + @aduh95/viz.js (Graphviz-wasm), injecting Graphviz pack to tile ~square, then wraps it in a self-contained viewer: pan, zoom-to-cursor, table search, click-to-trace-relationships, light/dark toggle (recolors only the two theme-sensitive baked colors via CSS vars + attribute selectors).
  • schema.md embeds the viewer (iframe) + links the full-screen page and DBML source; per-schema Mermaid diagrams remain as the GitHub-native fallback.
  • Wired into make docs-schema and the docs deploy workflow.

Verification (local)

  • make docs-schema → 60 tables, 37 FK edges, all three artifacts
  • doclint --enforce-adrs ✓ · link_check --fail-on-broken
  • Full mkdocs build ✓ — standalone page + DBML publish as siblings; the ../schema-erd.html embed resolves under directory URLs (no warnings)
  • Layout + dark/light rendering eyeballed via rasterized previews

Follows the two CI hotfixes (#543, #544) that got main green first.

https://claude.ai/code/session_017Her5fGimBvtzYD4q9tNnf

aaronsb added 2 commits July 2, 2026 01:14
The schema reference had only per-schema Mermaid snippets. This adds a full,
navigable ER diagram of all 60 tables, generated from the same DDL parse — no
database, no system Graphviz, so it runs in CI with Node + Python only.

- generate-schema-docs.py also emits docs/reference/schema.dbml: schema-
  qualified tables tinted by schema via headercolor (not TableGroups, so the
  renderer packs the mostly-disconnected tables into a compact block), column
  types/PK/NOT NULL/UNIQUE flags, table/column comments as notes, and FK edges
  as Refs. Doubles as a portable artifact you can paste into dbdiagram.io.

- render-schema-diagram.mjs renders that DBML to SVG via
  @softwaretechnik/dbml-renderer + @aduh95/viz.js (Graphviz-wasm), injecting
  Graphviz `pack` to tile the layout ~square, then wraps it in a self-contained
  viewer: pan, zoom-to-cursor, table search, click-to-trace-relationships, and
  light/dark theming (recolors only the two theme-sensitive baked SVG colors
  via CSS variables + attribute selectors; schema header colors stay fixed).

- schema.md embeds the viewer (iframe) and links the full-screen page + the
  DBML source; the per-schema Mermaid diagrams stay as the GitHub-native
  fallback where iframes don't render.

- Wired into `make docs-schema` and the docs deploy workflow. Verified with a
  full mkdocs build: the standalone page and DBML publish as siblings and the
  relative embed path resolves under directory URLs.

Claude-Session: https://claude.ai/code/session_017Her5fGimBvtzYD4q9tNnf
Follow-up to the code review of the interactive ER diagram:

- Declare @aduh95/viz.js as a direct dependency — the renderer script requires
  it directly rather than relying on it being hoisted transitively.
- Guard the Graphviz `pack` injection: throw if the `rankdir=LR;` token isn't
  found, so a renderer format change fails loudly instead of silently emitting
  an un-packed vertical strip.
- Assert the two theme-sensitive baked colors exist in the rendered SVG before
  building the page, and drive both the assertion and the viewer's CSS from the
  same BAKED_CELL/BAKED_INK constants — a renderer palette change now fails the
  build instead of rendering unreadably in dark mode.
- Single-source the schema legend: read headercolor values back from the DBML
  instead of a second hardcoded map that could drift from the diagram.
- Use `npm ci` (Makefile + workflow) so a dependency bump can't be skipped by a
  stale node_modules guard and the lockfile stays authoritative.
- Fix stale output paths in the renderer's header docstring.

Regenerating produces byte-identical schema-erd.html (output preserved).

Claude-Session: https://claude.ai/code/session_017Her5fGimBvtzYD4q9tNnf
@aaronsb aaronsb merged commit 813fd55 into main Jul 2, 2026
6 checks passed
@aaronsb aaronsb deleted the feat/schema-erd-diagram branch July 2, 2026 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant