Diagram as code

Updated

Diagram as code (also written diagrams as code) is the practice of defining a diagram in a text based language that a tool renders into a picture. Because the source is plain text, the diagram can be stored in version control, reviewed in a pull request and updated together with the software it describes.

How diagram as code works

The author writes a short description of the elements and their relationships. A renderer reads the text, chooses positions for the shapes and draws the result. The author controls what is in the diagram and leaves most of the layout to the tool.

A small example in Mermaid syntax:

flowchart LR
  Client --> API
  API --> Database
  API --> Cache

This produces four boxes connected by three arrows, laid out from left to right.

Common diagram as code tools

  • Mermaid. A widely used syntax that renders in many documentation tools. See Mermaid diagram.

  • PlantUML. A long established tool with strong support for UML.

  • Graphviz. Uses the DOT language for graphs and networks.

  • D2 and Structurizr. Newer tools aimed at software architecture, the latter built around the C4 model.

Benefits

  • Version history. Every change is a readable difference in text.

  • Review. Diagrams go through the same review as code.

  • Consistency. Layout and style are applied by the tool, so diagrams look alike.

  • Automation. Diagrams can be generated from code, configuration or an AI model.

Limitations

  • Layout control. Automatic layout rarely matches what a person would draw for a large or dense diagram.

  • Audience. People outside engineering are unlikely to edit a text syntax.

  • Exploration. Sketching options in a workshop is faster on a canvas than in a text file.

For these reasons many teams use both: code for reference diagrams that live with the repository, and a visual board for design discussions.

Diagram as code vs text to diagram

Text to diagram is the wider idea of creating a diagram from any written input, including a plain sentence interpreted by AI. Diagram as code is the stricter form, in which the text follows a defined syntax and gives the same result every time.

Example

A platform team keeps a sequence diagram of its login flow as a Mermaid file beside the service code. When a developer adds a token refresh step, the same pull request changes the code and the diagram, and the reviewer sees both.

Diagram as code in MockFlow

MockFlow offers a visual route to the same diagrams. The Mermaid diagram editor artifact brings Mermaid onto a board, and coding tools such as Claude Code, Cursor and VS Code can create editable boards through the MockFlow MCP server, so a diagram described in the terminal becomes one the whole team can open. See whiteboard for Claude Code and whiteboard for developers.

MockFlow

Turn ideas into plans on one board.

No account needed
mockflow.com/new

Open a blank board in one click. Boards last 24 hours, so sign up to keep one.

MCPBrainstorm with MockFlow MCP

Add MockFlow as an MCP connector in Claude, Cursor, or any MCP-compatible AI assistant to generate flowcharts, mindmaps, architecture diagrams, and 16 types of visualizations.

Desktop App MCP Powerful
CLI Web MCP Developer
Web MCP Easiest

Built into the MockFlow Desktop App. AI creates visuals directly on your open canvas — no URLs, no waiting.

1
Open Desktop App → open a MockFlow project
2
In Claude Code / Cursor, run:
claude mcp add --transport http -s user mockflow-ideaboard http://localhost:21193/mcp
3
Ask: "Create a flowchart for..."

Best for: Designers, product teams, daily MockFlow users.

Download Desktop App →

Install from npm, log in via browser (OAuth), and boards are saved to your MockFlow account.

1
npm install -g @mockflow/ideaboard-mcp
2
mockflow-ideaboard-mcp login
3
mockflow-ideaboard-mcp

Best for: Developers using Claude Code, Cursor, or VS Code Copilot.

npm Package →

Add MockFlow as a connector in Claude.ai or ChatGPT. No installation. A new board is created and you get a shareable URL.

1
Open Claude.ai → Settings → Connectors
2
Paste this URL, then click Connect and sign in to MockFlow: https://app.mockflow.com/ideaboard/connector/mcp
3
Ask Claude to create a flowchart — done!

ChatGPT: use https://app.mockflow.com/ideaboard/mcp and save its boards to your account to keep them

Best for: Managers, marketers, anyone using Claude.ai or ChatGPT in the browser.

Welcome back
Don't have an account? Sign up

Faster ways in

Sign in with an account you already use.