D2 is a free, open-source diagram scripting language by Terrastruct that turns text into architecture diagrams. See features, licensing and alternatives.
Category
Collaboration
Pricing
Free / Open Source, from Free
Verified
Not yet
Last updated
July 18, 2026
Founded
2022
Headquarters
San Francisco, California, USA
Free PlanWindowsAPIOpen SourceSelf-HostedMac
Overview
D2 is an open-source declarative diagram scripting language created by Terrastruct, a San Francisco company founded in 2019 by Alexander Wang. Terrastruct open-sourced D2 in November 2022 under the Mozilla Public License 2.0.
D2 lets users describe diagrams as plain text, which an automatic layout engine then renders as SVG, PNG or PDF, making it part of the growing diagrams-as-code category alongside Mermaid and PlantUML.
Key Features
D2 offers multiple auto-layout engines, including dagre and an ELK-based engine, a shape library tuned for software architecture (cylinders, queues, clouds, person icons), and several built-in visual themes including dark mode.
Because diagrams are plain text files, they can be stored in Git, diffed, and code-reviewed like any other source file, with tooling including an autoformatter, multi-error parser, syntax highlighting, and editor integrations for VS Code, Vim and Obsidian.
Pricing
The D2 language and command-line compiler are entirely free and open source, with no cost to download, run, or embed in personal or commercial projects.
Terrastruct's revenue comes from a separate paid diagramming application built around D2 that adds visual editing and real-time collaboration for teams, funding continued development of the open-source language.
Key Features
Declarative Text-to-Diagram Syntax — Describe diagram elements and relationships in plain text; layout is handled automatically.
Multiple Auto-Layout Engines — Choose between dagre and ELK-based layout engines depending on diagram complexity.
Architecture-Focused Shape Library — Shapes like cylinders, queues, clouds and person icons tuned for technical diagrams.
Built-in Themes — Official visual themes, including dark-mode options, for consistent styling.
Git-Friendly Plain-Text Files — Diagrams stored as text can be version-controlled, diffed and code-reviewed.
CLI & Server-Side Rendering — Compile diagrams via command line or run D2 as a server-side rendering service.
Autoformatter & Multi-Error Parser — Consistent formatting and clear error reporting across a broken diagram file.
Editor Integrations — Official VS Code extension plus community integrations for Vim, Obsidian, Slack and Discord.
Pros & Cons
Pros
Completely free and open source (MPL-2.0)
Diagrams stored as plain text, ideal for Git version control and code review
Purpose-built shape library and layout for software architecture diagrams
Active open-source community and growing ecosystem of integrations
Cons
Newer and less pre-integrated into platforms like GitHub or Notion than Mermaid
Requires learning a diagram-specific syntax rather than pure drag-and-drop
Advanced visual and collaborative editing requires Terrastruct's separate paid app
Auto-layout engines can require manual tuning for very complex diagrams
Pricing
D2 (Open Source) Free N/A
Frequently Asked Questions
Is D2 free?
Yes, the D2 language and command-line tool are free and open source under the Mozilla Public License 2.0.
Who created D2?
D2 was created by Terrastruct, a San Francisco-based company founded in 2019 by Alexander Wang.
What license is D2 released under?
D2 is licensed under the Mozilla Public License 2.0 (MPL-2.0).
How is D2 different from Mermaid?
D2 offers a more customizable visual output and an architecture-focused shape library, while Mermaid has broader native integration into platforms like GitHub and Notion.
Can I use D2 without installing anything?
Yes, D2 can be used via Terrastruct's hosted playground or editor, though the CLI tool can also be installed for local use.
Does Terrastruct sell a paid product built on D2?
Yes, Terrastruct offers a separate paid diagramming application with visual editing and collaboration features built around the D2 language.