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.
4.1pts
Detailed Notes
Pros 5 items
Cons 4 items
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
- Website: https://d2lang.com/
- Source repository: https://github.com/terrastruct/d2
- Syntax reference: https://d2lang.com/tour/intro
Articles
- 01 GitLab CI/CD Best Practices: From Beginner to Production-Grade Pipelines 07-18
- 02 Prometheus Monitoring System Setup: From Metric Collection to Alert Notifications 07-18
- 03 Ansible Automation Ops Guide: From Configuration Management to Application Deployment 07-18
- 04 Docker Beginner Tutorial: From Installation to Containerized Web Deployment 07-18
- 05 GitHub Actions CI/CD Tutorial: Automated Build, Test, and Deployment 07-18
- 06 API Integration Guide: REST vs GraphQL Comparison and Selection 07-18
- 07 Docker Compose Multi-Container Deployment: Building Complete Application Orchestration 07-18
- 08 Kubernetes Deployment Guide for Beginners: Building a K8s Cluster from Scratch 07-18
- 09 Best VS Code Extensions 2026: Boost Your Development Productivity 07-18
- 10 3D Secure 2 in Practice: Flows, Exemptions, and Liability Shift 11-09