Fundamentals 6 min read

Why Developers Are Turning to D2: A Code‑Like, Engineerable Diagramming Tool

The article explains how the open‑source D2 tool solves the frustrations of manual diagram editors by letting developers describe diagrams in plain text, version them with Git, and generate animated, LaTeX‑enabled, multi‑language charts that integrate smoothly into existing workflows.

macrozheng
macrozheng
macrozheng
Why Developers Are Turning to D2: A Code‑Like, Engineerable Diagramming Tool

When documenting architecture, the author struggled with traditional drag‑and‑drop editors like draw.io, which produce misaligned lines and require complete redraws after requirement changes.

Discovering the open‑source project D2 (Declarative Diagramming) on GitHub, the author found a script‑based approach that converts text into diagrams, eliminating manual alignment and enabling engineering‑style management.

Core Concept

D2 is a Go‑implemented language that treats diagram definitions as code, allowing pure‑text descriptions, Git version control, collaborative review, automation, and AI‑driven generation.

Key Features

Production‑grade themes : Over 100 professionally designed themes switchable with the -t flag.

Sketch mode : The --sketch flag adds a hand‑drawn jitter for informal presentations.

Animated charts : Unique ability to animate node and edge appearance, useful for illustrating flows.

LaTeX support : Direct embedding of mathematical formulas, ideal for research notes and papers.

Multilingual text : Handles Chinese, English, French, emojis, etc., without rendering issues.

Code‑block highlighting : Embed syntax‑highlighted code snippets directly in architecture diagrams.

Additional capabilities include multiple layout engines (Dagre, ELK, TALA), live preview with watch, modular file imports, and dark‑mode adaptation.

Quick Installation and First Use

# macOS / Linux universal installer
curl -fsSL https://D2lang.com/install.sh | sh -s --

# Homebrew on macOS
brew install D2

# With Go toolchain
go install oss.terrastruct.com/D2@latest

Windows users can install via winget install terrastruct.D2. After installation, a minimal "Hello World" diagram can be created:

# Create a D2 file
 echo 'x -> y -> z' > hello.D2

# Watch mode for live preview
 D2 --watch hello.D2 out.svg

The browser opens automatically, and any file edit refreshes the diagram instantly.

For those who prefer not to install locally, an online Playground is available at https://play.D2lang.com, and plugins exist for VSCode, Vim, and Obsidian, covering most common editors.

Conclusion

Using D2 feels like the "programmer's proper way to draw"; it transforms one‑off diagramming into maintainable, version‑controlled assets, freeing developers from tedious alignment work and enabling integration with automated and AI‑driven workflows.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Automationvisualizationinfrastructure as codeD2declarative diagrammingGit version control
macrozheng
Written by

macrozheng

Dedicated to Java tech sharing and dissecting top open-source projects. Topics include Spring Boot, Spring Cloud, Docker, Kubernetes and more. Author’s GitHub project “mall” has 50K+ stars.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.