Diagrams & workflows

C4 Diagram: One Application Across Context, Container and Component Views

Follow one room-booking application through C4 context, container and component views, with editable sources, consistent boundaries and corrected mistakes.

· · Diagram Studio Editorial

Direct answer

A C4 diagram describes software architecture at one of four levels: context, containers, components or code. A context view shows one system and its neighbors; a container view opens that system into applications and data stores; a component view opens one container into internal building blocks. Keep names, responsibilities and boundaries consistent between views.

Choose the right C4 diagram level

The C4 model describes architecture at four levels: system context, containers, components and code. A C4 diagram is one view at one of those levels. Start by naming the scope and the question; adding more boxes is not the same as increasing useful detail.

This guide follows one fictional application, RoomBook, through three views. Context shows its users and neighboring systems. Containers show its applications and data store. Components open only its Booking API. Stable names and responsibilities make it possible to check whether the zoomed-in views still describe the same design.

Use the smallest useful set of views.
LevelQuestionBoundary in this guide
1. System contextWho uses the system, and what does it depend on?RoomBook as one software system
2. ContainerWhich applications and data stores implement it?RoomBook decomposed into four containers
3. ComponentWhich modules collaborate inside one container?Booking API only
4. CodeHow is a component implemented?Omitted; create only when it answers a specific question

The official C4 context guidance centers a software system and its directly related people and systems. The container guidance then decomposes that system into applications and data stores. The component guidance narrows scope to a single container; it recommends creating that detail when it adds value.

The application and assumptions stay the same in every view

RoomBook lets employees reserve a meeting room for a fixed 30-minute slot. Employees sign in through an existing workplace identity system. A successful booking records the reservation and queues a confirmation email. The application owns its web app, API, worker and database; identity and email delivery are operated outside that ownership boundary.

  • Employees reserve one room for one fixed 30-minute slot.
  • Workplace Identity and Email Delivery are separately operated software systems.
  • The application owns the Web app, Booking API, Booking database and Notification worker.
  • A database uniqueness constraint on (room_id, slot_start) rejects concurrent duplicate reservations.
  • The booking and outbox records are written in one shared database transaction.
  • Outbox delivery is at least once; duplicate emails remain possible unless the email provider supports a suitable deduplication contract.

These are design choices for the worked example, not capabilities attributed to a real product. The fixed-slot rule matters: a uniqueness constraint can prevent two reservations for the same room and slot. A system allowing arbitrary overlapping time intervals would need a different availability constraint.

Download the complete editable C4 model as JSON. Each view below also includes Mermaid source. The JSON preserves shared element identities and assumptions; Mermaid provides a straightforward editable rendering of each separate level.

1. System context: RoomBook and its neighbors

At context level, treat RoomBook as one software system. The employee, workplace identity system and email delivery system sit outside it. A database, API controller or browser framework would answer a different question, so none belongs inside the RoomBook box at this level.

RoomBook system context with employee, workplace identity and email delivery as external neighbors.
One system is the focus; internal technology stays behind the boundary.
Labels and directions for the context view.
ArrowFromToRelationship
1EmployeeRoomBookFinds rooms and manages reservations
2RoomBookWorkplace IdentityUses employee identity and signing keys
3RoomBookEmail DeliveryRequests confirmation delivery

The employee interacts with RoomBook to find rooms and manage reservations. RoomBook depends on workplace identity and sends confirmation requests to email delivery. The exact HTTPS routes and data schema are intentionally deferred until the container view.

A common modeling error is to call everything hosted by a cloud vendor “external”. Ownership of the application architecture and provider ownership are different boundaries. In this example, the team owns the booking data model and its use, so the managed database appears as a RoomBook container in the next view.

Editable view JSON · Mermaid diagram source · SVG drawing

2. Containers: four parts inside RoomBook

Open the RoomBook system boundary and show four containers: a browser web app, a Booking API, a PostgreSQL database and a notification worker. In C4, “container” means an application or data store; it does not mean a Docker image. A single machine could host several of these containers, and one container could have several runtime instances.

RoomBook system boundary contains web app, Booking API, database and notification worker; identity and email services remain outside.
The software system contains four application or data-store containers.
Labels and directions for the container view.
ArrowFromToRelationship
1EmployeeWeb appUses [HTTPS]
2Web appWorkplace IdentitySigns in [OIDC / HTTPS]
3Web appBooking APIRequests rooms and bookings [JSON / HTTPS]
4Booking APIWorkplace IdentityFetches signing keys [JWKS / HTTPS]
5Booking APIBooking databaseReads rooms; commits booking + outbox [SQL / TLS]
6Notification workerBooking databaseClaims outbox; records delivery [SQL / TLS]
7Notification workerEmail DeliverySubmits confirmation [HTTPS API]

The web app signs the employee in and sends authenticated requests to the API. The API checks access and commits a reservation plus an outbox record. The worker polls the outbox and calls the email service. The database is shared deliberately here; a team choosing independent service data ownership would draw a different design.

The arrows describe dependencies or requests in one direction. For example, “worker claims outbox rows” points from worker to database; it does not mean that the database initiates a push. A response body is part of the request exchange rather than a reason to use an unlabeled double-headed arrow.

This view does not specify replicas, network subnets, failover or where the worker is hosted. Those are deployment questions. Keep a production deployment view separate so a staging topology does not silently change what the application containers mean.

Editable view JSON · Mermaid diagram source · SVG drawing

3. Components: open the Booking API only

Now open the Booking API container only. Its five components are Python modules in the same deployed API application: BookingController, AccessPolicy, BookingService, BookingRepository and OutboxWriter. They are implementation groupings, not five independently deployed services.

The Booking API boundary contains controller, access policy, booking service, repository and outbox writer; web app, identity and database are supporting neighbors.
Only the Booking API is decomposed; its five modules share one runtime and one transaction contract.
Labels and directions for the component view.
ArrowFromToRelationship
1Web appBookingControllerPOST /bookings [JSON / HTTPS]
2BookingControllerAccessPolicyChecks identity and room permission [in-process]
3AccessPolicyWorkplace IdentityRefreshes signing keys [JWKS / HTTPS]
4BookingControllerBookingServiceRequests reservation [in-process]
5BookingServiceBookingRepositoryReads and writes within shared transaction [in-process]
6BookingServiceOutboxWriterAdds notification within shared transaction [in-process]
7BookingRepositoryBooking databaseReads slots; inserts booking [SQL / TLS]
8OutboxWriterBooking databaseInserts outbox record [SQL / TLS]

BookingController handles HTTP input and response mapping. AccessPolicy validates the employee identity and permission to book the room. BookingService coordinates the transaction. BookingRepository reads room state and writes the reservation; OutboxWriter records the pending confirmation within that same database transaction.

The web app, identity system and database remain visible as supporting neighbors because they connect directly to these components. The notification worker is outside the API and has no direct component call here, so it is not added merely to repeat the entire container diagram.

“Same transaction” is an architectural requirement, not something an arrow guarantees. The service passes one shared unit of work to the repository and outbox writer. If those components commit independently, the design can create a booking without its queued notification, contradicting the assumption we started with.

Editable view JSON · Mermaid diagram source · SVG drawing

Trace one booking across the three levels

A static C4 view explains structure. The following request trace explains behavior without turning the static arrows into a misleading execution sequence.

  1. The employee uses the web app and signs in with Workplace Identity. The web app receives the credentials required by the chosen OIDC flow.
  2. The web app sends a booking request with a room, fixed slot and request key to BookingController over HTTPS.
  3. BookingController asks AccessPolicy to validate the token and permission. Signing keys can be cached and refreshed from the identity system; this design does not require a live identity request for every booking.
  4. BookingService begins one shared database transaction. BookingRepository inserts the reservation; the unique room-and-slot constraint rejects a conflicting concurrent insert.
  5. OutboxWriter adds a pending confirmation in the same transaction. The transaction commits both records or neither. The API returns the recorded reservation.
  6. The notification worker claims the pending outbox record, submits a message to Email Delivery and records the result. If delivery fails, the reservation remains valid while notification work is retried.

The trace exposes a useful distinction: booking success and email delivery success are different outcomes. A notification failure should not make the browser report that the room is still available. Conversely, a database conflict means the reservation did not succeed even if the employee saw availability a moment earlier.

Failure behavior is a design contract to implement and verify.
FailureExpected behavior in this exampleWhere the rule lives
Invalid or unauthorized tokenReject without creating a reservationAccessPolicy and controller response mapping
Two employees book the same slotOne reservation commits; conflicting request receives a conflict resultDatabase constraint and BookingService error mapping
Browser times out after commitLook up the recorded result by request key before creating another reservationAPI idempotency behavior and persistence
Email provider is unavailableKeep booking; retry the pending outbox messageNotification worker
Worker crashes after sending but before marking deliveredRetry may send a duplicate unless a delivery deduplication contract prevents itWorker and email provider integration

A request key alone does not create idempotency. Bind it to the authenticated employee and request payload, store the outcome durably and define what a replay returns. The example names that requirement; its diagrams are not proof that a codebase implements it.

Correct the boundary mistakes before adding detail

Each correction preserves one level of abstraction.
Incorrect exampleWhy it is wrong for this viewCorrect version
Context: Employee → API → PostgreSQLInternal containers are exposed where RoomBook should be one systemEmployee → RoomBook, with identity and email as neighbors
Container: controller, service, repository and databaseThree in-process modules are mixed with a data-store containerShow Booking API as one application; expand its modules in the component view
Component: Web app, API, worker and database all expanded togetherThe view decomposes several containers at onceExpand Booking API only; keep directly connected neighbors as supporting elements
Component: separate boxes imply separate servicesThe reader may infer independent deployment or networkingLabel Python modules and in-process relationships explicitly
Any level: unlabeled double-headed arrowsDirection and relationship meaning cannot be inspectedUse one directed arrow per stated relationship
Container: production replica counts replace responsibilitiesDeployment and static decomposition become entangledKeep responsibilities here and put environment topology in a deployment view

A supporting database on the component view is valid; decomposing that database into tables beside Python modules would change the scope. The issue is the role of the element in the view, not a blanket rule that no neighboring element can come from another level.

The official notation guidance asks for explicit element types, responsibilities, technologies, labeled directional relationships and a diagram key. It also makes clear that C4 does not mandate one drawing notation or color palette. The cream and purple diagrams here follow those semantics with their own visual style.

Edit the model and test consistency

  1. Rename a shared entity in all views. RoomBook, Booking API and Booking database should keep one meaning as you zoom.
  2. Change the boundary before moving a box. If identity becomes part of your owned application, update the context and container assumptions together.
  3. Keep container technologies on container and component views. Do not make a new deployment instance look like a new application responsibility.
  4. For each component, ask which single container contains it. If the answer is unclear, the view may be mixing levels.
  5. Read each arrow as a sentence from source to destination. Put the protocol on inter-process relationships and avoid using visual direction to imply an undocumented timing rule.
  6. Walk one success and one failure through the set. If the trace depends on a missing participant, add it at the appropriate level or state the omitted scope.

The downloads are source material for this worked example. Open Mermaid in a compatible editor to modify each diagram; edit the JSON to preserve the complete model and assumptions. A syntax-valid diagram can still describe the wrong architecture, so review responsibilities and boundaries with the people who build and operate the system.

If your next task is to explain a particular request rather than the static architecture, use a separate sequence diagram. Preserve the C4 views as the stable map and let the request trace answer the timing question.

Use the views to review a proposed change before implementing it. If confirmation delivery moves into the API process, remove the worker container, add the responsibility to an API component, and revisit the failure trace: an email timeout now affects the request path. A boundary change that appears in only one view leaves readers with two incompatible descriptions of the system.