Mermaid Diagrams
Generate diagrams in markdown that render in GitHub, GitLab, VS Code, Obsidian, Notion.
Quick Start
```mermaid
flowchart LR
A[Start] --> B{Decision}
B -->|Yes| C[Action]
B -->|No| D[End]
```
Quick Decision Tree
What to visualize?
├─ Process, algorithm, decision flow → flowchart
├─ API calls, service interactions → sequenceDiagram
├─ Database tables, relationships → erDiagram
├─ OOP, type hierarchy, domain model → classDiagram
├─ State machine, lifecycle → stateDiagram-v2
├─ System architecture, services → flowchart + subgraphs (or C4Context)
├─ Project timeline, sprints → gantt
├─ User experience, pain points → journey
├─ Git branches → gitGraph
├─ Data distribution → pie
└─ Priority matrix → quadrantChart
Diagram Types
| Type |
Declaration |
Best For |
| Flowchart |
flowchart LR/TB |
Processes, decisions, data flow |
| Sequence |
sequenceDiagram |
API flows, service calls |
| ER |
erDiagram |
Database schemas |
| Class |
classDiagram |
Types, domain models |
| State |
stateDiagram-v2 |
State machines |
| Gantt |
gantt |
Project timelines |
| Journey |
journey |
User experience |
| C4 |
C4Context |
System architecture |
| Git |
gitGraph |
Branch visualization |
Common Patterns
System Architecture
flowchart LR
subgraph Client
Browser & Mobile
end
subgraph Services
API --> Auth & Core
end
subgraph Data
DB[(PostgreSQL)]
end
Client --> API
Core --> DB
API Request Flow
sequenceDiagram
autonumber
Client->>+API: POST /orders
API->>Auth: Validate
Auth-->>API: OK
API->>+DB: Insert
DB-->>-API: ID
API-->>-Client: 201 Created
Database Schema
erDiagram
USER ||--o{ ORDER : places
ORDER ||--|{ LINE_ITEM : contains
USER { uuid id PK; string email UK }
ORDER { uuid id PK; uuid user_id FK }
State Machine
stateDiagram-v2
[*] --> Draft
Draft --> Submitted : submit()
Submitted --> Approved : approve()
Submitted --> Rejected : reject()
Approved --> [*]
Syntax Quick Reference
Flowchart Nodes
[Rectangle] (Rounded) {Diamond} [(Database)] [[Subroutine]]
((Circle)) >Asymmetric] {{Hexagon}}
Flowchart Edges
A --> B # Arrow
A --- B # Line
A -.-> B # Dotted arrow
A ==> B # Thick arrow
A -->|text| B # Labeled
Sequence Arrows
->> # Solid arrow (request)
-->> # Dotted arrow (response)
-x # X end (async)
-) # Open arrow
ER Cardinality
||--|| # One to one
||--o{ # One to many
}o--o{ # Many to many
Best Practices
- Choose the right type — Use decision tree above
- Keep focused — One concept per diagram
- Use meaningful labels — Not just A, B, C
- Direction matters —
LR for flows, TB for hierarchies
- Group with subgraphs — Organize related nodes
Reference Documentation
| File |
Purpose |
| references/FLOWCHARTS.md |
Nodes, edges, subgraphs, styling |
| references/SEQUENCE.md |
Participants, messages, activation |
| references/CLASS-ER.md |
Classes, ER diagrams, relationships |
| references/STATE-JOURNEY.md |
States, user journeys |
| references/DATA-CHARTS.md |
Gantt, Pie, Timeline, Quadrant |
| references/ARCHITECTURE.md |
C4, Block, Kanban |
| references/CHEATSHEET.md |
All syntax quick reference |
Resources
1---2name: mermaid-diagrams-43description: Generate Mermaid diagrams in markdown. Triggers on: diagrams, charts, visualizations, flowcharts, sequence diagrams, architecture diagrams, ER diagrams, state machines, Gantt charts, mindmaps, C4, class diagrams, git graphs. Use when: user asks for visual representations of code, systems, processes, data structures, database schemas, workflows, or API flows. Proactively suggest diagrams when explaining complex systems.4---5
6# Mermaid Diagrams
7
8Generate diagrams in markdown that render in GitHub, GitLab, VS Code, Obsidian, Notion.
9
10## Quick Start
11
12````markdown
13```mermaid
14flowchart LR
15 A[Start] --> B{Decision}
16 B -->|Yes| C[Action]
17 B -->|No| D[End]
18```
19````
20
21## Quick Decision Tree
22
23```
24What to visualize?
25├─ Process, algorithm, decision flow → flowchart
26├─ API calls, service interactions → sequenceDiagram
27├─ Database tables, relationships → erDiagram
28├─ OOP, type hierarchy, domain model → classDiagram
29├─ State machine, lifecycle → stateDiagram-v2
30├─ System architecture, services → flowchart + subgraphs (or C4Context)
31├─ Project timeline, sprints → gantt
32├─ User experience, pain points → journey
33├─ Git branches → gitGraph
34├─ Data distribution → pie
35└─ Priority matrix → quadrantChart
36```
37
38## Diagram Types
39
40| Type | Declaration | Best For |
41|------|-------------|----------|
42| **Flowchart** | `flowchart LR/TB` | Processes, decisions, data flow |
43| **Sequence** | `sequenceDiagram` | API flows, service calls |
44| **ER** | `erDiagram` | Database schemas |
45| **Class** | `classDiagram` | Types, domain models |
46| **State** | `stateDiagram-v2` | State machines |
47| **Gantt** | `gantt` | Project timelines |
48| **Journey** | `journey` | User experience |
49| **C4** | `C4Context` | System architecture |
50| **Git** | `gitGraph` | Branch visualization |
51
52## Common Patterns
53
54### System Architecture
55
56```mermaid
57flowchart LR
58 subgraph Client
59 Browser & Mobile
60 end
61 subgraph Services
62 API --> Auth & Core
63 end
64 subgraph Data
65 DB[(PostgreSQL)]
66 end
67 Client --> API
68 Core --> DB
69```
70
71### API Request Flow
72
73```mermaid
74sequenceDiagram
75 autonumber
76 Client->>+API: POST /orders
77 API->>Auth: Validate
78 Auth-->>API: OK
79 API->>+DB: Insert
80 DB-->>-API: ID
81 API-->>-Client: 201 Created
82```
83
84### Database Schema
85
86```mermaid
87erDiagram
88 USER ||--o{ ORDER : places
89 ORDER ||--|{ LINE_ITEM : contains
90 USER { uuid id PK; string email UK }
91 ORDER { uuid id PK; uuid user_id FK }
92```
93
94### State Machine
95
96```mermaid
97stateDiagram-v2
98 [*] --> Draft
99 Draft --> Submitted : submit()
100 Submitted --> Approved : approve()
101 Submitted --> Rejected : reject()
102 Approved --> [*]
103```
104
105## Syntax Quick Reference
106
107### Flowchart Nodes
108
109```
110[Rectangle] (Rounded) {Diamond} [(Database)] [[Subroutine]]
111((Circle)) >Asymmetric] {{Hexagon}}
112```
113
114### Flowchart Edges
115
116```
117A --> B # Arrow
118A --- B # Line
119A -.-> B # Dotted arrow
120A ==> B # Thick arrow
121A -->|text| B # Labeled
122```
123
124### Sequence Arrows
125
126```
127->> # Solid arrow (request)
128-->> # Dotted arrow (response)
129-x # X end (async)
130-) # Open arrow
131```
132
133### ER Cardinality
134
135```
136||--|| # One to one
137||--o{ # One to many
138}o--o{ # Many to many
139```
140
141## Best Practices
142
1431. **Choose the right type** — Use decision tree above
1442. **Keep focused** — One concept per diagram
1453. **Use meaningful labels** — Not just A, B, C
1464. **Direction matters** — `LR` for flows, `TB` for hierarchies
1475. **Group with subgraphs** — Organize related nodes
148
149## Reference Documentation
150
151| File | Purpose |
152|------|---------|
153| [references/FLOWCHARTS.md](references/FLOWCHARTS.md) | Nodes, edges, subgraphs, styling |
154| [references/SEQUENCE.md](references/SEQUENCE.md) | Participants, messages, activation |
155| [references/CLASS-ER.md](references/CLASS-ER.md) | Classes, ER diagrams, relationships |
156| [references/STATE-JOURNEY.md](references/STATE-JOURNEY.md) | States, user journeys |
157| [references/DATA-CHARTS.md](references/DATA-CHARTS.md) | Gantt, Pie, Timeline, Quadrant |
158| [references/ARCHITECTURE.md](references/ARCHITECTURE.md) | C4, Block, Kanban |
159| [references/CHEATSHEET.md](references/CHEATSHEET.md) | All syntax quick reference |
160
161## Resources
162
163- **Official Documentation**: https://mermaid.js.org
164- **Live Editor**: https://mermaid.live
165- **GitHub Repository**: https://github.com/mermaid-js/mermaid
166- **GitHub Markdown Support**: https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/creating-diagrams
167- **GitLab Markdown Support**: https://docs.gitlab.com/ee/user/markdown.html#diagrams-and-flowcharts