d2

Installation
SKILL.md

D2 — Authoring Diagrams

D2 is a declarative text-to-diagram language. You write a .d2 file; the d2 CLI compiles it to SVG/PNG/PDF/PPTX/GIF. Most files are short — five to fifty lines — and lean on layout engines (dagre/elk/tala) to position things automatically.

This skill is your reference for writing D2 well. The body below is the working overview; the detailed grammar and per-diagram-type references are in references/. Hand-edit examples are in assets/examples/.

When to reach for which diagram type

Pick the shape that actually matches the data, not the one that's flashy. D2 has eight specialized diagram modes plus the general-purpose flowchart mode that does everything else.

  • Architecture / system / flow / mind map / org chart / state machine → general D2 (default rectangle/cloud/cylinder/etc. shapes connected with arrows). This is the bread and butter; ~80% of D2 you write.
  • Time-ordered messages between actors → shape: sequence_diagram (alice → bob → carol with messages).
  • Database schema / entity relationship → shape: sql_table per table + crow's-foot connections (cf-many / cf-one).
  • UML class → shape: class (fields + methods with visibility prefixes).
  • Anything that needs grid layout → grid-rows: N / grid-columns: N on the container.
  • Tree from connections → shape: hierarchy.
  • Image-only node (no rectangle around it) → shape: image.
  • Plain text label / code block / LaTeX → shape: text, shape: code, or a |md ... | / |tex ... | block.
Installs
1
GitHub Stars
6
First Seen
Aug 24, 2026