PlantUML State Diagram: Order Lifecycle

Model entity lifecycles with PlantUML state diagrams. Track order states, transitions, guards, and actions for e-commerce and workflow systems.

State Diagrams

Detailed Explanation

Order Lifecycle State Diagram

State diagrams model the lifecycle of an entity as it moves through different states in response to events. They are essential for order management, workflow engines, and any system with status tracking.

Basic Order States

@startuml
title Order Lifecycle

[*] --> Draft

Draft --> Submitted : submit()
Draft --> Cancelled : cancel()

Submitted --> Processing : accept()
Submitted --> Cancelled : cancel()
Submitted --> Draft : edit()

Processing --> Shipped : ship()
Processing --> Cancelled : cancel()

Shipped --> Delivered : confirmDelivery()
Shipped --> Returned : initiateReturn()

Delivered --> [*]
Delivered --> Returned : initiateReturn()

Returned --> Refunded : processRefund()
Refunded --> [*]
Cancelled --> [*]

@enduml

Start and End States

[*] represents both the initial state (when an arrow leaves it) and the final state (when an arrow enters it). An entity can have multiple final states.

Transition Labels

The text after the colon is the trigger (event or method call). Format: Source --> Target : trigger [guard] / action

Guards and Actions

Submitted --> Processing : accept() [paymentValid] / reserveInventory()
Processing --> Shipped : ship() [inventoryAvailable] / generateTrackingNumber()

Guards (in square brackets) are conditions that must be true for the transition to fire. Actions (after the slash) are side effects executed during the transition.

Composite States

state Processing {
  [*] --> Validating
  Validating --> Picking : validated
  Picking --> Packing : picked
  Packing --> ReadyToShip : packed
  ReadyToShip --> [*]
}

Composite states contain sub-states. The Processing state in an order system might internally go through validation, picking, packing, and readiness.

Entry and Exit Actions

state Shipped {
  entry / sendTrackingEmail()
  exit / logDeliveryAttempt()
}

Entry actions fire every time the state is entered. Exit actions fire every time the state is left. These document side effects tied to state transitions.

Use Case

Designing order management systems for e-commerce, modeling ticket workflows for support systems, documenting state machines in embedded systems, and validating business rules for approval workflows.

Try It — PlantUML Editor

Open full tool