ak-diagram
Compile typed JSON IR into validated interactive maps and HTML readers of architecture, workflows, sequences, dataflow or lifecycles.
Files124
View on GitHubSKILL.md.claude/skills/ak-diagram/SKILL.md
GitHubak-diagram - Unified System Map & Interactive Diagram Surface
Compile typed JSON IR specifications into deterministic SVGs, embeddable fragments, and self-contained interactive HTML readers without browser dependencies. The compiler owns layout: it ranks the graph, orders columns to reduce crossings, routes orthogonal edges around unrelated nodes, and renders role-aware cards with a legend, so authors describe topology and never coordinates.
Archetype Decision Matrix
| User Intent | Archetype | Primary Entities | Key Fields |
|---|---|---|---|
| System topology, microservices, boundaries | architecture |
components, boundaries, connections |
role, layer (0–10), kind |
| Multi-step execution, lane handoffs, decisions | workflow |
lanes, steps, transitions |
kind, lane, condition |
| Ordered API calls, request/response timing | sequence |
participants, messages |
kind: sync-call | return |
| ETL pipelines, stream processing, data lineage | dataflow |
stages, nodes, flows |
stage, role, classification |
| Finite state machines, status transitions | lifecycle |
states, transitions, lanes |
kind: initial | active | ... |
5-Step Execution Playbook
- Select Archetype: Match user intent to one of the 5 archetypes above.
- Author Typed JSON IR:
- Set envelope:
{"schema_version": 1, "diagram_type": "<type>", "meta": {...}}. - Set visual preset:
classic(clean slate),signal-flow(emerald/cyan glow),blueprint(technical dark blue), oreditorial(warm serif). - Set theme:
lightordark. Every diagram plays a finite staggered entrance (nodes fade in by column, edges draw themselves). Setanimation: "trace"to add one finite flow pass along every route after the entrance. - Optional guided story: add
meta.views: [{"id": "ch1", "title": "...", "narrative": "...", "focus_nodes": [...]}](max 5 chapters).
- Set envelope:
- Apply Schema Invariants:
- Use strict role enums on nodes (compiler validates node roles at compile time).
- Keep IDs alphanumeric + hyphens (
^[a-zA-Z0-9_-]{1,64}$). - Placement follows the IR:
layerpicks the architecture column,lanepicks the workflow row,stage.orderpicks the dataflow column,initialstates open a lifecycle. Unranked nodes take the longest path from their predecessors; cycles are drawn as return routes.
- Compile Offline (Zero Browser):
node scripts/compiler/compile.mjs --input diagram.json --format html --out ./build/diagram.html --preset signal-flow --theme dark node scripts/compiler/compile.mjs --input diagram.json --format svg --out ./build/diagram.svg --preset signal-flow --theme dark - Deliver & Embed: Deliver the self-contained
.html(interactive reader with keyboard shortcuts) or clean vector.svg.
Schema Cheat Sheet & Valid Enums
Load references/schema-and-reader.md only for this part of the task.
Layout & Motion Contract
- Layout is deterministic: identical IR yields identical geometry. Nodes never overlap, routes never cross an unrelated node, boundaries, lanes and stages fully contain their members (
scripts/test_layout_geometry.mjsenforces this on every fixture). - Each node role maps to a visual family (client, service, data, queue, cache, gateway, security, external, worker, start, success, failure, waiting, decision, process, governance, transform, filter) with its own colour token, sigil and legend entry; families are exposed as
data-familyon.ak-node. - Motion is CSS only. Nodes and edges carry
data-animateand a--stepindex (capped at 40) so the whole entrance finishes in under 8 s;prefers-reduced-motion: reducerenders the final frame directly. The reader's Replay button (M) re-arms the sequence. - Compiler modules live under
scripts/compiler/: validation, layered graph ranking and ordering, per-archetype layout, orthogonal routing, semantics and palettes, and the SVG emitter. The emitted.ak-node/.ak-edgeattribute order is a consumer contract for the reader.
Common Commands
# Compile typed IR to standalone interactive HTML reader
node scripts/compiler/compile.mjs --input diagram.json --format html --out ./build/diagram.html
# Compile typed IR to clean vector SVG
node scripts/compiler/compile.mjs --input diagram.json --format svg --out ./build/diagram.svg
# Compile to embeddable scoped HTML fragment
node scripts/compiler/compile.mjs --input diagram.json --format fragment --preset signal-flow --theme dark
# Legacy Python wrapper (auto-detects typed IR vs Mermaid vs legacy template)
python3 scripts/render.py --input diagram.json --out ./build/
AK Render Page Embedding
Skills that compile an HTML page with AK Render (@bestagentkits/render) embed
diagrams through scripts/render-page.mjs. Put the typed IR in a
diagram-panel block's spec, then compile the whole page:
npx -y -p @bestagentkits/render@0.3.0 node <ak-diagram-dir>/scripts/render-page.mjs page.page.yaml --out page.html --json
The wrapper plugs this compiler into AK Render as its diagram adapter, refuses
any render version other than the pin; AK Render itself grants the page's CSP
nonce to the diagram styles. Exit 1 means an invalid spec, as with the AK Render CLI; exit 2
covers IO, environment and internal failures (the CLI reports internal failures
as a stack trace). It finds project theme presets from the spec's
folder upward and prints preset problems as warnings. Its JSON summary lists
diagramErrors and themeProblems; each failed panel keeps
AK Render's structured fallback, so repair the IR and recompile.
Security & Boundaries
- Zero Network:
scripts/compiler/compile.mjscompiles offline in pure Node.js; no remote calls, telemetry, or font downloads..mmdinput also renders offline through the vendored Pele bundle. Two exceptions: the AK Render page wrapper's firstnpxrun downloads the pinned package from npm (cached afterwards), and a.mmddiagram Pele rejects falls back to a page that loads Mermaid 11.4.1 from jsDelivr (SRI-pinned; seereferences/mermaid-input.md). Compiled typed-IR pages make zero network requests. - Deterministic: Compiling identical IR bytes emits identical SHA-256 output bytes across environments.
- Finite Motion: Entrance and trace animations are finite (under 8 s in total), replayable, and automatically disabled under
prefers-reduced-motion: reduce. - Scope Limit: For freeform whiteboard sketching, use
ak-excalidraw. For static print infographics, useak-tech-graph. For raw markdown inline doc blocks, useak-mermaidjs-v11.