When to use it
API design documents, detailed design specs and the login section of a project report. autonumber numbers every message so the text can refer to "step 3"; alt / else shows the correct-password and wrong-password branches.
Making it yours
- For SMS or email code login, replace "Enter username and password" with "Enter phone number" and add a "verify code" exchange between the auth service and the database.
- Add social login by declaring
participant T as Identity providerand inserting the redirect and callback messages. - Solid arrows
->>are requests, dashed arrows-->>are responses; deleteautonumberif you do not want numbers. - Participant names live in
participant X as Name; message text is everything after the colon.
Mermaid code
sequenceDiagram
autonumber
participant U as User
participant W as Web app
participant S as Auth service
participant D as Database
U->>W: Enter username and password
W->>S: POST /login
S->>D: Look up user
D-->>S: Return password hash
alt Password correct
S-->>W: Return token
W-->>U: Signed in, go to home
else Password wrong
S-->>W: 401 Unauthorized
W-->>U: Show "wrong username or password"
end
Note over W,S: Every later request carries the token in a headerAsk an AI for one with this structure
Send the prompt below to ChatGPT or Claude, then paste the whole reply into the editor; the code inside is detected automatically.
Draw a user login sequence diagram in Mermaid sequenceDiagram syntax with participants User, Web app, Auth service and Database. The user enters credentials, the web app calls the login endpoint, the auth service looks up the user in the database and verifies the password hash; on success it returns a token and the app goes to the home screen, on failure it returns 401 and shows an error. Use alt/else for the two branches and enable autonumber. Output only the mermaid code block.
FAQ
- What are alt, opt and loop?
alt … else … endis an either/or branch,opt … endis an optional fragment andloop … endrepeats. They can be nested; indentation is only for readability.- Can message text contain a colon?
Everything after the first colon is the message text, so "401 Unauthorized" and similar are fine. Avoid semicolons inside the text.
- Can numbering start from a value other than 1?
autonumber 10starts at 10;autonumber 10 5starts at 10 and increments by 5.
More in this category
Updated 2026-09-05