> For the complete documentation index, see [llms.txt](https://www.pranaypourkar.co.in/the-programmers-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.pranaypourkar.co.in/the-programmers-guide/system-design/system-design-methodology/diagrams/uml-diagrams/plantuml/sequence-diagram.md).

# Sequence Diagram

## About

A **Sequence Diagram** in UML represents **how objects interact in a particular sequence over time**. It is primarily used to **illustrate the flow of messages between different components** in a system. This diagram is essential for understanding **dynamic behavior** and how different parts of a system communicate.

{% hint style="success" %}
Refer to the official documentation for more details - <https://plantuml.com/sequence-diagram>
{% endhint %}

#### **Key Elements**

1. **Actors & Objects**&#x20;
   * Represented as **stick figures (Actors)** or **rectangles (Objects)**.
   * Actors interact with the system (e.g., User, External System).
2. **Lifelines**&#x20;
   * Dashed vertical lines indicating **the object's existence over time**.
   * Shows how long an object is active in the sequence.
3. **Messages**&#x20;
   * Arrows representing **method calls, responses, and interactions**.
   * Types:
     * **Synchronous** (`-->`) – Caller waits for a response.
     * **Asynchronous** (`->`) – Caller continues execution without waiting.
4. **Activation Bars**&#x20;
   * Vertical rectangles on lifelines showing **when an object is active/executing**.
   * Indicate processing time for a message.
5. **Return Messages**&#x20;
   * Dashed arrows (`-->>`) representing **responses or results** sent back.
6. **Loops & Conditions**&#x20;
   * Used to **model iterations or conditional logic** (e.g., `alt`, `loop`).
7. **Destroying Objects**&#x20;
   * Represented by **‘X’** at the bottom of a lifeline when an object is deleted.

## 1. Fund Transfer

This sequence diagram represents a **user performing a fund transfer** in a banking system.

{% hint style="success" %}

* **Actors (`participant`)**: Represent different entities in the system.
* **Messages (`->`)**: Show interactions between entities.
* **Alternative (`alt ... else`)**: Conditional logic for valid/invalid accounts.
* **Self-calls (`->`)**: Represents internal method calls within the same participant.
  {% endhint %}

```plant-uml
@startuml
title Fund Transfer Process

participant User
participant "Bank API" as BankAPI
participant "Account Service" as AccountService
participant "Transaction Service" as TransactionService
participant "Notification Service" as NotificationService

User -> BankAPI: initiateTransfer(sender, receiver, amount)
BankAPI -> AccountService: validateAccounts(sender, receiver)
AccountService -> BankAPI: return validation result

alt if accounts are valid
    BankAPI -> TransactionService: processTransaction(sender, receiver, amount)
    TransactionService -> AccountService: debit(sender, amount)
    TransactionService -> AccountService: credit(receiver, amount)
    TransactionService -> BankAPI: transaction success

    BankAPI -> NotificationService: sendTransferNotification(sender, receiver)
    NotificationService -> User: notify transaction success
else if accounts are invalid
    BankAPI -> User: notify validation failure
end

@enduml
```

<figure><img src="https://3632859567-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPd6ktrA5pPLsZJktj2fm%2Fuploads%2Fn3Bzi4qO5GznRcYJN8pt%2Fplantuml-sequence-diagram-1.png?alt=media&amp;token=fe43f821-f736-4956-a702-43d1158280bf" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://www.pranaypourkar.co.in/the-programmers-guide/system-design/system-design-methodology/diagrams/uml-diagrams/plantuml/sequence-diagram.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
