SequenceDiagram
Who talks to whom, in order: the browser, the API, the database and back. Each participant has a line down the page; each message is a numbered arrow.
import { SequenceDiagram, DiagramSkeleton } from '@sypnia/ui/react'
Signing in with a code
This diagram in words
- Browser to API: POST /login
- API to Database: save a code
- API to Mail: send the code
- API answers Browser: 202 check your mail
- Browser to API: POST /verify
- API to Database: read the code
- API answers Browser: 401 code expired (failed)
Code
import { SequenceDiagram } from '@sypnia/ui/react';
// Who talks to whom, in order. Answers are dashed; what failed is in the failure colour and said in words.
export default function SignIn() {
return (
<SequenceDiagram label="Signing in with a code" participants={[
{ id: 'b', label: 'Browser' }, { id: 'api', label: 'API' }, { id: 'db', label: 'Database' }, { id: 'mail', label: 'Mail' },
]} messages={[
{ from: 'b', to: 'api', label: 'POST /login' },
{ from: 'api', to: 'db', label: 'save a code' },
{ from: 'api', to: 'mail', label: 'send the code' },
{ from: 'api', to: 'b', label: '202 check your mail', reply: true },
{ from: 'b', to: 'api', label: 'POST /verify' },
{ from: 'api', to: 'db', label: 'read the code' },
{ from: 'api', to: 'b', label: '401 code expired', reply: true, fail: true },
]} />
);
} Skeleton
Code
import { DiagramSkeleton } from '@sypnia/ui/react';
// A diagram while it loads: its stage at the height it will have.
export default function Skeleton() {
return <DiagramSkeleton height={260} />;
} When to use it
Use it when
- Explaining a sign-in, a payment, a webhook.
- Showing where a conversation between services failed.
Do not use it when
- More than five participants: split it in two diagrams.
For everyone
- It is told in words as a numbered list: who sends what to whom, and which answers failed.
Props
| SequenceDiagram | Type | Default |
|---|---|---|
labelrequired | string | |
messagesrequired | SequenceMessage[] | |
participantsrequiredIn order, left to right: { id, label }. | { id: string; label: string; machine?: boolean | undefined; }[] |
| DiagramSkeleton | Type | Default |
|---|---|---|
height | number | 220 |