D2 is a free, open-source diagram scripting language by Terrastruct that turns text into architecture diagrams. See features, licensing and alternatives.
Researched and fact-checked by Bartu Cavusoglu · Updated July 18, 2026
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.
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.
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.
Yes, the D2 language and command-line tool are free and open source under the Mozilla Public License 2.0.
D2 was created by Terrastruct, a San Francisco-based company founded in 2019 by Alexander Wang.
D2 is licensed under the Mozilla Public License 2.0 (MPL-2.0).
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.
Yes, D2 can be used via Terrastruct's hosted playground or editor, though the CLI tool can also be installed for local use.
Yes, Terrastruct offers a separate paid diagramming application with visual editing and collaboration features built around the D2 language.