Mermaid Diagrams
Create professional software diagrams using Mermaid's text-based syntax. Mermaid renders diagrams from simple text definitions, making diagrams version-controllable, easy to update, and maintainable alongside code.
Installation
OpenClaw / Moltbot / Clawbot
npx clawhub@latest install mermaid-diagrams
Core Syntax
All Mermaid diagrams follow this pattern:
diagramType
definition content
Key principles:
- First line declares diagram type (e.g.,
classDiagram, sequenceDiagram, flowchart)
- Use
%% for comments
- Line breaks and indentation improve readability but aren't required
- Unknown words break diagrams; invalid parameters fail silently
Diagram Type Selection
| Type |
Use For |
Reference |
| Class Diagrams |
Domain modeling, OOP design, entity relationships |
references/class-diagrams.md |
| Sequence Diagrams |
API flows, auth flows, component interactions |
references/sequence-diagrams.md |
| Flowcharts |
Processes, algorithms, decision trees, user journeys |
references/flowcharts.md |
| ERD |
Database schemas, table relationships, data modeling |
references/erd-diagrams.md |
| C4 Diagrams |
System context, containers, components, architecture |
references/c4-diagrams.md |
| State Diagrams |
State machines, lifecycle states |
— |
| Git Graphs |
Branching strategies |
— |
| Gantt Charts |
Project timelines, scheduling |
— |
For styling, themes, and layout options: See references/advanced-features.md
Quick Start Examples
Class Diagram (Domain Model)
classDiagram
Title -- Genre
Title *-- Season
Title *-- Review
User --> Review : creates
class Title {
+string name
+int releaseYear
+play()
}
class Genre {
+string name
+getTopTitles()
}
Sequence Diagram (API Flow)
sequenceDiagram
participant User
participant API
participant Database
User->>API: POST /login
API->>Database: Query credentials
Database-->>API: Return user data
alt Valid credentials
API-->>User: 200 OK + JWT token
else Invalid credentials
API-->>User: 401 Unauthorized
end
Flowchart (User Journey)
flowchart TD
Start([User visits site]) --> Auth{Authenticated?}
Auth -->|No| Login[Show login page]
Auth -->|Yes| Dashboard[Show dashboard]
Login --> Creds[Enter credentials]
Creds --> Validate{Valid?}
Validate -->|Yes| Dashboard
Validate -->|No| Error[Show error]
Error --> Login
ERD (Database Schema)
erDiagram
USER ||--o{ ORDER : places
ORDER ||--|{ LINE_ITEM : contains
PRODUCT ||--o{ LINE_ITEM : includes
USER {
int id PK
string email UK
string name
datetime created_at
}
ORDER {
int id PK
int user_id FK
decimal total
datetime created_at
}
Best Practices
- Start simple — begin with core entities/components, add details incrementally
- Use meaningful names — clear labels make diagrams self-documenting
- Comment extensively — use
%% comments to explain complex relationships
- Keep focused — one diagram per concept; split large diagrams into multiple views
- Version control — store
.mmd files alongside code for easy updates
- Add context — include titles and notes to explain diagram purpose
- Iterate — refine diagrams as understanding evolves
Configuration and Theming
Configure diagrams using frontmatter:
---
config:
theme: base
themeVariables:
primaryColor: "#ff6b6b"
---
flowchart LR
A --> B
Available themes: default, forest, dark, neutral, base
Layout options:
layout: dagre (default) — classic balanced layout
layout: elk — advanced layout for complex diagrams
Look options:
look: classic — traditional Mermaid style
look: handDrawn — sketch-like appearance
Rendering and Export
Native support in:
- GitHub/GitLab — automatically renders in Markdown
- VS Code — with Markdown Mermaid extension
- Notion, Obsidian, Confluence — built-in support
Export options:
- Mermaid Live Editor — online editor with PNG/SVG export
- Mermaid CLI —
npm install -g @mermaid-js/mermaid-cli then mmdc -i input.mmd -o output.png
When to Create Diagrams
Always diagram when:
- Starting new projects or features
- Documenting complex systems
- Explaining architecture decisions
- Designing database schemas
- Planning refactoring efforts
- Onboarding new team members
Use diagrams to:
- Align stakeholders on technical decisions
- Document domain models collaboratively
- Visualize data flows and system interactions
- Plan before coding
- Create living documentation that evolves with code
Common Pitfalls
- Breaking characters — avoid
{} in comments; escape special characters
- Syntax errors — misspellings break diagrams; validate in Mermaid Live
- Overcomplexity — split complex diagrams into multiple focused views
- Missing relationships — document all important connections between entities
- Stale diagrams — a wrong diagram is worse than no diagram; update when systems change
NEVER Do
- NEVER create diagrams with more than 15 nodes — they become unreadable; split into multiple focused diagrams
- NEVER leave arrows unlabeled — every connection should explain the relationship or data flow
- NEVER create diagrams without a title or caption — context-free diagrams are useless outside the author's head
- NEVER use diagrams as the sole documentation — pair diagrams with prose that explains the "why"
- NEVER let diagrams go stale — update diagrams when architecture changes; stale diagrams mislead
- NEVER use Mermaid for data visualization — Mermaid is for architecture and flow diagrams, not charts of business data
1---
2name: mermaid-diagrams
3model: fast
4version: 1.0.0
5description: >
6 Create software diagrams using Mermaid syntax. Use when users need to create, visualize,
7 or document software through diagrams including class diagrams, sequence diagrams, flowcharts,
8 ERDs, C4 architecture diagrams, state diagrams, git graphs, and other diagram types. Triggers
9 include requests to diagram, visualize, model, map out, or show the flow of a system.
10tags: [diagrams, mermaid, visualization, architecture, documentation, modeling]
11metadata:
12 source: https://skillmd.com/skills/modbender/mermaid-diagrams
13---
14
15# Mermaid Diagrams
16
17Create professional software diagrams using Mermaid's text-based syntax. Mermaid renders diagrams from simple text definitions, making diagrams version-controllable, easy to update, and maintainable alongside code.
18
19
20## Installation
21
22### OpenClaw / Moltbot / Clawbot
23
24```bash
25npx clawhub@latest install mermaid-diagrams
26```
27
28
29## Core Syntax
30
31All Mermaid diagrams follow this pattern:
32
33```mermaid
34diagramType
35 definition content
36```
37
38**Key principles:**
39- First line declares diagram type (e.g., `classDiagram`, `sequenceDiagram`, `flowchart`)
40- Use `%%` for comments
41- Line breaks and indentation improve readability but aren't required
42- Unknown words break diagrams; invalid parameters fail silently
43
44## Diagram Type Selection
45
46| Type | Use For | Reference |
47|------|---------|-----------|
48| **Class Diagrams** | Domain modeling, OOP design, entity relationships | `references/class-diagrams.md` |
49| **Sequence Diagrams** | API flows, auth flows, component interactions | `references/sequence-diagrams.md` |
50| **Flowcharts** | Processes, algorithms, decision trees, user journeys | `references/flowcharts.md` |
51| **ERD** | Database schemas, table relationships, data modeling | `references/erd-diagrams.md` |
52| **C4 Diagrams** | System context, containers, components, architecture | `references/c4-diagrams.md` |
53| **State Diagrams** | State machines, lifecycle states | — |
54| **Git Graphs** | Branching strategies | — |
55| **Gantt Charts** | Project timelines, scheduling | — |
56
57**For styling, themes, and layout options**: See `references/advanced-features.md`
58
59## Quick Start Examples
60
61### Class Diagram (Domain Model)
62
63```mermaid
64classDiagram
65 Title -- Genre
66 Title *-- Season
67 Title *-- Review
68 User --> Review : creates
69
70 class Title {
71 +string name
72 +int releaseYear
73 +play()
74 }
75
76 class Genre {
77 +string name
78 +getTopTitles()
79 }
80```
81
82### Sequence Diagram (API Flow)
83
84```mermaid
85sequenceDiagram
86 participant User
87 participant API
88 participant Database
89
90 User->>API: POST /login
91 API->>Database: Query credentials
92 Database-->>API: Return user data
93 alt Valid credentials
94 API-->>User: 200 OK + JWT token
95 else Invalid credentials
96 API-->>User: 401 Unauthorized
97 end
98```
99
100### Flowchart (User Journey)
101
102```mermaid
103flowchart TD
104 Start([User visits site]) --> Auth{Authenticated?}
105 Auth -->|No| Login[Show login page]
106 Auth -->|Yes| Dashboard[Show dashboard]
107 Login --> Creds[Enter credentials]
108 Creds --> Validate{Valid?}
109 Validate -->|Yes| Dashboard
110 Validate -->|No| Error[Show error]
111 Error --> Login
112```
113
114### ERD (Database Schema)
115
116```mermaid
117erDiagram
118 USER ||--o{ ORDER : places
119 ORDER ||--|{ LINE_ITEM : contains
120 PRODUCT ||--o{ LINE_ITEM : includes
121
122 USER {
123 int id PK
124 string email UK
125 string name
126 datetime created_at
127 }
128
129 ORDER {
130 int id PK
131 int user_id FK
132 decimal total
133 datetime created_at
134 }
135```
136
137## Best Practices
138
1391. **Start simple** — begin with core entities/components, add details incrementally
1402. **Use meaningful names** — clear labels make diagrams self-documenting
1413. **Comment extensively** — use `%%` comments to explain complex relationships
1424. **Keep focused** — one diagram per concept; split large diagrams into multiple views
1435. **Version control** — store `.mmd` files alongside code for easy updates
1446. **Add context** — include titles and notes to explain diagram purpose
1457. **Iterate** — refine diagrams as understanding evolves
146
147## Configuration and Theming
148
149Configure diagrams using frontmatter:
150
151```mermaid
152---
153config:
154 theme: base
155 themeVariables:
156 primaryColor: "#ff6b6b"
157---
158flowchart LR
159 A --> B
160```
161
162**Available themes:** default, forest, dark, neutral, base
163
164**Layout options:**
165- `layout: dagre` (default) — classic balanced layout
166- `layout: elk` — advanced layout for complex diagrams
167
168**Look options:**
169- `look: classic` — traditional Mermaid style
170- `look: handDrawn` — sketch-like appearance
171
172## Rendering and Export
173
174**Native support in:**
175- GitHub/GitLab — automatically renders in Markdown
176- VS Code — with Markdown Mermaid extension
177- Notion, Obsidian, Confluence — built-in support
178
179**Export options:**
180- [Mermaid Live Editor](https://mermaid.live) — online editor with PNG/SVG export
181- Mermaid CLI — `npm install -g @mermaid-js/mermaid-cli` then `mmdc -i input.mmd -o output.png`
182
183## When to Create Diagrams
184
185**Always diagram when:**
186- Starting new projects or features
187- Documenting complex systems
188- Explaining architecture decisions
189- Designing database schemas
190- Planning refactoring efforts
191- Onboarding new team members
192
193**Use diagrams to:**
194- Align stakeholders on technical decisions
195- Document domain models collaboratively
196- Visualize data flows and system interactions
197- Plan before coding
198- Create living documentation that evolves with code
199
200## Common Pitfalls
201
202- **Breaking characters** — avoid `{}` in comments; escape special characters
203- **Syntax errors** — misspellings break diagrams; validate in Mermaid Live
204- **Overcomplexity** — split complex diagrams into multiple focused views
205- **Missing relationships** — document all important connections between entities
206- **Stale diagrams** — a wrong diagram is worse than no diagram; update when systems change
207
208## NEVER Do
209
2101. **NEVER create diagrams with more than 15 nodes** — they become unreadable; split into multiple focused diagrams
2112. **NEVER leave arrows unlabeled** — every connection should explain the relationship or data flow
2123. **NEVER create diagrams without a title or caption** — context-free diagrams are useless outside the author's head
2134. **NEVER use diagrams as the sole documentation** — pair diagrams with prose that explains the "why"
2145. **NEVER let diagrams go stale** — update diagrams when architecture changes; stale diagrams mislead
2156. **NEVER use Mermaid for data visualization** — Mermaid is for architecture and flow diagrams, not charts of business data