Class diagram
Last updated: 2026-05-01
A class diagram is a static view of a software system in terms of classes (or types), their members, and their relationships. Boxes represent classes; lines between them represent inheritance, association, composition, or aggregation. Mermaid uses a familiar UML-inspired syntax: <|-- for inheritance, *-- for composition (filled diamond), o-- for aggregation (open diamond), and --> for plain association.
Class diagrams are useful for domain models (“here are the five core types in our codebase”), library overviews (“here is the public surface”), and onboarding new engineers. They are the wrong tool when the audience cares about runtime behaviour rather than type structure — for that, reach for a sequence diagram or a state diagram.
The class diagram is not the same as an ER diagram. Class diagrams describe code; ER diagrams describe database schemas. They look superficially similar but answer different questions, and the wrong choice makes the diagram harder to read.
See the dedicated class diagram guide for the full Mermaid grammar.
Related
- ER diagram — An entity-relationship diagram for database schemas. Shows tables, columns, primary and foreign keys, and the cardinality of each relationship.
- Sequence diagram — A diagram that shows messages exchanged between actors over time, drawn with vertical lifelines and horizontal arrows.