Class diagrams in Confluence

A class diagram shows the types of a system, their fields and methods, and how they relate.

Last updated

When to use it

Use a class diagram to document a domain model or the layers of a service: which types exist, what they hold and which one depends on which. Inheritance, composition and interfaces each have their own arrow. Keep one diagram per topic; a diagram of every class in a codebase helps nobody.

Example

This is the code of the Domain model template: customers, orders, order lines and products with their relations.

classDiagram
  class Customer {
    +String name
    +String email
    +placeOrder()
  }
  class Order {
    +Date createdAt
    +OrderStatus status
    +total() Money
  }
  class OrderLine {
    +int quantity
    +Money unitPrice
  }
  class Product {
    +String sku
    +String name
    +Money price
  }
  Customer "1" --> "*" Order : places
  Order "1" *-- "1..*" OrderLine : contains
  OrderLine "*" --> "1" Product : refers to

Vellnar Diagrams draws it like this:

Change a line and the diagram changes with it. Nobody needs the original drawing file, because there is none: the code is the diagram.

Add it to a Confluence page

  1. Edit a Confluence page and type /mermaid where the diagram should go.
  2. Select Mermaid diagram. The editor opens with the template list.
  3. Pick a template, or choose Start blank and paste the code above. The preview follows every keystroke.
  4. Choose Save. The diagram appears on the page.

The documentation covers the editor, the settings and the exports.

Templates

The Templates button in the editor has 4 class diagrams ready to use:

  • Domain model: Customers, orders, order lines and products with their relations.
  • Service layers: Controller, service and repository behind an interface.
  • Inheritance: An abstract notification with email, SMS and push variants.
  • Event system: An event bus, event types and the handlers it notifies.

Syntax

The code of a class diagram starts with classDiagram. The Mermaid documentation describes every element of the syntax. Vellnar Diagrams draws it with Mermaid 12.3; if a line has an error, the editor marks the line and keeps the last valid diagram on screen.

More

  • Mermaid in Confluence: how diagrams as code work in a page, and every diagram type.
  • Security: the app asks for no permissions and sends nothing outside Atlassian.