VP OpenDocs: Modeling Dynamic E-Commerce Flows with VPasCode Sequence Diagrams

In modern software architecture, understanding the flow of data between components is just as critical as understanding the components themselves. This tutorial explores how to construct a robust Sequence Diagram using VPasCode’s PlantUML integration. By shifting from static drawing tools to code-based modeling, teams can ensure their architectural documentation remains synchronized with their actual application logic.
The diagram captured in the provided interface illustrates a classic Order Processing Flow. It maps the journey of a transaction from the moment a customer initiates an action in the Web App, through the API Gateway, and into the orchestration of backend microservices.
1. Defining the Participants
The foundation of any sequence diagram is the definition of the actors and participants. In VPasCode, this is done using the actor and participant keywords. These are the “lifelines” that the vertical dashed lines represent in the visual output.
For our e-commerce example, we define the external user and the internal system boundaries:
@startuml
title Order Processing Flow
actor Customer
participant "Web App" as web
participant "API Gateway" as gateway
participant "Order Service" as order
participant "Payment Service" as payment
participant "Inventory Service" as inventory
database "Order DB" as orderdb
@enduml
- Actor: Represents an entity outside the system boundary. Here, the
Customeris the trigger for the entire process. - Participants: These are the system components. We use aliases (e.g.,
as web) to make the message references concise and readable later in the code. - Databases: In PlantUML, specific database shapes can be rendered using the
databasekeyword, as seen with theOrder DB.
2. Mapping the Request Lifecycle
The diagram is divided into three distinct phases: Request Handling, Business Logic, and Response Handling.
Phase 1: Request Handling
The sequence begins with the customer placing an order. The traffic flows through the frontend and the gateway.
Customer -> web : Place Order
web -> gateway : POST /orders
gateway -> order : Create Order
Note the syntax Actor -> Participant : Message. This represents a synchronous message (a solid line with a filled arrowhead), implying the sender waits for the receiver to process the request.
Phase 2: Business Logic & Orchestration
The Order Service acts as the orchestrator. It does not handle inventory or payments directly but delegates these responsibilities to other microservices.
order -> inventory : Check Availability
inventory --> order : Available
order -> payment : Process Payment
payment --> order : Payment Confirmed
order -> orderdb : Save Order
Here, we see a mix of synchronous calls and return messages. For instance, when the Order Service checks availability, it sends a request to the Inventory Service. The Inventory Service returns a status (solid line with an open arrowhead, inventory --> order), indicating the completion of that specific task.
3. Handling Asynchronous Returns
One of the most common errors in sequence diagrams is confusing synchronous returns with asynchronous notifications. In the final phase of the diagram, the system returns a success status to the client.
order --> gateway : Order Created
gateway --> web : 201 Created
web --> Customer : Order Confirmation
The use of the dashed line with an open arrowhead (-->) is standard PlantUML syntax for a return message. This visually distinguishes the “reply” from the “call,” clarifying that the processing is complete.
4. Enriching the Diagram with Notes
While the lines show the flow, they don’t explain the “why” or the specific constraints. VPasCode allows us to attach Notes directly to specific lifelines or messages.
note right of order : Validates stock,
processes payment,
persists order
This note is pinned to the Order Service lifeline, providing a summary of its responsibilities without cluttering the message lines themselves. The
character allows for multi-line text within a single note.
5. Why Diagram-as-Code?
By defining this architecture in VPasCode rather than drawing it, we gain several engineering advantages:
- Version Control: The diagram becomes a text file in Git. You can see exactly which line changed when the API protocol shifted.
- CI/CD Integration: Automated pipelines can render these diagrams into documentation automatically whenever a merge request is made.
- Consistency: The code enforces a consistent layout engine, ensuring that participant spacing and alignment remain professional and readable regardless of the complexity of the flow.
By adopting this workflow, engineering teams ensure that their architectural documentation is not just a static image, but a living artifact that evolves alongside the system.