clearfelt-diagram · v0.2 · engine + Astro adapter
Mermaid that renders the same way twice.
A diagram that renders correctly once and wrong the next time isn't a diagram you can ship. This is the render pipeline, theming system and linter extracted from a production blog's diagram system after 95 real diagrams and several rounds of "looked fine in source, wrong once rendered."
Reproducible Mermaid: static SVG at build time, theme-aliased colors, 12 Cardinal Rules linted in CI.
npx clearfelt-diagram-init init my-docsNo pass reparses or reserializes the SVG. Every one is a scoped, targeted string replacement, so unrelated markup is never touched.
Why not just write raw Mermaid?
You still do, mostly. This is not a new diagramming language. What it adds:
12 Cardinal Rules
Color semantics, layout, typography hierarchy and decision-diamond sizing. Each rule was written after a real diagram shipped wrong.
Static SVG, zero client JS
Diagrams render once, at build time, through a real headless browser. No client-side Mermaid bundle shipped to every visitor.
Theme-reactive without a re-render
Colors are tokenized to your CSS variables, so a diagram baked once still follows your site's light and dark toggle through the ordinary cascade.
A linter that renders
One check actually renders the SVG and counts nodes per visual row, rather than pattern-matching the source text and hoping.
Baseline-diffed CI
Only new rule violations fail a check, so you can adopt it on an existing diagram corpus without a big-bang fix-everything pass.
Your palette, contrast-checked
The extract-palette skill reads your real CSS tokens, proposes a mapping onto the diagram color slots, validates contrast, and writes a theme for you to review before anything is saved.
Three packages
@clearfelt/diagram-engine
The payload, framework-agnostic: render, lint, theming, palette, a CSS token resolver, a WCAG contrast checker, the typed defineDiagram wrapper, and the CLI.
@clearfelt/diagram-astro
A thin Diagram component for Astro projects, depending only on the engine.
@clearfelt/cli
The scaffolder: init and upgrade with hash-gated skill files, all ten palettes selectable at scaffold time, and the full Claude Code skill set.
What you can ask it to do
create-diagramDescribe the diagram you want and it writes the source, then renders it.
diagram-reviewReads a finished diagram back and says where it is hard to follow.
cardinal-rules-lintChecks it against the 12 rules and reports only what is newly broken.
extract-paletteReads your site's real colours, maps them onto the diagram, checks contrast.
Quick start
pnpm install node packages/engine/dist/cli.js new architecture --pattern flowchart node packages/engine/dist/cli.js render architecture.mmd
render writes architecture.svg and, on the shipped default theme, a companion architecture.theme.css, so the diagram displays correctly with zero project styling. If your project already has real design tokens, run extract-palette instead of taking the default.