Software Architecture
Moving From UML to C4
Moving From UML to C4
3 Day(s)
🎯 LEARNING OBJECTIVES
Understand the purpose and scope of UML and the C4 model.
Identify the four C4 levels: Context, Containers, Components, and Code.
Select suitable diagrams to communicate architecture to technical and non-technical stakeholders.
Apply UML and C4 to document system structure, behavior, and architectural boundaries.
🧠 PREREQUISITES
Basic knowledge of software architecture and system components.
Familiarity with UML fundamentals, including class, sequence, and use-case diagrams.
📖 Topics / Lesson
From UML To C4
The C4 Model is a hierarchical architecture modeling approach for visualizing software systems, developed by Simon Brown.
1. Context: Big-picture view: system and users
2. Container: Applications/services inside the system
3. Component: Internal structure of a container
4. Code: (Optional) Class/module-level view
Clarity: Simple, focused diagrams
Audience: all stakeholders (tech + business)
Flexibility: Lightweight and pragmatic
Abstraction Levels: Explicit 4 abstraction layers
Tool Support: Lightweight (e.g., PlantUML, Structurizr)
🧍 Person: Context
End user who uses the systems.
Examples: Customer, admin user or employee.
🏢 System
The highest level of abstraction that delivers value to end users, whether they are human or not. Systems are often owned by a development team.
Examples: SendGrid is an external system.
📦 Container (App/Store)
Applications and data stores that make up a system. These are independently deployable and runnable. (Not to be confused with Docker containers)
Example: API service, front-end application or mobile app.
🧩 Component
Building blocks and modules that make up each container.
Example: Authentication module or payment card validator.
Level 4 - Code diagram
Usually in the form of UML class diagrams that are ideally autogenerated from the actual code. This level is rarely used as it goes into too much technical detail for most teams.
C4 Model overview. The C4 model describes a software system at four levels of zoom, like a map that goes from the whole country down to a single street. Each level shows a different amount of detail for a different audience, so people can understand the solution without being overwhelmed.
Level 1, Context. This level shows the whole e-commerce platform as a single box, together with the people who use it and the external systems it depends on. Customers shop through the mobile app or website, and the platform connects to a payment gateway, a shipping provider and an email/SMS service. It has no technical detail, so business, product and technical people can agree on what the system is and where its boundaries are.
Level 2, Containers. This level opens the platform box and shows the separately runnable or deployable pieces inside it. In the example these are the mobile app, the web app, the API gateway, the Java Spring Boot microservices (catalog, order, user and payment), their databases and cache, and the Kafka event bus. It shows which technology each piece uses and how they communicate, which helps architects and developers see what to build, deploy and scale independently.
Level 3, Components. This level zooms into one container, here the Order Service, and shows its internal building blocks. A controller receives requests, a service holds the business rules, a repository saves data, and separate clients talk to inventory, payment and the event bus. It makes responsibilities and dependencies inside the service clear, which guides code structure, reviews and onboarding of new developers.
Level 4, Code. This level shows how one component is implemented, using classes, interfaces and entities such as OrderService, OrderServiceImpl, Order and OrderRepository. It maps the design directly to Java code. This level is optional and is usually generated from the IDE or UML tools, so it is best kept for complex or critical parts.
Use C4 as the structure that organizes your diagrams and UML as the notation that adds precision inside it. Each C4 level decides where you are zooming, and a matching UML diagram answers the detailed question at that level. Keep the same names in both (for example “Order Service”), so readers can move between diagrams without confusion.
The customer and external systems (payment gateway, shipping provider, email/SMS) become actors. The platform becomes the system boundary, and the customer’s goals inside it become use cases such as Place Order, Track Shipment and Pay. The use case diagram adds what C4 Context leaves out: what each actor actually wants to do.
The mobile app, web app, API gateway, Java microservices, databases and Kafka become nodes or artifacts, such as Spring Boot jars and PostgreSQL instances. They sit on the servers, cloud services or devices where they run. The arrows become communication paths labeled with the protocol (HTTPS, REST, Kafka). Where you need the logical rather than the physical view, a UML Component diagram can show the same containers with their interfaces.
Inside the Order Service, OrderController, OrderService, OrderRepository and the payment and inventory clients become UML components. Each is connected through provided and required interfaces, so the dependencies between them are precise.
The classes behind one component, such as the OrderService interface, OrderServiceImpl, the Order entity and the JPA repository, become UML classes and interfaces with their fields, methods and relationships. Generate this from the code or the IDE rather than drawing it by hand.
C4 shows structure but says little about behavior, so add these at the level where you need them:
A Sequence diagram shows a key flow, such as Place Order, across containers or components.
A State machine shows the order lifecycle (Created, Paid, Shipped, Delivered, Cancelled).
An Activity diagram shows a workflow with decisions, such as checkout or returns.
The sequence to follow.
Draw C4 Context and add a Use Case diagram if the goals need detail.
Draw C4 Containers, then add a Sequence diagram for each critical flow, such as Place Order.
Add C4 Components and a UML Component diagram only for complex or risky containers, such as the Order Service.
Add the State machine for the order lifecycle and the Class diagram for the domain model.
Keep all the diagrams as code next to the source, update them each release, and generate the code level automatically.
Dr. Ghoniem Lawaty
Tech Evangelist