ai newsDi., 1. Dez.
EilmeldungThe Model Proposes, Your Code Disposes: A Tool-Calling Agent Loop for Android with Gemini Nano

Stop Shipping Mermaid Slop: Building a Zero-LLM Editorial SVG Compiler & Architecture Drift Gate in TypeScript

Every developer has seen the same lifecycle play out in a growing repository: Someone writes a clean Mermaid diagram in README.md on day one. Three months later, half the files have been renamed, two modules silently formed a circular dependency, and a parser started importing directly from the CLI

dev.toDienstag 07:47 · 01.12.4 Min. Lesezeit
Bild: dev.to

Every developer has seen the same lifecycle play out in a growing repository:

I wanted something fundamentally different: a deterministic, zero-LLM compiler and CI gate that treats architecture diagrams as verifiable build artifacts instead of disposable drawings.

That is why I built archink — an open-source TypeScript CLI and library that:

When diagrams are written by hand or generated by an LLM prompt without grounding, three failure modes show up immediately:

Everything in archink runs 100% locally with zero paid APIs, zero headless browsers, and zero network calls.

Under the hood, archink is split into nine single-responsibility TypeScript modules under src/:

Let's walk through how each stage works in detail.

Two details trip up naive TypeScript dependency scanners:

For polyglot codebases, scanner.ts also parses:

Once the directed adjacency list is built, findCycles() runs Tarjan's Strongly Connected Components algorithm. Any SCC with size > 1 (or a self-loop) is flagged as an architectural cycle, and every edge inside that SCC is tagged with style: 'cycle' so it renders in crimson dashed linework and fails CI when --fail-on-cycles is enabled.

Running archink scan. on archink itself outputs:

archink scan:: archink Architecture Files: 9 | Edges: 22 | Cycles: 0 | Orphans: 0 Languages: typescript=9 Top hubs: src/types.ts(in:8,out:0), src/scanner.ts(in:3,out:1), src/themes.ts(in:3,out:1), src/layout.ts(in:2,out:1), src/parsers.ts(in:2,out:1) Enter fullscreen mode Exit fullscreen mode Stage 2: Deterministic Sugiyama Layered Layout ( src/layout.ts ) Most messy auto-diagrams fail because they place nodes on naive grids and draw straight lines between centers. archink implements a full Sugiyama layered graph pipeline:

Here is the actual SVG archink generated for its own src/ directory in swiss-paper (TB) and obsidian-ink (LR):

Instead of generic gradients or blurry drop shadows, archink ships four crisp 1px-hairline palettes:

Already have Mermaid.mmd files? You can compile flowchart / graph (with subgraph, shapes like [(db)], ([pill]), {diamond}, {{hexagon}}, chains A --> B --> C, and A & B --> C ) or sequenceDiagram directly into editorial SVGs:

node dist/cli.js render ci-sequence.mmd --theme obsidian-ink --format svg --out sequence.svg node dist/cli.js render tradeoff-matrix.json --theme warm-editorial --format svg --out matrix.svg Enter fullscreen mode Exit fullscreen mode

Passing --format html embeds the vector SVG inside a single self-contained HTML file with zero external scripts or CDNs:

Pretty diagrams are only half the story. The real superpower is keeping architecture honest on every pull request.

node dist/cli.js init --dir. --out.archink.json Enter fullscreen mode Exit fullscreen mode Then run archink check in CI:

node dist/cli.js check.archink.json \ --repo. \ --rule "parser!-> entry" \ --rule "themes!-> scanner" \ --fail-on-cycles \ --fail-on-drift \ --format sarif \ --out archink.sarif Enter fullscreen mode Exit fullscreen mode

Here is what archink check catches automatically:

Verified failing output on a fixture containing a cycle, layer leak, stale node, and undocumented edge:

archink check:: FAIL (Demo Service) Summary: errors=4, warnings=0, cycles=1, drift(phantom=1+0, missing=0+1), boundary=1 [ERROR] ARCH_CYCLE:: Circular dependency cycle detected: src/cli.ts <-> src/parser.ts at src/cli.ts hint: Extract shared types/interfaces into a lower-layer module to break the cycle. [ERROR] ARCH_LAYER_VIOLATION:: Forbidden dependency: parser!-> entry (src/parser.ts -> src/cli.ts) at src/parser.ts hint: Invert the dependency with an interface or move shared logic out of src/cli.ts. [ERROR] DRIFT_PHANTOM_NODE:: Diagram node "src/legacy_cache.ts" (legacy_cache.ts) does not match any source module. hint: Remove stale module from diagram or update its path/label to match the codebase. [ERROR] DRIFT_MISSING_EDGE:: Actual import "src/parser.ts -> src/cli.ts" is undocumented in diagram "Demo Service". at src/parser.ts hint: Add this dependency edge or refactor the import if unintended. Enter fullscreen mode Exit fullscreen mode Because verifier.ts emits SARIF 2.1.0, Markdown, JSON, and terminal output, you can drop it straight into GitHub Actions to annotate PR diffs or fail builds on exit code 1.

archink ships with an Agent Skills standard SKILL.md so coding agents like Claude Code, Antigravity, Cursor, and Codex follow a strict deterministic workflow:

git clone https://github.com/md1qamar/archink.git cd archink npm install npm run typecheck npm test # 12/12 tests passing across scanner, parsers, layout/renderer, and verifier/CLI Enter fullscreen mode Exit fullscreen mode You can also use it programmatically from TypeScript:

import { scanRepository, renderSvg, verifyArchitecture, parseBoundaryRule } from 'archink'; const scan = scanRepository ( '.', { ignoreTests: true } ); const svg = renderSvg ( scan. spec, { theme: 'swiss-paper', direction: 'LR' } ); const report = verifyArchitecture ( { repoDir: '.', spec: scan. spec, failOnCycles: true, failOnDrift: true, rules: [ parseBoundaryRule ( 'parser!-> entry' ) ], } ); Enter fullscreen mode Exit fullscreen mode Wrapping Up Diagrams should be as trustworthy as your compiler and test suite. By tying visual layout directly to AST import extraction, Tarjan cycle detection, and CI drift gates, archink makes sure your architecture docs stay sharp and honest as your codebase evolves.

Check out the full source code, tests, and SKILL.md on GitHub: 👉 github.com/md1qamar/archink (MIT Licensed)

If you try it on one of your TypeScript, Python, or Go repos, let me know what diagrams or boundary rules you'd like to see next!

Quelle: dev.to (dev.to). Original öffnen