C4 + UML + AI: Runtime Diagrams with VPasCode

C4 static structure and UML sequence diagram showing software system runtime flow

In the rapidly evolving landscape of Enterprise Architecture, the C4 model has established itself as the standard for communicating software architecture. However, a static picture of your system—showing containers and components—often fails to capture the complexity of how data actually flows during execution. This tutorial explores how to bridge that gap by integrating UML Sequence Diagrams into the C4 ecosystem, utilizing modern tools like VPasCode and AI assistance to create “Architecture as Code.”

Understanding the Gap: Static vs. Runtime Views

The C4 model excels at describing the static structure of a system. It answers the question: “What is in the system?” using Context, Container, and Component diagrams. It shows people, software systems, containers, and components, and how they are related.

However, static diagrams cannot explain when or how things happen. This is where the Sequence Diagram comes in. It adds a runtime view, showing how selected participants exchange messages over time. It supplements the C4 views; it does not replace them.

Key concepts for the sequence diagram include:

  • Participants: People, systems, containers, or components involved in the scenario.
  • Lifelines: Vertical lines representing participants over the course of the interaction.
  • Messages: Arrows showing calls, events, responses, or other communications.
  • Activation bars: Markers showing when a participant is actively performing work.

When to Deploy a Sequence Diagram

As an Agile EA team, you should not diagram every single interaction. Instead, use sequence diagrams selectively for complex scenarios where the order and timing are critical. You should use a sequence diagram when:

  1. A request passes through several services: You need to visualize the chain of calls from a Web App to an API and then to a Database.
  2. Workflows involve complex logic: Scenarios with callbacks, retries, or timeouts require a clear timeline.
  3. Asynchronous processes occur: You need to distinguish between an initial request and a later result (e.g., an order placed vs. an email notification sent).
  4. Security or reliability is sensitive: Paths involving authentication or payment processing need review.

Integrating VPasCode and AI in Your Workflow

Traditionally, creating diagrams involved dragging and dropping shapes in a GUI tool like Visual Paradigm. While powerful, this often leads to files that are hard to version control or review. The modern approach involves using VPasCode (Diagram-as-Code).

Why Diagram-as-Code?

By treating diagrams as text files, you gain several practical benefits for Agile teams:

  • Reviewable Changes: You can see exactly what changed in a diagram using text diffs.
  • Version History: Diagram updates can be traced alongside code changes in Git.
  • Repeatable Rendering: The source can be rendered automatically in documentation pipelines.
  • Faster Small Edits: Changing a participant name is as fast as typing a line of text.

The AI Advantage

Visual Paradigm’s ecosystem leverages AI to accelerate the drafting process. You can start with a natural-language description of a scenario (e.g., “Customer places an order, system validates payment, and sends email”). The AI can assist in generating the initial VPasCode structure, which you then refine.

Important Distinction: AI can accelerate drafting, but it cannot establish that a diagram accurately reflects the system. Engineers must verify participant identities, message direction, error paths, and consistency with the code.

Step-by-Step: Creating a C4 Sequence Diagram

Let’s walk through a practical workflow to document a “Checkout” scenario using the principles of C4 and VPasCode.

Step 1: Establish the Context

Before drawing the sequence, ensure you have a static C4 Container or Component view established. Your participants in the sequence diagram must match the names in your static architecture.

Step 2: Draft the Scenario

Identify the specific scenario. For example: “Customer places an order when payment succeeds.”

Step 3: Define the Code Structure

Use a notation like PlantUML within VPasCode. The syntax allows you to define participants (containers/components) and the messages they exchange. Below is an example of a synchronous request and response flow:

@startuml
title Checkout: Place an Order

actor Customer
participant "Web Store" as Web
participant "Checkout API" as Checkout
database "Order DB" as DB

Customer -> Web: Submit order
Web -> Checkout: POST /orders
activate Checkout
Checkout -> DB: Save pending order
DB --> Checkout: Order ID
Checkout --> Web: 201 Created + order ID
deactivate Checkout
Web --> Customer: Show confirmation
@enduml

Step 4: Handle Asynchronous and Complex Flows

Real-world systems often involve asynchronous work. For instance, after an order is placed, the system might publish an event to a queue for fulfillment. You can use control-flow fragments like loop for retries and alt for alternatives.

@startuml
title Order Processing: Asynchronous Fulfillment

participant "Checkout API" as Checkout
queue "Order Events" as Queue
participant "Fulfillment Worker" as Worker
participant "Inventory Service" as Inventory

Checkout -> Queue: Publish OrderPlaced
Queue -> Worker: Deliver event
activate Worker

loop Retry up to configured limit
    Worker -> Inventory: Reserve items
    alt Reservation succeeds
        Inventory --> Worker: Reserved
        break
    else Temporary failure
        Inventory --> Worker: Unavailable
        Worker -> Worker: Wait before retry
    end
end
deactivate Worker
@enduml

Best Practices for C4 Sequence Diagrams

To ensure your diagrams add value to your Agile EA team:

  1. Start from a Named Scenario: Don’t try to document “everything.” Focus on specific paths like “Success Path” or “Payment Failure Path.”
  2. Keep Names Consistent: Use the exact names from your C4 Container/Component views to avoid confusion.
  3. Show Only Relevant Detail: Include protocols (like HTTP/HTTPS) only when they explain the design. Don’t clutter the diagram with every single parameter.
  4. Make Uncertainty Explicit: If a diagram describes a proposed design, label it as such rather than presenting it as implemented fact.
  5. Review Against Architecture: A sequence diagram can expose undocumented dependencies. Check it against your actual system implementation.

Conclusion

By combining the structural clarity of the C4 model with the runtime detail of Sequence Diagrams, you create a comprehensive architectural narrative. Using tools like VPasCode allows you to manage these diagrams as code, making them easier to maintain, version, and automate. Whether you are drafting a simple synchronous call or a complex asynchronous retry loop, remember that the goal is to make runtime behavior visible while keeping it tightly connected to the static architecture.