C4 Diagram

Master this essential documentation concept

Quick Definition

A hierarchical software architecture diagramming model that visualizes systems at four levels: Context, Containers, Components, and Code.

How C4 Diagram Works

Understanding C4 Diagram

A hierarchical software architecture diagramming model that visualizes systems at four levels: Context, Containers, Components, and Code.

Key Features

  • Centralized information management
  • Improved documentation workflows
  • Better team collaboration
  • Enhanced user experience

Benefits for Documentation Teams

  • Reduces repetitive documentation tasks
  • Improves content consistency
  • Enables better content reuse
  • Streamlines review processes

Keeping Your C4 Diagram Walkthroughs Searchable and Up to Date

Architecture reviews and onboarding sessions are common places where teams walk through a C4 diagram in detail — explaining why the system is structured across those four levels, what each container owns, and how components interact. These walkthroughs are often recorded precisely because they contain nuanced reasoning that's hard to capture in a static image alone.

The problem is that a recorded explanation of a C4 diagram is difficult to reference later. When a new engineer joins and needs to understand the boundary between your Context and Container levels, they're left scrubbing through a 45-minute architecture meeting hoping the relevant section comes up. The diagram itself may be in Confluence, but the reasoning behind it lives only in the video.

Converting those recordings into structured documentation changes this entirely. Imagine your team's last architecture review — where your lead engineer explained why a particular microservice was elevated to its own Container rather than staying a Component — becoming a searchable, linkable section that sits alongside the C4 diagram itself. That decision context becomes part of your living documentation instead of disappearing into a video archive.

If your team regularly records architecture discussions, system design reviews, or onboarding walkthroughs that reference C4 diagrams, turning those recordings into structured docs makes that knowledge genuinely reusable.

Real-World Documentation Use Cases

Onboarding Engineers to a Microservices Platform Without Tribal Knowledge

Problem

New backend engineers joining a fintech team spend 2–3 weeks reverse-engineering how 30+ microservices communicate, which services own which databases, and where external payment APIs are integrated — all because architecture exists only in senior engineers' heads.

Solution

C4 Diagrams provide a progressive disclosure model: the Context diagram shows the entire payment platform in one view, the Container diagram reveals service boundaries and technology choices, and Component diagrams expose internal routing logic — each level answering a specific onboarding question.

Implementation

['Create a Level 1 Context diagram identifying the payment platform, its end users (merchants, cardholders), and external systems (Visa network, fraud detection APIs) to give new hires a mental model in under 10 minutes.', 'Build Level 2 Container diagrams for each bounded domain (payments, identity, reporting) showing service names, tech stacks (e.g., Kafka for event streaming, Go for transaction processing), and communication protocols.', "Embed these diagrams in the team's Confluence onboarding runbook, linking each container box to its corresponding GitHub repository and Runbook page.", 'Schedule a 1-hour architecture walkthrough using the C4 diagrams as the visual agenda, replacing ad-hoc whiteboard sessions with a repeatable, versioned reference.']

Expected Outcome

New engineer time-to-first-PR drops from 3 weeks to 8 days, and senior engineers report 60% fewer architecture clarification questions in Slack during the first month.

Communicating Architecture Change Impact to Non-Technical Stakeholders Before a Cloud Migration

Problem

A platform team planning to migrate a monolithic ERP system to AWS cannot get sign-off from business stakeholders because infrastructure diagrams filled with VPCs, subnets, and EC2 instances are incomprehensible to product owners and finance leads who control the budget.

Solution

The C4 Level 1 Context diagram abstracts away all infrastructure detail, showing only the ERP system, its users (warehouse staff, finance team), and its integrations (SAP, Salesforce) — a view that business stakeholders can validate and approve without technical expertise.

Implementation

['Draw a before-state C4 Context diagram showing the monolithic ERP system and all its external touchpoints, then present it to stakeholders to confirm the team has correctly captured business relationships.', 'Create an after-state C4 Context diagram showing the same external relationships but with the monolith replaced by named cloud-native services (Inventory API, Finance Reporting Service), making the migration scope tangible.', 'Use the Level 2 Container diagram in a separate technical review to show the AWS deployment topology, ALB routing, and RDS migration — keeping this view separate from business stakeholder sessions.', 'Version both diagrams in Git alongside the migration RFC document so that approval decisions are traceable to a specific architectural snapshot.']

Expected Outcome

Stakeholder sign-off is obtained in one review cycle instead of three, and the approved Context diagram becomes the contractual boundary for scope creep discussions throughout the 6-month migration.

Documenting API Surface Area for Third-Party Developer Portals

Problem

A SaaS company's developer portal contains only Swagger/OpenAPI endpoint references, but external developers integrating the platform cannot understand which combination of APIs to call, in what order, or which backend service owns each endpoint — leading to a high volume of developer support tickets.

Solution

A C4 Level 2 Container diagram embedded in the developer portal shows exactly how the API Gateway, Auth Service, Webhooks Engine, and Data Export Service relate to each other, giving integrating developers a mental model of the system before they write a single line of code.

Implementation

['Map all public-facing containers (API Gateway, OAuth Server, Webhook Dispatcher) in a C4 Container diagram, labeling each with its base URL, authentication method, and rate limit tier.', "Add external developer personas to the Context diagram to show which user types (ISV partners, enterprise IT admins) interact with which entry points, replacing the current single 'API User' abstraction.", "Embed the rendered C4 SVG diagrams directly in the developer portal's 'Architecture Overview' section, generated from PlantUML source stored in the docs repository for automated updates on release.", 'Link each container box in the diagram to its corresponding API reference page, creating a navigable map from architecture overview to endpoint specification.']

Expected Outcome

Developer support tickets related to 'how do I integrate X with Y' drop by 45% in the quarter following the portal update, and average time-to-first-successful-API-call decreases from 4 days to 1.5 days.

Maintaining Architecture Documentation Accuracy During Rapid Feature Development

Problem

A startup's architecture documentation in Confluence becomes outdated within weeks of each sprint because engineers update code but never update diagrams, leading to a situation where the documented architecture contradicts production reality and cannot be trusted for incident response or security reviews.

Solution

C4 Diagrams defined as code (using Structurizr DSL or C4-PlantUML) can be stored in the application repository and rendered in CI/CD pipelines, making architecture diagrams subject to the same pull request review process as the code they describe.

Implementation

['Migrate existing Confluence whiteboard diagrams to C4-PlantUML or Structurizr DSL files stored in a /docs/architecture directory within the monorepo, with one file per C4 level.', 'Add a GitHub Actions workflow that renders updated C4 diagrams to SVG on every pull request and posts them as PR comments, so reviewers can see architecture changes alongside code changes.', "Create a PR template checklist item: 'If this PR adds or removes a service, database, or external integration, update the corresponding C4 diagram file' to enforce the documentation habit.", 'Configure the CI pipeline to publish rendered diagrams to the internal developer portal on merge to main, replacing the manually-updated Confluence pages with an automated, always-current source.']

Expected Outcome

Architecture documentation lag drops from an average of 6 weeks behind production to under 48 hours, and the security team can use C4 diagrams directly as input for quarterly threat modeling sessions without requiring a separate architecture discovery exercise.

Best Practices

Strictly Enforce One Abstraction Level Per Diagram

Each C4 level answers a different question: Context answers 'what is this system and who uses it?', Containers answers 'what are the deployable units?', Components answers 'what are the internal building blocks?', and Code answers 'how is a specific component structured?'. Mixing levels — such as showing a PostgreSQL table schema on a Container diagram — destroys the cognitive clarity that makes C4 valuable. Audiences for each level are different: executives need Context, architects need Containers, and developers need Components.

✓ Do: Create separate, dedicated diagram files for each C4 level and label them explicitly (e.g., `c4-level1-context.puml`, `c4-level2-containers.puml`) so readers always know which abstraction they are viewing.
✗ Don't: Don't add database table names, API endpoint paths, or class names to a Container diagram just because the information seems relevant — it belongs in a Component or Code diagram and pollutes the Container view.

Label Every Relationship Arrow with Protocol and Data Description

Unlabeled arrows between containers are one of the most common C4 anti-patterns and force readers to guess whether services communicate via REST, gRPC, a message queue, or a database trigger. A relationship label should answer three questions: what data flows, in which direction, and over which protocol. This information is critical for security reviews, performance analysis, and incident response.

✓ Do: Label every relationship with the interaction verb, data description, and protocol, such as 'Sends order confirmation events [JSON] via Kafka topic orders.confirmed' or 'Queries customer profile [SQL] via JDBC over TLS'.
✗ Don't: Don't use vague labels like 'uses', 'calls', or 'connects to' on relationship arrows — these convey no actionable information and are equivalent to having no label at all.

Include Technology Stack Labels on Every Container and Component

The technology choice for each container (e.g., 'Python / FastAPI', 'React / TypeScript', 'Apache Kafka') is one of the most valuable pieces of information for engineers evaluating the architecture, planning migrations, or debugging cross-service issues. C4 explicitly reserves a secondary label on each element for this purpose. Omitting it forces readers to search codebases or ask colleagues for information that should be immediately visible.

✓ Do: Use the C4 element's secondary descriptor field for the technology stack, formatted consistently across all diagrams (e.g., 'Java 17 / Spring Boot 3.x' or 'PostgreSQL 15'), and update it whenever a major version migration occurs.
✗ Don't: Don't leave the technology field blank or use vague entries like 'backend service' or 'database' — these descriptions are already implied by the element shape and add zero information value.

Store C4 Diagram Source as Code in Version Control Alongside the System It Documents

Architecture diagrams stored as image files in Confluence or SharePoint become orphaned from the codebase they describe and are never updated. Storing C4 diagram source (Structurizr DSL, C4-PlantUML, or Mermaid) in the same Git repository as the application creates a forcing function for keeping documentation synchronized with code changes. It also enables diff reviews on architecture changes and supports automated rendering in CI/CD pipelines.

✓ Do: Place C4 diagram source files in a `/docs/architecture/` directory within the service repository, include diagram updates in the Definition of Done for any PR that adds or removes a service boundary, and automate SVG rendering on merge.
✗ Don't: Don't export C4 diagrams as PNG or SVG files and commit those binary files to Git — they cannot be meaningfully diff-reviewed and will inevitably become stale without the source that generated them.

Scope Context Diagrams to Show Only Direct Integrations, Not the Entire Enterprise Landscape

A common mistake is including every system in the enterprise on a Level 1 Context diagram to demonstrate thoroughness, resulting in a diagram with 30+ boxes that is impossible to read and conveys no clear system boundary. The Context diagram should show only the system being documented, its direct human users, and the external systems it directly calls or is called by. Indirect dependencies belong on a separate enterprise architecture diagram.

✓ Do: Apply a strict rule: if the system being documented does not make a direct API call, database query, or event subscription to another system, that system does not appear on the Context diagram — even if it is architecturally related.
✗ Don't: Don't include transitive dependencies (systems that your dependencies depend on) or organizational systems that are only tangentially related to the system being documented, as this turns the Context diagram into an unreadable enterprise map.

How Docsie Helps with C4 Diagram

Build Better Documentation with Docsie

Join thousands of teams creating outstanding documentation

Start Free Trial