If you work with software documentation, architecture planning, or team communication, you have probably needed to describe how components interact with each other over time. PlantUML sequence diagrams let you do exactly that using plain text instead of dragging boxes around in a drawing tool. Having a solid PlantUML sequence diagram syntax reference handy saves you from constantly searching for the right keywords, arrow types, and formatting options every time you sit down to document a process.
What Is a PlantUML Sequence Diagram?
A PlantUML sequence diagram is a text-based diagram that shows how different participants (objects, systems, users, or services) exchange messages in a time-ordered flow. You write simple markup, and PlantUML renders a visual diagram from it. This approach falls under the broader category of diagram-as-code tools for developers, where diagrams live alongside your source code and get version-controlled just like any other file.
Because you define everything in text, you can diff changes, review diagram updates in pull requests, and generate diagrams automatically in your build pipeline. No binary image files to manage. No proprietary file formats that lock you into one editor.
How Do You Start a Sequence Diagram in PlantUML?
Every sequence diagram begins and ends with specific keywords. Here is the bare minimum you need:
@startuml
Alice -> Bob: Hello there
@enduml
The @startuml and @enduml tags wrap your diagram definition. Between those tags, each line represents a message or a structural element. PlantUML automatically creates participant boxes from the names you use in message lines.
How Do You Declare Participants?
You can let PlantUML auto-detect participants from your message lines, but explicit declarations give you more control over ordering, aliases, and display names.
actor "User" as Udeclares a stick-figure actor with an aliasparticipant "Order Service" as OSstandard participant boxdatabase "PostgreSQL" as DBdatabase-shaped boxqueue "RabbitMQ" as MQqueue-shaped boxcollections "Cache Layer" as CLcollections-shaped box
The declaration order determines the left-to-right positioning of participants in the rendered diagram. If you want to reorder them, change the declaration order rather than relying on automatic detection.
What Arrow Types Are Available?
Arrow syntax is the core of any sequence diagram. PlantUML supports several arrow styles that communicate different types of interaction:
A -> Bsolid arrow with a solid head (synchronous message)A ->> Bsolid arrow with an open head (asynchronous message)A --> Bdashed arrow (return or response message)A -->> Bdashed arrow with an open headA ->o Barrow ending with a circleA o-> Barrow starting with a circleA <-> Bbidirectional solid arrowA <--> Bbidirectional dashed arrow
You can also add x at the end (like A ->x B) to indicate a lost message, or use o to show a found message. These small details make your diagrams more precise and closer to formal UML semantics.
How Do You Add Notes and Comments?
Notes give context to specific messages or participants. PlantUML offers several placement options:
note left of Alice: She initiated the requestnote right of Bob: He processes itnote over Alice, Bob: This is a shared note
For multi-line notes, use the end note syntax:
note left of Alice
This note spans
multiple lines
end note
Floating notes (not attached to any participant) can be positioned using rnote or by placing them after a specific message number.
How Do You Show Loops, Alternatives, and Conditions?
Sequence diagrams in PlantUML support combined fragments that mirror UML's interaction operators. These are some of the most commonly used ones:
Loops:
loop every 5 minutes
Alice -> Bob: Heartbeat ping
Bob --> Alice: Ack
end
Alternative (if/else):
alt success
Bob --> Alice: OK response
else failure
Bob --> Alice: Error response
end
Optional:
opt authenticated request
Alice -> Bob: Protected resource
end
Parallel:
par send email
Alice -> EmailService: Welcome email
also send notification
Alice -> PushService: Push notification
end
You can nest these blocks inside each other, which is useful for modeling complex workflows with multiple decision points.
How Do You Group Messages Into Boxes and Dividers?
When your diagram covers a long flow, visual grouping helps readers follow the logic.
box "Authentication Phase" #LightBlue...end boxwraps participants and messages in a colored region== Step 3: Payment Processing ==inserts a horizontal divider with a label
Dividers work well for breaking a long sequence into logical stages without adding structural complexity.
How Do You Show Object Creation and Destruction?
Sequence diagrams sometimes need to show when a participant appears or disappears during the interaction:
create Participant Cthe participant is created at this point in the sequencedestroy Cthe participant is destroyed (shown with an X marker)
Creation messages use a dashed arrow with a create keyword:
Alice -> create C: new C()
How Do You Use Activation and Deactivation?
Activation bars (the thin rectangles on lifelines) show when a participant is actively processing. You can control these manually:
activate Bobstarts an activation bar on Bob's lifelinedeactivate Bobends it
You can also use shorthand by adding + and - to your arrows:
Alice -> Bob: Process order
activate Bob
Bob -> DB: Query inventory
DB --> Bob: Results
deactivate Bob
Bob --> Alice: Order confirmed
PlantUML often auto-generates activation bars, but explicit control keeps your diagram accurate when multiple calls overlap.
How Do You Handle Self-Messages and Ref Frames?
A participant can send a message to itself:
Alice -> Alice: Validate input
This shows a message arrow that loops back to the same lifeline. Self-activation is automatically drawn if you use activate and deactivate around it.
For referencing another sequence diagram (a "ref" frame), you can use:
ref over Alice, DB: See Authentication Sequence
This is useful when you want to point readers to a more detailed sub-diagram without cluttering the current one.
How Do You Customize the Look of Your Diagram?
PlantUML supports skin parameters that change the visual style:
skinparam backgroundColor #FEFEFEskinparam sequenceArrowThickness 2skinparam roundcorner 10skinparam maxMessageSize 200hide footboxremoves the foot boxes at the bottom of lifelines
You can also apply inline styling with #color on individual elements and use themes by including predefined style sheets.
What Are Common Mistakes When Writing Sequence Diagrams?
These errors come up frequently, especially when you are new to PlantUML syntax:
- Missing @enduml the renderer will throw a syntax error, and the cause is not always obvious
- Mismatched alt/else/end blocks every
alt,loop,opt, andparblock must have a matchingend - Confusing arrow direction
->sends rightward,<-sends leftward, and mixing them up reverses the message flow - Forgetting return arrows using
-->for responses clarifies that a message is a return value, not a new request - Overcrowding a single diagram splitting complex flows across multiple linked diagrams with ref frames keeps things readable
- Not using aliases long participant names repeat in every message line; aliases reduce clutter and make edits easier
What Are Useful PlantUML Sequence Diagram Shortcuts?
A few lesser-known features can speed up your workflow:
autonumberautomatically numbers every message, which helps during reviews and discussionsautonumber 10 10starts at 10 and increments by 10header My Diagram Titleadds a header to the rendered outputfooter Page 1adds a footertitle Diagram Titleadds a centered title above the diagramnewpagesplits the diagram across multiple pages in the outputgroup Authenticationsimilar toboxbut labeled with a UML combined fragment frame
These features are especially helpful when you are generating documentation from PlantUML files automatically.
How Does PlantUML Compare to Other Diagram Tools?
PlantUML is not the only text-based diagram option available. If you are evaluating alternatives, tools like Mermaid for flowcharts and other Mermaid diagram examples are worth exploring. Mermaid has a simpler syntax and integrates natively with GitHub Markdown, while PlantUML supports a wider range of diagram types and more detailed UML constructs. Your choice depends on whether you need basic flow documentation or formal UML modeling.
For the official syntax details and full feature list, the PlantUML sequence diagram documentation is the authoritative reference maintained by the project.
Quick Syntax Checklist for Your Next Diagram
- Wrap everything in
@startumland@enduml - Declare participants in the order you want them displayed
- Use
->for requests and-->for responses - Add
autonumberfor easier discussion references - Use
alt/else/endfor conditional flows - Use
loop/endfor repeated interactions - Add notes for context that the arrows alone cannot convey
- Break long diagrams with
refframes or==dividers - Use aliases for long participant names
- Test your diagram by rendering it at each major edit do not batch a full document and troubleshoot at the end
Start by sketching the simplest version of your flow with just participants and messages. Once the basic shape looks right, layer on notes, fragments, and styling. That incremental approach catches syntax errors early and keeps your diagrams clear from the start.
Uml Diagram Code Snippets in Python
Diagram as Code Tools for Developers Comparison
Mermaid Flowchart Syntax and Examples Reference Guide
Mermaid Diagram Code Examples and Snippet Collection
Diagram Codes and Symbols: What They Mean in Diagramming Software
Uml Diagram Codes Quick Reference Cheat Sheet for Diagramming Software