When to use it
Requirements specifications, the analysis chapter of a thesis and coursework. Mermaid has no dedicated use case syntax, so this uses a flowchart: pills are use cases, a subgraph is the system boundary and actors sit outside it. The result matches a UML use case diagram and only the text needs editing.
Make it yours
- Actors: rectangle nodes such as
R[Reader], one per role, outside thesubgraph. - Use cases: each line inside the
subgraph, phrased as verb plus noun, such as "Borrow a book". - Connect an actor to a use case with
---, which has no arrowhead. - Write include as
A -. include .-> B(doing A always involves B) and extend asC -. extend .-> A(C happens only under a condition). - Actors are rectangles and use cases are pills, so the two are easy to tell apart; Mermaid cannot draw the UML stick figure.
Mermaid code
flowchart LR
R[Reader]
L[Librarian]
subgraph SYS[Library system]
U1([Search books])
U2([Borrow a book])
U3([Return a book])
U4([Sign in])
U5([Pay a late fee])
U6([Add books])
U7([Manage readers])
end
R --- U1
R --- U2
R --- U3
U6 --- L
U7 --- L
U2 -. include .-> U4
U3 -. include .-> U4
U5 -. extend .-> U3Ask 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 use case diagram with Mermaid flowchart LR syntax. The system is a library system and the actors are Reader and Librarian, written as rectangle nodes such as R[Reader] outside the subgraph. Put the use cases in a subgraph named "Library system", also as pills ([Text]): search books, borrow a book, return a book, sign in, pay a late fee, add books and manage readers. Connect actors to use cases with ---; write include as A -. include .-> B and extend as C -. extend .-> A. Output only the mermaid code block.
FAQ
- Can Mermaid draw a use case diagram?
Mermaid has no dedicated use case diagram type at the moment. Pill-shaped flowchart nodes for use cases and a subgraph for the system boundary give the same structure; this template is drawn that way and renders and exports normally.
- What is the difference between include and extend?
Include means the base use case always uses the included one: borrowing a book always requires signing in. Extend is optional behavior under a condition: a late fee is paid only when a return is overdue. The include arrow points from the base use case to the included one, and the extend arrow points from the extension to the base use case.
- How detailed should a use case diagram be?
One diagram per subsystem, with ten use cases or fewer. A use case is one complete thing a user can get done. Steps such as clicking a button or filling in a form are not use cases and belong in a flowchart or the use case description.
More in this category
Updated 2026-11-11