Skip to main content
Developer 8 min read · In-depth 2026-04-13

Mermaid Diagrams for Technical Documentation: A Complete Guide

Mermaid lets you create diagrams from text. Learn the syntax for flowcharts, sequence diagrams, Gantt charts, and more — directly in your documentation.

1

Why Text-Based Diagrams Transform Documentation

Technical documentation that relies on image-based diagrams has a maintenance problem. When the system architecture evolves — a new service is added, an API endpoint changes, a database relationship is modified — someone has to open a diagramming tool, find the original file, make the edit, export a new image, and upload it to the documentation. This friction is why so many diagrams in technical documentation become stale and inaccurate within weeks or months of their creation.

Mermaid solves this by treating diagrams as code. Instead of dragging boxes and connectors in a visual editor, you write a simple text description of the diagram, and Mermaid renders it as a visual graphic. The text lives in the same repository as your code and documentation, which means it can be updated in the same pull request as the changes it describes. Reviewers can see exactly what changed in the diagram by reading the diff — something impossible with binary image files.

The adoption of Mermaid has been accelerated by native support in platforms like GitHub, GitLab, Notion, Obsidian, Docusaurus, and MkDocs. Write a code block tagged with the mermaid language in any Markdown file on GitHub, and the platform renders it as a diagram automatically. No uploads, no image exports, no separate files to manage. This zero-friction workflow is what makes diagrams-as-code practical for teams that previously found diagramming too cumbersome to maintain.

Mermaid supports a growing range of diagram types: flowcharts, sequence diagrams, class diagrams, state diagrams, entity-relationship diagrams, Gantt charts, pie charts, mind maps, and more. Each type has a concise syntax designed to be readable even before rendering. This guide covers the most useful types for technical documentation, with practical syntax examples you can adapt to your own projects.

2

Flowcharts: Decision Trees and Process Flows

Flowcharts are the most versatile diagram type for technical documentation. They model decision logic, user journeys, deployment pipelines, error handling, and any process with branches and sequences.

The basic Mermaid flowchart syntax uses short identifiers for nodes and arrows for connections:

flowchart TD
A[Start] --> B{Decision?}
B -->|Yes| C[Action A]
B -->|No| D[Action B]
C --> E[End]
D --> E

The TD directive sets the flow direction to top-down. You can also use LR (left-right), RL (right-left), or BT (bottom-top). Node shapes convey meaning: square brackets [text] create rectangles, curly braces {text} create decision diamonds, and rounded parentheses (text) create stadium-shaped nodes for start and end points.

For more complex flows, use subgraph blocks to group related nodes visually. This adds structure without changing the underlying logic:

flowchart LR
subgraph Frontend
A[UI] --> B[API Client]
end
subgraph Backend
C[API Server] --> D[Database]
end
B --> C

Flowcharts are ideal for documenting algorithms, authentication flows, data processing pipelines, and user onboarding journeys. A developer reading your authentication docs can trace the flowchart from login attempt through token validation to session creation and immediately understand the complete state machine.

3

Sequence Diagrams: API Interactions and Message Flows

Sequence diagrams show how components interact over time, making them perfect for documenting API calls, microservice communication, authentication handshakes, and any scenario where multiple actors exchange messages in order.

A simple OAuth2 flow in Mermaid:

sequenceDiagram
participant User
participant App
participant Auth
participant API
User->>App: Click Login
App->>Auth: Redirect /authorize
Auth->>User: Show consent
User->>Auth: Grant permission
Auth->>App: Return auth code
App->>Auth: Exchange code for token
Auth->>App: Return access token
App->>API: Request with token
API->>App: Return data
App->>User: Display data

Participants are displayed across the top, and messages flow vertically in chronological order. Solid arrows (->>) represent synchronous calls, while dashed arrows (-->>) represent responses or asynchronous messages. You can add activation boxes with activate and deactivate to show when a participant is actively processing.

Sequence diagrams are invaluable for API documentation and integration guides. Instead of describing a multi-step flow in paragraphs of prose, you present it visually and let readers trace the interactions themselves. This is especially powerful for debugging: when an integration fails, developers can compare actual network calls against the documented sequence and immediately spot where the flow diverged.

For distributed systems, sequence diagrams clarify causality that is hard to express in text. A request that fans out to three services, aggregates the responses, and returns a composite result can be described in words, but a sequence diagram shows the parallelism, the dependencies, and the failure modes at a glance.

4

Class Diagrams and Entity-Relationship Diagrams

Class diagrams document object-oriented systems, showing classes, their attributes and methods, and the relationships between them. Mermaid class diagram syntax maps closely to UML conventions:

classDiagram
class User {
+String name
+String email
+login()
+logout()
}
class Order {
+Date created
+String status
+total() float
}
User "1" --> "*" Order : places

This renders as two class boxes with their properties and methods, connected by an arrow indicating that one User places zero or more Orders. The + prefix denotes public visibility; you can use - for private and # for protected members. Relationship notations include --> (association), --|> (inheritance), ..|> (implementation), and ..> (dependency).

Entity-relationship diagrams (ERDs) serve a related purpose for database documentation:

erDiagram
CUSTOMER ||--o{ ORDER : places
ORDER ||--|{ LINE_ITEM : contains
PRODUCT ||--o{ LINE_ITEM : includes
CUSTOMER {
int id PK
string name
string email
}
ORDER {
int id PK
date created_at
string status
}

ERDs use cardinality notation like ||--o{ (one-to-many) and ||--|{ (one-to-one-or-more) to express relationships. The PK and FK annotations clarify primary and foreign keys. For database migrations, onboarding new developers, or planning schema changes, an up-to-date ERD is worth dozens of Slack messages asking how tables relate to each other.

5

Gantt Charts, State Diagrams, and Pie Charts

Gantt charts in Mermaid visualize project timelines and task dependencies. Each task has a start date, duration, and optional dependency on other tasks:

gantt
title Project Timeline
dateFormat YYYY-MM-DD
section Planning
Requirements :done, req, 2026-04-01, 10d
Design :active, des, after req, 7d
section Development
Backend : back, after des, 14d
Frontend : front, after des, 12d
section Testing
QA : qa, after back, 7d

Gantt charts are useful for project documentation where stakeholders need to see the planned timeline, task dependencies, and current progress. The done, active, and default states provide visual cues about task status.

State diagrams model systems with discrete states and transitions between them — perfect for documenting order statuses, payment flows, and application state machines:

stateDiagram-v2
[*] --> Draft
Draft --> Review : Submit
Review --> Approved : Accept
Review --> Draft : Reject
Approved --> Published : Publish
Published --> Archived : Archive
Archived --> [*]

Pie charts provide a quick way to visualize proportional data in documentation — market share, time allocation, bug distribution by category, or resource usage:

pie title Task Distribution
"Development" : 40
"Testing" : 20
"Meetings" : 15
"Documentation" : 15
"Admin" : 10

Each diagram type serves a different documentation need. Flowcharts for processes, sequences for interactions, class diagrams for code structure, ERDs for databases, Gantt charts for timelines, state diagrams for lifecycle logic, and pie charts for proportions.

6

Integrating Mermaid into Your Documentation Workflow

The practical power of Mermaid becomes apparent when you integrate it into your existing documentation workflow. Because Mermaid renders from text, it works wherever Markdown works — and Markdown works nearly everywhere.

In GitHub repositories, create a code block with the mermaid language tag in any README, issue, pull request, or discussion comment. GitHub renders the diagram inline without any configuration. This makes it trivially easy to add architecture diagrams to README files, flowcharts to pull request descriptions, and sequence diagrams to issue comments.

In documentation sites, most static site generators support Mermaid through plugins or built-in integration. Docusaurus has an official Mermaid plugin. MkDocs supports it through the mkdocs-mermaid2-plugin. Astro, Next.js, and Hugo all have community plugins. Once configured, you write Mermaid code blocks in your Markdown files and they render automatically during the build process.

In the Utiliify Mermaid Chart Editor, you can write, preview, and iterate on Mermaid diagrams in real time before embedding them in your documentation. The editor provides instant visual feedback as you type, making it easy to experiment with syntax, adjust layouts, and verify that the diagram communicates clearly before you commit the code to your repository.

A recommended workflow: draft the diagram in the Mermaid Chart Editor until it communicates clearly, then copy the Mermaid code into your Markdown documentation. The diagram now lives as version-controlled text alongside your documentation. When the system changes, you update the Mermaid code in the same commit that updates the code and prose — keeping everything in sync with minimal effort.

More Guides

View all