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
List the participants
Load the example.
actordraws a person;participantdraws a box.asgives a short ID a longer label, as inparticipant DB as Database.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.Show alternatives
Wrap the two outcomes in
altandelse, closed withend. Readers see both paths in one picture.alt Password matches Server-->>Browser: 200 OK + session cookie else Wrong password Server-->>Browser: 401 Unauthorized endPut 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.
Common mistakes
- Forgetting end
- Every
alt,opt,loopandparneeds its ownend. 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: