name: d2-diagram description: Generate D2 diagram files (.d2) for technical reference — flowcharts, architecture diagrams, sequence diagrams, state machines, database schemas, and class diagrams. Use whenever the user wants to create, document, or visualize any system, flow, architecture, API, database, or process. Trigger on "make a diagram", "draw a flowchart", "document this architecture", "visualize this flow", "create a sequence diagram", "map this system", or any request to illustrate how something works.
D2 Diagram Skill
Generates .d2 files for VS Code (requires D2 extension).
Workflow → guides/workflow.md
- How to greet user, offer templates, generate file, give preview instructions
Templates → templates/
flowchart.d2— process flows, decision trees, request handlingarchitecture.d2— microservices, layered system architecturesequence.d2— API calls, auth flows, request/response chainsstate-machine.d2— order lifecycle, connection states, workflow stagessql-schema.d2— database tables with relationshipsclass-diagram.d2— OOP class hierarchies, interfaces, SDKsinfra-cloud.d2— cloud/VPC/subnet topology (AWS-style)grid-dashboard.d2— UI layouts, component maps, dashboards
Syntax Quick-Reference → syntax/
nodes.md— declaring nodes, labels, IDsconnections.md— arrows, labels, chaining, bidirectionalcontainers.md— grouping nodes, nested references,_parentshapes.md— full shape list with when to use eachstyles.md— fill, stroke, dash, bold, shadow, opacitydimensions.md— width, height, grid-rows, grid-columnslayout.md— direction, layout engines (dagre/elk/tala)globs.md—*,**,***bulk selectors for global styles and connectionsvars.md— variables, substitution (${var}),d2-configblockclasses.md— reusable style definitions applied to multiple nodesicons.md— built-in and URL-based icons on nodesnear.md— positioning labels/nodes relative to constants (top-left, etc.)null.md— removing/hiding nodes withnullcomments.md—#comments and block commentsgotchas.md— naming rules, cross-container refs, common errors
Advanced Features → advanced/
layers.md— multiple diagram layers for step-by-step viewsscenarios.md— scenario variations branching from a base diagramimports.md— importing from other.d2filestooltips-links.md— interactive hover text and clickable linksthemes.md— built-in theme IDs, dark themes, sketch mode
Special Diagram Types → special/
sequence.md— sequence_diagram syntax, actors, self-messagessql-table.md— sql_table shape, constraints, FK relationshipsclass.md— class shape, visibility (+/-/#), inheritance linesmarkdown-code.md— embedding md/code blocks inside nodes
Validation — ALWAYS
d2 path/to/file.d2 /dev/null # errors → stdout
Validate before starting + after each logical round of changes (not after every single line). VS Code diagnostics API misses D2 errors; CLI only.