Text-based diagrams stay inside version control, diff cleanly in pull requests, and take seconds to edit when a design changes. Mermaid has become the standard syntax for Markdown docs, wikis and architecture notes — and you can test any snippet below live in the Diagram Creator with zoom, pan and instant SVG or 2× PNG export.
Flowcharts and decision trees
Start with flowchart followed by a direction (TD top-down, LR left-to-right, BT bottom-to-top, or RL right-to-left). Node brackets control the shape: [Box], (Rounded), ([Stadium]), {Decision}, and [(Database)].
flowchart TD
A([Incoming request]) --> B{Valid JWT?}
B -->|Yes| C[Check cache]
B -->|No| D([Return 401])
C --> E{Cache hit?}
E -->|Yes| F([Return cached JSON])
E -->|No| G[(Query database)] --> F
Use subgraph Title ... end to group related steps into a labelled boundary, and classDef to highlight error or warning paths without repeating inline styles:
flowchart LR
subgraph Client
A[Form submit]
end
subgraph Server
B[Validate] --> C{OK?}
C -->|Yes| D[Save]
C -->|No| E[Return 422]:::warn
end
A --> B
classDef warn fill:#fee,stroke:#c33
Swimlanes for cross-team workflows
Mermaid's swimlane layout uses the swimlane-beta header (the bare word swimlane is not a valid diagram type). Every subgraph becomes a lane, and edges can cross lanes freely. Use LR for horizontal lane rows or TD for vertical columns:
swimlane-beta LR
subgraph Customer
A([Place order]) --> D([Receive parcel])
end
subgraph Billing
B[Charge card]
end
subgraph Warehouse
C[Pack & ship]
end
A --> B
B --> C
C --> D
Sequence diagrams for APIs and protocols
Sequence diagrams show message order over time. Use ->> for synchronous calls, -->> for dashed replies, alt / else / end for conditional branches, and Note over for context:
sequenceDiagram
autonumber
actor User
participant App
participant API
User->>App: Click "Export"
App->>+API: POST /exports
alt Authorised
API-->>App: 202 Accepted (jobId)
Note over App,API: Client polls status until ready
App-->>User: Download link ready
else Session expired
API-->>-App: 401 Unauthorised
App-->>User: Prompt to sign in
end
Entity-relationship (ER) schemas
For database tables and foreign keys, erDiagram uses crow's-foot notation: || (exactly one), o| (zero or one), }| (one or more), and o{ (zero or more).
erDiagram
CUSTOMER ||--o{ ORDER : places
ORDER ||--|{ LINE_ITEM : contains
CUSTOMER {
uuid id PK
string email UK
timestamp created_at
}
ORDER {
uuid id PK
uuid customer_id FK
string status
}
State machines
Use stateDiagram-v2 to document lifecycles, job queues, or UI states. [*] marks both the start and end states:
stateDiagram-v2
[*] --> Draft
Draft --> Review : submit
Review --> Approved : approve
Review --> Draft : request changes
Approved --> Published : deploy
Published --> [*]
Gantt timelines
Project schedules use gantt with explicit dateFormat and task dependencies via after <id>:
gantt
title Release Schedule
dateFormat YYYY-MM-DD
section Engineering
API endpoints :a1, 2026-12-01, 5d
Frontend wiring :a2, after a1, 4d
section Launch
QA & preflight :a3, after a2, 2d
Production roll :milestone, m1, after a3, 0d
Common syntax pitfalls
- Quotes around punctuation: Labels containing parentheses, colons, or brackets should be wrapped in double quotes — write
A["Parse JSON (v2)"]instead ofA[Parse JSON (v2)]. - Reserved words: Avoid lowercase
endas a bare node ID because Mermaid treats it as the closing keyword forsubgraph,alt, andloop. - Direction vs diagram type:
TD/LRheaders work on flowcharts andswimlane-beta, whereasstateDiagram-v2andclassDiagramtake a separatedirection LRline inside the body.
Using Mermaid in Markdown and exporting cleanly
Every diagram you draft in the Diagram Creator can be exported as scalable .svg, crisp 2× .png, or raw .mmd source — all rendered locally in your browser without uploading internal architecture to a third-party service.
Need the diagram inside a Markdown specification or README? Click Send to ▾ in the Diagram Creator to hand it directly to Markdown Preview or Markdown Reader already wrapped in a ```mermaid fenced code block. If you need to inspect or adjust the exported vector markup afterwards, open the .svg in the SVG Editor or rasterise it at custom pixel sizes with the SVG Converter.