D2

Overview

D2 is a modern, open-source diagram scripting language that converts text-based code into diagrams with automatic layout and styling. Standing for “Declarative Diagramming,” it enables developers and technical professionals to create architecture diagrams, flowcharts, and system visualizations without manual design or drag-and-drop interfaces.

D2 treats diagramming as a developer tool rather than a design application, allowing users to describe what they want diagrammed and letting the system generate the layout automatically.

Philosophy

D2 solves a fundamental problem in technical documentation: most diagramming tools function as design applications with blank canvases and drag-and-drop toolbars, requiring spatial design skills that engineers often lack. D2 removes this friction by treating diagrams as code—updates require simple text changes rather than tedious repositioning and resizing.

Core Features

Declarative Syntax

  • Define nodes, connections, and containers through plain text code
  • Intuitive syntax: client -> server: request creates a connection with a labeled relationship
  • Simple and readable for developers

Automatic Layout Engines

  • Multiple layout algorithms: dagre, elk, and tala
  • Automatically position diagram elements without manual intervention

Diagram Types (per the d2lang.com description; not all re-checked)

  • System architecture diagrams
  • Flowcharts and decision trees
  • Workflow diagrams
  • Sequence diagrams
  • Entity-relationship diagrams (ERDs)
  • UML class diagrams
  • Network topologies
  • Organizational structures

Extensive Customization

  • Apply themes, custom styling, colors, and fonts (.ttf files)
  • Interactive elements including tooltips and clickable links
  • Shape styling (cylinders, rectangles, circles, etc.)
  • Color palettes and visual hierarchy control

Multi-Language Support

  • Non-English text and emoji labels (not verified here)

Modular Architecture

  • Split diagrams into multiple files using imports
  • Modularize code like traditional programming
  • Reusable diagram components

Built-in Tools

  • Automatic code formatting
  • Syntax highlighting
  • Watch mode for live auto-regeneration
  • Browser preview capabilities

Basic Syntax Examples

Simple Architecture

A: Web Server  
B: Database  
C: Load Balancer  
  
A -> B: "Fetch Data"  
A <- C: "Balance Traffic"  

Complex Multi-Layer Architecture

direction: right  
  
client: Client {  
  icon: https://icons.terrastruct.com/essentials/user.svg  
}  
  
lb: Load Balancer {  
  icon: https://icons.terrastruct.com/aws/Networking%20&%20Content%20Delivery/Elastic%20Load%20Balancing.svg  
}  
  
services: Services {  
  api: API Server  
  auth: Auth Service  
  api -> auth: validate  
}  
  
data: Data Layer {  
  db: PostgreSQL {  
    shape: cylinder  
  }  
  cache: Redis {  
    shape: cylinder  
  }  
}  
  
client -> lb -> services.api  
services.api -> data.db  
services.api -> data.cache  

Use Cases

Software Development

  • Application architecture documentation
  • System design visualization
  • API interaction diagrams

Business Process Mapping

  • Workflow visualization
  • Decision tree documentation
  • Organizational process mapping

Engineering and IT

  • Network topology design
  • System interaction diagrams
  • Infrastructure layouts

Database Documentation

  • Entity-relationship diagrams
  • Database schema visualization
  • Data flow mapping

Education and Research

  • Concept structure documentation
  • System relationship illustration
  • Technical education materials

Technical Implementation

Language Foundation

  • Open-source project on GitHub (d2lang/d2, formerly terrastruct/d2), MPL-2.0 licence, ~25.6k stars as of 2026-10-05; fiscally sponsored by Hack Club per d2lang.com
  • Parser with error reporting
  • Autoformatter for consistent code styling

Output Formats

  • SVG, PNG, PDF, PPTX, GIF (animated) and ASCII (per d2lang.com); v0.9.0 (2026-09-07) renders PNG, GIF, PDF and PPTX with a built-in renderer

Programmatic Access

  • Language API for creating diagrams via function calls
  • Alternative to text file-based diagramming
  • Integration with code generation workflows

Rendering Engines

  • dagre - General-purpose graph layout
  • elk - Enterprise layout kit for complex diagrams
  • tala - layout engine; per the v0.9.0 release notes (2026-09-07) TALA is now open source and bundled with D2 (d2 --layout=tala), no separate plugin or licence key

Access and Resources

Official Website

  • d2lang.com with comprehensive documentation
  • Interactive playgrounds for experimentation
  • Examples and language guides
  • Latest release checked: v0.9.0 (2026-09-07, GitHub)

Documentation

  • Language reference
  • Tutorial guides
  • Example gallery
  • Community resources

Integration Options

Editor Support (not verified here: VS Code extension, LSP and other editor integrations; see d2lang.com)

Workflow Integration

  • Export to multiple formats
  • Text-based source, so it can be kept in version control
  • CI/CD use not verified here

Strengths (author’s view)

✅ Developer-friendly - Treats diagrams as code
✅ Automatic layout - Removes manual positioning burden
✅ Multiple diagram types - Supports diverse visualization needs
✅ Open source - MPL-2.0 (GitHub)
✅ Customizable - Extensive theming and styling options
✅ Modular - Supports code organization and reuse
✅ Multiple output formats - SVG, PNG, PDF, GIF
✅ Version control friendly - Text-based, diff-able format

Limitations (author’s view)

❌ Learning curve - New syntax to learn
❌ Manual layout control limited - Automatic layout may not match desired positioning
❌ Smaller ecosystem - Less established than some alternatives (Mermaid, PlantUML)
❌ Complex diagrams - Very large diagrams may become unwieldy as code

Comparison (author’s opinion, not benchmarked)

vs Mermaid

  • D2: More sophisticated layout algorithms, more diagram types
  • Mermaid: Larger ecosystem, more existing examples

vs PlantUML

  • D2: Cleaner syntax, modern approach
  • PlantUML: More established, broader integration

vs Traditional Design Tools

  • D2: Version controllable, programmatic, efficient
  • Design Tools: Manual but sometimes more flexible for complex positioning
  • Mermaid - alternative diagram language with larger ecosystem (see also Mermaid testing notes)
  • PlantUML - Traditional UML diagram tool

Sources

Open items

  • Comparison statements (vs Mermaid, PlantUML) are the author’s opinion, not benchmarked.
  • Terrastruct (the original maker) has no company note in RESOURCES/COMPANIES.