MermaidSequence DiagramsAPI Design

    Sequence Diagrams for API Design, with Mermaid Examples

    Build a login flow step by step: branches, activations, notes and asynchronous messages

    7 October 20267 min read

    A class diagram shows what exists. A sequence diagram shows what happens, in order, between the parts of a system. That makes it the most useful picture for designing an API: you can see who calls whom, what is synchronous, where a failure can occur and what the user is waiting for. This guide builds one in Mermaid, step by step.

    The basics

    Name the participants, then write one line per message. ->> is a call, and -->> is a reply.

    DatabaseAPIBrowserDatabaseAPIBrowserPOST /loginfind user by emailuser record200 + session token

    A login request

    Show the branches that matter

    A diagram with only the happy path hides the interesting decisions. Use alt for either/or, opt for optional steps and loop for repetition.

    DatabaseAPIBrowserDatabaseAPIBrowsercount the failed attemptalt[passwordmatches][wrongpassword]POST /loginfind user by emailuser record200 + session token401 Unauthorized

    Handling a wrong password

    Make time and cost visible

    • Activations (activate / deactivate, or + and - on arrows) show how long a participant is busy, which exposes long synchronous chains.
    • Notes carry the facts the arrows cannot: timeouts, retries, idempotency keys.
    • Async messages deserve a different arrow than calls the user waits on. -) draws an open arrow for fire-and-forget.
    Email workerQueueOrders APIClientEmail workerQueueOrders APIClientsends the receipt, retries on failurePOST /orderspublish order.created201 Createdorder.created

    A synchronous call with an asynchronous follow-up

    Keep them useful

    1. One scenario per diagram. "Checkout, card declined" is one diagram, not a section of a bigger one.
    2. Limit to about six participants. More than that, split the flow or group services.
    3. Name messages with the real call (POST /orders), so the diagram and the API stay in step.
    4. Keep the source in the repository next to the API spec, and update both in the same pull request.

    In Archgram you can edit sequence diagrams as text or through a form, restyle them, or ask the AI to draft one from a sentence like "login with email and password, lock the account after five failures". Sequence diagrams also convert to D2 and PlantUML if your documentation uses those. Open the editor to start.

    Ready to apply this?

    Start diagramming in seconds with AI generation — no installation required.

    Open Free Editor