elefcode

Mermaid diagram

Class Diagram — free online editor

Mermaid class diagrams model UML classes — their members, methods, and the relationships between them.

What is a Mermaid class diagram?

Class diagrams document the structure of object-oriented code. Each class becomes a box listing fields (with visibility +, -, #) and methods. Relationship arrows show inheritance (`<|--`), composition (`*--`), aggregation (`o--`), and dependency (`<--`). Cardinality labels are also supported.

When to use it

  • Document an object-oriented domain model
  • Plan class hierarchy before coding
  • Communicate architecture in a design review
  • Generate UML from a quick code sketch

Syntax in one paragraph

Inside a class body: `+publicField : Type`, `-privateField`, `#protectedField`, `+method() Return`. Relationships: `A <|-- B` (B inherits A), `A *-- B` (composition), `A o-- B` (aggregation).

Example: Vehicle hierarchy with composition

classDiagram
    class Vehicle {
        +String make
        +String model
        +int year
        +start() void
        +stop() void
    }
    class Car {
        +int numDoors
        +drive() void
    }
    class ElectricCar {
        +int batteryKWh
        +charge() void
    }
    class Engine {
        +int cylinders
        +getHorsepower() int
    }
    Vehicle <|-- Car
    Car     <|-- ElectricCar
    Vehicle  *-- Engine

More Mermaid diagrams