classDiagramv0.9.4

What is a Class diagram?

Object-oriented relationships and inheritance.

classDiagramUserOrgSession+ id+ email+ login()+ id+ name+ token+ revoke()
When to use it

Use a Class when…

01

Object-oriented domain modeling

02

API client/server contracts

03

Inheritance and composition diagrams

Syntax basics

The minimal syntax

Copy this and you have a working class. Build from here.

class.mmd
classDiagram
    class User {
      +UUID id
      +string email
      +login()
      +logout()
    }
    class Org {
      +UUID id
      +string name
    }
    class Session {
      +string token
      +revoke()
    }
    User class="code-str">"1" -- class="code-str">"*" Session : owns
    Org class="code-str">"1" -- class="code-str">"*" User : employs
UserOrgSession+ id+ email+ login()+ id+ name+ token+ revoke()
Common patterns

Patterns worth memorizing

Visibility prefixes

`+` public, `-` private, `#` protected, `~` package — exactly like UML.

Cardinality

`User "1" -- "*" Post : writes` — quoted multiplicities flank the relation.

Generics

`class List~T~` renders the angle brackets; useful for typed collections.

Common gotchas

The things that will trip you up

Mermaid silently ignores misspellings — these are the failures we see most.

  1. 01

    Method bodies aren't supported — only signatures.

  2. 02

    The relation arrow direction matters: `<|--` is inheritance pointing to the parent.

  3. 03

    Notes attach to a class with `note for ClassName "text"`.