A sequence diagram is an interaction diagram that shows how processes operate with one another and in what order.

Most developers would find the syntax fairly familiar. The following example demonstrates some basic syntaxes.

A->B: Event
A->B.method() {
  if(x) {
    C.doSomething
  }
}
A->B: Event
A->B.method() {
  if(x) {
    C.doSomething
  }
}

Participants

The participants can be defined implicitly as in the first example on this page. The participants are rendered in order of appearance in the diagram source text. Sometimes you might want to show the participants in a different order than how they appear in the first message. It is possible to specify the participant’s order of appearance by doing the following:

B
A
A.method()
A->B: Event

Participant group

We can group the participants with group keyword.

group GroupName {
  A
  B
}
C
group GroupName {
  A
  B
}
C

Participant type (Annotation)

We can change the shape of the participant representation with annotations.

@Actor A
@Database B
@Boundary C
@Control D
@Entity E
@EC2 F
@ECS G
@RDS H
@S3 I
@IAM J
@Lambda K

Stereotype

It is possible to add stereotypes to participants using << and >>.

<<Callable>> B
<<Service>> A
A.method()
A->B: Event
<<Callable>> B
<<Service>> A
A.method()
A->B: Event

Starter

By default, the “client” of the interaction is not shown in the diagram. However, you can specify a “client” with the @Starter keyword. Specifically, if the starter’s name is “User” or “Actor”, we will use a Stickman icon. @Starter must be put after you have declared all participants and before any messages.

<<Callable>> B
<<Service>> A
@Starter(User)
A.method()
A->B: Event
<<Callable>> B
<<Service>> A
@Starter(User)
A.method()
A->B: Event

Messages

A message is shown as a line from the sender MessageEnd to the receiver MessageEnd.

See Unified Modeling Language v2.5.1, section 17.4.4.1.

Message type

DSL

Line and arrowhead (Spec)

Async

A->B: Async message

solid line with open arrowhead

A->B: Async Message

Sync

A.method()

filled arrowhead

A->B.method

Reply

  1. ret = A.method

  2. return ret

  3. @return

dashed line with either an open or filled arrowhead
* ZenUML renderer use open arrowhead.

// 1
ret = A.method()
B.method() {
  // 2
  return ret
  // 3
  @return
  B->A: ret
}

Object creation

new ClassName()

dashed line with an open arrowhead

new A()

Object deletion

Must end in a DestructionOccurrenceSpecification

Lost

A small black circle at the arrow end of the message

Found

A small black cirle at the starting end of the message

Loops

The loop operand will be repeated a number of times. This is expressed by the notation:

while(condition) {}
for(enumerator) {}
forEach(enumerator) {}

See the example below:

loop("Every minute") {
  Alice->Bob: Great!
}
loop("Every minute") {
  Alice->Bob: Great!
}

Alt

The alt operand represents a choice of behavior. At most one of the operands will be chosen. This is expressed by the notions:

if (condition1) {
  ...
} else if (condition2) {
  ...
} else {
  ...
}
if (x) {
  A.m1()
} else if (y) {
  A.m2()
} else {
  A.m3()
}
if (x) {
  A.m1()
} else if (y) {
  A.m2()
} else {
  A.m3()
}