PlantUML Class Diagram: Domain Modeling

Create domain models with PlantUML class diagrams for DDD projects. Define aggregates, entities, value objects, and domain events with proper UML notation.

Class Diagrams

Detailed Explanation

Domain-Driven Design Models in PlantUML

Domain modeling is where class diagrams shine. PlantUML's stereotype and packaging features map directly to DDD tactical patterns.

Defining Aggregates

@startuml
package "Order Aggregate" <<Rectangle>> {
  class Order <<Aggregate Root>> {
    -orderId: OrderId
    -status: OrderStatus
    -items: List<OrderItem>
    +addItem(product, qty): void
    +submit(): void
    +cancel(): void
  }

  class OrderItem <<Entity>> {
    -lineId: LineId
    -productId: ProductId
    -quantity: int
    -unitPrice: Money
    +subtotal(): Money
  }

  class Money <<Value Object>> {
    -amount: BigDecimal
    -currency: Currency
    +add(other: Money): Money
    +multiply(factor: int): Money
  }

  Order *-- OrderItem
  OrderItem *-- Money
}
@enduml

Stereotypes

Use <<Aggregate Root>>, <<Entity>>, <<Value Object>>, and <<Domain Event>> stereotypes to label DDD building blocks. PlantUML renders stereotypes in guillemets above the class name.

Domain Events

class OrderSubmitted <<Domain Event>> {
  -orderId: OrderId
  -submittedAt: DateTime
  -totalAmount: Money
}

Order ..> OrderSubmitted : publishes

Bounded Context Boundaries

package "Order Context" {
  class Order
  class OrderItem
}

package "Inventory Context" {
  class Product
  class StockLevel
}

Order ..> Product : references by ID only

The package boundaries visualize bounded context separation. Cross-context references should only use IDs, never direct object references — the dashed dependency arrow with a note makes this constraint explicit.

Color Coding

skinparam class {
  BackgroundColor<<Aggregate Root>> LightBlue
  BackgroundColor<<Entity>> LightGreen
  BackgroundColor<<Value Object>> LightYellow
}

Using skinparam to color-code DDD building blocks makes large domain models much easier to scan.

Use Case

Kickstarting domain modeling sessions in event storming workshops, documenting bounded contexts for microservice boundary decisions, creating shared team vocabulary artifacts, and validating aggregate designs before implementation.

Try It — PlantUML Editor

Open full tool