PlantUML Sequence Diagram: Basic Syntax
Learn the fundamentals of PlantUML sequence diagrams including participants, arrows, messages, and lifelines. Complete syntax guide with examples.
Detailed Explanation
PlantUML Sequence Diagram Basics
Sequence diagrams show how objects interact over time. They are one of the most commonly used UML diagram types for documenting APIs, microservice communication, and user flows.
Declaring Participants
@startuml
participant "Web Client" as WC
participant "API Server" as API
database "PostgreSQL" as DB
@enduml
Participants appear in the order they are declared. Use the as keyword to create shorter aliases. PlantUML supports several participant types: participant, actor, database, boundary, control, entity, collections, and queue.
Arrow Types
| Arrow | Meaning |
|---|---|
-> |
Solid line, solid arrowhead (synchronous call) |
--> |
Dashed line, solid arrowhead (return/response) |
->> |
Solid line, open arrowhead (asynchronous) |
--> |
Dashed return |
Adding Messages
Alice -> Bob: Hello Bob
Bob --> Alice: Hi Alice
Alice ->> Bob: Async message
The text after the colon becomes the message label on the arrow. Messages are rendered in the order they appear in the source.
Activation and Deactivation
Use activate and deactivate to show when a participant is processing:
Client -> Server: Request
activate Server
Server -> DB: Query
activate DB
DB --> Server: Results
deactivate DB
Server --> Client: Response
deactivate Server
Grouping Messages
Use alt, else, opt, loop, par, and break to group messages:
alt success
Server --> Client: 200 OK
else failure
Server --> Client: 500 Error
end
Use Case
Documenting REST API call flows, debugging microservice communication patterns, creating technical specifications for code reviews, and illustrating authentication flows for security audits.
Try It — PlantUML Editor
Related Topics
PlantUML Sequence Diagram: OAuth2 Authentication Flow
Sequence Diagrams
PlantUML Sequence Diagram: Async Message Queues
Sequence Diagrams
PlantUML Class Diagram: Inheritance and Interfaces
Class Diagrams
PlantUML Activity Diagram: Branching and Loops
Activity Diagrams
PlantUML Component Diagram: Microservices Architecture
Component Diagrams