elefcode

Mermaid diagram

Sequence Diagram — free online editor

Mermaid sequence diagrams show how participants exchange messages over time — ideal for API flows, auth handshakes, and protocol design.

What is a Mermaid sequence diagram?

A sequence diagram has actors or participants drawn left-to-right, each with a vertical lifeline. Messages flow between them top-to-bottom in chronological order. Mermaid supports synchronous arrows, async messages, notes, activations, and control-flow blocks like alt/else, opt, loop, and par.

When to use it

  • Document an API request/response flow
  • Visualize an OAuth or login handshake
  • Explain a distributed-system protocol
  • Capture requirements in a UML-style spec

Syntax in one paragraph

Use `participant A as Name` to declare actors. Messages: `A->>B: text` (solid), `A-->>B` (dotted/reply), `A-)B` (async). Wrap conditional or repeated steps in `alt/end`, `opt/end`, or `loop/end` blocks.

Example: Login + token refresh

sequenceDiagram
    autonumber
    participant U as User
    participant A as API
    participant DB as Database

    U->>A: POST /login
    A->>DB: SELECT user
    DB-->>A: user row
    A->>A: verify password

    alt Valid credentials
        A-->>U: 200 { token, refresh }
    else Invalid
        A-->>U: 401 Unauthorized
    end

More Mermaid diagrams