Create UML class diagrams with Mermaid syntax. Classes, interfaces, inheritance, composition, and visibility modifiers. Live preview.
Loading editor...
Diagram preview will appear here...
Class diagrams show the structure of a system by mapping out classes, their attributes and methods, and the relationships between them. They are the standard UML diagram for documenting object-oriented designs, API client libraries, and domain models. Mermaid renders them from a text definition that reads like a simplified version of the code itself.
classDiagram
class UserService {
-UserRepository repo
-Logger logger
+getUser(id) User
+createUser(data) User
+deleteUser(id) void
-validate(data) bool
}
Each line inside the class block defines a member. The format is visibility name type for fields and visibility name(params) returnType for methods.
| Symbol | Meaning | UML term |
|---|---|---|
+ |
Public | Accessible from anywhere |
- |
Private | Class internal only |
# |
Protected | Class and subclasses |
~ |
Package | Same package/module |
Relationships are drawn between classes using arrow syntax:
classDiagram
Animal <|-- Dog : extends
Animal <|-- Cat : extends
Dog *-- Leg : has
Owner o-- Pet : owns
Kennel --> Dog : houses
Animal ..> Food : depends on
| Syntax | Type | Meaning |
|---|---|---|
A <|-- B |
Inheritance | B extends A |
A <|.. B |
Realization | B implements A |
A *-- B |
Composition | B is part of A, lifecycle bound |
A o-- B |
Aggregation | B belongs to A, can exist alone |
A --> B |
Association | A references B |
A ..> B |
Dependency | A uses B temporarily |
Add multiplicity labels to relationships:
Customer "1" --> "*" Order : places
Order "1" *-- "1..*" LineItem : contains
Common cardinality values: "1", "0..1", "*", "1..*", "0..*".
Mark classes as abstract, interface, enumeration, or any custom stereotype:
classDiagram
class Shape {
<<abstract>>
+area() double
+perimeter() double
}
class Drawable {
<<interface>>
+draw(canvas) void
}
class Color {
<<enumeration>>
RED
GREEN
BLUE
}
Annotations render in guillemets above the class name.
Use tildes instead of angle brackets:
classDiagram
class Repository~T~ {
+findById(id) T
+findAll() List~T~
+save(entity T) T
+delete(id) void
}
class UserRepository {
+findByEmail(email) User
}
Repository~T~ <|-- UserRepository
Repository~T~ renders as Repository<T>.
classDiagram
class Repository~T~ {
<<interface>>
+findById(id) T
+save(entity) T
+delete(id) void
}
class UserRepository {
<<interface>>
+findByEmail(email) User
}
class PostgresUserRepository {
-DataSource ds
+findById(id) User
+findByEmail(email) User
+save(entity) User
+delete(id) void
}
Repository~T~ <|.. UserRepository
UserRepository <|.. PostgresUserRepository
classDiagram
class EventEmitter {
-Map~String, List~Handler~~ listeners
+on(event, handler) void
+emit(event, data) void
+off(event, handler) void
}
class Handler {
<<interface>>
+handle(data) void
}
class LogHandler {
+handle(data) void
}
class MetricsHandler {
+handle(data) void
}
EventEmitter o-- Handler
Handler <|.. LogHandler
Handler <|.. MetricsHandler
For documenting how these classes interact at runtime, use the Mermaid Sequence Diagram. For the database tables behind your domain model, try the Mermaid ER Diagram.
Nothing you paste leaves this tab. Every tool runs entirely in your browser — no upload, no server, no account.