Mermaid for

Class diagrams

Model your code before you write it

Design object models, define relationships, and document your architecture in a format that lives next to your code.

What is a class diagram?

A class diagram is a UML structural diagram that shows the classes in a system, their attributes and methods, and the relationships between them. The Object Management Group adopted UML (Unified Modeling Language) as a standard in 1997, and the class diagram is one of its most widely used diagrams.

Class diagrams are used for upfront design and for documenting existing codebases. In Mermaid, you write them as text with classDiagram. Mermaid supports inheritance, composition, aggregation, association, dependency, and realization; multiplicity labels such as 1 and 0..*; generics; visibility markers; annotations such as <<interface>>; and namespaces.

What you can map
with a class diagram

Object-oriented system design

Domain model documentation

API resource structures

Inheritance and interface hierarchies

Database ORM layer design

Microservice data contracts

Framework and library architecture

Object-oriented system design

Domain model documentation

API resource structures

Inheritance and interface hierarchies

Database ORM layer design

Microservice data contracts

Framework and library architecture

Who uses class diagrams
on Mermaid

Developers

Design your object model before writing it, or document an existing codebase so the structure is visible.

System Architects

Define the domain model and class structure at the design stage, before implementation begins.

Tech Leads

Review class design in architecture discussions and PRs with a shareable diagram that’s always current.

Data Analysts

Understand and document the structure of an ORM or data model in a format that’s easier to read than raw code.

Consultants

Audit or redesign a client’s software architecture with a diagram that bridges business and technical stakeholders.

When a class diagram is
the right call

Product, Order, Customer, and Payment classes — with attributes, methods, and relationships mapped.

User, Role, Permission, and Session classes — showing inheritance and composition across the auth layer.

The core resource classes of an API — with their fields, types, and relationships to other resources.

A classic Observer pattern implementation — showing subject, observer, and concrete class relationships.

Less time syncing, more time building

One shared canvas for mapping ideas, collaborating live, and keeping teams on the same page, literally.

FAQ

Common questions about building class diagrams in Mermaid.

A class diagram shows the classes in a software system, their attributes, methods, and how they relate to each other. It’s a structural view of your code, used for design, documentation, and review.
An ER diagram models data: tables, columns, keys, and how records relate in a database. A class diagram models code: classes, their methods, and relationships like inheritance that databases don’t have. Use ER for schema design and class diagrams for application design.
No. A basic diagram needs only class names and arrows. The arrows follow UML conventions, such as <|-- for inheritance and *-- for composition, and you can add detail as you go.
Yes. List the main classes and their relationships, or describe the structure to Mermaid’s AI and refine the result.
Keep it in the same repo and update it in the same pull request as structural changes, so reviewers see diagram changes in the diff. Focus on the classes that matter, since a diagram of every class goes stale fastest.
FAQ Icon