Mermaid class diagrams for interfaces and ownership

Explain a small software design using Mermaid class diagrams. Show interfaces, dependencies, composition, and multiplicities without copying every method.

Updated November 19, 2026 · 2 min read

A class diagram is most useful when it explains a design decision. Showing every field and private method can create a large picture without helping someone understand responsibilities.

Start with the part under discussion. For an order service, the important questions may be which interface handles payments and whether an order owns its line items.

Show the relationships that matter

classDiagram
  class Order {
    +String id
    +total() Decimal
  }
  class LineItem {
    +Integer quantity
    +Decimal unitPrice
  }
  class PaymentGateway {
    <<interface>>
    +charge(orderId, amount) PaymentResult
  }
  class CardGateway {
    +charge(orderId, amount) PaymentResult
  }
  class CheckoutService {
    +submit(order) PaymentResult
  }
  Order "1" *-- "1..*" LineItem : contains
  CardGateway ..|> PaymentGateway
  CheckoutService ..> PaymentGateway : uses

The filled diamond describes composition between an order and its line items. The realization arrow connects the concrete gateway to its interface. The dependency from checkout to the interface emphasizes the boundary the application relies on.

These choices are meaningful only if they match the design. Do not add inheritance because two classes happen to share a field. A dependency or a shared interface may explain the relationship more accurately.

Treat multiplicity as a review question

The example gives an order one or more line items and each line item one order. That fits an order after submission. It may not fit a draft order that starts empty.

Say which lifecycle stage the diagram represents. If a single diagram must cover both stages, either allow an empty collection or attach a note explaining the invariant at submission time. A visually tidy relationship is not a substitute for a precise rule.

Choose the right level of detail

Include public operations when they explain responsibility: submit, charge, or total conveys more than a list of getters. Omit infrastructure helpers that do not affect the discussion.

The type names here are explanatory labels, not a compilable declaration for a specific language. A class diagram also does not show call order, retries, or exceptions in enough detail to define a complete checkout protocol. Add a sequence diagram when that conversation matters.

Keep the source beside the decision

Store the Mermaid with a design note explaining why checkout depends on an interface. A future maintainer should be able to understand both the structure and the reasoning. When an implementation changes, review the note and diagram together.

In Flowgraph Studio, Manual mode supports class arrangement, members, and relationships. Keep the source open while editing to see how the changes are represented. Export an image for a presentation and retain the source for subsequent reviews.

For the complete notation, use Mermaid's class diagram documentation. The successful diagram is the one that helps a reviewer ask a better question about the design, not the one with the most boxes.

More guides