Architecture

C4 Model Diagrams with Mermaid: Context & Containers

Compare native Mermaid C4 syntax with flowchart-based architecture views. Read a context example and choose the right level for your model.

Pele Editor guide · Published

One level at a time

A system context view names the people and external systems around a product. A container view explains the major applications and data stores inside it. Combining every level in one drawing makes the important relationships hard to see.

Use a simple context sketch

A flowchart can communicate the boundary without introducing specialized syntax. Label relationships with a verb and keep infrastructure details out of the context view.

flowchart LR
  Person[Customer] -->|Uses| Product[Product]
  Product -->|Sends notifications| Mail[Email service]
  Product -->|Stores records| Store[(Data store)]
UsesSends notificationsStores recordsCustomerProductEmail serviceData store

Choose a C4 starting point

The C4 builder creates structured C4-style views using flowchart syntax. For native C4 syntax, start with the system context, container or component templates and edit their source in the editor. Choose one level for each view and describe the responsibility of each element before adding implementation detail.

Choose a level before choosing notation

C4 separates system context, containers, components, and code. A system context view explains the system and its users or external dependencies. A container view opens that system to show applications and data stores. A component view opens a container further. You do not need every level for every project; start with the view that answers the audience’s question.

Choose a level before choosing notation
ViewQuestion
System contextWho uses the system and what external systems does it depend on?
ContainersWhich applications and data stores make up the system?
ComponentsWhat responsibilities exist inside one container?
CodeWhich implementation details need a closer explanation?

Label relationships with a purpose

An arrow labeled Uses can be too vague to guide a design review. Prefer a short explanation such as Submits order or Reads customer profile. Where it helps, document the protocol or technology in accompanying text. Keep runtime interactions, deployment dependencies, and ownership relationships distinct; they answer different architecture questions.

Be explicit about the diagram format

A flowchart can communicate a C4-style view without being native C4 syntax. This site’s C4 builder takes elements and relations and produces flowchart LR source. That makes the model editable as a flowchart, but it should not be presented as a lossless native C4 model. Keep the underlying architecture names and boundaries consistent across separate views, even when their layout changes.

Try native C4 context syntax

This native C4Context example declares a person, a system, an external system, and their relationships directly. Compare it with the flowchart sketch above: the context model has the same purpose, but the grammar and renderer behavior differ. Preview native C4 in the destination before adopting it for a documentation collection. A container view should be a separate diagram that opens the system boundary, rather than mixing deployment resources into this context view.

C4Context
  title Customer portal context
  Person(customer, "Customer", "Places orders")
  System(portal, "Customer portal", "Manages orders")
  System_Ext(mail, "Email service", "Delivers notifications")
  Rel(customer, portal, "Places orders")
  Rel(portal, mail, "Sends notifications")
Customer portal context«person»CustomerPlaces orders«system»Customer portalManages orders«external system»Email serviceDelivers notificationsPlaces ordersSendsnotifications
Try it in the editor ↗