All diagram types Open editor

merIDK / Diagram types / Sequence diagram

Mermaid sequence diagram: example and syntax

Sequence diagrams show how participants such as users, services and databases exchange messages over time. They are the standard way to document API calls, login flows and service-to-service interactions.

Open this example in the editor

Example code

sequenceDiagram
    autonumber
    actor U as User
    box Backend
      participant A as API
      participant DB as Database
    end
    U->>+A: POST /login
    A->>+DB: SELECT user
    DB-->>-A: row
    alt valid password
        A-->>U: 200 + token
    else invalid
        A-->>U: 401
    end
    loop every 15 min
        U->>A: refresh token
    end
    Note over U,A: Token expires after 1 hour
    deactivate A

Result

sequenceDiagram
    autonumber
    actor U as User
    box Backend
      participant A as API
      participant DB as Database
    end
    U->>+A: POST /login
    A->>+DB: SELECT user
    DB-->>-A: row
    alt valid password
        A-->>U: 200 + token
    else invalid
        A-->>U: 401
    end
    loop every 15 min
        U->>A: refresh token
    end
    Note over U,A: Token expires after 1 hour
    deactivate A

Syntax quick reference

How to use it

  1. Open the example in the editor, or paste your own Mermaid code.
  2. Edit the code on the left. The preview updates as you type, and errors point to the line.
  3. Export SVG or PNG, copy a Markdown block for GitHub or Notion, or copy a share link.

More diagram types