Mermaid Diagram Editor · Tutorial

How to make a sequence diagram of an API call

7 min readintermediateUpdated

New teammates keep asking how login works. A sequence diagram shows each message between the parts of the system in order. You will build one with a success and an error path.

What you need

Steps

  1. List the participants

    Load the example. actor draws a person; participant draws a box. as gives a short ID a longer label, as in participant DB as Database.

  2. Add the messages

    ->> is a request with a solid line; -->> is a reply with a dashed line. Messages appear in the order you write them.

  3. Show alternatives

    Wrap the two outcomes in alt and else, closed with end. Readers see both paths in one picture.

    alt Password matches
        Server-->>Browser: 200 OK + session cookie
    else Wrong password
        Server-->>Browser: 401 Unauthorized
    end
  4. Put it in the docs

    Copy as Markdown and paste it into your repository’s docs. When the flow changes, edit the text in the same pull request.

Try it yourself

Opens the Mermaid Diagram Editor with this tutorial's sample loaded.

Try it now

Common mistakes

Forgetting end
Every alt, opt, loop and par needs its own end. The error message points at the end of the diagram when one is missing.
Too much detail
Show the messages that matter for understanding. Split long flows into several diagrams.

Next steps

Go back to the Mermaid Diagram Editor, or keep going with one of these: