D2 Architecture Diagrams Guide
A modern, highly productive declarative language for generating beautiful architecture diagrams directly from text.
D2 (Declarative Diagramming) is a relatively new language built specifically for modern software architecture. Unlike Mermaid, which has separate syntax for flowcharts, sequence diagrams, and class diagrams, D2 utilizes a unified, object-oriented syntax.
To use D2, wrap your code in a d2 fenced code block.
The D2 Philosophy
D2 is designed to be highly readable. You declare objects and the relationships between them. The layout engine (which incorporates elements of the ELK layout) automatically places them intelligently.
Basic Syntax
|
|
|
Shapes and Styling
Unlike older text-to-diagram tools, D2 treats styling and shapes as properties of the objects, not separate commands.
|
|
|
Classes and Reusability
D2 supports the concept of “classes” to apply consistent styling across many nodes without repeating yourself.
|
|
|
Advanced Features: Icons and Markdown
D2 supports rendering simple Markdown inside nodes, and it has built-in support for fetching popular icons.
|
|
|
Why D2?
If you are designing high-level cloud architectures or microservices topologies, D2 is vastly superior in its ease-of-use and aesthetic output compared to older tools. Its clean syntax and powerful auto-layout make it ideal for modern documentation.