collab/mermaid/docs/syntax/zenuml.mdblame
View source
6dd74de1> **Warning**
6dd74de2>
6dd74de3> ## THIS IS AN AUTOGENERATED FILE. DO NOT EDIT.
6dd74de4>
6dd74de5> ## Please edit the corresponding file in [/packages/mermaid/src/docs/syntax/zenuml.md](../../packages/mermaid/src/docs/syntax/zenuml.md).
6dd74de6
6dd74de7# ZenUML
6dd74de8
6dd74de9> A Sequence diagram is an interaction diagram that shows how processes operate with one another and in what order.
6dd74de10
6dd74de11Mermaid can render sequence diagrams with [ZenUML](https://zenuml.com). Note that ZenUML uses a different
6dd74de12syntax than the original Sequence Diagram in mermaid.
6dd74de13
6dd74de14```mermaid-example
6dd74de15zenuml
6dd74de16 title Demo
6dd74de17 Alice->John: Hello John, how are you?
6dd74de18 John->Alice: Great!
6dd74de19 Alice->John: See you later!
6dd74de20```
6dd74de21
6dd74de22```mermaid
6dd74de23zenuml
6dd74de24 title Demo
6dd74de25 Alice->John: Hello John, how are you?
6dd74de26 John->Alice: Great!
6dd74de27 Alice->John: See you later!
6dd74de28```
6dd74de29
6dd74de30## Syntax
6dd74de31
6dd74de32### Participants
6dd74de33
6dd74de34The participants can be defined implicitly as in the first example on this page. The participants or actors are
6dd74de35rendered in order of appearance in the diagram source text. Sometimes you might want to show the participants in a
6dd74de36different order than how they appear in the first message. It is possible to specify the actor's order of
6dd74de37appearance by doing the following:
6dd74de38
6dd74de39```mermaid-example
6dd74de40zenuml
6dd74de41 title Declare participant (optional)
6dd74de42 Bob
6dd74de43 Alice
6dd74de44 Alice->Bob: Hi Bob
6dd74de45 Bob->Alice: Hi Alice
6dd74de46```
6dd74de47
6dd74de48```mermaid
6dd74de49zenuml
6dd74de50 title Declare participant (optional)
6dd74de51 Bob
6dd74de52 Alice
6dd74de53 Alice->Bob: Hi Bob
6dd74de54 Bob->Alice: Hi Alice
6dd74de55```
6dd74de56
6dd74de57### Annotators
6dd74de58
6dd74de59If you specifically want to use symbols instead of just rectangles with text you can do so by using the annotator syntax to declare participants as per below.
6dd74de60
6dd74de61```mermaid-example
6dd74de62zenuml
6dd74de63 title Annotators
6dd74de64 @Actor Alice
6dd74de65 @Database Bob
6dd74de66 Alice->Bob: Hi Bob
6dd74de67 Bob->Alice: Hi Alice
6dd74de68```
6dd74de69
6dd74de70```mermaid
6dd74de71zenuml
6dd74de72 title Annotators
6dd74de73 @Actor Alice
6dd74de74 @Database Bob
6dd74de75 Alice->Bob: Hi Bob
6dd74de76 Bob->Alice: Hi Alice
6dd74de77```
6dd74de78
6dd74de79Here are the available annotators:
6dd74de80![img.png](img/zenuml-participant-annotators.png)
6dd74de81
6dd74de82### Aliases
6dd74de83
6dd74de84The participants can have a convenient identifier and a descriptive label.
6dd74de85
6dd74de86```mermaid-example
6dd74de87zenuml
6dd74de88 title Aliases
6dd74de89 A as Alice
6dd74de90 J as John
6dd74de91 A->J: Hello John, how are you?
6dd74de92 J->A: Great!
6dd74de93```
6dd74de94
6dd74de95```mermaid
6dd74de96zenuml
6dd74de97 title Aliases
6dd74de98 A as Alice
6dd74de99 J as John
6dd74de100 A->J: Hello John, how are you?
6dd74de101 J->A: Great!
6dd74de102```
6dd74de103
6dd74de104## Messages
6dd74de105
6dd74de106Messages can be one of:
6dd74de107
6dd74de1081. Sync message
6dd74de1092. Async message
6dd74de1103. Creation message
6dd74de1114. Reply message
6dd74de112
6dd74de113### Sync message
6dd74de114
6dd74de115You can think of a sync (blocking) method in a programming language.
6dd74de116
6dd74de117```mermaid-example
6dd74de118zenuml
6dd74de119 title Sync message
6dd74de120 A.SyncMessage
6dd74de121 A.SyncMessage(with, parameters) {
6dd74de122 B.nestedSyncMessage()
6dd74de123 }
6dd74de124```
6dd74de125
6dd74de126```mermaid
6dd74de127zenuml
6dd74de128 title Sync message
6dd74de129 A.SyncMessage
6dd74de130 A.SyncMessage(with, parameters) {
6dd74de131 B.nestedSyncMessage()
6dd74de132 }
6dd74de133```
6dd74de134
6dd74de135### Async message
6dd74de136
6dd74de137You can think of an async (non-blocking) method in a programming language.
6dd74de138Fire an event and forget about it.
6dd74de139
6dd74de140```mermaid-example
6dd74de141zenuml
6dd74de142 title Async message
6dd74de143 Alice->Bob: How are you?
6dd74de144```
6dd74de145
6dd74de146```mermaid
6dd74de147zenuml
6dd74de148 title Async message
6dd74de149 Alice->Bob: How are you?
6dd74de150```
6dd74de151
6dd74de152### Creation message
6dd74de153
6dd74de154We use `new` keyword to create an object.
6dd74de155
6dd74de156```mermaid-example
6dd74de157zenuml
6dd74de158 new A1
6dd74de159 new A2(with, parameters)
6dd74de160```
6dd74de161
6dd74de162```mermaid
6dd74de163zenuml
6dd74de164 new A1
6dd74de165 new A2(with, parameters)
6dd74de166```
6dd74de167
6dd74de168### Reply message
6dd74de169
6dd74de170There are three ways to express a reply message:
6dd74de171
6dd74de172```mermaid-example
6dd74de173zenuml
6dd74de174 // 1. assign a variable from a sync message.
6dd74de175 a = A.SyncMessage()
6dd74de176
6dd74de177 // 1.1. optionally give the variable a type
6dd74de178 SomeType a = A.SyncMessage()
6dd74de179
6dd74de180 // 2. use return keyword
6dd74de181 A.SyncMessage() {
6dd74de182 return result
6dd74de183 }
6dd74de184
6dd74de185 // 3. use @return or @reply annotator on an async message
6dd74de186 @return
6dd74de187 A->B: result
6dd74de188```
6dd74de189
6dd74de190```mermaid
6dd74de191zenuml
6dd74de192 // 1. assign a variable from a sync message.
6dd74de193 a = A.SyncMessage()
6dd74de194
6dd74de195 // 1.1. optionally give the variable a type
6dd74de196 SomeType a = A.SyncMessage()
6dd74de197
6dd74de198 // 2. use return keyword
6dd74de199 A.SyncMessage() {
6dd74de200 return result
6dd74de201 }
6dd74de202
6dd74de203 // 3. use @return or @reply annotator on an async message
6dd74de204 @return
6dd74de205 A->B: result
6dd74de206```
6dd74de207
6dd74de208The third way `@return` is rarely used, but it is useful when you want to return to one level up.
6dd74de209
6dd74de210```mermaid-example
6dd74de211zenuml
6dd74de212 title Reply message
6dd74de213 Client->A.method() {
6dd74de214 B.method() {
6dd74de215 if(condition) {
6dd74de216 return x1
6dd74de217 // return early
6dd74de218 @return
6dd74de219 A->Client: x11
6dd74de220 }
6dd74de221 }
6dd74de222 return x2
6dd74de223 }
6dd74de224```
6dd74de225
6dd74de226```mermaid
6dd74de227zenuml
6dd74de228 title Reply message
6dd74de229 Client->A.method() {
6dd74de230 B.method() {
6dd74de231 if(condition) {
6dd74de232 return x1
6dd74de233 // return early
6dd74de234 @return
6dd74de235 A->Client: x11
6dd74de236 }
6dd74de237 }
6dd74de238 return x2
6dd74de239 }
6dd74de240```
6dd74de241
6dd74de242## Nesting
6dd74de243
6dd74de244Sync messages and Creation messages are naturally nestable with `{}`.
6dd74de245
6dd74de246```mermaid-example
6dd74de247zenuml
6dd74de248 A.method() {
6dd74de249 B.nested_sync_method()
6dd74de250 B->C: nested async message
6dd74de251 }
6dd74de252```
6dd74de253
6dd74de254```mermaid
6dd74de255zenuml
6dd74de256 A.method() {
6dd74de257 B.nested_sync_method()
6dd74de258 B->C: nested async message
6dd74de259 }
6dd74de260```
6dd74de261
6dd74de262## Comments
6dd74de263
6dd74de264It is possible to add comments to a sequence diagram with `// comment` syntax.
6dd74de265Comments will be rendered above the messages or fragments. Comments on other places
6dd74de266are ignored. Markdown is supported.
6dd74de267
6dd74de268See the example below:
6dd74de269
6dd74de270```mermaid-example
6dd74de271zenuml
6dd74de272 // a comment on a participant will not be rendered
6dd74de273 BookService
6dd74de274 // a comment on a message.
6dd74de275 // **Markdown** is supported.
6dd74de276 BookService.getBook()
6dd74de277```
6dd74de278
6dd74de279```mermaid
6dd74de280zenuml
6dd74de281 // a comment on a participant will not be rendered
6dd74de282 BookService
6dd74de283 // a comment on a message.
6dd74de284 // **Markdown** is supported.
6dd74de285 BookService.getBook()
6dd74de286```
6dd74de287
6dd74de288## Loops
6dd74de289
6dd74de290It is possible to express loops in a ZenUML diagram. This is done by any of the
6dd74de291following notations:
6dd74de292
6dd74de2931. while
6dd74de2942. for
6dd74de2953. forEach, foreach
6dd74de2964. loop
6dd74de297
6dd74de298```zenuml
6dd74de299while(condition) {
6dd74de300 ...statements...
6dd74de301}
6dd74de302```
6dd74de303
6dd74de304See the example below:
6dd74de305
6dd74de306```mermaid-example
6dd74de307zenuml
6dd74de308 Alice->John: Hello John, how are you?
6dd74de309 while(true) {
6dd74de310 John->Alice: Great!
6dd74de311 }
6dd74de312```
6dd74de313
6dd74de314```mermaid
6dd74de315zenuml
6dd74de316 Alice->John: Hello John, how are you?
6dd74de317 while(true) {
6dd74de318 John->Alice: Great!
6dd74de319 }
6dd74de320```
6dd74de321
6dd74de322## Alt
6dd74de323
6dd74de324It is possible to express alternative paths in a sequence diagram. This is done by the notation
6dd74de325
6dd74de326```zenuml
6dd74de327if(condition1) {
6dd74de328 ...statements...
6dd74de329} else if(condition2) {
6dd74de330 ...statements...
6dd74de331} else {
6dd74de332 ...statements...
6dd74de333}
6dd74de334```
6dd74de335
6dd74de336See the example below:
6dd74de337
6dd74de338```mermaid-example
6dd74de339zenuml
6dd74de340 Alice->Bob: Hello Bob, how are you?
6dd74de341 if(is_sick) {
6dd74de342 Bob->Alice: Not so good :(
6dd74de343 } else {
6dd74de344 Bob->Alice: Feeling fresh like a daisy
6dd74de345 }
6dd74de346```
6dd74de347
6dd74de348```mermaid
6dd74de349zenuml
6dd74de350 Alice->Bob: Hello Bob, how are you?
6dd74de351 if(is_sick) {
6dd74de352 Bob->Alice: Not so good :(
6dd74de353 } else {
6dd74de354 Bob->Alice: Feeling fresh like a daisy
6dd74de355 }
6dd74de356```
6dd74de357
6dd74de358## Opt
6dd74de359
6dd74de360It is possible to render an `opt` fragment. This is done by the notation
6dd74de361
6dd74de362```zenuml
6dd74de363opt {
6dd74de364 ...statements...
6dd74de365}
6dd74de366```
6dd74de367
6dd74de368See the example below:
6dd74de369
6dd74de370```mermaid-example
6dd74de371zenuml
6dd74de372 Alice->Bob: Hello Bob, how are you?
6dd74de373 Bob->Alice: Not so good :(
6dd74de374 opt {
6dd74de375 Bob->Alice: Thanks for asking
6dd74de376 }
6dd74de377```
6dd74de378
6dd74de379```mermaid
6dd74de380zenuml
6dd74de381 Alice->Bob: Hello Bob, how are you?
6dd74de382 Bob->Alice: Not so good :(
6dd74de383 opt {
6dd74de384 Bob->Alice: Thanks for asking
6dd74de385 }
6dd74de386```
6dd74de387
6dd74de388## Parallel
6dd74de389
6dd74de390It is possible to show actions that are happening in parallel.
6dd74de391
6dd74de392This is done by the notation
6dd74de393
6dd74de394```zenuml
6dd74de395par {
6dd74de396 statement1
6dd74de397 statement2
6dd74de398 statement3
6dd74de399}
6dd74de400```
6dd74de401
6dd74de402See the example below:
6dd74de403
6dd74de404```mermaid-example
6dd74de405zenuml
6dd74de406 par {
6dd74de407 Alice->Bob: Hello guys!
6dd74de408 Alice->John: Hello guys!
6dd74de409 }
6dd74de410```
6dd74de411
6dd74de412```mermaid
6dd74de413zenuml
6dd74de414 par {
6dd74de415 Alice->Bob: Hello guys!
6dd74de416 Alice->John: Hello guys!
6dd74de417 }
6dd74de418```
6dd74de419
6dd74de420## Try/Catch/Finally (Break)
6dd74de421
6dd74de422It is possible to indicate a stop of the sequence within the flow (usually used to model exceptions).
6dd74de423
6dd74de424This is done by the notation
6dd74de425
6dd74de426```
6dd74de427try {
6dd74de428 ...statements...
6dd74de429} catch {
6dd74de430 ...statements...
6dd74de431} finally {
6dd74de432 ...statements...
6dd74de433}
6dd74de434```
6dd74de435
6dd74de436See the example below:
6dd74de437
6dd74de438```mermaid-example
6dd74de439zenuml
6dd74de440 try {
6dd74de441 Consumer->API: Book something
6dd74de442 API->BookingService: Start booking process
6dd74de443 } catch {
6dd74de444 API->Consumer: show failure
6dd74de445 } finally {
6dd74de446 API->BookingService: rollback status
6dd74de447 }
6dd74de448```
6dd74de449
6dd74de450```mermaid
6dd74de451zenuml
6dd74de452 try {
6dd74de453 Consumer->API: Book something
6dd74de454 API->BookingService: Start booking process
6dd74de455 } catch {
6dd74de456 API->Consumer: show failure
6dd74de457 } finally {
6dd74de458 API->BookingService: rollback status
6dd74de459 }
6dd74de460```
6dd74de461
6dd74de462## Integrating with your library/website.
6dd74de463
6dd74de464Zenuml uses the experimental lazy loading & async rendering features which could change in the future.
6dd74de465
6dd74de466You can use this method to add mermaid including the zenuml diagram to a web page:
6dd74de467
6dd74de468```html
6dd74de469<script type="module">
6dd74de470 import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.esm.min.mjs';
6dd74de471 import zenuml from 'https://cdn.jsdelivr.net/npm/@mermaid-js/mermaid-zenuml@0.1.0/dist/mermaid-zenuml.esm.min.mjs';
6dd74de472 await mermaid.registerExternalDiagrams([zenuml]);
6dd74de473</script>
6dd74de474```