If you've ever needed to document how systems or components communicate who talks to whom, in what order, and under what conditions a sequence diagram is one of the clearest ways to do it. And PlantUML lets you create those diagrams using plain text. The problem? You need to know the right syntax to make it work. This reference covers the PlantUML sequence diagram syntax you'll actually use, from basic messages to advanced control structures, so you can stop guessing and start diagramming.
What Is PlantUML and Why Use It for Sequence Diagrams?
PlantUML is an open-source tool that renders diagrams from a text-based language. Instead of dragging boxes and arrows in a GUI editor, you write short, readable code that PlantUML compiles into an image. For sequence diagrams, this means you can define participants, messages, loops, conditions, and notes all in a few lines of plain text.
Why does this matter? Text-based diagrams live in version control alongside your code. They're diffable, reviewable, and easy to update. If a flow changes, you edit a line of text rather than redrawing boxes. Teams that work in Git find this especially useful for keeping documentation in sync with the actual system.
PlantUML uses the @startuml and @enduml tags to frame every diagram. Everything between those tags defines your sequence diagram.
How Do You Declare Participants in a PlantUML Sequence Diagram?
Participants are the actors, services, or objects that appear in your diagram. You declare them at the top, and PlantUML arranges them left to right in the order you define.
Here's the basic syntax:
@startuml
actor User
participant "Web Server" as WS
database "PostgreSQL" as DB
@enduml
The keyword you choose affects the icon shape:
- participant standard rectangular box
- actor stick figure (useful for human users)
- database cylinder shape
- queue queue-style box
- entity rectangular box with a different style
You can also give participants short aliases using the as keyword, like participant "Authentication Service" as Auth. This keeps your message lines shorter and more readable. If you want to control the display order differently from the declaration order, use the order keyword.
For a full breakdown of the different sequence diagram notation symbols and what they mean, that topic deserves its own dedicated look.
How Do You Send Messages Between Participants?
Messages are the core of any sequence diagram. In PlantUML, you use arrow syntax to define who sends what to whom.
A -> B : messagesolid arrow, synchronous messageA --> B : responsedashed arrow, return or asynchronous messageA ->> B : async callopen arrowhead, asynchronousA -->> B : async returndashed open arrowhead
A practical example of a login flow:
@startuml
actor User
participant "Web App" as App
participant "Auth Service" as Auth
User -> App : Enter credentials
App -> Auth : Validate credentials
Auth --> App : Token issued
App --> User : Login success
@enduml
You can also use <- and <-- to send messages in reverse direction. PlantUML figures out the layout either way, though most people find left-to-right reading easier to follow.
What About Self-Messages and Nested Calls?
Sometimes a participant needs to call itself for example, a method invoking a private helper. Use a self-arrow:
@startuml
participant Service
Service -> Service : Validate input
@enduml
For nested or recursive calls, PlantUML automatically indents the activation bar to show depth. Each message pair that stays on the same participant increases the nesting level visually.
How Do You Add Notes, Boxes, and Dividers?
Notes help explain logic that the arrows alone can't convey. You can attach them to participants or messages:
Note left of A : some noteNote right of B : some noteNote over A, B : spans both
Use box to group participants visually:
@startuml
box "Internal Services" #LightBlue
participant Auth
participant Billing
end box
@enduml
Dividers split long diagrams into logical sections with == Section Name ==.
How Do Loops, Alternatives, and Optional Blocks Work?
This is where PlantUML's syntax gets especially useful. You can model conditional logic and repetition directly in the diagram.
- Loop:
loop Every 5 minutes...end - Alternative (if/else):
alt Success...else Failure...end - Optional:
opt User is premium...end - Parallel:
par Action A...else Action B...end - Region:
region Important Section...end
Example with a loop and condition:
@startuml
Client -> Server : Poll for updates
loop Every 30 seconds
Client -> Server : GET /updates
alt New data available
Server --> Client : 200 + data
else No new data
Server --> Client : 204 No Content
end
end
@enduml
These control structures map directly to concepts in sequence diagram loop, alt, and opt notation, so if any of those blocks feel confusing, reviewing the notation details helps.
How Do You Show Activation Bars and Lifelines?
Activation bars (the thin vertical rectangles on lifelines) show when a participant is actively processing. You control them manually with activate and deactivate:
@startuml
A -> B : Request
activate B
B -> C : Forward
activate C
C --> B : Response
deactivate C
B --> A : Reply
deactivate B
@enduml
Without explicit activate/deactivate, PlantUML may or may not render them depending on the message style. For clarity in complex diagrams, explicit control is better.
How Do You Add Colors and Styling?
You can color participants, messages, and activation bars to make diagrams easier to scan:
participant Auth #LightGreenactivate B #FFDDDDA ->[#FF0000] B : critical message
You can also use skinparam directives to change fonts, arrow styles, and spacing globally. For example:
@startuml
skinparam sequenceArrowThickness 2
skinparam responseMessageBelowArrow true
@enduml
What Are the Most Common Mistakes People Make?
Working with PlantUML sequence diagrams daily, certain errors come up over and over:
- Forgetting to close blocks. Every
loop,alt,opt,par,box, andregionneeds a matchingend. Missing one produces cryptic render errors. - Mismatched aliases. If you write
as Authin the declaration but referenceAuthServicein a message, PlantUML creates a second participant instead of showing an error. - Using colons in participant names without quotes. Write
participant "My Service: V2" as MS, notparticipant My Service: V2. The colon without quotes breaks the parser. - Overcrowding a single diagram. If your diagram has 12+ participants or 50+ messages, split it into smaller focused views. Readability drops fast.
- Ignoring return messages. Diagrams with only forward arrows and no responses look incomplete. Even simple
-->dashed return arrows improve clarity.
What's the Difference Between PlantUML and Other Tools Like Mermaid?
PlantUML and Mermaid.js for sequence diagrams both use text-based syntax, but they have different strengths. PlantUML supports more advanced features like nested grouping, richer styling options, and broader diagram types beyond sequence diagrams. Mermaid renders natively in GitHub and many markdown editors, which makes it convenient for quick inline documentation. PlantUML typically requires a rendering server or local Java installation, though online editors like PlantUML's official online server remove that friction.
If your team already uses one tool consistently, the syntax differences are secondary to having diagrams that stay current. Pick the one your team will maintain.
Where Can You Practice and Render PlantUML Diagrams?
You don't need to install anything to start. Several free tools let you write and preview PlantUML code in your browser:
- PlantUML Online Server the official tool from the PlantUML team
- VS Code extensions search for "PlantUML" in the extension marketplace for live preview while you type
- IntelliJ IDEA plugin built-in PlantUML support with diagram preview
For teams, running a local PlantUML server (available as a Docker image) keeps diagram rendering fast and doesn't depend on external services.
Quick Reference: Essential PlantUML Sequence Diagram Syntax
Here's a consolidated cheat sheet for the syntax you'll use most often:
@startuml/@endumlwraps every diagramparticipant "Name" as Aliasdeclare a participantA -> B : textsolid arrow, synchronousA --> B : textdashed arrow, returnA -> B : text+activate B/deactivate Bshow processingloop ... endrepetition blockalt ... else ... endconditional branchingopt ... endoptional blockNote left of A/Note right of B/Note over A, Bannotations== Divider Text ==section separatorbox "Title" #Color ... end boxparticipant groupingA ->[#Color] Bcolored arrow
What Should You Do Next?
Start with this checklist to get productive with PlantUML sequence diagrams quickly:
- Open the PlantUML online server and paste a simple two-participant diagram to confirm rendering works.
- Write one real diagram from your current project. Pick a single user flow like login, checkout, or API call and map it out with participants, messages, and one conditional block.
- Commit the
.pumlfile to your repo next to the relevant code or docs folder. - Add it to a README or wiki page so your team sees and starts using it.
- Review the full list of sequence diagram symbols once you're comfortable with basics, so you know what's available when diagrams get more complex.
The syntax feels unfamiliar for about 15 minutes. After that, it's faster than any drag-and-drop tool for documenting system interactions and your diagrams will actually stay up to date because editing a line of text is painless.
Uml Sequence Diagram Combined Fragment Examples and Notation Guide
Sequence Diagram Loop, Alt, and Opt Notation Explained
Sequence Diagram Notation Symbols and Meanings: a Complete Visual Guide
Mermaid.js Sequence Diagram Cheat Sheet – Syntax & Code Reference
Flowchart Code Syntax: a Beginner's Guide
Mermaid Flowchart Syntax Examples and Usage