classDiagramv0.9.4
What is a Class diagram?
Object-oriented relationships and inheritance.
classDiagram
When to use it
Use a Class when…
01
Object-oriented domain modeling
02
API client/server contracts
03
Inheritance and composition diagrams
Syntax basics
The minimal syntax
Copy this and you have a working class. Build from here.
class.mmd
classDiagram class User { +UUID id +string email +login() +logout() } class Org { +UUID id +string name } class Session { +string token +revoke() } User class="code-str">"1" -- class="code-str">"*" Session : owns Org class="code-str">"1" -- class="code-str">"*" User : employs
Common patterns
Patterns worth memorizing
Visibility prefixes
`+` public, `-` private, `#` protected, `~` package — exactly like UML.
Cardinality
`User "1" -- "*" Post : writes` — quoted multiplicities flank the relation.
Generics
`class List~T~` renders the angle brackets; useful for typed collections.
Common gotchas
The things that will trip you up
Mermaid silently ignores misspellings — these are the failures we see most.
- 01
Method bodies aren't supported — only signatures.
- 02
The relation arrow direction matters: `<|--` is inheritance pointing to the parent.
- 03
Notes attach to a class with `note for ClassName "text"`.
Related diagram types