๐ŸŽง Listen

1. Introduction

Every software system needs diagrams. Architecture diagrams, sequence diagrams, data flow diagrams, deployment topologies โ€” they're the visual language of engineering. Yet most developers dread creating them. You open Lucidchart or draw.io, drag boxes around for an hour, realize the layout is wrong, start over, and by the time it's done, the architecture has already changed.

There's a better way: diagram as code. Instead of dragging and dropping, you write a simple text description and a tool renders the diagram for you. And now, with LLMs, you don't even need to learn the syntax โ€” you can describe what you want in plain English and get a professional diagram in seconds.

This guide explores the entire landscape of diagram-as-code tools in 2026, compares them head-to-head, examines how AI is transforming diagram generation, and lays out a concrete blueprint for building an OpenClaw skill that turns natural language into visual architecture diagrams.[1]

2. The Problem with Traditional Diagramming

Let's be honest about why we're here. Traditional diagramming is broken for developer workflows:

2.1 Manual Tools Break the Flow

Tools like Lucidchart, Visio, and draw.io produce beautiful diagrams โ€” but they require switching context from your editor to a visual canvas, positioning elements pixel by pixel, and wrestling with auto-layout algorithms that never quite do what you want. A diagram that takes 5 minutes to describe in words takes 45 minutes to draw.

2.2 Diagrams Rot Faster Than Code

The architecture changes, but nobody updates the diagrams. Within weeks of creation, most architecture diagrams are out of date. If diagrams lived in the same repo as code โ€” written in text, version-controlled with Git, diffable in pull requests โ€” they'd stay current.

2.3 ASCII Art Doesn't Scale

Developers who refuse to leave the terminal resort to ASCII art. It works for simple things, but try drawing a microservices architecture with 12 services, 3 databases, a message queue, and an API gateway in ASCII. You'll run out of patience before you run out of characters.

2.4 Collaboration Is Painful

Sharing a diagram as a PNG in Slack is a dead end. Nobody can edit it, version it, or update it. Diagram-as-code solves this: the diagram source is text that lives in your repo, reviewed in PRs, and rendered automatically in your docs.

๐Ÿ’ก The Core Insight The best diagram is one that's generated from a source of truth โ€” whether that's a text DSL, a code definition, or a natural language description processed by an LLM. If it can be regenerated, it stays current.

3. The Diagram-as-Code Tool Landscape

The ecosystem has matured significantly. Here's every major tool worth considering in 2026, with honest assessments of each.

3.1 Mermaid.js

Mermaid is the most widely adopted diagram-as-code tool. Created by Knut Sveidqvist, it uses a simple markdown-like syntax to define flowcharts, sequence diagrams, class diagrams, Gantt charts, ER diagrams, state diagrams, pie charts, and more.[2]

Why it dominates: Native support in GitHub markdown, GitLab, Notion, Obsidian, Docusaurus, and dozens of other platforms. Write a Mermaid code block in a README and GitHub renders it automatically. No setup, no build step, no server.

graph TD
    A[User] -->|HTTP Request| B[API Gateway]
    B --> C[Auth Service]
    B --> D[Order Service]
    D --> E[(PostgreSQL)]
    D --> F[Payment Service]
    F --> G[Stripe API]

Strengths: Zero-config rendering in GitHub/GitLab, huge community, extensive diagram types (flowcharts, sequence, class, ER, Gantt, state, pie, mindmap, timeline, C4, git graph), active development, JavaScript-based (runs in browser).

Weaknesses: Limited layout control (you can't precisely position elements), styling can be clunky, complex diagrams can look messy, some diagram types are less mature than others.

Output: SVG (primary), PNG via CLI (mmdc from @mermaid-js/mermaid-cli).

3.2 PlantUML

PlantUML is the veteran of text-based diagramming. Started in 2009, it supports a staggering range of UML diagram types: sequence, use case, class, object, activity, component, deployment, state, and timing diagrams. It also handles non-UML diagrams like JSON/YAML visualization, wireframes, and Gantt charts.[3]

@startuml
actor User
User -> "API Gateway" : HTTP Request
"API Gateway" -> "Auth Service" : Validate Token
"API Gateway" -> "Order Service" : Create Order
"Order Service" -> Database : Store Order
"Order Service" -> "Payment Service" : Process Payment
"Payment Service" -> "Stripe" : Charge Card
@enduml

Strengths: The most comprehensive UML support of any tool. Excellent sequence diagrams (arguably the best). Mature, battle-tested, enormous documentation. Java-based with CLI, can run as a server. Supported by Confluence, VS Code, IntelliJ, and many more.

Weaknesses: Requires Java runtime. The syntax is verbose compared to Mermaid or D2. Output aesthetics are functional but dated โ€” it looks like 2010. Less native integration with modern platforms (no GitHub markdown rendering).

Output: PNG, SVG, EPS, PDF, LaTeX.

3.3 D2 (Terrastruct)

D2 is the modern challenger. Created by Terrastruct in 2022, it's a purpose-built declarative language for diagrams with a focus on readability and aesthetics. D2 supports multiple layout engines (dagre, ELK, TALA) and produces diagrams that look significantly better than Mermaid or PlantUML out of the box.[4]

user: User {shape: person}
gateway: API Gateway
auth: Auth Service
orders: Order Service
db: PostgreSQL {shape: cylinder}
payments: Payment Service
stripe: Stripe API {shape: cloud}

user -> gateway: HTTP Request
gateway -> auth: Validate
gateway -> orders: Create Order
orders -> db: Store
orders -> payments: Process
payments -> stripe: Charge

Strengths: Beautiful default output, readable syntax, multiple layout engines (including the commercial TALA engine for optimal layouts), built-in theming, supports containers/groups, animations, tooltips, and links. Fast Go binary with no dependencies. Actively developed.

Weaknesses: Smaller ecosystem than Mermaid or PlantUML. No native GitHub/GitLab rendering. The TALA layout engine (the best one) requires a commercial license. Fewer diagram types than PlantUML.

Output: SVG, PNG, PDF, GIF (animated).

3.4 Graphviz (DOT Language)

Graphviz is the granddaddy of graph visualization, originally developed at AT&T Labs in the 1990s. The DOT language describes directed and undirected graphs, and Graphviz's layout algorithms (dot, neato, fdp, circo, twopi) remain among the best for automatic graph layout.[5]

Strengths: The most powerful automatic layout algorithms for complex graphs. Handles hundreds or thousands of nodes gracefully. Universal installation (available everywhere). Used as a layout engine by other tools (including D2).

Weaknesses: Low-level โ€” it's a graph renderer, not a diagram tool. No concept of sequence diagrams, ER diagrams, or domain-specific shapes. The output looks technical/academic. Steep learning curve for advanced customization.

Output: SVG, PNG, PDF, PS, and dozens of other formats.

3.5 Diagrams (Python)

Diagrams by Mingrammer is a Python library specifically designed for cloud infrastructure architecture diagrams. You write Python code that describes your infrastructure, and it renders beautiful diagrams with official cloud provider icons (AWS, Azure, GCP, Kubernetes, etc.).[6]

from diagrams import Diagram, Cluster
from diagrams.aws.compute import ECS
from diagrams.aws.database import RDS
from diagrams.aws.network import ELB, Route53

with Diagram("Web Service", show=False):
    dns = Route53("dns")
    lb = ELB("lb")
    with Cluster("Services"):
        svc_group = [ECS("web1"), ECS("web2"), ECS("web3")]
    db = RDS("userdb")
    dns >> lb >> svc_group >> db

Strengths: Gorgeous output with real cloud provider icons. Programmatic โ€” generate diagrams dynamically from infrastructure state. Perfect for cloud architecture documentation. Active community with 40,000+ GitHub stars.

Weaknesses: Only for infrastructure/cloud diagrams โ€” no sequence diagrams, ER diagrams, etc. Requires Python and Graphviz installed. Limited layout control (uses Graphviz under the hood).

Output: PNG, JPG, SVG, PDF, DOT.

3.6 Structurizr (C4 Model)

Structurizr implements Simon Brown's C4 model โ€” a hierarchical approach to software architecture with four levels: Context, Container, Component, and Code. You define your architecture in a DSL, and Structurizr renders it at each C4 level.[7]

Strengths: The definitive tool for C4 diagrams. Forces good architectural thinking. Multiple rendering backends (PlantUML, Mermaid, D2, Ilograph). Available as a cloud service, on-premises, or CLI.

Weaknesses: C4-specific โ€” not a general-purpose diagramming tool. The DSL has a learning curve. The cloud version has limited free tier.

Output: SVG, PNG (via rendering backends).

3.7 Kroki โ€” The Meta-Tool

Kroki deserves special attention because it's not a diagramming language โ€” it's a unified HTTP API that wraps 25+ diagramming tools behind a single endpoint. Send your Mermaid, PlantUML, D2, Graphviz, Excalidraw, C4, DBML, or any other supported syntax to Kroki's API, and get back an SVG or PNG.[8]

Supported tools: BlockDiag, BPMN, Bytefield, C4 (PlantUML), D2, DBML, Ditaa, Erd, Excalidraw, GraphViz, Mermaid, Nomnoml, Pikchr, PlantUML, Structurizr, SvgBob, Symbolator, TikZ, UMLet, Vega, Vega-Lite, WaveDrom, WireViz, and more.

Why this matters for us: Instead of installing and maintaining 10 different rendering tools, you install Kroki (or use their free public API) and get access to all of them through one HTTP call. This is exactly what an OpenClaw skill needs.

# Render a Mermaid diagram via Kroki API
curl -X POST https://kroki.io/mermaid/svg \
  -H "Content-Type: text/plain" \
  -d 'graph TD
    A[Client] --> B[Load Balancer]
    B --> C[Server 1]
    B --> D[Server 2]' \
  -o diagram.svg

Self-hosting: Kroki runs as a Docker container. GitLab has native Kroki integration โ€” you can point any GitLab instance to a self-hosted Kroki server and render diagrams in wiki pages and issues.[9]

3.8 Other Notable Tools

4. Head-to-Head Comparison

Tool Input Format Output Diagram Types Self-Hosted CLI Quality
Mermaid Custom DSL (Markdown-like) SVG, PNG Flowchart, Sequence, Class, ER, Gantt, State, C4, Mindmap, Timeline, Git โœ… (JS/CLI) โœ… mmdc โญโญโญยฝ
PlantUML Custom DSL SVG, PNG, PDF, EPS All UML types + Gantt, JSON, YAML, Wireframe, MindMap โœ… (Java) โœ… plantuml โญโญโญ
D2 D2 Language SVG, PNG, PDF, GIF Flowchart, Sequence, Class, Grid, SQL tables โœ… (Go binary) โœ… d2 โญโญโญโญยฝ
Graphviz DOT Language SVG, PNG, PDF, PS, +30 more Directed/undirected graphs, trees, clusters โœ… (C binary) โœ… dot/neato/fdp โญโญโญ
Diagrams (Python) Python code PNG, SVG, PDF Cloud infrastructure only โœ… (Python) โœ… python โญโญโญโญ
Structurizr Structurizr DSL SVG, PNG (via backends) C4 model (Context, Container, Component, Code) โœ… โœ… structurizr-cli โญโญโญโญ
Kroki Any of 25+ syntaxes SVG, PNG, PDF All types (via backends) โœ… (Docker) HTTP API Depends on backend
Pikchr PIC-like markup SVG Flowcharts, custom line drawings โœ… (C) โœ… pikchr โญโญโญ
๐Ÿ’ก Quick Recommendation For GitHub-native docs: Mermaid (zero setup). For beautiful output: D2. For comprehensive UML: PlantUML. For cloud infra: Diagrams (Python). For maximum flexibility via API: Kroki.

5. AI + Diagrams: LLMs as Diagram Generators

This is where it gets exciting. Large language models โ€” Claude, GPT-4, Gemini โ€” are surprisingly good at generating diagram syntax from natural language descriptions. This opens the door to a workflow where you simply describe your architecture and get a rendered diagram.

5.1 Can LLMs Generate Diagram Code Reliably?

Yes, with caveats. Here's what we've found across extensive testing:

5.2 Best Prompting Strategies

Through experimentation, we've identified the prompting patterns that produce the best results:

Strategy 1: Explicit Format + Example

Generate a Mermaid flowchart diagram for the following architecture:
- Users connect through a CDN (CloudFront)
- CloudFront routes to an Application Load Balancer
- ALB distributes to 3 ECS containers
- Containers read/write to Aurora PostgreSQL
- Containers publish events to SQS
- A Lambda function processes SQS messages
- Lambda writes to DynamoDB for analytics

Use the 'graph TD' (top-down) direction.
Use descriptive node labels.
Add edge labels for the type of communication.

Strategy 2: Two-Phase Generation

First, ask the LLM to list the components and their relationships as structured data. Then, ask it to convert that into diagram syntax. This reduces errors because the LLM separates the "understanding" step from the "syntax generation" step.

Strategy 3: Validation Loop

Generate the diagram code, attempt to render it, and if rendering fails, feed the error message back to the LLM for correction. Most syntax errors can be fixed in one retry. This is the approach we recommend for an automated skill.

5.3 Example: Natural Language โ†’ Mermaid โ†’ Diagram

Input (natural language):

"I have a microservices architecture with a React frontend that talks to an API gateway. The gateway routes to three services: user service, order service, and notification service. The user service and order service each have their own PostgreSQL database. The order service also publishes events to a RabbitMQ message broker, which the notification service subscribes to. The notification service sends emails via SendGrid and push notifications via Firebase."

Output (LLM-generated Mermaid):

graph TD
    FE[React Frontend] -->|REST API| GW[API Gateway]
    GW --> US[User Service]
    GW --> OS[Order Service]
    GW --> NS[Notification Service]
    US --> UDB[(User DB - PostgreSQL)]
    OS --> ODB[(Order DB - PostgreSQL)]
    OS -->|Publish Events| MQ{{RabbitMQ}}
    MQ -->|Subscribe| NS
    NS -->|Email| SG[SendGrid]
    NS -->|Push| FB[Firebase Cloud Messaging]

This is valid Mermaid syntax that renders correctly on the first try. For most architecture descriptions of this complexity, LLMs produce correct output without needing retries.

5.4 AI Diagram Tools in the Wild

Several products already combine AI with diagram generation:[12]

6. Kroki: The Unified Rendering API

Kroki is the linchpin of our recommended approach, so it deserves deeper coverage. Instead of installing Mermaid CLI, PlantUML (Java), D2 (Go binary), and Graphviz separately, Kroki wraps them all in a single Docker container with a clean HTTP API.[8]

6.1 How It Works

Kroki exposes a simple REST API:

# POST endpoint: /<diagram-type>/<output-format>
POST https://kroki.io/mermaid/svg
Content-Type: text/plain

graph TD
    A --> B --> C

# GET endpoint (Base64-encoded diagram in URL):
GET https://kroki.io/mermaid/svg/Z3JhcGggVEQKICAgIEEgLS0+IEIgLS0+IEM=

6.2 Self-Hosting

# Docker Compose for Kroki with all backends
docker compose up -d
# Kroki + Mermaid + BPMN + Excalidraw companions
# See: https://docs.kroki.io/kroki/setup/install/

For our OpenClaw skill, we can either use the free public API at kroki.io (rate-limited but functional) or self-host for production use. The public API is sufficient for development and moderate usage.

6.3 GitLab Integration

GitLab natively supports Kroki. In your GitLab admin settings, point to a Kroki server, and every code block with a supported diagram language is automatically rendered. This means your architecture docs in GitLab wikis stay up to date with zero manual effort.[9]

Based on our research, here's the architecture we recommend for building a "natural language to diagram" skill:

7.1 The Pipeline

  1. Natural language input โ€” User describes the architecture in plain English
  2. LLM generates Mermaid syntax โ€” Mermaid as the primary target because of the best LLM-generation accuracy and broadest platform support
  3. Validation โ€” Parse the Mermaid output to check for syntax errors
  4. Retry on failure โ€” If validation fails, feed the error back to the LLM (max 2 retries)
  5. Render via Kroki or Mermaid CLI โ€” Convert to SVG/PNG
  6. Return the image โ€” Deliver to the user or embed in a blog post

7.2 Why Mermaid as the Primary Target?

7.3 When to Use Other Tools

โœ… Our Pick: Mermaid + Kroki Use Mermaid as the default LLM target for its accuracy and ecosystem support. Use Kroki as the rendering backend for its flexibility โ€” if a user needs D2 or PlantUML output instead, just change the Kroki endpoint. One API, any diagram language.

8. Proof of Concept

Here's a working proof of concept that demonstrates the full pipeline: natural language โ†’ LLM โ†’ Mermaid โ†’ rendered diagram.

8.1 The Script

#!/bin/bash
# diagram-from-text.sh โ€” Generate a diagram from natural language
# Dependencies: curl, jq, @mermaid-js/mermaid-cli (mmdc)

DESCRIPTION="$1"
OUTPUT="${2:-diagram.png}"

# Step 1: Ask the LLM to generate Mermaid syntax
MERMAID_CODE=$(curl -s https://api.openai.com/v1/chat/completions \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d "{
    \"model\": \"gpt-4o\",
    \"messages\": [{
      \"role\": \"system\",
      \"content\": \"Generate ONLY valid Mermaid diagram syntax. No markdown fences, no explanation. Just the Mermaid code.\"
    }, {
      \"role\": \"user\",
      \"content\": \"Create an architecture diagram: $DESCRIPTION\"
    }],
    \"temperature\": 0.3
  }" | jq -r '.choices[0].message.content')

# Step 2: Write to temp file
echo "$MERMAID_CODE" > /tmp/diagram.mmd

# Step 3: Render with Mermaid CLI
npx -y @mermaid-js/mermaid-cli mmdc \
  -i /tmp/diagram.mmd \
  -o "$OUTPUT" \
  -t dark \
  -b transparent

echo "Diagram saved to: $OUTPUT"

8.2 Alternative: Using Kroki API (No Local Install)

#!/bin/bash
# No local tools needed โ€” just curl

DESCRIPTION="$1"
OUTPUT="${2:-diagram.svg}"

# Step 1: LLM generates Mermaid
MERMAID=$(curl -s https://api.openai.com/v1/chat/completions \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d "{
    \"model\": \"gpt-4o\",
    \"messages\": [{
      \"role\": \"system\",
      \"content\": \"Generate ONLY valid Mermaid diagram syntax. No fences, no explanation.\"
    }, {
      \"role\": \"user\",
      \"content\": \"Create an architecture diagram: $DESCRIPTION\"
    }],
    \"temperature\": 0.3
  }" | jq -r '.choices[0].message.content')

# Step 2: Render via Kroki
curl -s -X POST https://kroki.io/mermaid/svg \
  -H "Content-Type: text/plain" \
  -d "$MERMAID" \
  -o "$OUTPUT"

echo "Diagram saved to: $OUTPUT"

8.3 Results

In testing with 20 different architecture descriptions ranging from simple three-tier web apps to complex microservices with event-driven patterns, we achieved:

9. OpenClaw Skill Design

Here's the proposed architecture for the OpenClaw "diagram" skill:

9.1 Skill Manifest

---
name: diagram
description: Generate architecture diagrams from natural language descriptions.
  Supports Mermaid, PlantUML, D2, and Graphviz via Kroki API. 
  Use when asked to create, draw, or visualize any system architecture,
  sequence diagram, ER diagram, flow chart, or data pipeline.
triggers:
  - "draw a diagram"
  - "create an architecture diagram"  
  - "visualize this system"
  - "generate a sequence diagram"
  - "diagram this"
---

9.2 Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                  OpenClaw Agent                  โ”‚
โ”‚                                                  โ”‚
โ”‚  1. Receive natural language description         โ”‚
โ”‚  2. Determine diagram type (flowchart, sequence, โ”‚
โ”‚     ER, C4, etc.) from context                   โ”‚
โ”‚  3. Select target syntax (Mermaid by default)    โ”‚
โ”‚  4. Generate diagram code via LLM                โ”‚
โ”‚  5. Validate syntax                              โ”‚
โ”‚  6. Retry if invalid (max 2 attempts)            โ”‚
โ”‚  7. Render via Kroki API or local CLI            โ”‚
โ”‚  8. Return PNG/SVG to user                       โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚                        โ”‚
         โ–ผ                        โ–ผ
  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”        โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  โ”‚  Kroki API  โ”‚        โ”‚ Mermaid CLI  โ”‚
  โ”‚  (remote)   โ”‚        โ”‚  (local)     โ”‚
  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜        โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

9.3 Required Tools

9.4 Integration Points

10. Community Insights

10.1 Hacker News Perspectives

The Hacker News community is passionate about diagram-as-code tools. The Diagrams (Python) library by Mingrammer has been featured multiple times on the HN front page, with users praising its cloud-native approach. D2 generated significant discussion when launched, with many comparing it favorably to Mermaid for output quality. Recurring themes include:[13]

10.2 GitHub Trends

The most-starred repositories in the diagram-as-code space (as of February 2026):

10.3 Reddit & Developer Communities

On r/ExperiencedDevs, the consensus is shifting toward a combined approach: use Mermaid for day-to-day documentation (because of GitHub rendering), PlantUML + Copilot for detailed UML when needed, and D2 when presentation quality matters. The thread "PlantUML vs Mermaid?" (April 2025) captures this nuance well โ€” there's no single winner, but Mermaid's GitHub integration gives it the strongest default position.[14]

References

  1. Text to Diagram Tools Comparison 2025 โ€” Side-by-side comparison of D2, Mermaid, PlantUML, and Graphviz
  2. Mermaid.js Official Documentation โ€” mermaid.js.org
  3. PlantUML Official Site โ€” plantuml.com
  4. D2 Language โ€” Terrastruct โ€” d2lang.com
  5. Graphviz โ€” Graph Visualization Software โ€” graphviz.org
  6. Diagrams (Python) โ€” Diagram as Code โ€” diagrams.mingrammer.com
  7. Structurizr โ€” C4 Model Architecture โ€” structurizr.com
  8. Kroki โ€” Creates diagrams from textual descriptions โ€” kroki.io
  9. Kroki Integration โ€” GitLab Docs โ€” docs.gitlab.com
  10. Pikchr โ€” A PIC-like markup language for diagrams โ€” pikchr.org
  11. How to Choose the Best AI Diagram Generator (2025) โ€” Mermaid Chart Blog
  12. Mermaid vs. PlantUML Comparison โ€” Gleek.io
  13. Diagram as Code โ€” Hacker News Discussion โ€” news.ycombinator.com
  14. PlantUML vs Mermaid? โ€” r/ExperiencedDevs โ€” reddit.com (April 2025)
๐Ÿ›ก๏ธ No Third-Party Tracking