PlantUML sequence diagram guide

PlantUML Sequence Diagram Syntax and Examples

Learn PlantUML sequence diagram syntax through an editable API example covering participants, messages, responses, conditions, and loops.

Editable PlantUML Sequence Diagram Example

Change the annotated example to see how each PlantUML sequence construct affects the rendered result.

Template
Open Full Editor
Diagram preview

Use this focused tool to draft a sequence diagram. Open the full editor for AI generation, syntax repair, sharing, and saved projects.

PlantUML Sequence Diagram Syntax at a Glance

Use the editable example to understand lifelines, request and response arrows, conditional fragments, loops, notes, and asynchronous messages.

Editable syntax example

Change a complete API authentication example and compare the source with its rendered output.

Participants and lifelines

Learn how actors, services, databases, aliases, and lifelines structure an interaction.

Requests and responses

Compare synchronous, asynchronous, solid, and dashed message arrows in context.

Conditions and repetition

Use alt, else, loop, opt, and par blocks to express realistic control flow.

Practical API example

Follow a login request through a web app, API, database lookup, and two outcomes.

Portable PlantUML source

Reuse the example in documentation, repositories, IDE extensions, or the online editor.

How to Create a PlantUML Sequence Diagram

Start with the participants, write the interaction from top to bottom, and use PlantUML blocks when the flow branches or repeats.

  1. 1

    Define actors, participants, and services as lifelines.

  2. 2

    Add messages and return values in time order.

  3. 3

    Use alt, loop, or par to describe branches, retries, and parallel work.

  4. 4

    Preview the diagram, refine the source, and export PNG or SVG.

PlantUML Sequence Diagram Syntax and Examples

Learn the PlantUML syntax behind participants, messages, return values, conditions, loops, and asynchronous interactions.

What Is a PlantUML Sequence Diagram?

A PlantUML sequence diagram is a UML behavioral diagram that shows messages exchanged between users, objects, services, and other participants in time order. It makes the order of an interaction visible, from the first request through each response or side effect.

Common Use Cases for Sequence Diagrams

Use sequence diagrams to document REST API requests and responses, login and payment flows, microservice calls, and asynchronous messages. They also help with production troubleshooting, user-story discussions, and architecture reviews because everyone can inspect the same interaction timeline.

Participants and Lifelines

Declare each lifeline with the keyword that best describes its role: actor for a person or external system, participant for a general component, boundary for an interface, control for orchestration, entity for domain data, and database for stored records. Add an alias such as participant "Payment API" as PaymentApi to keep messages short while preserving clear labels.

Messages and Return Values

Use -> for a synchronous request and --> for a return value. Use ->> and -->> when the message or response is asynchronous. Label every arrow with an action or meaningful result, such as "POST /orders" or "201 Created", so readers can understand the intent and outcome without guessing.

Conditions with alt and else

Use alt and else to show mutually exclusive outcomes in one readable interaction, such as a login, authorization check, or payment decision. Put the business condition in the alt label and make each response explicit.

alt Payment approved
  Client -> Payment API: Capture payment
  Payment API --> Client: Payment confirmed
else Payment declined
  Payment API --> Client: Decline reason
end

Loops, Notes, and Grouped Interactions

Use loop for repeated work such as polling, retries, or processing batches. Add a note over one or more participants when an assumption needs context, and use group or box to visually organize related interactions, services, or bounded responsibilities.

loop Retry up to 3 times
  Worker -> Queue: Poll message
  Queue --> Worker: Return job or empty result
end

Asynchronous Messages and Parallel Work

Use ->> to distinguish an asynchronous event or queued command from a synchronous call that waits for a reply. Use par, and, and end to show independent work that can happen in parallel, such as notifying a customer while a worker updates analytics.

Sequence Diagram Best Practices

Give participants stable, descriptive names and keep message granularity consistent across the diagram. Limit crossing lines by ordering lifelines thoughtfully, split very long flows into focused diagrams, and keep the PlantUML source with the code or documentation so the diagram can be reviewed and updated.

PlantUML Sequence Diagram Example

This editable example shows an API authentication flow with participants, request and response messages, a database lookup, and valid or invalid credential branches.

@startuml
title API Authentication Flow

actor User
participant "Web App" as App
participant "Auth API" as API
database "User Database" as DB

User -> App: Submit email and password
App -> API: POST /login
API -> DB: Find user by email
DB --> API: User record

alt Credentials are valid
  API -> API: Create access token
  API --> App: 200 OK + access token
  App --> User: Show dashboard
else Credentials are invalid
  API --> App: 401 Unauthorized
  App --> User: Show login error
end
@enduml

Why Use PlantUML for Sequence Diagrams

PlantUML keeps interaction diagrams in readable text, making them easy to edit, review, version, and export whenever system behavior changes.

Learn source and output together

The editable example keeps PlantUML syntax beside the diagram it produces.

Cover real interaction patterns

The guide focuses on API requests, responses, branches, retries, and asynchronous work.

Move from learning to production

Open the dedicated online tool when you are ready to build and export your own sequence diagram.

Frequently Asked Questions

How do I convert PlantUML to SVG online?

Paste PlantUML code into the editor, wait for the preview to render, and click Download SVG.

Do I need to install PlantUML locally?

No. This page renders PlantUML through an online preview workflow, so you do not need Java, Graphviz, or a local extension.

Can I preview the diagram before downloading SVG?

Yes. The preview panel updates before export, which helps you check the rendered diagram and catch syntax issues.

Can OnUML fix PlantUML syntax errors?

Yes. AI repair is available in the full OnUML editor. This converter page is focused on quick preview and file export.

What is the difference between this converter and the full editor?

This page is optimized for one quick conversion. The full editor adds AI generation, syntax repair, sharing, saved projects, and support for Mermaid and draw.io.

What is a PlantUML sequence diagram?

A PlantUML sequence diagram is a text-defined UML behavioral diagram that shows participants, their lifelines, and the messages they exchange over time. PlantUML renders that source into a visual interaction flow that is easy to review and version.

How do I show an API request and response?

Declare the client and API as participants, then use -> for the request and --> for the response. Add clear message labels such as "GET /profile" and "200 OK + profile" to make the REST API flow readable at a glance.

How do I add an if/else branch?

Wrap alternative outcomes in an alt block, add an else line for the second branch, and close the block with end. This is useful for login success versus failure, authorization decisions, and payment approval or decline paths.

Can I show asynchronous messages?

Yes. Use ->> for an asynchronous message, such as publishing an event or sending work to a queue, and -->> for an asynchronous response when it helps explain the flow. Combine these arrows with par blocks when concurrent work matters.

When should I use a sequence diagram?

Use a sequence diagram when the order of interactions matters: REST API behavior, user journeys, microservice orchestration, background jobs, incident investigation, or an architecture review. It is especially helpful when several systems exchange messages to complete one outcome.

Can I export a PlantUML sequence diagram as PNG or SVG?

Yes. Preview the PlantUML sequence diagram in the online tool, then export PNG for slides and quick sharing or SVG for scalable documentation and web pages. Both formats preserve the same interaction flow from the source diagram.

Need a Complete Diagram Workspace?

Open the full OnUML editor for AI generation, syntax repair, sharing, saved projects, and broader diagram workflows.

Open Full Editor