d2-diagram

Write and verify D2 architecture diagrams rendered as terminal text with TALA layout.

22|1|Updated Mar 30, 2026
One-click install
npx skills add https://github.com/mizchi/vlmkit --skill d2-diagram-mizchi
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: d2-diagram
Source: https://github.com/mizchi/vlmkit/tree/main/.apm/skills/vlmkit/workflows/d2-diagram
Command: npx skills add https://github.com/mizchi/vlmkit --skill d2-diagram-mizchi

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes assets (resource) components.

What problem does it solve? D2 validates syntax but never tells you the picture is wrong: an out-of-scope reference silently creates duplicate boxes, a pin can truncate the terminal render while exiting 0, and reversed arrows pass every check. This Skill closes that gap by reading the drawn shapes and edges back out of the render and holding them to a fact sheet. ## Core Features & Use Cases - Terminal-first rendering: Render D2 files with TALA as Unicode box drawing or plain ASCII for READMEs, PR comments, and code blocks, with width measured the way a terminal sees it. - Fact-sheet verification: The bundled d2-facts.mjs script extracts boxes, containers, edges, and column width from the SVG render and checks them against a JSON sheet, catching duplicates, reversed edges, overlaps, and truncation. - Task routing and width tuning: Route architecture, data-model, sequence, class, and deployment diagrams to the right D2 shapes, then apply measured levers (root direction, per-container direction, seeds, pins) to fit a column budget. - Use Case: You need an architecture diagram that lives as editable text in the repo and displays in a terminal. Write the fact sheet first, write the .d2, then loop validate → facts check → PNG review → terminal render until every gate passes. ## Quick Start Draw the service architecture of this repository as a D2 diagram with TALA layout, verify it against a fact sheet, and show me the terminal render.

Frequently Asked Questions about d2-diagram

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I render a D2 diagram as ASCII or terminal text?

Run `d2 --layout=tala arch.d2 arch.txt` for a Unicode box-drawing render, or add `--ascii-mode standard` for plain ASCII suitable for READMEs. Use `--stdout-format ascii -` to pipe the render to stdout.

How do I verify a D2 diagram matches what I intended?

D2 itself only validates syntax, so write a JSON fact sheet listing expected boxes, edges, and containers, then run `node assets/d2-facts.mjs arch.d2 --expect facts.json`. It reads the drawn shapes back from the SVG render and reports missing, reversed, or forbidden edges.

Why does my D2 diagram show duplicate boxes?

A reference to an id that is not in scope silently creates a new shape instead of failing. Write cross-container connections at the root with full paths like `edge.gateway -> cluster.orders`, or use `_.` from inside a container to reach its parent level.

Does D2 support the TALA layout engine?

TALA is bundled with D2 since version 0.9.0 and is also present in some earlier builds; check with `d2 layout`, which must list `tala (bundled)`. Pass `--layout=tala` explicitly because the in-file config is ignored for text renders on some builds.

Why is my D2 terminal render wider than expected or truncated?

Width levers are not monotone: try the root `direction`, then the `direction` of the fullest container, then `--tala-seeds`, measuring with `LC_ALL=C.UTF-8 wc -L` after each change. A `top`/`left` pin can push shapes off the ascii canvas while d2 exits 0, so re-check the render after pinning.

When should I not use D2 for a diagram?

Avoid D2 text renders for animations or step-by-step walkthroughs, which need a different tool. Also split diagrams with more than about thirty shapes into multiple files, since TALA's runtime is nonlinear and large layouts read poorly regardless of engine.