Home / Examples / Flowchart

Mermaid Flowchart Examples

Flowcharts are the most common Mermaid diagram. They show decisions, branches, and the order in which a system or a person handles work. Every example below renders live, and you can open any of them in the editor to change it.

A flowchart starts with flowchart and a direction: TD (top-down) or LR (left-right). Nodes are declared the first time you use their ID, and arrows connect them.

API request validation flow

A classic decision flow for documenting authentication and validation paths. Each diamond is a question, and the labeled arrows show the answer that leads to each branch.

flowchart TD
  A[Client request] --> B{Authenticated?}
  B -->|No| C[Return 401]
  B -->|Yes| D{Payload valid?}
  D -->|No| E[Return 400]
  D -->|Yes| F[Process request]
  F --> G[Return 200]

CI/CD pipeline with subgraphs

Use subgraph to group related steps. Here the build stage and the deployment stage are separate boxes, and one arrow links the end of one group to the start of the next.

flowchart LR
  subgraph CI[Continuous integration]
    A[Push to main] --> B[Install dependencies]
    B --> C[Run tests]
    C --> D[Build image]
  end
  subgraph CD[Deployment]
    E[Deploy to staging] --> F{Smoke tests pass?}
    F -->|Yes| G[Promote to production]
    F -->|No| H[Roll back]
  end
  D --> E

Node shapes cheat sheet

The brackets around a label set the node shape. This upload flow uses a stadium for the start, a parallelogram for input, a diamond for the decision, a cylinder for storage, a subroutine box, and a circle for the end.

flowchart TD
  start([Start]) --> upload[/User uploads file/]
  upload --> check{File under 10 MB?}
  check -->|Yes| store[(Object storage)]
  check -->|No| reject[[Reject upload]]
  store --> done((Done))
  reject --> done

Cache lookup with classDef styling

classDef defines a reusable style, and class applies it to nodes. This is the cleanest way to highlight the happy path or mark a slow component without styling each node by hand.

flowchart LR
  A[Request] --> B{In cache?}
  B -->|hit| C[Return cached value]
  B -->|miss| D[(Database)]
  D --> E[Write to cache]
  E --> C
  classDef fast fill:#d1fae5,stroke:#059669
  classDef slow fill:#fee2e2,stroke:#dc2626
  class C fast
  class D slow

Flowchart syntax cheat sheet

SyntaxMeaning
flowchart TD / LRDirection: top-down, left-right (also BT, RL)
A[Text]Rectangle node with ID A
A{Text}Decision (diamond)
A([Text]) / A((Text))Stadium / circle
A[(Text)]Database cylinder
A --> BArrow
A -->|label| BArrow with a label
A -.-> B / A ==> BDotted / thick arrow
subgraph Name ... endGroup nodes in a box
%% commentComment line, ignored when rendering

Common flowchart mistakes

  • Using the word end in lowercase as a node label breaks the parser. Write End or wrap it in quotes: A["end"].
  • Labels with parentheses, brackets, or other special characters need double quotes: A["Retry (max 3)"].
  • Reusing a node ID points to the same node. If two boxes say "Done", give them different IDs such as done1 and done2.
  • Large flowcharts get hard to read. Split them by reader task instead of putting every branch into one diagram.

Flowchart FAQ

What is the difference between graph and flowchart?
flowchart is the newer keyword. It supports everything graph does plus newer features such as extra link types, so use flowchart in new diagrams.
How do I change the direction of a single subgraph?
Add a direction LR (or TB) line as the first line inside the subgraph. It only takes effect when no node inside the subgraph is linked directly to a node outside it.

Keep going

More Mermaid examples

Last updated 2026-11-28.