
Architectural documentation has long suffered from a “death by PowerPoint” syndrome, where complex diagrams become stale artifacts that no one reads. However, the industry is shifting towards a more sustainable model. By integrating the C4 Model’s Level 4 (Code/Class Diagrams) with modern “Diagram-as-Code” workflows using VPasCode and AI assistance, teams can turn documentation into a living, breathing asset that evolves alongside the software.
This tutorial guides you through the strategic implementation of code-level diagrams in Visual Paradigm. We will explore how to bridge the gap between high-level architectural vision and the gritty reality of implementation, ensuring your documentation is maintainable, automated, and truly valuable to Agile teams.
The Evolution: From Static UML to C4 Level 4
Traditional UML class diagrams often attempt to capture every single attribute and method in a class. While technically accurate, this results in massive, unreadable diagrams that developers avoid updating. The C4 model revolutionized this by introducing a hierarchical approach (Context, Container, Component, Code).
Level 4 (Code) is the most granular level. Unlike its predecessors, it is purpose-driven. It does not try to show the entire system at once. Instead, it zooms into specific components to answer critical questions about implementation, design patterns, and domain models.
Core Principles of Effective Level 4 Diagrams
- Selective Detail: Only include classes and relationships relevant to the specific problem or narrative you are documenting.
- Living Documentation: Diagrams must be maintained alongside code changes, not created as one-time deliverables.
- Consistency: The classes shown in Level 4 must align perfectly with the boundaries defined in Level 3 (Component) diagrams.
The Modern Toolkit: Visual Paradigm + VPasCode + AI
To make Level 4 diagrams viable in a fast-paced Agile environment, we rely on a powerful ecosystem provided by Visual Paradigm.
1. VPasCode: Diagram-as-Code
VPasCode allows you to write diagrams using PlantUML syntax directly. This approach treats documentation as source code. By storing diagrams in text format, you can:
- Version control them alongside your Java or C# code.
- Review changes via Pull Requests (code reviews).
- Automate generation through CI/CD pipelines.
2. AI-Assisted Generation
Writing PlantUML code manually can still be tedious. Modern AI capabilities integrated into Visual Paradigm can scan your existing codebase or accept natural language descriptions to generate initial class structures. This reduces the “overhead” of documentation, making it a seamless part of the development process.
Practical Application: Creating an Order Processing Diagram
Let’s walk through creating a focused Level 4 diagram for an E-Commerce “Order Processing Component.” This example demonstrates how to use VPasCode to define a domain model that includes classes, enums, and relationships.
Step 1: Define the Context
Before drawing, identify the scope. For this example, we are documenting the logic behind order creation, payment, and shipping.
Step 2: Write the VPasCode (PlantUML)
Open your Visual Paradigm editor, switch to VPasCode mode, and input the following structure. Note the use of packages to group related classes and the use of comments to explain relationships.
@startuml
skinparam backgroundColor #FEFECE
skinparam borderColor black
skinparam shadowing false
' Define styles for C4 Level 4
skinparam class {
BackgroundColor White
BorderColor Black
}
package "Order Processing Component" {
class Order {
-orderId: String
-customerId: String
-orderDate: DateTime
-status: OrderStatus
+calculateTotal(): Decimal
+addItem(item: OrderItem): void
+submit(): boolean
}
class OrderItem {
-itemId: String
-productId: String
-quantity: Integer
-unitPrice: Decimal
+getSubtotal(): Decimal
}
class Payment {
-paymentId: String
-orderId: String
-amount: Decimal
-paymentMethod: PaymentMethod
-status: PaymentStatus
+process(): boolean
+refund(): boolean
}
class Shipping {
-shippingId: String
-orderId: String
-address: Address
-carrier: String
-trackingNumber: String
+schedulePickup(): void
+updateStatus(status: String): void
}
enum OrderStatus {
CREATED
CONFIRMED
SHIPPED
DELIVERED
CANCELLED
}
enum PaymentStatus {
PENDING
COMPLETED
FAILED
REFUNDED
}
class Address {
-street: String
-city: String
-state: String
-zipCode: String
-country: String
+toString(): String
}
' Relationships
Order "1" *-- "1..*" OrderItem : contains
Order "1" --> "1" Payment : has
Order "1" --> "1" Shipping : has
Order --> OrderStatus : has status
Payment --> PaymentStatus : has status
}
note right of Order
Aggregate root for
order processing
end note
@enduml
Step 3: Visualize and Refine
Upon rendering, Visual Paradigm will generate a clean, professional diagram. You can see the Order class acting as an aggregate root, composed of OrderItems, and linked to Payment and Shipping. The use of enums for status (CREATED, CONFIRMED, etc.) keeps the diagram readable while capturing critical state logic.
Advanced Patterns: Repository and Strategy
C4 Level 4 diagrams are not just for domain models; they are excellent for documenting design patterns and architectural decisions.
Documenting the Repository Pattern
Use Level 4 diagrams to visualize your Data Access Layer. Show how a generic interface (e.g., IRepository) is implemented by specific classes (e.g., ProductRepository, OrderRepository) and how they interact with an EntityManager.
@startuml
skinparam backgroundColor #FEFECE
package "Data Access Layer" {
interface IRepository {
+findById(id: ID): T
+findAll(): List
+save(entity: T): T
+delete(id: ID): void
}
class ProductRepository {
-entityManager: EntityManager
+findById(id: Long): Product
+save(product: Product): Product
}
class EntityManager {
-connection: Connection
+persist(entity: Object): void
}
IRepository <|-- ProductRepository : implements
ProductRepository --> EntityManager : uses
}
note bottom of IRepository
Generic repository interface
following DDD principles
end note
@enduml
Visualizing the Strategy Pattern
For dynamic behavior, such as payment processing, use diagrams to show how a PaymentService delegates work to different strategies (CreditCardStrategy, PayPalStrategy). This visualizes how the system remains extensible without modifying existing code.
Integration into Agile Workflows
To truly leverage these tools, you must integrate them into your Agile cadence.
- Automate with CI/CD: Configure your build pipeline to run VPasCode and fail the build if the diagram becomes inconsistent with the codebase.
- Onboarding Tool: Use these diagrams as the primary resource for new developers. Instead of reading thousands of lines of code, they can view the Order Processing Component diagram to understand the system in minutes.
- Code Reviews: Require diagram updates alongside code changes. If a new class is added, the diagram must be updated to reflect it.
Conclusion
The combination of the C4 Model, VPasCode, and AI assistance transforms class diagrams from neglected documentation into strategic assets. By focusing on purpose-driven, code-level views, Agile teams can maintain a clear understanding of their system architecture, reduce technical debt, and foster better collaboration across the organization.
Start by documenting one critical component today. Treat your diagrams as living code, and watch your team’s efficiency and code quality soar.