Skip to main content

Sequence Diagrams

This example shows how a sequence diagram represents the interaction between objects as messages or method calls.

Simple message exchange: Alice & Bob

The classic "Hello World" of sequence diagrams shows simple messages between two participants:

Classic Alice & Bob

PlantUML source for "Classic Alice & Bob"
@startuml
Alice -> Bob: Hello Bob!
Bob --> Alice: Hi Alice!
@enduml

Sequence diagram with 2 participants: Alice and Bob.

Interactions:

  • Alice calls Bob.Hello Bob!()
  • Bob responds to Alice: 'Hi Alice!'

This minimal example demonstrates:

  • Participants are automatically created from the names used
  • Solid arrows (->) represent synchronous messages
  • Dashed arrows (-->) represent responses

Method calls with types: Café ordering

In software design, we use typed participants to show which class or role an object has. The syntax alice: Customer means "alice of type Customer".

Café order with typed participants

PlantUML source for "Café order with typed participants"
@startuml
autonumber

actor "alice: Customer" as alice
participant "bob: Waiter" as bob
participant "wallet: Wallet" as wallet

alice -> bob: orderDrink("apple juice")
bob --> alice: pay(2.00)

alice -> wallet: pay(2.00)
wallet --> alice: confirmation(walletId="ere-34-23")

alice --> bob: paid(2.00, walletId="ere-34-23")
bob --> alice: serveDrink("apple juice")
bob -> alice: "Enjoy!"

@enduml

Sequence diagram with 3 participants: alice of type Customer, bob of type Waiter and wallet of type Wallet.

Interactions:

  1. alice calls bob.orderDrink("apple juice")
  2. bob responds to alice: pay(2.00)
  3. alice calls wallet.pay(2.00)
  4. wallet responds to alice: confirmation(walletId="ere-34-23")
  5. alice responds to bob: 'paid(2.00, walletId="ere-34-23")'
  6. bob responds to alice: 'serveDrink("apple juice")'
  7. bob calls alice.Enjoy!()

This example is more realistic for software design because:

  • Participants have types (Customer, Waiter, Wallet)
  • The messages resemble method calls with parameters
  • There is a return value (confirmation)
  • There is a third object (wallet) that alice uses

With a11yDescriptionOverride

When the automatically generated description isn't suitable, you can provide a manual override using the a11yDescriptionOverride attribute. This is useful when you want to refer to an explanation in the surrounding text:

Café order

PlantUML source for "Café order"
@startuml
autonumber

actor "alice: Customer" as alice
participant "bob: Waiter" as bob

alice -> bob: orderDrink("apple juice")
bob --> alice: pay(2.00)
bob --> alice: serveDrink("apple juice")
@enduml

Sequence diagram showing a café ordering flow. See the explanation below for a step-by-step description.

Explanation of the diagram

The sequence diagram above shows the following interaction:

  1. alice orders - alice calls orderDrink("apple juice") on bob
  2. bob requests payment - bob returns pay(2.00) to alice
  3. bob serves - bob calls serveDrink("apple juice") on alice

The a11yDescriptionOverride is useful when:

  • The explanation in the surrounding text provides better context
  • The diagram type doesn't have automatic parsing support yet
  • You want to provide a more tailored description for your audience