Cette page est affichée en anglais. Une traduction française est en cours.
ScriptsJul 19, 2026·3 min de lecture

D2 — Text-to-Diagram Scripting Language for Developers

D2 is a declarative diagram scripting language that turns text into diagrams. It supports various layout engines and output formats, letting developers create and maintain complex diagrams as code.

Prêt pour agents

Installation agent prête

Cet actif peut être installé après choix du runtime, vérification du plan et exécution de la commande adaptée.

Native · 98/100Policy : autoriser
Surface agent
Tout agent MCP/CLI
Type
Skill
Installation
Single
Confiance
Confiance : Established
Point d'entrée
D2 — Text-to-Diagram Scripting Language for Developers
Commande d'installation directe
npx -y tokrepo@latest install e6fd929c-8390-11f1-9bc6-00163e2b0d79 --target codex

À exécuter après confirmation du plan en dry-run.

Introduction

D2 is a modern, declarative diagramming language developed by Terrastruct. You write text descriptions and D2 compiles them into SVG, PNG, or PDF output. It focuses on readability, making diagrams easy to version-control alongside code.

What D2 Does

  • Compiles .d2 text files into SVG, PNG, and PDF diagrams with automatic layout
  • Supports multiple layout engines including dagre, ELK, and TALA
  • Provides containers, connections, shapes, icons, and markdown labels
  • Includes watch mode that live-reloads rendered output as you edit
  • Handles sequence diagrams, class diagrams, and ER diagrams natively

Architecture Overview

D2 is written in Go and operates as a CLI compiler. Source files are parsed into an AST, processed through a pluggable layout engine, then rendered to the chosen output format. Open-source layout engines dagre and ELK are bundled; the TALA engine is an optional proprietary add-on.

Self-Hosting & Configuration

  • Install from source with go install oss.terrastruct.com/d2 or use prebuilt binaries
  • Configure layout engine, theme, and output format via CLI flags
  • Built-in themes are selectable by name; dark-mode variants included
  • Embed D2 in CI pipelines to auto-generate diagrams on each commit
  • Use the VS Code extension for syntax highlighting and inline preview

Key Features

  • Declarative syntax: readable, indentation-based text format
  • Multiple output formats: SVG, PNG, and PDF from the same source
  • Pluggable layouts: choose dagre, ELK, or TALA per diagram
  • Sequence diagrams: first-class lifelines and message arrows
  • Markdown labels: inline markdown for rich text inside shapes

Comparison with Similar Tools

  • Mermaid: browser-native, widely embedded in doc platforms; D2 offers more layout control
  • PlantUML: mature UML focus; D2 has cleaner syntax and faster rendering
  • Graphviz: classic graph layout tool; D2 provides modern syntax and better defaults
  • Excalidraw: hand-drawn canvas editor; D2 is text-first and version-control friendly

FAQ

Q: Is D2 free and open source? A: Yes, under the MPL-2.0 license. The TALA layout engine is a separate proprietary option but not required.

Q: Can I use D2 in CI/CD pipelines? A: Yes. D2 is a standalone CLI binary that integrates into any CI pipeline.

Q: Does D2 support dark mode? A: Yes, D2 ships with multiple themes including dark-mode variants.

Q: How does D2 compare to Mermaid? A: Mermaid renders in-browser and is natively supported by GitHub. D2 produces higher-quality output with more layout options but requires a build step.

Sources

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires