Examples
The diagrams in examples/, drawn by
sirene svg --theme dark and sirene ascii when this site was built. Open one in the editor with
sirene examples/architecture.mmd.
Architecture
flowchart LR
user((User)) --> cdn[CDN]
cdn --> lb{{Load balancer}}
subgraph app [Application]
lb --> api1[API server 1] & api2[API server 2]
api1 & api2 --> queue>Job queue]
queue --> worker[[Worker]]
end
subgraph data [Data]
db[(Postgres)]
cache[(Redis)]
blob[(Object store)]
end
api1 & api2 --> db
api1 & api2 -.-> cache
worker --> db
worker --> blob
classDef store fill:#e8f1fb,stroke:#3b6ea5
classDef edge fill:#fdf2e3,stroke:#c77d1a
class db,cache,blob store
class cdn,lb edge
┌─ Application ─────────────────────────────────────────────────────────────────┐ ┌─ Data ─────────────┐
│ ┌────────────────────────────────────┼─┐ │ ╭──────────╮ │
│ ┌──────────────┐ │ │ └───────────┼───►├──────────┤ │
│ │ ├─┘ ┌───────────┐ ┌┬────────┬┐ │ ┌────┼───►│ Postgres │ │
│ ┌►│ API server 1 ├──────►> Job queue │ ││ Worker │├──┼─────┐ │┌───┼───►│ │ │
│ ┌──┘ │ ├┄┄┐ ┌►> ├───►││ │├──┼────┐│ ││ │ ╰──────────╯ │
│ ╱───────────────╲ │ └──────────────┘ ┆ │ └───────────┘ └┴────────┴┘ │ ┌──┼┼──┘│ │ │
╭──────╮ ┌─────┐ │ < Load balancer ├─┘ ┌┼──┘ │ │┌┄┼┼┄┄┄┼┄┐ │ ╭───────╮ │
( User ├───►│ CDN ├────┼─►< ├─┐ ┌──────────────┐ │└┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┼┄┼┘┌┼┼┄┄┄┼┐└┄┼┄┄┄┄►├───────┤ │
╰──────╯ └─────┘ │ ╲───────────────╱ └──┐ │ ├─┘ │ │ ┆│└───┘└┄┄┼┄┄┄┄►│ Redis │ │
│ └►│ API server 2 ├──────────────────────────────────────┼─┘ ┆└───┐ │ ╰───────╯ │
│ │ ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┼┄┄┄┘ │ │ │
│ └──────────────┘ │ │ │ ╭──────────────╮ │
└───────────────────────────────────────────────────────────────────────────────┘ │ │ ├──────────────┤ │
└────┼─►│ Object store │ │
│ ╰──────────────╯ │
└────────────────────┘
Build graph (DOT)
digraph build {
rankdir=LR;
node [shape=box, style=rounded];
subgraph cluster_sources {
label = "sources";
style = dashed;
parser; layout; render;
}
subgraph cluster_outputs {
label = "outputs";
color = blue;
svg; png; ascii [label="ASCII"];
}
parser -> layout -> render;
render -> svg;
render -> png;
render -> ascii;
tests [shape=note];
tests -> parser [style=dotted];
}
┌─ outputs ───┐
│ ╭─────╮ │
┌─┼──►│ svg │ │
┌─ sources ────────────────────────────────┐ │ │ ╰─────╯ │
│ ╭────────╮ │ ┌──┘ │ │
┌───────╮ │ ╭────────╮ ╭────────╮ │ ├──┼─┘ │ ╭─────╮ │
│ tests ├┄┄┄┄┼┄►│ parser ├───►│ layout ├───►│ render ├──┼──────┼──►│ png │ │
└───────┘ │ ╰────────╯ ╰────────╯ │ ├──┼─┐ │ ╰─────╯ │
│ ╰────────╯ │ │ │ │
└──────────────────────────────────────────┘ └──┐ │ ╭───────╮ │
└─┼─►│ ASCII │ │
│ ╰───────╯ │
└─────────────┘
Checkout (PlantUML)
@startuml
title Checkout
actor Customer
participant "Web Shop" as Shop
participant Payments
database Orders
Customer -> Shop : place order
activate Shop
Shop -> Payments : charge card
alt approved
Payments --> Shop : receipt
Shop -> Orders : save order
Shop --> Customer : confirmation
else declined
Payments --> Shop : declined
Shop --> Customer : ask for another card
end
deactivate Shop
@enduml
Checkout
o
/|\ ┌───────────┐ ┌───────────┐ ┌─────────┐
/ \ │ Web Shop │ │ Payments │ │ Orders │
Customer └─────┬─────┘ └─────┬─────┘ └────┬────┘
│ │ │ │
│ place order │ │ │
├────────────────────►┃ │ │
│ ┃ │ │
│ ┃ charge card │ │
│ ├──────────────►│ │
│ ┃ │ │
┌─alt [approved]────────┼───────────────┼──────────────┼─┐
│ │ ┃ receipt │ │ │
│ │ ┃◄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┤ │ │
│ │ ┃ │ │ │
│ │ ┃ save order │ │
│ │ ├───────────────┼─────────────►│ │
│ │ ┃ │ │ │
│ │ confirmation ┃ │ │ │
│ │◄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┤ │ │ │
│ │ ┃ │ │ │
├┄[declined]┄┄┄┄┄┄┄┄┄┄┄┄┼┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┼┄┄┄┄┄┄┄┄┄┄┄┄┄┄┼┄┤
│ │ ┃ declined │ │ │
│ │ ┃◄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┤ │ │
│ │ ┃ │ │ │
│ │ask for another card ┃ │ │ │
│ │◄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┤ │ │ │
│ │ ┃ │ │ │
└─┼─────────────────────┼───────────────┼──────────────┼─┘
o ┌─────┴─────┐ ┌─────┴─────┐ ┌────┴────┐
/|\ │ Web Shop │ │ Payments │ │ Orders │
/ \ └───────────┘ └───────────┘ └─────────┘
Customer
CI pipeline
---
title: CI pipeline
---
flowchart LR
push([Push to a branch]) --> lint[fmt and clippy]
lint --> test[Tests]
test --> cov{Coverage at least 98%?}
cov -->|yes| pr[Ready to merge]
cov -->|no| fail[[Fail the run]]
lint -. warnings .-> fail
subgraph release [Release, on main]
decide{New version?} -->|yes| build[Build binaries]
build --> publish[(crates.io)]
decide -->|no| skip(Nothing to do)
end
pr ==> decide
%% A subgraph's direction applies when no edge crosses its border.
subgraph checks [Checks run on each push]
direction TB
fmt[cargo fmt] --> clippy[cargo clippy] --> tests[cargo test]
end
CI pipeline
┌─ Release, on main ─────────────────────────────────────────────┐
│ ╭───────────╮ │
│ ┌────────────────┐ ├───────────┤ │
│ ┌►│ Build binaries ├───►│ crates.io │ │
│ ╱──────────────╲ ┌─yes─┘ └────────────────┘ ╰───────────╯ │
┌────────────────┐ │ │ New version? ├─┘ │
╱────────────────────────╲ ┌─yes──►│ Ready to merge ├━━━━┼━►│ ├─┐ ╭───────────────╮ │
┌───────┐ │ Coverage at least 98%? ├─┘ └────────────────┘ │ ╲──────────────╱ └─no───►│ Nothing to do │ │
┌────────────────┐ ┌►│ Tests ├───────────►│ ├─┐ │ ╰───────────────╯ │
╭──────────────────╮ │ fmt and clippy ├────┘ └───────┘ ╲────────────────────────╱ └─no──┐ ┌┬──────────────┬┐ └────────────────────────────────────────────────────────────────┘
( Push to a branch ├────────►│ ├┄┐ └►││ Fail the run ││
╰──────────────────╯ └────────────────┘ └┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄warnings┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄►││ ││
└┴──────────────┴┘
┌─ Checks run on each push ─┐
│ │
│ ┌───────────┐ │
│ │ cargo fmt │ │
│ └─────┬─────┘ │
│ │ │
│ ▼ │
│ ┌──────────────┐ │
│ │ cargo clippy │ │
│ └───────┬──────┘ │
│ │ │
│ ▼ │
│ ┌────────────┐ │
│ │ cargo test │ │
│ └────────────┘ │
│ │
└───────────────────────────┘
Fulfillment (PlantUML)
@startuml
title Fulfillment
start
:Receive order;
if (In stock?) then (yes)
:Pick items;
else (no)
:Order from supplier;
endif
fork
:Charge card;
fork again
:Pack box;
end fork
while (More boxes?) is (yes)
:Label box;
endwhile (no)
:Ship;
note right: tracked
stop
@enduml
Fulfillment
●
│
▼
╭───────────────╮
│ Receive order │
╰───────┬───────╯
│
▼
╱───────────╲
│ In stock? │
╲──┬─────┬──╱
│ │
┌───┘ └───┐
│ │
yes no
│ │
┌──┘ └───┐
▼ ▼
╭────────────╮ ╭─────────────────────╮
│ Pick items │ │ Order from supplier │
╰──────┬─────╯ ╰──────────┬──────────╯
│ │
└───┐ ┌────┘
│ │
│ │
└────┐ ┌────┘
▼ ▼
━┬━┬━
│ │
┌───┘ └───┐
│ │
│ │
┌──┘ └───┐
▼ ▼
╭─────────────╮ ╭──────────╮
│ Charge card │ │ Pack box │
╰──────┬──────╯ ╰─────┬────╯
│ │
└──┐ ┌───┘
│ │
│ │
└───┐ ┌───┘
▼ ▼
━━┬━━
│
▼
╱─────────────╲
│ More boxes? │
╲──┬───────┬──╱
│ ▲ │
┌┘ │ └───┐
│ │ │
yes │ no
│ │ │
┌┘ │ └──┐
▼ │ ▼
╭────────┴──╮ ╭──────╮ ┌─────────╮
│ Label box │ │ Ship │┄┄│ tracked │
╰───────────╯ ╰───┬──╯ └─────────┘
│
▼
◉
Login
flowchart TD
%% A sign-in flow with two-factor authentication.
start([Open the app]) --> session{Signed in?}
session -->|yes| home[Home screen]
session -->|no| form[/Email and password/]
form --> check{Valid?}
check -->|no| error[Show the error] --> form
check -->|yes| twofa{Two-factor on?}
twofa -->|no| home
twofa -->|yes| code[/Enter the code/]
code --> verify{Code matches?}
verify -->|yes| home
verify -->|no, 3 tries| locked[Lock the account]
verify -->|no| code
╭──────────────╮
( Open the app )
╰───────┬──────╯
│
▼
╱────────────╲
│ Signed in? │
╲───┬─────┬──╱
│ │
│ └──────┐
│ │
│ no
│ │
│ └──────┐
│ ▼
│ ┌────────────────────┐
│ ╱ Email and password ╱
│ └─────┬──────────────┘
│ │ ▲
│ ▼ │
│ ╱────────╲ │
│ │ Valid? │ │
│ ╲──┬───┬─╱ │
│ │ │ │
│ ┌┘ └───┐ └┐
│ │ │ │
│ no yes │
│ │ │ │
└┐ ┌┘ ┌─┼────┘
│ │ │ └──────────────┐
│ ▼ │ ▼
│ ┌────────────┴───┐ ╱────────────────╲
yes │ Show the error │ │ Two-factor on? │
│ └────────────────┘ ╲────┬───────┬───╱
│ │ │
└──────────────┐ ┌───────────┘ ┌──┘
│ │ │
│ │ yes
│ │ │
│ │ ┌───┘
│ │ ▼
│ │ ┌────────────────┐
│ │ ╱ Enter the code ╱
│ │ └────┬───────────┘
│ │ │ ▲
│ └┐ │ │
│ │ │ │
│ no │ no
│ │ │ │
│ ┌┘ │ │
│ │ ▼ │
│ │ ╱───────────┴───╲
│ │ │ Code matches? │
│ │ ╲───┬───────┬───╱
│ │ │ │
│ │ ┌─┘ └─┐
│ │ │ │
│ │ yes no, 3 tries
│ │ │ │
│ │ ┌──┘ └─┐
▼ ▼ ▼ ▼
┌─────────────┐ ┌──────────────────┐
│ Home screen │ │ Lock the account │
└─────────────┘ └──────────────────┘
Order lifecycle
flowchart LR
%% Edge kinds: solid, thick, dotted, invisible, and arrowheads.
cart[Cart] --> placed[Placed]
placed ==>|paid| paid[Paid]
placed -. timeout .-> cancelled[Cancelled]
paid --> packed[Packed] --> shipped[Shipped]
shipped ==> delivered([Delivered])
shipped --x lost[Lost in transit]
delivered <-->|exchange| paid
delivered --o review[Review]
lost ~~~ cancelled
┌─────────┐
│ Shipped ├━━━━┓ ╭───────────╮
┌────────┐ ┌►│ ├─┐ ┗━━━━►( Delivered ) ┌────────┐
┌►│ Packed ├───────────┘ └─────────┘ │ ┌───►( ├────────o│ Review │
┌──────┐ ┌──┘ └────────┘ └──┐│ ╰───────────╯ └────────┘
│ Paid ├─┘ ┌────────────────┼┘
┏►│ │◄─────────────────exchange─┘ │ ┌─────────────────┐
┏━paid━┛ └──────┘ └─x│ Lost in transit │ ┌───────────┐
┌────────┐ ┃ └─────────────────┘ │ Cancelled │
┌──────┐ │ Placed ├━┛ ┌►│ │
│ Cart ├───►│ ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄timeout┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┘ └───────────┘
└──────┘ └────────┘
Request timing (PlantUML)
@startuml
title Request timing
clock "Clock" as C with period 50
binary "Enable" as EN
robust "Web Browser" as WB
concise "Web User" as WU
WB has Processing, Waiting, Idle
@0
WU is Idle
WB is Idle
EN is low
@100 as :request
WU is Waiting
WB is Processing
EN is high
@300
WB is Waiting
@500
WU is Idle
WB is Idle
EN is low
@:request
WU -> WB : URL
WB@100 <-> @+200 : {200 ms}
highlight 300 to 500 #Gold : waiting
@enduml
Request timing
════════waiting════════
Clock ───┐ ┌──┐ ┌──┐ ┌──┐ ┌──┐ ┌──┐ ┌─┐ ┌──┐ ┌─┐ ┌──┐ ┌─┐
└─┘ └──┘ └─┘ └──┘ └─┘ └──┘ └──┘ └──┘ └──┘ └──┘ └───
Enable ┌───────────────────────────────────────────┐
───────────┘ └─────
Web Browser Processing ┌─────────────────────┐
Waiting │ └─────────────────────┐
Idle ───────────┘ └─────
▲─URL── 200 ms ───────►
┆
Web User ┌──────────┬───────────────────────────────────────────┬────┐
│ Idle │ Waiting │Idle│
└──────────┴───────────────────────────────────────────┴────┘
┬──────────┬──────────┬──────────┬──────────┬──────────┬─────
0 100 200 300 400 500
Shapes
flowchart TD
%% Every node shape.
rect[Rectangle] --> round(Rounded) --> stadium([Stadium]) --> sub[[Subroutine]]
cyl[(Cylinder)] --> circle((Circle)) --> dbl(((Double circle))) --> odd>Asymmetric]
diamond{Diamond} --> hex{{Hexagon}} --> leanR[/Lean right/] --> leanL[\Lean left\]
trap[/Trapezoid\] --> inv[\Inverted trapezoid/] --> ellipse(-Ellipse-) --> bare
┌───────────┐ ╭──────────╮ ╱─────────╲ ┌───────────┐
│ Rectangle │ ├──────────┤ │ Diamond │ ╱ Trapezoid ╲
└─────┬─────┘ │ Cylinder │ ╲────┬────╱ └─────┬─────┘
│ ╰─────┬────╯ │ │
│ │ │ │
▼ ▼ ▼ ▼
╭─────────╮ ╭────────╮ ╱─────────╲ ┌────────────────────┐
│ Rounded │ ( Circle ) < Hexagon > ╲ Inverted trapezoid ╱
╰────┬────╯ ╰────┬───╯ ╲────┬────╱ └──────────┬─────────┘
│ │ │ │
▼ ▼ ▼ ▼
╭─────────╮ ╔═══════════════╗ ┌────────────┐ ╭─────────╮
( Stadium ) ║ Double circle ║ ╱ Lean right ╱ ( Ellipse )
╰────┬────╯ ╚═══════┬═══════╝ └──────┬─────┘ ╰────┬────╯
│ │ │ │
▼ ▼ ▼ ▼
┌┬────────────┬┐ ┌────────────┐ ┌───────────┐ ┌──────┐
││ Subroutine ││ > Asymmetric │ ╲ Lean left ╲ │ bare │
└┴────────────┴┘ └────────────┘ └───────────┘ └──────┘
Shop model (PlantUML)
@startuml
title Shop model
package catalog {
abstract class Product {
-id : UUID
+price() : Money
}
class Book extends Product {
+isbn : String
}
interface Shippable
}
enum Status {
NEW
PAID
SHIPPED
}
class Order {
+status : Status
--
+total() : Money
}
Book ..|> Shippable
Order "1" *-- "many" Product : contains >
Order --> Status
@enduml
Shop model
┌──────────────────┐
│ Order │
├──────────────────┤
│ +status : Status │
├──────────────────┤
│ +total() : Money │
└─────────────┬────┘
◆1 │
┌────────┘ │
│ │
contains > │
│ │
┌────┘ └──┐
│ │
┌───────────┼─── catalog ─┐ │
│ │many │ │
│ ┌─────────┴────────┐ │ │
│ │ «abstract» │ │ │
│ │ Product │ │ │
│ ├──────────────────┤ │ │
│ │ -id : UUID │ │ │
│ ├──────────────────┤ │ ▼
│ │ +price() : Money │ │ ┌───────────────┐
│ └──────────────────┘ │ │ «enumeration» │
│ △ │ │ Status │
│ │ │ ├───────────────┤
│ ┌────────┴───────┐ │ │ NEW │
│ │ Book │ │ │ PAID │
│ ├────────────────┤ │ │ SHIPPED │
│ │ +isbn : String │ │ ├───────────────┤
│ ├────────────────┤ │ └───────────────┘
│ └────────┬───────┘ │
│ ┆ │
│ ▽ │
│ ┌─────────────┐ │
│ │ «interface» │ │
│ │ Shippable │ │
│ └─────────────┘ │
│ │
└─────────────────────────┘
Styling
flowchart LR
%% classDef, class, :::, style, and linkStyle.
a[Default] --> b[Hot]:::hot --> c[Cold] --> d[Dashed] --> e["`**Markdown** label`"]
c --> f[Line 1<br>Line 2]
classDef hot fill:#fde2e1,stroke:#c0392b,stroke-width:2px,color:#7b241c
classDef cold fill:#e3f2fd,stroke:#1f618d
class c cold
style d fill:#fff,stroke:#555,stroke-dasharray: 5 3
linkStyle 0 stroke:#c0392b,stroke-width:3px
linkStyle 2 stroke:#1f618d,stroke-dasharray: 4 2
┌────────┐ ┌────────────────┐
┌►│ Dashed ├───►│ Markdown label │
┌──────┐ ┌──┘ └────────┘ └────────────────┘
┌─────────┐ ┌─────┐ │ Cold ├─┘
│ Default ├───►│ Hot ├───►│ ├─┐ ┌────────┐
└─────────┘ └─────┘ └──────┘ └──┐ │ Line 1 │
└►│ Line 2 │
└────────┘