- System: install plantuml (e.g.
brew install plantuml
) - Emacs: install plantuml-mode. Configuration:
(setq plantuml-jar-path "/usr/local/Cellar/plantuml/1.2019.6/libexec/plantuml.jar")
(setq plantuml-jar-args '("-charset" "UTF-8" "-config" "~/plantuml.txt"))
(setq org-startup-with-inline-images t)
(add-to-list 'org-src-lang-modes '("plantuml" . plantuml))
(org-babel-do-load-languages
'org-babel-load-languages
'((plantuml . t)))
C-c C-c
in a source block to render a diagram.- May need to
org-toggle-inline-images
to view inline.
#+begin_src plantuml :file output.png
- Begin diagram
#+end_src
- End diagram
#+STARTUP: inlineimages
- Display diagrams inline (put at top of file)
Bob -> Alice : Hello, alice
User -> (Start)
User --> (Use the application) : A small label
:Main Admin: ---> (Use the application) : This is\nyet another\nlabel
->
or<-
- Solid arrow
-->
or<--
- Dotted arrow
-\
or-/
- Half arrowhead
- -~\~,
->>
,<<-
,-//
- Skinny arrowhead
->o
- Arrow points to circle
<->
- Bidirectional arrow
-[#red]->
- Arrow color
[->
,->]
,[<-
,<-]
- Un-anchored lines
Bob ->x Alice
Bob -> Alice
Bob ->> Alice
Bob -\ Alice
Bob \\- Alice
Bob //-- Alice
Bob ->o Alice
Bob o\\-- Alice
Bob <-[#green]-> Alice
Bob <->o Alice
Bob -> Bob
Alice -> Alice
[--> Bob
Alice -->]
[<-- Bob
Alice <--]
actor ActorName
- Define an actor
boundary BoundaryName
- Define boundary system
control ControlName
- Define a control system
entity EntityName
- Define an entity
database DatabaseName
- Define a database
collections CollectionsName
- Define a collection
actor Actor #red
boundary Boundary #orange
control Control #yellow
entity Entity #green
database Database #blue
collections Collections #white
participant Participant #white
Actor -> Boundary : To boundary
Actor -> Control : To control
Actor -> Entity : To entity
Actor -> Database : To database
Actor -> Collections : To collections
Actor -> Participant : To Participant
autonumber <start>
- Begin numbering at <start> or 1
actor Actor #red
boundary Boundary #orange
control Control #yellow
entity Entity #green
database Database #blue
collections Collections #white
participant Participant #white
autonumber
Actor -> Boundary : To boundary
Actor -> Control : To control
Actor -> Entity : To entity
Actor -> Database : To database
Actor -> Collections : To collections
Actor -> Participant : To Participant
header <content>
- Defines header content
title
<content>- Defines title content
footer <content>
- Defines footer content
title Sequence Title Example
header Sequence Diagrams
footer Page %page% of %lastpage%
actor Actor #red
boundary Boundary #orange
control Control #yellow
entity Entity #green
database Database #blue
collections Collections #white
participant Participant #white
autonumber
Actor -> Boundary : To boundary
Actor -> Control : To control
Actor -> Entity : To entity
Actor -> Database : To database
Actor -> Collections : To collections
Actor -> Participant : To Participant
alt <title> ... else <title> ... end
- Define alternates
loop <title>
- Steps in group are looped
par
- Steps run in parallel
break
- Steps supercede subsequent steps
critical
- Steps must not be interleaved
group <title>
- Custom grouping
title Sequence Diagram with Alternate Paths
Alice -> Bob: Authentication Request
alt Successful authentication
Bob -> Alice: Authentication Accepted
else Authentication failure
Bob -> Alice: Authentication Failure
else Connection failure
Alice -> Bob: Repeat request
end
title Sequence Diagram with Loop
Alice -> Log : Log attack start
loop 1000 times
Alice -> Bob: DNS Attack
end
title Sequence Diagram with Parallel
Alice -> Log : Log attack start
par
Alice -> Bob: DNS Attack
Alice -> Bob: Fuzz Attack
Alice -> Bob: Social Engineering Attack
end
Put note below the message
note left: <note text>
- Add a note to the left
note right: <note right>
- Add a note to the right
note left ... end note
- Multiline note
Put note below the participant
note left of <Participant>
- Place note left of participant
note over <Participant>
- Place note over participant
note right of <Particpant>
- Place note right of participant
title Sequence Diagram With Notes
participant Alice
participant Bob
Alice -> Bob : Good Morning. How was your weekend?
note left: Alice greets Bob.
Alice <- Bob : Hi Alice! Great snow in Tahoe this weekend.
note right #E3DCCA: Bob greets Alice.
note left of Alice #E3DCCA
This is displayed
Left of alice.
end note
note right of Alice: This is displayed to the right of Alice.
note over Alice: This is displayed over Alice.
note over Alice, Bob #F9DEDE
This is displayed
over Alice and Bob.
end note
**bold**
- Bold text
//italics//
- Italics text
""monospaced""
- Monospaced text
--strikethrough--
- Strikethrough text
__underline__
- Underlined text
~~wavy underline~~
- Wavy underline text
title Sequence Diagram With Formatting
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
== label ==
- Insert a split
title Sequence Diagram With Splits
== Initialization ==
Alice -> Bob: Authentication Request
Bob --> Alice: Authentication Response
== ==
Alice -> Bob: Another authentication Request
Alice <-- Bob: another authentication Response
...
- A delay in the sequence
|||
- Add extra Vertical Spacing
title Sequence Diagram With Delays and Spacing
Alice -> Bob: message 1
...
Bob --> Alice: ok
|||
Alice -> Bob: message 2
...5 minutes later...
Bob --> Alice: ok
||45||
Alice -> Bob: message 3
Bob --> Alice: ok
activate <id>
or++
- Mark start of lifeline <id>
deactivate <id>
or--
- Mark end of lifeline <id>
autoactivate on
- Turn on autoactivation
create <type> <name>
or**
- Create a participant
destroy <id>
or!!
- Destroy participant
return <label>
- Deactivate lifeline with <label>
title Sequence Diagram With Lifelines
participant User
User -> A: DoWork
activate A #4682AF
A -> A: Internal call
activate A #F9DEDE
A -> B: << createRequest >>
activate B
B -> C: DoWork
activate C
C --> B: WorkDone
destroy C
B --> A: RequestCreated
deactivate B
deactivate A
A -> User: Done
deactivate A
title Sequence Diagram With Auto-Lifelines
autoactivate on
participant User
User -> A: UserRequest
A -> A: Internal call
A -> B: << createRequest >>
B -> C: DoWork
return Work Done
return RequestCreated
return InternalResponse
return UserResponse
title Sequence Diagram With Shortcut Lifelines
alice -> bob ++ : hello
bob -> bob ++ : self call
bob -> bib ++ #005500 : hello
bob -> george ** : create
return done
return rc
bob -> george !! : delete
return success
- ~create <participant type> <participant name>
- Create a participant
title Sequence Diagram With Participant Creation
Bob -> Alice : hello
create Other
Alice -> Other : new
create control String
Alice -> String
note right : You can also put notes!
Alice --> Bob : ok
box <name> <color> ... end box
- Wrap in a box
title Sequence Diagram With System Boundary
box "Internal Service"
participant Bob
participant Alice
end box
participant Other
Bob -> Alice : hello
Alice -> Other : hello
entity EntityName
- Define an entity
* indentifying_attribute
- Identifying attribute
--
- Divider
* indentifying_attribute
- Identifying attribute
optional_attribute
- Optional attribute
A |o--o| B
- Zero or one
A ||--|| B
- Eactly one
A }o--o{ B
- Zero or many (“crows foot”)
A }|--|{
- One or many
title Example Entity Relationship Diagram
entity Customer {
first_name
last_name
}
entity Address {
street_1
street_2
city
state
postal_code
country
}
entity Order {
order_amount
tax_amount
shipping_amount
total_amount
}
entity OrderItem {
}
entity Item {
description
}
Customer }o--o{ Address
Order }o--o{ Customer
Order }o--|| Address : shipping
Order }o--o| Address : billing
Order ||--|{ OrderItem
OrderItem }o--|| Item
--
- Solid line
..
- Dotted line
<|--
,--|>
- Extension
*--
,--*
- Composition
o--
,--o
- Aggregation
()--
,--()
- Lollipop (interfaces)
--
- Relationships with two dashes are laid out vertically
-
- Relationships with one dash are laid out horizontally
Class A -- Class B
- Relation
ClA -- ClB : label
- Labeled relation
Driver - Car : drives >
<
,>
“acts on” label
(Student, Course) .. Enrollment
- Enrollment associates Student & Course
<ClassName> : <field>
- Add a field to a class
<ClassName> : <method>()
- Add a method to a class
class <ClassName> { (fields/methods) }
- Define a class
-
: private#
: protected~
: package private+
: public
{static}
- static modifier
{abstract}
- Abstract modifer
<< name >>
- Stereotype (interface)
enum
- Define an enumeration
- anootation
- Define an annotation
==
- Thick line
..
- Dotted line
--
- Plain line
__
- Medium line
-- label --
- Labeled line
note "text" as N1
- Define a floating note; attach with
..
note left of <class>
- Attach note above <class>
note right of <class>
- Attach note right <class>
note top of <class>
- Attach note top <class>
note bottom of <class>
- Attach note bottom <class>
note <left|right|top|bottom> on link
- Add a note to a link
title Example Class Diagram
HumanDriver "1" -- Car : drives >
MachineDriver "1" -- Car : controls >
Car *- "4" Wheel : has >
note bottom on link #F9DEDE: TODO: change to # axles
Car --> HumanDriver : < owns
Driver ()-- HumanDriver
Driver ()-- MachineDriver
note as DISCLAIMER
Use flymode at your own risk.
Provided as-is.
end note
note top of Driver : Can be human or machine
abstract class Driver
class HumanDriver << Driver >> {
+ name
+ dob
+ license
}
DISCLAIMER .. Car
class Car {
- internalSpecs
--
+ color
+ turn()
+ accelerate()
+ brake()
..
+ fly()
}
class Foo {
color
wheels
}