Example
sequenceDiagram
participant User
participant Editor
participant API
participant DB
User->>Editor: Paste Mermaid code
Editor->>Editor: Render diagram (300ms debounce)
User->>Editor: Click Share
Editor->>API: POST /api/diagrams
API->>DB: INSERT diagram
DB-->>API: id
API-->>Editor: { id }
Editor-->>User: Share link copied! Syntax
Participants and actors
sequenceDiagram
actor User
participant App
participant API as Backend API
User->>App: Tap "Sign in"
App->>API: POST /session Participants appear in declaration order. as sets a display name so the alias can stay short in message lines. actor draws a stick figure.
Arrow types
sequenceDiagram
A->B: solid line, no head
A-->B: dotted line, no head
A->>B: solid line, arrowhead
A-->>B: dotted line, arrowhead (reply)
A-xB: solid line, cross (lost)
A-)B: solid line, open arrow (async) Convention: ->> for a call, -->> for its response. Mixing them consistently is what makes a diagram readable.
Activation bars
sequenceDiagram
Client->>+Server: request
Server-->>-Client: response + after the arrow activates the target, - deactivates. Or write activate Server / deactivate Server on their own lines.
Control blocks
sequenceDiagram
loop every 30s
App->>API: heartbeat
end
alt token valid
API-->>App: 200 OK
else expired
API-->>App: 401
end
par fetch in parallel
App->>CDN: GET /assets
and
App->>API: GET /me
end
opt cache warm
App->>App: skip fetch
end Notes and numbering
sequenceDiagram
autonumber
Note over App,API: Both sides validate the token
App->>API: GET /me
Note right of API: Cached for 60s autonumber prefixes every message with a sequence number, which is handy when a document references steps by number.
Common mistakes
These are the parse errors that come up most, including in code written by ChatGPT and Claude. Paste any failing diagram into the editor and it marks the offending line.
-
Missing colon:
User->>App Tap button.Fix: Every message needs
: textafter the target, even if the text is empty-ish. WriteUser->>App: Tap button. -
Flowchart arrows (
-->with a target in brackets) inside a sequence diagram.Fix: Sequence arrows are
->>,-->>,->,-->. Brackets are not shapes here; they will be read as part of the participant name. -
Participant names with spaces or slashes used directly:
Auth Service->>DB: query.Fix: Declare an alias:
participant AS as Auth Service, then useAS->>DB: query. -
Unbalanced blocks: an
altwithoutend, or anelseoutside analt.Fix: Every
loop,alt,opt,par,critical, andrectneeds its ownend. Indent blocks so the pairing is visible.
Real-world examples
Complete, copy-ready sequence diagrams for common situations. Each one opens in the editor with a click.
-
Web Request Lifecycle Sequence Diagram: CDN to Database
Mermaid sequence diagram tracing one page request from browser through CDN, load balancer, and app server to cache and database, with alt blocks for cache hits.
-
OAuth 2.0 Authorization Code Flow Sequence Diagram
Mermaid sequence diagram of the OAuth 2.0 authorization code flow with PKCE: user, client app, authorization server, and resource server, sign-in to API call.
-
JWT Authentication Sequence Diagram with Token Refresh
Mermaid sequence diagram of JWT auth: login returns access and refresh tokens, an API call fails on expiry, and nested alt blocks show the refresh and re-login.
-
Webhook Delivery Sequence Diagram with Retries and Backoff
Mermaid sequence diagram of outbound webhook delivery: signed payload, a loop of five attempts with backoff, alt for success or failure, and dead-lettering.
-
Online Card Payment Authorization Sequence Diagram
A Mermaid sequence diagram of a card payment: storefront, payment gateway, and card network exchange an authorization, with alt branches for approve or decline.
FAQ
How do I show a message a participant sends to itself?
Use the same name on both sides: App->>App: validate input. Mermaid draws a loop-back arrow on that lifeline.
Can I change the order participants appear in?
Yes. Participants are placed in the order they are first mentioned, so declare them explicitly at the top in the order you want.
Is there a limit on diagram width?
No hard limit, but more than seven or eight participants becomes hard to read. Split by concern (auth, payment, notification) into separate diagrams and share each one with its own link.