C4 Architecture

Views

The model holds elements and relationships; views decide what each diagram shows. Declare views in the views array: the HTML page shows them in that order, each under an anchor named after its key.

View types

type C4 diagram scope Shows by default
systemLandscape Landscape none every person and software system
systemContext Level 1 a software system the system, and the people and systems directly connected to it
container Level 2 a software system its containers (inside its boundary), and the people and systems directly connected to them
component Level 3 a container its components (inside its boundary), and the people, systems and containers directly connected to them
dynamic Dynamic none, a software system or a container exactly the elements cited by its steps

Every view has a key (required, unique across the workspace), and an optional title and description shown above the diagram. Without a title, the key is used.

A view only ever shows the element kinds of its level: a context view never shows containers, even if you include one. In a container or component view, the scope itself is the dashed boundary, not a box.

Choosing what a view shows

include and exclude take a list of selectors:

Selector In include In exclude
"*" the default selection of the view type (table above) —
"api" the element with this id removes the element and its relationships
{ "tag": "Database" } every element with the tag removes elements and relationships with the tag
{ "relationship": "webToApi" } both ends of the relationship removes the relationship only

include defaults to ["*"]. Relationships are never listed: a view shows every relationship whose two ends are both shown, minus the excluded ones. To target a relationship, give it an id.

{ "type": "systemContext", "key": "context", "scope": "banking", "include": ["*", "advisor"] }
{ "type": "container", "key": "core", "scope": "banking", "include": ["web", "api"] }
{ "type": "container", "key": "noDb", "scope": "banking", "exclude": [{ "tag": "Database" }] }

The first view adds an element that is not connected to the system; the second shows only two containers and the relationship between them; the third hides every database.

Implied relationships

Declare relationships at the most detailed level you model. Below, only container-level relationships are declared: user → web and api → mail. The runtime derives user → app and app → mail for the context view. That is how a context view stays correct without duplicating every link:

JSON source: site/models/implied.json
{
  "$schema": "../../schema/c4.schema.json",
  "version": 1,
  "name": "Implied relationships",
  "model": {
    "people": [
      {
        "id": "user",
        "name": "User",
        "description": "Uses the app"
      }
    ],
    "softwareSystems": [
      {
        "id": "app",
        "name": "App",
        "description": "The system",
        "containers": [
          {
            "id": "web",
            "name": "Web app",
            "description": "User interface",
            "technology": "Vue"
          },
          {
            "id": "api",
            "name": "API",
            "description": "Business logic",
            "technology": "Python"
          }
        ]
      },
      {
        "id": "mail",
        "name": "Mail service",
        "description": "Sends emails",
        "external": true
      }
    ],
    "relationships": [
      {
        "from": "user",
        "to": "web",
        "description": "Uses",
        "technology": "HTTPS"
      },
      {
        "from": "web",
        "to": "api",
        "description": "Calls",
        "technology": "HTTPS/JSON"
      },
      {
        "from": "api",
        "to": "mail",
        "description": "Sends emails using",
        "technology": "SMTP"
      }
    ]
  },
  "views": [
    {
      "type": "systemContext",
      "key": "context",
      "scope": "app",
      "title": "Context: links derived from the containers"
    },
    {
      "type": "container",
      "key": "containers",
      "scope": "app",
      "title": "Containers: links as declared"
    }
  ]
}
UserUser[Person]Uses the appAppApp[Software System]The systemMail serviceMail service[Software System]Sends emailsUses[HTTPS]Sends emails using[SMTP]PersonSoftware SystemExternalRelationship
App[Software System]UserUser[Person]Uses the appWeb appWeb app[Container: Vue]User interfaceAPIAPI[Container: Python]Business logicMail serviceMail service[Software System]Sends emailsUses[HTTPS]Calls[HTTPS/JSON]Sends emails using[SMTP]PersonSoftware SystemContainerExternalRelationship

Rules, as in Structurizr:

Groups

Give elements the same group name to draw them inside a dashed frame. Groups never change what a view selects; they only frame what is shown. In container and component views, a group stays inside the boundary.

Store[Software System]Front endBack endWeb shopWeb shop[Container: React]StorefrontMobile appMobile app[Container: Flutter]iOS and AndroidAPIAPI[Container: Java]Business logicDatabaseDatabase[Container: PostgreSQL]Products and ordersCalls[HTTPS/JSON]Calls[HTTPS/JSON]Reads and writes[SQL]ContainerDatabaseRelationship

Dynamic views

A dynamic view tells one scenario as numbered steps. It has no include or exclude: it shows exactly the elements its steps cite.

{
  "type": "dynamic", "key": "transfer", "scope": "banking", "title": "Make a transfer",
  "steps": [
    { "from": "customer", "to": "web", "description": "Submits a transfer" },
    { "from": "web", "to": "api", "description": "Sends the transfer" }
  ]
}

The scope sets the level of the steps:

scope Steps may involve
none people and software systems
a software system people, other software systems, and containers (the scope's are drawn inside its boundary)
a container people, other software systems, other containers, and components (the scope's are drawn inside its boundary)

The scope itself (and, for a container, its software system) cannot be a step end.

Not supported yet: parallel sequences (1.1, 1.2) and reply steps.

Layout

The layout is automatic (ELK layered algorithm, orthogonal links with rounded corners). Each view can tune it:

{ "type": "container", "key": "containers", "scope": "banking",
  "layout": { "direction": "LR", "rankSeparation": 96, "nodeSeparation": 48 } }
Field Values Default
direction TB top to bottom, BT, LR left to right, RL TB
rankSeparation space between ranks, in pixels 64
nodeSeparation space between elements of the same rank, in pixels 48

There is no manual positioning: if a diagram is hard to read, split the view, exclude elements, or change the direction.