cheatsheet / current
Class Diagram
Use Mermaid classDiagram to show classes, interfaces, inheritance, composition, and associations in object-oriented designs.
Class Diagram
Use Mermaid classDiagram to show classes, interfaces, inheritance, composition, and associations in object-oriented designs.
Basic template
classDiagram
class User
class Account
User --> Account
Core syntax
- Start with
classDiagram - Define a class with
class Name - Add members inside braces
- Use
+public,-private,#protected - Show relationships with:
--|>inheritance..|>interface realization-->association*--compositiono--aggregation
Common example
classDiagram
class User {
+string name
+login()
}
class Report {
+run()
}
class ExportService {
+export(report)
}
class CsvExporter {
+write(data)
}
User --> Report : runs
Report --> ExportService : uses
ExportService *-- CsvExporter : owns
Good for
- Domain models
- Code design notes
- Refactoring discussions
Watch for
- Mermaid class diagrams are great for structure, not detailed UML perfection
- Keep method lists short unless the note is specifically about API design