If you've ever needed to explain how systems communicate with each other a login flow, an API call, a payment process you know that words alone often fall short. A sequence diagram makes those interactions visible. And PlantUML lets you create one using plain text, no drag-and-drop tools required. This reference covers the syntax you need to write PlantUML sequence diagrams from scratch, fix common errors, and build diagrams that actually make sense to your team.
What is PlantUML sequence diagram syntax?
PlantUML is a text-based diagramming tool that converts simple markup into UML diagrams. The sequence diagram syntax is a specific set of keywords and symbols you write in a .puml file to describe interactions between participants over time. Instead of drawing boxes and arrows in a GUI, you type declarations like participant, ->, and activate.
The output is a visual timeline showing messages exchanged between actors, objects, or systems read from top to bottom. This approach is especially popular with developers because the diagram source lives alongside code in version control.
For broader context on how PlantUML compares with other text-based diagramming tools, see our comparison of diagramming languages for cloud architecture.
How do you declare participants in a sequence diagram?
Every sequence diagram starts with participants the entities that exchange messages. You can declare them explicitly or let PlantUML create them implicitly when you reference them in a message.
Basic participant declarations
participant "Web Browser" as WBdeclares a participant with a display name and aliasactor "User" as Udeclares a human actor (renders as a stick figure)database "UserDB" as DBdeclares a database (renders with a cylinder icon)queue "Message Queue" as MQdeclares a queue component
If you skip the declaration entirely, PlantUML will still render the participant the first time it appears in a message. But declaring participants upfront gives you control over display order and aliases.
Controlling participant order
Participants appear left to right in the order you declare them. If you want to reorder them later, use:
order ParticipantA, ParticipantC, ParticipantB
How do you send messages between participants?
Messages are the core of any sequence diagram. In PlantUML, you write each message as a single line with an arrow between two participants.
Solid and dashed arrows
WB -> Server : Send login requestsolid arrow (synchronous message)Server --> WB : Return session tokendashed arrow (reply or asynchronous message)
The direction of the arrow (-> vs <-) controls which participant is the sender and which is the receiver. You can also use ->> for open arrows and --> for open dashed arrows if your style preference calls for them.
Self-messages
When a participant calls itself common in logging, validation, or internal method calls you write:
Server -> Server : Validate token
This renders as a loop-back arrow on the participant's lifeline.
How do you show activation and deactivation?
Activation bars indicate when a participant is actively processing a request. They make complex diagrams much easier to follow.
activate Serverstarts an activation bar on the Server lifelinedeactivate Serverends the activation bar
You can nest activations too. If Server calls the Database while already processing, you get a stacked set of bars showing both operations happening. This is one of the syntax features that separates a readable diagram from a confusing one.
How do you add conditions, loops, and alternative flows?
Real-world interactions rarely follow a single straight path. PlantUML has built-in keywords for grouping messages into logical blocks.
Conditional (alt/else)
alt Login successful
Server --> WB : Return session token
else Invalid credentials
Server --> WB : Return 401 error
end
Optional block (opt)
opt User has 2FA enabled
Server -> AuthApp : Send verification code
AuthApp --> Server : Return confirmation
end
Loop block
loop Retry up to 3 times
Client -> API : Send request
API --> Client : Response
end
Parallel execution (par)
par Send email notification
Server -> EmailService : Queue email
else Log the event
Server -> Logger : Write log entry
end
These blocks can be nested inside each other. For example, you can put an alt block inside a loop to model retry logic with different outcomes on each attempt.
How do you add notes and dividers?
Notes give context that messages alone can't convey. Dividers break long diagrams into labeled sections.
note right of Server : JWT tokens expire after 15 minutesnote left of DB : Uses connection poolingnote over WB, Server : TLS handshake happens herespans across multiple participants== Authentication Phase ==horizontal divider with label
Notes are especially useful when your diagram is shared with people who weren't involved in the original design discussion.
How do you represent time delays and lost messages?
Sometimes you need to show that time passes or that a message doesn't arrive. PlantUML supports both.
...5 minutes later...renders as a dotted gap on the timeline->x Server : Requestshows a message that was lost (X at the end)x-> Server : Requestshows a message that was lost (X at the start)
These are small syntax details, but they matter when you're documenting timeout handling, network failures, or asynchronous workflows where delivery isn't guaranteed.
How do you group participants and create references?
For diagrams with many participants, you can group them into boxes for clarity. You can also reference other diagrams to avoid cluttering a single view.
box "Backend Services" #LightBlue...end boxwraps multiple participants in a labeled boxref over Server, DB : See authentication sequencereferences another diagram or use case
Grouping helps readers scan a large diagram and quickly understand which participants belong to which subsystem. If you've worked with advanced Graphviz styling techniques, the idea of visually organizing nodes into clusters will feel familiar.
What are the most common mistakes in PlantUML sequence diagrams?
- Forgetting the
endkeyword. Everyalt,loop,opt, andparblock must close withend. Omitting it causes rendering errors with no helpful error message. - Mixing up arrow syntax. Using
-->when you meant->changes the meaning. Solid means synchronous; dashed means reply or asynchronous. Get this wrong and your diagram sends the wrong signal. - Not declaring participants first. While implicit declarations work, they give you no control over order or naming. Declare explicitly, especially in shared projects.
- Overloading one diagram. Sequence diagrams with 15+ participants become unreadable. Split into multiple linked diagrams using
ref over. - Skipping activation bars. Without them, it's hard to tell who is processing what and when. They add one line per start/end but dramatically improve readability.
- Using special characters without escaping. Characters like
~,[, and]can break rendering. Use~to escape them (e.g.,~[).
What are practical tips for better PlantUML sequence diagrams?
- Start with the happy path. Write the main success scenario first, then layer in
altandoptblocks for error and edge cases. - Use aliases consistently. If you alias
participant "Authentication Service" as Auth, useAutheverywhere. Mixing the full name and alias causes duplicate participant boxes. - Keep message labels short. Long labels stretch arrows and push participants apart. Move details into notes.
- Use themes for consistent styling. PlantUML supports built-in themes like
!theme ceruleanat the top of your file. This keeps diagrams visually consistent across a project. - Version control your
.pumlfiles. The biggest advantage of text-based diagramming is that diffs are readable. Commit diagrams alongside the code they describe. Our detailed PlantUML sequence diagram syntax reference covers more advanced patterns if you want to go deeper. - Use
hide footboxto simplify. This removes the small box at the bottom of each lifeline, which reduces visual noise in simpler diagrams.
Quick-start example: a complete login flow
Here's a working example that ties together participants, messages, activation, conditions, and notes:
@startuml
title User Login Flow
actor "User" as U
participant "Web App" as WA
participant "Auth Service" as Auth
database "UserDB" as DB
U -> WA : Enter credentials
activate WA
WA -> Auth : POST /login
activate Auth
Auth -> DB : Query user record
activate DB
DB --> Auth : User data
deactivate DB
alt Valid credentials
Auth --> WA : 200 + JWT token
note right of Auth : Token expires in 15 min
WA --> U : Show dashboard
else Invalid credentials
Auth --> WA : 401 Unauthorized
WA --> U : Show error message
end
deactivate Auth
deactivate WA
@enduml
This renders a clean, readable diagram with proper activation, conditional branches, a note, and labeled messages. It's the kind of diagram you can drop into a pull request or design doc and everyone will understand it immediately.
Where do you render PlantUML diagrams?
You have several options for converting your .puml text into images:
- PlantUML online server paste your code at plantuml.com/plantuml for instant rendering
- VS Code extension the PlantUML extension provides live preview as you type
- IntelliJ IDEA plugin integrated preview in JetBrains IDEs
- Command line generate PNG, SVG, or PDF from the Java-based PlantUML JAR
- CI/CD pipelines auto-generate diagrams as build artifacts so docs stay current
Quick reference checklist for your next sequence diagram
- Declare all participants with aliases and proper types (
participant,actor,database,queue) - Use solid arrows (
->) for requests and dashed arrows (-->) for responses - Add activation bars to show processing time on each lifeline
- Use
alt/else/endblocks for branching logic - Add notes for context that messages can't express on their own
- Keep each diagram under 8-10 participants; use
ref overto link related flows - Test rendering before committing one missing
endkeyword breaks the whole diagram - Commit
.pumlfiles to version control alongside related code
Mermaid Diagram Codes for Flowchart Creation: Syntax and Examples
Best Javascript Libraries for Programmatic Uml Diagram Generation
Advanced Graph Styling Techniques in Graphviz Dot Language
Comparing Diagramming Programming Languages for Cloud Architecture Design
Uml Diagram Implementation in Code Syntax Guide
Uml Diagram Syntax Guide: Complete Reference for All Diagram Types