🧩 Mermaid

Class diagram

Model your domain and object structure

What is a Class diagram?

A class diagram describes the types in a system — their attributes, methods and relationships: inheritance, composition, association. It is the UML classic for domain modeling and code design.

Live example

Mermaid code
classDiagram
    class Order {
      +String id
      +Date createdAt
      +total() Money
    }
    class Customer {
      +String name
      +String email
    }
    class OrderLine {
      +int quantity
    }
    Customer "1" --> "*" Order
    Order "1" *-- "*" OrderLine
Live example

1

1

*

*

Order

+String id

+Date createdAt

+total() : Money

Customer

+String name

+String email

OrderLine

+int quantity

When to use it

Model a domain before writing code (DDD, OOP design)
Document existing codebases for onboarding
Design database object mappings and API resource models

Basic syntax

.mmd
classDiagram
    class Animal {
      +String name
      +makeSound() void
    }
    Animal <|-- Dog : inheritance

Questions about this diagram

Which relationships does Mermaid support?

Inheritance (<|--), composition (*--), aggregation (o--), association (-->), dependency (..>) and realization (..|>), each with optional cardinalities and labels.

Can I generate a class diagram from code?

Paste your classes or describe your domain and the AI extracts entities, attributes and relationships into a clean class diagram.

Create your Class diagram now

Describe it in plain language — the AI writes the Mermaid code for you.

Open Mermaid Studio