C4 Architecture

The C4 model

C4 is a way to describe software architecture as a set of maps at different zoom levels, created by Simon Brown. This page is a short introduction; the reference is c4model.com.

Most architecture diagrams are boxes and arrows with no agreed meaning: is that box a server, a library, a team? C4 fixes this with a small set of abstractions and one diagram per zoom level. Like Google Maps, you zoom in only where it helps.

Abstractions

Level Abstraction What it is Examples
1 Person A human user or role, not an individual. Customer, Back-office agent
1 Software system Something that delivers value to people, owned by one team or organisation. Your product, a payment provider, an ERP
2 Container A separately deployable or runnable unit that executes code or stores data. Not a Docker container in the strict sense. Web app, mobile app, API, worker, database, queue
3 Component A grouping of related functionality behind an interface, inside one container. Module, package, service class
4 Code Classes, functions, tables. Usually generated by your IDE: not supported here.

Each element has a name, a short description of its responsibility and, for containers and components, a technology. Relationships link elements with a verb phrase ("Places orders using") and, between containers, a protocol ("HTTPS/JSON").

The diagrams

Each view shows one level, plus the elements directly connected to it. All views below come from the same file, examples/online-banking.json.

Level 1: System context

The big picture, for everyone, technical or not: the system, its users and the systems it depends on.

BranchCustomerCustomer[Person]Personal banking customerOnline bankingOnline banking[Software System]Account overview and transfersMainframeMainframe[Software System]Core banking systemEmail systemEmail system[Software System]Sends emailsSends an emailViews accounts[HTTPS]Syncs transfers[MQ]Sends notifications[SMTP]PersonSoftware SystemExternalRelationship

Level 2: Containers

Inside the system: what runs or is deployed separately, and how the pieces talk. The dashed frame is the boundary of the system.

Online banking[Software System]BranchCustomerCustomer[Person]Personal banking customerWeb applicationWeb application[Container: React]Customer interfaceAPIAPI[Container: Node.js]Business logicDatabaseDatabase[Container: PostgreSQL]Accounts and transactionsMainframeMainframe[Software System]Core banking systemEmail systemEmail system[Software System]Sends emailsViews accounts[HTTPS]Sends an emailCalls[HTTPS/JSON]Reads and writes[SQL]Syncs transfers[MQ]Sends notifications[SMTP]PersonSoftware SystemContainerDatabaseExternalRelationship

Level 3: Components

Inside one container: its main building blocks. Draw this level only where it helps; many teams stop at containers.

API[Container]BranchWeb applicationWeb application[Container: React]Customer interfaceAccounts controllerAccounts controller[Component: Express]Exposes the REST routesAccounts serviceAccounts service[Component: TypeScript]Business rulesAccounts repositoryAccounts repository[Component: Prisma]Data accessDatabaseDatabase[Container: PostgreSQL]Accounts and transactionsMainframeMainframe[Software System]Core banking systemEmail systemEmail system[Software System]Sends emailsCalls[HTTPS/JSON]Delegates toReads and writesReads and writes[SQL]Syncs transfers[MQ]Sends notifications[SMTP]Software SystemContainerComponentDatabaseExternalRelationship

Supplementary diagrams

Online banking[Software System]BranchCustomerCustomer[Person]Personal banking customerWeb applicationWeb application[Container: React]Customer interfaceAPIAPI[Container: Node.js]Business logicDatabaseDatabase[Container: PostgreSQL]Accounts and transactionsMainframeMainframe[Software System]Core banking systemEmail systemEmail system[Software System]Sends emails1. Submits a transfer[HTTPS]2. Sends the transfer[HTTPS/JSON]3. Records the transfer[SQL]4. Syncs the transfer[MQ]5. Requests a confirmation[SMTP]6. Sends the confirmationPersonSoftware SystemContainerDatabaseExternalRelationship

C4 also defines deployment diagrams. They are not supported yet.

Notation used here

C4 is notation independent. This runtime draws:

The colour belongs to the element, not to the view: an element looks the same in every diagram. Tags and styles change it on purpose.

Modelling tips

Anti-patterns

Credits and further reading

The C4 model was created by Simon Brown, who maintains it at c4model.com. Its abstractions, diagram types and modelling advice are his; this page only summarises them. Read the original for the complete method.