# Diagram as Code: Replace Lucidchart With AI and Draw.io

Source: https://truvocyber.com/blog/diagram-as-code-replaced-lucidchart
Published: 2026-06-26
Topic cluster: Cybersecurity

> Generate architecture diagrams, data flows, and network diagrams from code using AI and draw.io. Free, version-controlled, and fast.

Diagram as code means generating architecture diagrams, data flows, and network diagrams from text. We describe the architecture to [Claude Code](https://docs.anthropic.com/en/docs/claude-code/overview), which writes Mermaid or [draw.io](https://www.drawio.com/) XML. A first draft that used to take an hour now takes seconds, plus up to 15 minutes of human finishing.

As a cybersecurity consulting firm, one of the first things we do with any client is map the architecture: network diagrams, data flow diagrams, and system architecture. Here is how we replaced Lucidchart and most of the manual work.
 

## Why is manual diagramming so slow?

The traditional workflow:

1. Sit in a meeting. Listen to the client describe the architecture.

2. Open Lucidchart or Visio. Stare at a blank canvas.

3. Drag boxes for 30 minutes to get the layout roughly right.

4. Spend another 30 minutes on colors, alignment, labels, and legends.

5. Send the draft for review. The client says "actually, the load balancer goes here."

6. Redo half of the diagram.

7. The architecture changes next quarter, and nobody updates the diagram.

The blank page is the hardest part, especially for junior team members who are not sure what the diagram should look like.
 

## How does diagram as code work with draw.io?

Every [draw.io](https://www.drawio.com/) file is an XML document describing shapes, positions, connections, colors, and labels. If you can edit XML, you can edit a draw.io diagram without opening the GUI, and AI edits XML well.

The workflow:

1. Describe the architecture to Claude.

2. Point Claude at a previous diagram as a template.

3. [Claude Code](https://docs.anthropic.com/en/docs/claude-code/overview) generates a new draw.io file from scratch.

The result is a normal, editable diagram anyone can open in draw.io. No special tools and no paid subscriptions.
 

## Mermaid or draw.io: which should you use?

### When should you use Mermaid?

[Mermaid](https://mermaid.js.org/) is a text-based diagramming syntax. You write something like:
```mermaid
    graph LR 
    A[Client] --> B[Load Balancer] 
    B --> C[App Server] 
    C --> D[Database]
```

![Mermaid data flow diagram: Client to Load Balancer to App Server to Database](https://341945322.fs1.hubspotusercontent-na3.net/hubfs/341945322/image-png.png)

Claude generates the Mermaid syntax from a plain-language description, and the output needs almost no manual editing. Mermaid works best for:

- Data flow diagrams

- Sequence diagrams

- Simple architecture overviews

- Process flows

- Anything where relationships matter more than physical layout

Mermaid controls the layout automatically, so you cannot position elements by hand. Network diagrams that show physical or logical topology need more control.

### When should you use draw.io XML?

For diagrams where layout matters, Claude generates the complete draw.io XML: shapes, positions, connections, styles, colors, and labels. The file opens in draw.io as a finished diagram.

**Templates keep deliverables consistent.** We keep templates from previous engagements. For a new diagram, we point Claude at a similar one and ask for a new version with specific changes.
 

## How do you color-code network diagrams by risk?

Claude applies one color system for traffic risk:

TRAFFIC RISK COLOR CONVENTIONS

**Red** - Inbound traffic from the internet (highest risk, before any filtering)

**Yellow** - Traffic after the firewall or WAF (filtered but still external-origin)

**Green** - Internal traffic from trusted sources

Anyone can read the risk of each traffic path at a glance, without reading labels. Once the convention lives in a template, Claude applies the colors correctly every time.
 

## How accurate are AI-generated diagrams?

- **Data flow diagrams: nearly perfect.** Mermaid data flows are almost always production-ready on the first try. You might tweak a label or reorder a flow.

- **System architecture: 70 to 80 percent right.** Components, connections, and groupings (VPC, subnets, availability zones) are correct. The layout needs some manual adjustment.

- **Network diagrams: need human finishing.** AI puts the right components in roughly the right places with the right colors. Topology, routing, and spatial arrangement still need a human eye.

**The real win:** finishing takes 10 to 15 minutes, compared with an hour or more from scratch. You polish a draft instead of starting from a blank canvas.
 

## What does the diagram-as-code stack cost?

- **[Draw.io](https://www.drawio.com/):** free and open source, desktop or browser

- **Claude Code:** generates and edits diagram XML

- **GitHub:** stores diagrams with version control

- **[Mermaid](https://mermaid.js.org/):** free, and renders in GitHub, VS Code, and most documentation tools

Total cost: whatever you already pay for Claude. We cancelled our Lucidchart subscription and no longer pay per seat or hit usage limits.

### What about real-time collaboration?

Lucidchart and Miro are better at live multi-user editing. Our team versions the files in GitHub and takes turns: pull, edit, push. If your workflow depends on simultaneous editing, weigh that tradeoff. For most small teams the tradeoff does not matter.
 

## What do clients get from diagram as code?

- **Faster delivery.** Architecture documentation arrives early in the engagement, not weeks later.

- **Diagrams that stay current.** Updating a diagram means editing the XML or regenerating from a new description, so diagrams actually change when the architecture does.

- **Consistent quality.** Color conventions, layout patterns, and labels live in templates, so every client gets the same visual language.

- **Client access.** The files live in the client's GitHub repo. Clients can open, edit, and share them in draw.io with no license.

- **Edits without the GUI.** Labels, colors, and component positions change through a prompt to Claude. Batch changes across a dozen client engagements save real time.

 

### Architecture Reviews, Automated

We build effective security programs with documentation that stays current.

[Book Your Strategy Call](/contact-us)

 

## How do you get started with diagram as code?

1. **Start with Mermaid.** Pick a data flow you need. Ask Claude or ChatGPT for Mermaid syntax and paste the result into the [Mermaid Live Editor](https://mermaid.live/).

2. **Try a draw.io generation.** Ask Claude for a simple architecture diagram as a draw.io XML file, then open the file in draw.io.

3. **Set color conventions early.** Encode a color system in a template so every diagram uses the same colors.

4. **Version control your diagrams.** Keep them in a Git repo so you can see what changed between versions as client architectures evolve.

Part of our [Consulting as Code](/blog/what-is-consulting-as-code) series.

**More in this series:**

- [What Is Consulting as Code?](/blog/what-is-consulting-as-code)

- [GRC Engineering: What It Looks Like in Practice](/blog/grc-engineering)

- [Google Search Console API + Claude](/blog)

- [Down With .docx, Long Live .md](/blog/why-we-switched-to-markdown)

- [How to Create a Security Architecture Diagram (With a Worked Example)](/blog/how-to-create-a-security-architecture-diagram)

 

## Frequently Asked Questions

### What is diagram as code?

Diagram as code means defining architecture diagrams, data flows, and network diagrams in text, using Mermaid or draw.io XML, instead of dragging shapes in a GUI. The file can be version-controlled, generated by AI, and rendered on demand.

### Can AI generate draw.io XML files directly?

Yes. Draw.io files are XML documents that describe shapes, connections, positions, colors, and labels. Claude can generate complete draw.io XML from a text description, and the file opens in draw.io as a fully editable diagram.

### Is Mermaid or draw.io XML better for architecture diagrams?

Mermaid fits data flows, sequence diagrams, and process flows, where relationships matter more than layout. Draw.io XML fits network diagrams and system architecture, where the position of components matters. We use both.

### Can diagram as code replace Lucidchart or Visio?

For most small and mid-size teams, yes. Draw.io is free and open source, and AI-generated XML removes the blank-page problem. Commercial tools still lead on real-time multi-user editing.

### How do you keep AI-generated diagrams consistent across projects?

Templates. We keep draw.io XML templates with standard color conventions, layout patterns, and labels, and point Claude at a template for each new diagram. Git keeps every team member on the same templates.
