Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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
the drawing of the mermaid source above

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];
}
the drawing of the dot source above

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
the drawing of the plantuml source above

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
the drawing of the mermaid source above

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
the drawing of the plantuml source above

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
the drawing of the mermaid source above

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
the drawing of the mermaid source above

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
the drawing of the plantuml source above

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
the drawing of the mermaid source above

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
the drawing of the plantuml source above

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
the drawing of the mermaid source above