Mermaid class diagrams
A Mermaid class diagram is UML-style modelling as text: classes with attributes and methods, plus the relationships between them — inheritance, composition, association. It lives next to the code it describes and diffs in the same pull request.
A small e-commerce domain model.
Class diagrams shine for domain modelling and onboarding: one diagram of the core entities saves a new teammate hours of reading. Paste an existing model or let AI draft one from a description of your domain.
When to use a class diagram
- Domain models for design docs and RFCs
- Documenting public SDK / library surfaces
- Database-adjacent object models before writing migrations
- Teaching object-oriented design
The Mermaid code
Copy it anywhere Mermaid renders — or see the full syntax reference.
classDiagram
class Customer {
+String name
+String email
+placeOrder() Order
}
class Order {
+String id
+Date placedAt
+total() float
}
class OrderItem {
+int quantity
}
Customer "1" --> "*" Order : places
Order "1" *-- "*" OrderItem : contains
Order <|-- SubscriptionOrderFrequently asked questions
- How do I create a class diagram in Mermaid?
- Start with `classDiagram`, declare classes with their members inside braces (`class Order { +String id +total() float }`), then connect them: `A <|-- B` for inheritance, `A *-- B` for composition, `A --> B` for an association. Quoted multiplicities like "1" and "*" go on either side of the arrow.
- Does Mermaid support UML notation?
- Mermaid class diagrams cover the practical core of UML: visibility markers (+ public, - private, # protected), inheritance, interfaces via `<<interface>>` annotations, composition, aggregation, and dependencies. It's not a full UML tool, but for documentation purposes it covers what teams actually draw.
- Can I generate a class diagram from a description?
- Yes. Describe your domain to MermaidCreator's AI — 'a library system with books, members, and loans' — and it drafts the classes, members, and relationships as editable Mermaid code.
Class diagram templates
Dependency injection pattern
Class structure for injectable dependencies and container wiring.
Event sourcing architecture
Event store, projections, snapshots, and eventual consistency.
Multi-tenant architecture
Database isolation patterns for SaaS: shared schema, separate databases, and hybrid.