Mermaid Diagram Generator
Quick Start: Wrap diagram source in a ```mermaid fenced code block. No HTML, no external scripts — the renderer handles it.
flowchart LR
A[Browser] --> B[CDN]
B --> C[API]
C --> D[(Postgres)]
Why Mermaid
| Property |
Value |
| Format |
Plain text inside ```mermaid fence |
| Renders in |
GitHub (native since 2022), GitLab, Bitbucket, VS Code, Notion, Obsidian, Confluence (plugin), Hugo, Docusaurus, MkDocs |
| Diagram types |
18+ (see table below) |
| Toolchain |
Browser-only — no install needed for viewing; @mermaid-js/mermaid-cli for static export |
| Cost |
Zero runtime if your viewer supports it; ~1 MB JS if you self-host |
This is the diagram format with the widest renderer support today. Default to Mermaid unless you specifically need draw.io's shape libraries, PlantUML's stdlibs, or Vega's data binding.
When to use this skill vs. others
| If you need… |
Use |
| Quick diagram inside a README, PR description, or wiki |
mermaid (this skill) |
| Rich shape libraries (Cisco, AWS service icons, BPMN) |
drawio |
| Strict C4 modeling notation with PlantUML stdlib |
c4 — though Mermaid has C4Context blocks too |
| Visual layered architecture with semantic colors |
architecture |
| Charts driven by data |
vega |
Critical Rules
Rule 1: Fenced block only
Always use ```mermaid exactly — not ```Mermaid, not ```mmd. Renderers are case-sensitive.
Rule 2: First line declares diagram type
The first non-empty line must be the type keyword. Mermaid won't auto-detect.
flowchart LR ← required
sequenceDiagram ← required
classDiagram ← required
erDiagram ← required
stateDiagram-v2 ← required (note: -v2 is the modern syntax)
gantt ← required
mindmap ← required
C4Context ← required
Rule 3: Direction matters for flowcharts
flowchart LR (left-right), TB / TD (top-bottom), RL, BT. Pick based on reading flow — pipelines = LR, hierarchies = TB.
Rule 4: IDs vs. labels
Node id is what edges reference; the bracketed text is the label.
flowchart LR
api[API Gateway]
db[(Postgres)]
api --> db
api and db are IDs (no spaces). Labels can have spaces and Markdown.
Rule 5: Shape syntax encodes meaning
| Syntax |
Shape |
Use for |
id[Text] |
Rectangle |
Default / process |
id(Text) |
Rounded rectangle |
Soft step |
id([Text]) |
Stadium |
Start/end |
id[[Text]] |
Subroutine |
Internal call |
id[(Text)] |
Cylinder |
Database |
id((Text)) |
Circle |
State / event |
id{Text} |
Diamond |
Decision |
id{{Text}} |
Hexagon |
Preparation |
id[/Text/] |
Parallelogram |
Input/output |
Rule 6: Edge styles signal flow type
| Syntax |
Meaning |
A --> B |
Solid arrow |
A --- B |
Solid line, no arrow |
A -.-> B |
Dashed arrow (async / optional) |
A ==> B |
Thick arrow (critical path) |
| `A --> |
"label" |
A -- text --> B |
Alternative label syntax |
Rule 7: Use subgraphs for grouping
flowchart LR
subgraph aws[AWS us-east-1]
api --> db
end
user --> aws
Diagram type cheatsheet
| Type |
Keyword |
Best for |
| Flowchart |
flowchart LR |
Generic graphs, system topology, decision trees |
| Sequence |
sequenceDiagram |
API call traces, user interactions over time |
| Class |
classDiagram |
OO design, type hierarchies |
| State |
stateDiagram-v2 |
State machines, workflows |
| ER |
erDiagram |
Database schemas |
| Gantt |
gantt |
Project timelines |
| Mindmap |
mindmap |
Brainstorms, taxonomies |
| Pie |
pie title |
Simple proportions |
| Journey |
journey |
User journey maps with sentiment |
| GitGraph |
gitGraph |
Branch/merge visualization |
| C4 |
C4Context / C4Container |
Software architecture, lightweight |
| Quadrant |
quadrantChart |
2x2 strategy plots |
| Sankey |
sankey-beta |
Flow volumes |
| Timeline |
timeline |
Historical / event timelines |
| Block |
block-beta |
Layered block diagrams |
| Architecture |
architecture-beta |
Cloud architecture (cluster + service) |
| Requirement |
requirementDiagram |
RM / safety-critical specs |
Examples
| File |
Type |
Demonstrates |
| examples/flowchart.md |
flowchart |
Subgraphs, shape variety, edge labels |
| examples/sequence.md |
sequenceDiagram |
Activations, alt/loop blocks, notes |
| examples/erd.md |
erDiagram |
Entities, cardinality, attributes |
| examples/c4-context.md |
C4Context |
Mermaid's lightweight C4 alternative |
Static export
For PDF / slide / static-site embedding when the renderer doesn't speak Mermaid:
npx -p @mermaid-js/mermaid-cli mmdc -i diagram.mmd -o diagram.svg
npx -p @mermaid-js/mermaid-cli mmdc -i diagram.mmd -o diagram.png -w 1600
-t dark for dark theme, -c config.json for custom theming.
Best Practices
- Keep node IDs short.
api, db, lb — not apiGatewayService. Labels carry the description.
- Direction matches reading flow. Pipelines and request flows:
LR. Trees and inheritance: TB.
- Use
%%{init: {...}}%% at the top to override theme/font globally for that diagram only:%%{init: {'theme':'neutral', 'flowchart': {'curve':'basis'}}}%%
flowchart LR
- Don't fight the layout engine. Mermaid auto-routes — if it looks wrong, the structure is wrong, not the layout. Restructure with subgraphs before adding
linkStyle.
- One concept per diagram. Don't try to show users + infra + data flow + auth in one flowchart. Split.
- Comment with
%% — useful for marking sections in long sequence diagrams.
- GitHub renders Mermaid 4.x. New diagram types like
architecture-beta may not work everywhere — check renderer support before relying on them in shared docs.
1---2name: mermaid3description: Generate Mermaid diagrams (flowchart, sequence, class, state, ER, gantt, mindmap, C4, gitGraph, pie, journey, quadrant, sankey, timeline, architecture) using fenced code blocks. Renders natively in GitHub, GitLab, Obsidian, VS Code, Notion, and most modern Markdown viewers.4---56# Mermaid Diagram Generator78**Quick Start:** Wrap diagram source in a ` ```mermaid ` fenced code block. No HTML, no external scripts — the renderer handles it.910```mermaid11flowchart LR12 A[Browser] --> B[CDN]13 B --> C[API]14 C --> D[(Postgres)]15```1617## Why Mermaid1819| Property | Value |20|---|---|21| Format | Plain text inside ` ```mermaid ` fence |22| Renders in | GitHub (native since 2022), GitLab, Bitbucket, VS Code, Notion, Obsidian, Confluence (plugin), Hugo, Docusaurus, MkDocs |23| Diagram types | 18+ (see table below) |24| Toolchain | Browser-only — no install needed for viewing; `@mermaid-js/mermaid-cli` for static export |25| Cost | Zero runtime if your viewer supports it; ~1 MB JS if you self-host |2627This is the diagram format with the widest renderer support today. Default to Mermaid unless you specifically need draw.io's shape libraries, PlantUML's stdlibs, or Vega's data binding.2829## When to use this skill vs. others3031| If you need… | Use |32|---|---|33| Quick diagram inside a README, PR description, or wiki | **mermaid** (this skill) |34| Rich shape libraries (Cisco, AWS service icons, BPMN) | [drawio](../drawio/SKILL.md) |35| Strict C4 modeling notation with PlantUML stdlib | [c4](../c4/SKILL.md) — though Mermaid has `C4Context` blocks too |36| Visual layered architecture with semantic colors | [architecture](../architecture/SKILL.md) |37| Charts driven by data | [vega](../vega/SKILL.md) |3839## Critical Rules4041### Rule 1: Fenced block only42Always use ` ```mermaid ` exactly — not ` ```Mermaid `, not ` ```mmd `. Renderers are case-sensitive.4344### Rule 2: First line declares diagram type45The first non-empty line **must** be the type keyword. Mermaid won't auto-detect.4647```48flowchart LR ← required49sequenceDiagram ← required50classDiagram ← required51erDiagram ← required52stateDiagram-v2 ← required (note: -v2 is the modern syntax)53gantt ← required54mindmap ← required55C4Context ← required56```5758### Rule 3: Direction matters for flowcharts59`flowchart LR` (left-right), `TB` / `TD` (top-bottom), `RL`, `BT`. Pick based on reading flow — pipelines = LR, hierarchies = TB.6061### Rule 4: IDs vs. labels62Node `id` is what edges reference; the bracketed text is the label.6364```65flowchart LR66 api[API Gateway]67 db[(Postgres)]68 api --> db69```7071`api` and `db` are IDs (no spaces). Labels can have spaces and Markdown.7273### Rule 5: Shape syntax encodes meaning74| Syntax | Shape | Use for |75|---|---|---|76| `id[Text]` | Rectangle | Default / process |77| `id(Text)` | Rounded rectangle | Soft step |78| `id([Text])` | Stadium | Start/end |79| `id[[Text]]` | Subroutine | Internal call |80| `id[(Text)]` | Cylinder | Database |81| `id((Text))` | Circle | State / event |82| `id{Text}` | Diamond | Decision |83| `id{{Text}}` | Hexagon | Preparation |84| `id[/Text/]` | Parallelogram | Input/output |8586### Rule 6: Edge styles signal flow type87| Syntax | Meaning |88|---|---|89| `A --> B` | Solid arrow |90| `A --- B` | Solid line, no arrow |91| `A -.-> B` | Dashed arrow (async / optional) |92| `A ==> B` | Thick arrow (critical path) |93| `A -->|"label"| B` | Labeled edge |94| `A -- text --> B` | Alternative label syntax |9596### Rule 7: Use subgraphs for grouping97```98flowchart LR99 subgraph aws[AWS us-east-1]100 api --> db101 end102 user --> aws103```104105## Diagram type cheatsheet106107| Type | Keyword | Best for |108|---|---|---|109| Flowchart | `flowchart LR` | Generic graphs, system topology, decision trees |110| Sequence | `sequenceDiagram` | API call traces, user interactions over time |111| Class | `classDiagram` | OO design, type hierarchies |112| State | `stateDiagram-v2` | State machines, workflows |113| ER | `erDiagram` | Database schemas |114| Gantt | `gantt` | Project timelines |115| Mindmap | `mindmap` | Brainstorms, taxonomies |116| Pie | `pie title` | Simple proportions |117| Journey | `journey` | User journey maps with sentiment |118| GitGraph | `gitGraph` | Branch/merge visualization |119| C4 | `C4Context` / `C4Container` | Software architecture, lightweight |120| Quadrant | `quadrantChart` | 2x2 strategy plots |121| Sankey | `sankey-beta` | Flow volumes |122| Timeline | `timeline` | Historical / event timelines |123| Block | `block-beta` | Layered block diagrams |124| Architecture | `architecture-beta` | Cloud architecture (cluster + service) |125| Requirement | `requirementDiagram` | RM / safety-critical specs |126127## Examples128129| File | Type | Demonstrates |130|---|---|---|131| [examples/flowchart.md](examples/flowchart.md) | flowchart | Subgraphs, shape variety, edge labels |132| [examples/sequence.md](examples/sequence.md) | sequenceDiagram | Activations, alt/loop blocks, notes |133| [examples/erd.md](examples/erd.md) | erDiagram | Entities, cardinality, attributes |134| [examples/c4-context.md](examples/c4-context.md) | C4Context | Mermaid's lightweight C4 alternative |135136## Static export137138For PDF / slide / static-site embedding when the renderer doesn't speak Mermaid:139140```bash141npx -p @mermaid-js/mermaid-cli mmdc -i diagram.mmd -o diagram.svg142npx -p @mermaid-js/mermaid-cli mmdc -i diagram.mmd -o diagram.png -w 1600143```144145`-t dark` for dark theme, `-c config.json` for custom theming.146147## Best Practices1481491. **Keep node IDs short.** `api`, `db`, `lb` — not `apiGatewayService`. Labels carry the description.1502. **Direction matches reading flow.** Pipelines and request flows: `LR`. Trees and inheritance: `TB`.1513. **Use `%%{init: {...}}%%`** at the top to override theme/font globally for that diagram only:152 ```153 %%{init: {'theme':'neutral', 'flowchart': {'curve':'basis'}}}%%154 flowchart LR155 ```1564. **Don't fight the layout engine.** Mermaid auto-routes — if it looks wrong, the structure is wrong, not the layout. Restructure with subgraphs before adding `linkStyle`.1575. **One concept per diagram.** Don't try to show users + infra + data flow + auth in one flowchart. Split.1586. **Comment with `%%`** — useful for marking sections in long sequence diagrams.1597. **GitHub renders Mermaid 4.x.** New diagram types like `architecture-beta` may not work everywhere — check renderer support before relying on them in shared docs.