Clean Store System with VPasCode: UML Package Diagrams for Layered Architecture

VPasCode PlantUML interface showing store architecture diagram

In modern software engineering, separating concerns is the golden rule for building maintainable applications. One of the most effective ways to visualize this separation is through a Package Diagram. These diagrams group model elements into namespaces or layers, illustrating how different parts of your codebase interact without getting bogged down in class-level details.

This tutorial utilizes VPasCode, a powerful Diagram-as-Code tool from Visual Paradigm, to demonstrate how to model a clean “Store” architecture. We will break down a layered design pattern—ranging from the web interface down to data persistence—using concise PlantUML syntax.

Understanding the Layered Architecture

The diagram presented here follows a classic layered architecture often used in enterprise applications. It divides the system into four distinct vertical layers, each with a specific responsibility. This structure prevents the “spaghetti code” problem where business logic is mixed with database logic.

1. The Web Layer (store.web)

This is the entry point of the application. It handles HTTP requests and responses. In our example, the CheckoutController resides here. Its job is to receive data from the user interface and delegate the actual work to the application layer. It should contain no business logic.

2. The Application Layer (store.application)

This layer orchestrates the business process. The PlaceOrder class represents a use case or a service that coordinates the steps required to fulfill an order. It acts as the bridge between the user’s request and the core domain rules.

3. The Domain Layer (store.domain)

This is the heart of the system, containing the core business entities. The Order and Product classes live here. They define the rules and state of the business, independent of how they are displayed or stored. This layer is agnostic of the UI and the database.

4. The Persistence Layer (store.persistence)

This layer handles data storage. The OrderRepository is responsible for saving and retrieving order data from the database. It ensures that the domain layer doesn’t need to know about SQL queries or file systems.

Translating Architecture to Code with VPasCode

VPasCode allows developers to define these architectural structures using code, which is faster than dragging and dropping boxes in a GUI. Below is the PlantUML syntax used to generate the diagram shown in the interface.

@startuml
package "store.web" {
  class CheckoutController
}

package "store.application" {
  class PlaceOrder
}

package "store.domain" {
  class Order
  class Product
}

package "store.persistence" {
  class OrderRepository
}

' Defining Dependencies
CheckoutController ..> PlaceOrder
PlaceOrder ..> Order
PlaceOrder ..> OrderRepository
@enduml

Analyzing the Dependencies

The power of this diagram lies in the dependencies defined at the bottom. Notice the use of the ..> operator, which represents a dependency relationship.

  • CheckoutController ..> PlaceOrder: The controller relies on the application service to execute the logic. It does not handle the logic itself.
  • PlaceOrder ..> Order: The application service relies on the domain model to define the state of the order.
  • PlaceOrder ..> OrderRepository: The application service relies on the persistence layer to save the order.

This flow confirms that dependencies point from the more specific layer to the more abstract layer (e.g., Web depends on Application, Application depends on Domain). This is crucial for the Dependency Inversion Principle.

Why Use Diagram-as-Code?

Using a tool like VPasCode to generate this architecture offers several advantages over manual drawing:

  1. Version Control Friendly: Your architecture is stored in a text file. You can commit changes to your directory structure directly alongside your code, allowing for easy review and rollback.
  2. Refactoring Safety: If you rename a class in your codebase, you can easily update the diagram file and regenerate the image, ensuring the documentation never becomes stale.
  3. AI Integration: As seen in the VPasCode interface, AI tools can parse these text files to suggest improvements or generate the visual representation instantly, bridging the gap between design and implementation.

By mastering Package Diagrams and leveraging Diagram-as-Code tools, you ensure that your system’s architecture remains clear, organized, and scalable.