PROVIDER - A declarative diagramming language

D2

D2 is a declarative diagramming language where 1 .d2 file produces an architecture diagram, with auto layout removing about 90% of manual positioning, 5 or more export formats and a Watch mode under MPL-2.0; the gaps are ecosystem size and layout engine tuning.

Developer Tools United States 2026.11.19
4.1pts

Detailed Notes

Pros 5 items

Declarative syntax where 1 .d2 file produces a complete architecture diagram
Built-in auto layout that removes roughly 90% of manual positioning work
Exports to 5 or more formats including SVG, PNG and PDF
Offers a Watch mode that re-renders within 1 second of saving
Released under MPL-2.0 with the CLI shipped as a single binary

Cons 4 items

Diagram types and ecosystem remain smaller than Mermaid
Advanced layout tuning requires understanding dagre and ELK settings
Few resources in non-English communities, raising troubleshooting effort
Themes and fonts need extra configuration for polished output

Service Overview

D2 is Terrastruct's declarative diagramming language that shifts architecture drawing from dragging boxes to describing structure.

In the development tools category it is the newer generation of diagrams as code: readable syntax plus auto layout that removes a lot of manual nudging.

Key Strengths

  • Declarative syntax: describe relations, not coordinates
  • Auto layout: cuts about 90% of manual work
  • Multiple exports: 5 or more formats
  • Watch mode: save and see it refresh
  • Single binary: simple install and distribution

Product Ecosystem

Platform capabilities

Container and hierarchy modelling, auto layout, icon and font configuration, themes, watch-mode rendering, Markdown embedding and CLI batch export.

Integrations

Combines with VS Code and Obsidian plugins, GitHub Actions and documentation build pipelines.

Typical scenarios

Maintaining system architecture maps, describing cloud resource topologies, illustrating data flows and supplying design review diagrams.

Limitations

  • Ecosystem size: fewer diagram types than Mermaid
  • Tuning barrier: layout engine settings need study
  • Resource volume: little non-English material
  • Styling: themes and fonts need extra setup

Use Cases

  • Long-lived architecture maps (★★★★★): declarative evolution
  • Strong auto layout needs (★★★★☆): no manual alignment
  • Multi-format delivery (★★★★☆): flexible exports
  • Quick lightweight diagrams (★★★☆☆): Mermaid is faster to start

Pricing

Item Price Notes
D2 CLI $0 MPL-2.0, free and open source
D2 Studio Per user subscription Visual editing and collaboration
Self-managed use $0 Single binary or container image

FAQ

How does D2 compare with Mermaid?

D2 has stronger auto layout and container modelling, while Mermaid enjoys broader native platform support.

Does it need connectivity?

No, the CLI renders fully offline.

Can it export PDF?

Yes, SVG, PNG and PDF outputs are available.

Can diagrams embed in a docs site?

Yes, through plugins or by pre-rendering to SVG.

Code Examples

# diagram.d2
direction: right

user: User {
  shape: person
}

api: API Gateway
db: PostgreSQL {
  shape: cylinder
}

user -> api: HTTPS
api -> db: SQL
api -> cache: GET/SET
cache: Redis {
  shape: cylinder
}
# Install and render
curl -fsSL https://d2lang.com/install.sh | sh -s --
d2 diagram.d2 diagram.svg

# Watch mode refreshes on save
d2 --watch diagram.d2 diagram.svg

Community & Resources

Visit D2 Website → https://d2lang.com/
Visit Website ↗