Table of Contents

Sequence Diagram

Basic examples

The sequence “→” is used to draw a message between two participants. Participants do not have to be explicitly declared. To have a dotted arrow, you use –> It is also possible to use ← and ←-. That does not change the drawing, but may improve readability. <uml t=“sequence.png”> Alice → Bob: Authentication Request Bob –> Alice: Authentication Response

Alice → Bob: Another authentication Request Alice ←- Bob: another authentication Response </uml>

Comments

Everything that starts with simple quote ' is a comment. You can also put comments on several lines using /' to start and '/ to end.

Declaring participant

It is possible to change participant order using the participant keyword. It is also possible to use other keywords to declare a participant:

<uml t=“sequence_001.png”> actor Foo1 boundary Foo2 control Foo3 entity Foo4 database Foo5 Foo1 → Foo2 : To boundary Foo1 → Foo3 : To control Foo1 → Foo4 : To entity Foo1 → Foo5 : To database

</uml>

You can rename a participant using the as keyword. You can also change the background color of actor or participant. <uml t=“sequence_002.png”> actor Bob #red ' The only difference between actor 'and participant is the drawing participant Alice participant “I have a really\nlong name” as L #99FF99 /' You can also declare:

 participant L as "I have a really\nlong name"

#99FF99

'/

Alice→Bob: Authentication Request Bob→Alice: Authentication Response Bob→L: Log transaction </uml>

Use non-letters in participants

You can use quotes to define participants. And you can use the as keyword to give an alias to those participants. <uml t=“sequence_003.png”> Alice → “Bob()” : Hello “Bob()” → “This is very\nlong” as Long ' You can also declare: ' “Bob()” → Long as “This is very\nlong” Long –> “Bob()” : ok </uml>

Message to Self

A participant can send a message to itself. It is also possible to have multi-line using \n. <uml t=“sequence_004.png”> Alice→Alice: This is a signal to self.\nIt also demonstrates\nmultiline \ntext </uml>

Change arrow style

You can change arrow style by several ways:

arrow

<uml t=“sequence_005.png”> Bob →x Alice Bob → Alice Bob →> Alice Bob -\ Alice Bob \\- Alice Bob – Alice Bob →o Alice Bob o\\– Alice Bob ↔ Alice Bob ↔o Alice </uml> ====== Change arrow color ====== You can change the color of individual arrows using the following notation: <uml t=“sequence_006.png”> Bob -[#red]> Alice : hello Alice -[#0000FF]→Bob : ok </uml> ====== Message sequence numbering ====== The keyword autonumber is used to automatically add number to messages. <uml t=“sequence_007.png”> autonumber Bob → Alice : Authentication Request Bob ← Alice : Authentication Response </uml> You can specify a startnumber with autonumber 'start' , and also an increment with autonumber 'start' 'increment'. <uml t=“sequence_008.png”> autonumber Bob → Alice : Authentication Request Bob ← Alice : Authentication Response autonumber 15 Bob → Alice : Another authentication Request Bob ← Alice : Another authentication Response autonumber 40 10 Bob → Alice : Yet another authentication Request Bob ← Alice : Yet another authentication Response </uml> You can specify a format for your number by using between double-quote. The formatting is done with the Java class DecimalFormat ('0' means digit, '#' means digit and zero if absent). You can use some html tag in the format. <uml t=“sequence_009.png”> autonumber “<b>[000]” Bob → Alice : Authentication Request Bob ← Alice : Authentication Response autonumber 15 “<b>(<u>##</u>)” Bob → Alice : Another authentication Request Bob ← Alice : Another authentication Response autonumber 40 10 “<font color=red><b>Message 0 ” Bob → Alice : Yet another authentication Request Bob ← Alice : Yet another authentication Response </uml> ====== Title ====== The title keywords is used to put a title. <uml t=“sequence_010.png”> title Simple communication example Alice → Bob: Authentication Request Bob –> Alice: Authentication Response </uml> ====== Legend the diagram ====== The legend and end legend are keywords is used to put a legend. You can optionally specify to have left, right or center alignment for the legend. <uml t=“sequence_011.png”> Alice → Bob : Hello legend right Short legend endlegend </uml> ====== Splitting diagrams ====== The newpage keyword is used to split a diagram into several images. You can put a title for the new page just after the newpage keyword. This is very handy with Word to print long diagram on several pages. <uml t=“sequence_012.png”> Alice → Bob : message 1 Alice → Bob : message 2 ' newpage Alice → Bob : message 3 Alice → Bob : message 4 ' newpage A title for the\nlast page Alice → Bob : message 5 Alice → Bob : message 6 </uml> ====== Grouping message ====== It is possible to group messages together using the following keywords: * alt/else * opt * loop * par * break * critical * group, followed by a text to be displayed It is possible a add a text that will be displayed into the header (except for group). The end keyword is used to close the group. Note that it is possible to nest groups. <uml t=“sequence_013.png”> Alice → Bob: Authentication Request alt successful case Bob → Alice: Authentication Accepted else some kind of failure Bob → Alice: Authentication Failure group My own label Alice → Log : Log attack start loop 1000 times Alice → Bob: DNS Attack end Alice → Log : Log attack end end else Another type of failure Bob → Alice: Please repeat end </uml> ====== Notes on messages ====== It is possible to put notes on message using the note left or note right keywords just after the message. You can have a multi-line note using the end note keywords. <uml t=“sequence_014.png”> Alice→Bob : hello note left: this is a first note Bob→Alice : ok note right: this is another note Bob→Bob : I am thinking note left a note can also be defined on several lines end note </uml> ====== Some other notes ====== It is also possible to place notes relative to participant with note left of , note right of or note over keywords. It is possible to highlight a note by changing its background color. You can also have a multi-line note using the end note keywords. <uml t=“sequence_015.png”> participant Alice participant Bob note left of Alice #aqua This is displayed left of Alice. end note note right of Alice: This is displayed right of Alice. note over Alice: This is displayed over Alice. note over Alice, Bob #FFAAAA: This is displayed\n over Bob and Alice. note over Bob, Alice This is yet another example of a long note. end note </uml> ====== Changing notes shape ====== You can use hnote and rnote keywords to change note shapes. <uml t=“sequence_016.png”> caller → server : conReq hnote over caller : idle caller ← server : conConf rnote over server “r” as rectangle “h” as hexagon endrnote </uml> ====== Creole and HTML ====== It_is_also_possible_to_use_creole_formatting: <uml t=“sequence_017.png”> participant Alice participant “The Famous Bob” as Bob Alice → Bob : hello –there– … Some ~~long delay~~ … Bob → Alice : ok note left This is bold This is italics This is ““monospaced”” This is –stroked– This is underlined This is ~~waved~~ end note Alice → Bob : A well formatted message note right of Alice This is <back:cadetblue><size:18>displayed</size></ back> left of Alice. end note note left of Bob <u:red>This</u> is <color #118888>displayed</color> <color purple>left of</color> <s:red>Alice</strike> Bob. end note note over Alice, Bob <w:#FF33FF>This is hosted</w> by <img sourceforge.jpg> end note </uml> ====== Divider ====== If you want, you can split a diagram using == separator to divide your diagram into logical steps. <uml t=“sequence_018.png”> == Initialization == Alice → Bob: Authentication Request Bob –> Alice: Authentication Response == Repetition == Alice → Bob: Another authentication Request Alice ←- Bob: another authentication Response </uml> ====== Reference ====== You can use reference in a diagram, using the keyword ref over. <uml t=“sequence_019.png”> participant Alice actor Bob ref over Alice, Bob : init Alice → Bob : hello ref over Bob This can be on several lines end ref </uml> ====== Delay ====== You can use … to indicate a delay in the diagram. And it is also possible to put a message with this delay. <uml t=“sequence_020.png”> Alice → Bob: Authentication Request … Bob –> Alice: Authentication Response …5 minutes latter… Bob –> Alice: Bye ! </uml> ====== Space ====== You can use ||| to indicate some spacing in the diagram. It is also possible to specify a number of pixel to be used. <uml t=“sequence_021.png”> Alice → Bob: message 1 Bob –> Alice: ok ||| Alice → Bob: message 2 Bob –> Alice: ok ||45|| Alice → Bob: message 3 Bob –> Alice: ok </uml> ====== Lifeline Activation and Destruction ====== The activate and deactivate are used to denote participant activation. Once a participant is activated, its lifeline appears. The activate and deactivate apply on the previous message. The destroy denote the end of the lifeline of a participant. <uml t=“sequence_022.png”> participant User User → A: DoWork activate A A → B: « createRequest » activate B B → C: DoWork activate C C –> B: WorkDone destroy C B –> A: RequestCreated deactivate B A → User: Done deactivate A </uml> Nested lifeline can be used, and it is possible to add a color on the lifeline. <uml t=“sequence_023.png”> participant User User → A: DoWork activate A #FFBBBB A → A: Internal call activate A #DarkSalmon A → B: « createRequest » activate B B –> A: RequestCreated deactivate B deactivate A A → User: Done deactivate A </uml> ====== Participant creation ====== You can use the create keyword just before the first reception of a message to emphasize the fact that this message is actually creating this new object. <uml t=“sequence_024.png”> Bob → Alice : hello create Other Alice → Other : new create control String Alice → String note right : You can also put notes! Alice –> Bob : ok </uml> ====== Incoming and outgoing messages ====== You can use incoming or outgoing arrows if you want to focus on a part of the diagram. Use square brackets to denote the left “[” or the right “]” side of the diagram. <uml t=“sequence_025.png”> [→ A: DoWork activate A A → A: Internal call activate A A →] : « createRequest » A←-] : RequestCreated deactivate A [← A: Done deactivate A </uml> You can also have the following syntax: <uml t=“sequence_026.png”> [→ Bob [o→ Bob [o→o Bob [x→ Bob [← Bob [x← Bob Bob →] Bob →o] Bob o→o] Bob →x] Bob ←] Bob x←] </uml> ====== Stereotypes and Spots ====== It is possible to add stereotypes to participants using « and ». In the stereotype, you can add a spotted character in a colored circle using the syntax (X,color). <uml t=“sequence_027.png”> participant “Famous Bob” as Bob « Generated » participant Alice « (C,#ADD1B2) Testable » Bob→Alice: First message </uml> <uml t=“sequence_028.png”> participant Bob « (C,#ADD1B2) » participant Alice « (C,#ADD1B2) » Bob→Alice: First message </uml> ====== More information on titles ====== You can use creole_formatting in the title. <uml t=“sequence_029.png”> title Simple communication example Alice → Bob: Authentication Request Bob → Alice: Authentication Response </uml> You can add newline using \n in the title description. <uml t=“sequence_030.png”> title Simple communication example\non several lines Alice → Bob: Authentication Request Bob → Alice: Authentication Response </uml> You can also define title on several lines using title and end title keywords. <uml t=“sequence_031.png”> title <u>Simple</u> communication example on <i>several</i> lines and using <font color=red>html</font> This is hosted by <img:sourceforge.jpg> end title Alice → Bob: Authentication Request Bob → Alice: Authentication Response </uml> ====== Participants encompass ====== It is possible to draw a box around some participants, using box and end box commands. You can add an optional title or a optional background color, after the box keyword. <uml t=“sequence_032.png”> box “Internal Service” #LightBlue participant Bob participant Alice end box participant Other Bob → Alice : hello Alice → Other : hello </uml> ====== Removing Footer ====== You can use the hide footbox keywords to remove the footer of the diagram. <uml t=“sequence_033.png”> hide footbox title Footer removed Alice → Bob: Authentication Request Bob –> Alice: Authentication Response </uml> ====== Skinparam ====== You can use the skinparam command to change colors and fonts for the drawing. You can use this command: * In the diagram definition, like any other commands, * In an included_file, * In a configuration file, provided in the command_line or the ANT_task. <uml t=“sequence_034.png”> skinparam backgroundColor #EEEBDC skinparam sequence { ArrowColor DeepSkyBlue ActorBorderColor DeepSkyBlue LifeLineBorderColor blue LifeLineBackgroundColor #A9DCDF ParticipantBorderColor DeepSkyBlue ParticipantBackgroundColor DodgerBlue ParticipantFontName Impact ParticipantFontSize 17 ParticipantFontColor #A9DCDF ActorBackgroundColor aqua ActorFontColor DeepSkyBlue ActorFontSize 17 ActorFontName Aapex } actor User participant “First Class” as A participant “Second Class” as B participant “Last Class” as C User → A: DoWork activate A A → B: Create Request activate B B → C: DoWork activate C C –> B: WorkDone destroy C B –> A: Request Created deactivate B A –> User: Done deactivate A </uml>