Get the FREE Ultimate OpenClaw Setup Guide →

d2

Scanned
npx machina-cli add skill LiorCohen/sdd/d2 --openclaw
Files (1)
SKILL.md
5.7 KB

D2 Diagramming Language

D2 is a text-to-diagram language. Write .d2 files and render them to SVG/PNG via the d2 CLI or https://play.d2lang.com.


When to Use

  • Creating architecture or system diagrams for plans and documentation
  • Drawing sequence diagrams for API or workflow interactions
  • Building data model diagrams with SQL table shapes
  • Laying out grid-based comparison or dashboard diagrams
  • Visualizing deployment topologies, state machines, or flowcharts

Quick Reference

ConceptSyntax
Shapename or name: Label
Connectiona -> b or a -> b: label
Reverse / bidirectionala <- b / a <-> b
Line (no arrow)a -- b
Containerparent: { child1; child2 }
Dot nestingparent.child.grandchild
Set shape typename.shape: oval
Stylename.style.fill: "#ff0000"
Iconname.icon: https://url/icon.svg
Tooltipname.tooltip: hover text
Linkname.link: https://example.com
Classclasses: { c: { style: {...} } } then name.class: c
Variablevars: { k: v } then ${k}
Directiondirection: right
Comment# single line comment
SQL tablename.shape: sql_table then col: type {constraint: pk}
Sequence diagramname.shape: sequence_diagram
Gridname.grid-rows: 3 or name.grid-columns: 3
Layerslayers: { name: { ... } }
Scenariosscenarios: { name: { ... } } (inherits parent)
Stepssteps: { 1: { ... } 2: { ... } } (each inherits previous)
Importa: @file or ...@file (spread)
Glob*.style.fill: red / **.style.fill: red
Null (delete)x: null / (a -> b)[0]: null

Core Syntax

Shapes

Any identifier becomes a shape. The default shape is rectangle.

server
database: My Database
api: API Gateway {
  shape: hexagon
}

All shape types: rectangle, square, page, parallelogram, document, cylinder, queue, package, step, callout, stored_data, person, diamond, oval, circle, hexagon, cloud, text, code, class, sql_table, image, sequence_diagram, c4-person.

Connections

a -> b: request
b -> a: response
a <-> b: bidirectional
a -- b: line (no arrowhead)

# Multiple connections between same shapes are indexed
a -> b: first   # (a -> b)[0]
a -> b: second  # (a -> b)[1]

Connection References

Style existing connections by referencing them:

a -> b: request
(a -> b)[0].style.stroke: red
(a -> b)[0].style.stroke-dash: 5

Arrowheads

a -> b: {
  source-arrowhead: 1 {
    shape: diamond
  }
  target-arrowhead: * {
    shape: cf-many
  }
}

Arrowhead shapes: triangle (default), arrow, diamond, circle, cf-one, cf-many, cf-one-required, cf-many-required.

Containers (Nesting)

cloud: AWS {
  vpc: VPC {
    subnet: Private Subnet {
      ec2: Web Server
      db: Database {
        shape: cylinder
      }
    }
  }
}

# Dot notation shorthand
cloud.vpc.subnet.ec2 -> cloud.vpc.subnet.db: query

Labels and Text

# Markdown labels
explanation: |md
  # Architecture Overview
  This system uses **microservices**.
|

# Code blocks
snippet: |go
  func main() {
    fmt.Println("hello")
  }
|

# LaTeX
formula: |latex
  \\frac{n!}{k!(n-k)!}
|

Direction

Controls layout flow. Values: up, down (default), left, right.

direction: right
a -> b -> c

Null (Deletion)

Remove shapes, connections, or attributes:

x: {style.fill: red}
x.style.fill: null    # remove fill
x: null                # remove shape entirely
(a -> b)[0]: null      # remove connection

Comments

# This is a comment
server  # Inline comment

"""
This is a block comment
spanning multiple lines
"""

Positions (near)

Position items at fixed points around the diagram:

title: Architecture Overview {
  shape: text
  near: top-center
  style.font-size: 28
}

legend: {
  near: bottom-right
}

Values: top-left, top-center, top-right, center-left, center-right, bottom-left, bottom-center, bottom-right.

Label/icon positioning (additional values):

node: {
  label.near: outside-top-center
  icon: https://icons.terrastruct.com/aws/Compute/Amazon-EC2.svg
  icon.near: outside-left-center
}

Extra values for label/icon: outside-top-left, outside-top-center, outside-top-right, outside-left-center, outside-right-center, outside-bottom-left, outside-bottom-center, outside-bottom-right.


Dimensions

node: {
  width: 200
  height: 100
}

Cannot be set on containers (they resize to fit children).


Configuration via Vars

vars: {
  d2-config: {
    theme-id: 4
    dark-theme-id: 200
    pad: 50
    center: true
    sketch: true
    layout-engine: elk
  }
}

Layout engines: dagre (default, free), elk (free, more features), tala (premium).


Resource Files

For detailed guidance, read these on-demand:


Input / Output

This skill defines no input parameters or structured output.

Source

git clone https://github.com/LiorCohen/sdd/blob/main/.claude/skills/d2/SKILL.mdView on GitHub

Overview

D2 is a text-to-diagram language. Write .d2 files and render them to SVG/PNG via the d2 CLI or play.d2lang.com. It supports architecture diagrams, sequence diagrams, SQL table shapes, grid layouts, and deployment/topology visuals.

How This Skill Works

Define shapes, connections, and layout using a concise syntax. Shapes default to rectangles and can be nested with dot notation or containers. Render diagrams to SVG/PNG with the d2 CLI or the online playground at play.d2lang.com.

When to Use It

  • Creating architecture or system diagrams for plans and documentation
  • Drawing API or workflow sequence diagrams
  • Building data model diagrams with SQL table shapes
  • Laying out grid-based comparison or dashboard diagrams
  • Visualizing deployment topologies, state machines, or flowcharts

Quick Start

  1. Step 1: Create a .d2 file with shapes and connections
  2. Step 2: Render the file using the d2 CLI or paste into the playground
  3. Step 3: Tweak nesting, styles, and directions until it fits your diagram

Best Practices

  • Start with a simple anchor shape and expand gradually
  • Use containers to reflect hierarchical groups and ownership
  • Explicitly set shape types for SQL tables and sequence diagrams
  • Control layout direction to guide flow (right, left, up, down)
  • Comment code and reuse named blocks with nesting to stay organized

Example Use Cases

  • Cloud deployment diagram showing VPCs, subnets, and services
  • API call sequence between microservices with labeled edges
  • SQL table schema with columns and primary key constraints
  • Grid-based dashboard layout comparing metrics side by side
  • State machine or workflow diagram for user onboarding

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers