Skill Tracer
Skills › Scientific Agent Skills › markdown-mermaid-writing › c4.md

c4.md

149 lines · skills/markdown-mermaid-writing/references/diagrams/c4.md at 5f2bc03

Open on GitHub
1<!-- Source: https://github.com/SuperiorByteWorks-LLC/agent-project | License: Apache-2.0 | Author: Clayton Young / Superior Byte Works, LLC (Boreal Bytes) -->
2
3# C4 Diagram
4
5> **Back to [Style Guide](../mermaid_style_guide.md)** — Read the style guide first for emoji, color, and accessibility rules.
6
7**Syntax keyword:** `C4Context`, `C4Container`, `C4Component`
8**Best for:** System architecture at varying zoom levels — context, containers, components
9**When NOT to use:** Infrastructure topology (use [Architecture](architecture.md)), runtime sequences (use [Sequence](sequence.md))
11---
13C4 remains experimental. In the Mermaid 12.0.0 checks, `accTitle` parsed but did
14not produce an SVG `<title>`; retain a visible text description and meaningful
15alt text for exports. An automatic layout still needs a visual overlap check.

<!-- Source: https://github.com/SuperiorByteWorks-LLC/agent-project | License: Apache-2.0 | Author: Clayton Young / Superior Byte Works, LLC (Boreal Bytes) -->

C4 Diagram

Back to Style Guide — Read the style guide first for emoji, color, and accessibility rules.

Syntax keyword: C4Context, C4Container, C4Component Best for: System architecture at varying zoom levels — context, containers, components When NOT to use: Infrastructure topology (use Architecture), runtime sequences (use Sequence)


C4 remains experimental. In the Mermaid 12.0.0 checks, accTitle parsed but did not produce an SVG <title>; retain a visible text description and meaningful alt text for exports. An automatic layout still needs a visual overlap check.

Raw lines 1 to 16
17## Exemplar Diagram — System Context
19_Illustrative context: a customer uses a store, which calls an external payment provider._
21```mermaid
22C4Context
23 accTitle: Online Store System Context
24 accDescr: C4 context diagram showing how a customer interacts with the store and its external payment dependency
26 title Online Store - System Context
28 Person(customer, "Customer", "Places orders")
29 System(store, "Online Store", "Catalog and checkout")
30 System_Ext(payment, "Payment Provider", "Card processing")
32 Rel(customer, store, "Orders", "HTTPS")
33 Rel(store, payment, "Pays", "API")
35 UpdateRelStyle(customer, store, $offsetY="-40", $offsetX="-30")
36 UpdateRelStyle(store, payment, $offsetY="-40", $offsetX="-30")
37```
39---

Exemplar Diagram — System Context

Illustrative context: a customer uses a store, which calls an external payment provider.

C4Context
    accTitle: Online Store System Context
    accDescr: C4 context diagram showing how a customer interacts with the store and its external payment dependency

    title Online Store - System Context

    Person(customer, "Customer", "Places orders")
    System(store, "Online Store", "Catalog and checkout")
    System_Ext(payment, "Payment Provider", "Card processing")

    Rel(customer, store, "Orders", "HTTPS")
    Rel(store, payment, "Pays", "API")

    UpdateRelStyle(customer, store, $offsetY="-40", $offsetX="-30")
    UpdateRelStyle(store, payment, $offsetY="-40", $offsetX="-30")

Raw lines 17 to 40
41## C4 Zoom Levels
43| Level | Keyword | Shows | Audience |
44| ------------- | ------------- | --------------------------------------- | --------------- |
45| **Context** | `C4Context` | Systems + external actors | Everyone |
46| **Container** | `C4Container` | Apps, databases, queues within a system | Technical leads |
47| **Component** | `C4Component` | Internal modules within a container | Developers |

C4 Zoom Levels

LevelKeywordShowsAudience
ContextC4ContextSystems + external actorsEveryone
ContainerC4ContainerApps, databases, queues within a systemTechnical leads
ComponentC4ComponentInternal modules within a containerDevelopers
Raw lines 41 to 48
49## Tips
51- Use `Person()` for human actors
52- Use `System()` for internal systems, `System_Ext()` for external
53- Use `Container()`, `ContainerDb()`, `ContainerQueue()` at the container level
54- Label relationships with **verbs** and **protocols**: `"Reads from", "SQL/TLS"`
55- Use `Container_Boundary(id, "name") { ... }` to group containers
56- **Keep descriptions short** — long text causes label overlaps
57- **Limit to 4–5 elements** at the Context level to avoid crowding
58- **Avoid emoji in C4 labels** — the C4 renderer handles its own styling
59- Use `UpdateRelStyle()` to adjust label positions if overlaps occur
61---

Tips

  • Use Person() for human actors
  • Use System() for internal systems, System_Ext() for external
  • Use Container(), ContainerDb(), ContainerQueue() at the container level
  • Label relationships with verbs and protocols: "Reads from", "SQL/TLS"
  • Use Container_Boundary(id, "name") { ... } to group containers
  • Keep descriptions short — long text causes label overlaps
  • Limit to 4–5 elements at the Context level to avoid crowding
  • Avoid emoji in C4 labels — the C4 renderer handles its own styling
  • Use UpdateRelStyle() to adjust label positions if overlaps occur

Raw lines 49 to 62
63## Template
65_Describe the system, its user, and its external dependency here._
67```mermaid
68C4Context
69 accTitle: Your System Context
70 accDescr: Describe the system boundaries and external interactions
72 Person(user, "User", "Role description")
74 System(main_system, "Your System", "What it does")
75 System_Ext(external, "External Service", "What it provides")
77 Rel(user, main_system, "Uses", "HTTPS")
78 Rel(main_system, external, "Calls", "API")
79```
81---

Template

Describe the system, its user, and its external dependency here.

C4Context
    accTitle: Your System Context
    accDescr: Describe the system boundaries and external interactions

    Person(user, "User", "Role description")

    System(main_system, "Your System", "What it does")
    System_Ext(external, "External Service", "What it provides")

    Rel(user, main_system, "Uses", "HTTPS")
    Rel(main_system, external, "Calls", "API")

Raw lines 63 to 82
83## Complex Example
85A C4 Container diagram for an e-commerce platform with 3 `Container_Boundary` groups, 8 containers, and 2 external systems. Shows how to use boundaries to organize services by layer, with `UpdateRelStyle` offsets preventing label overlaps.
87```mermaid
88C4Container
89 accTitle: E-Commerce Platform Container View
90 accDescr: C4 container diagram showing a web frontend, core backend services, and data stores with external payment and email dependencies
92 Person(customer, "Customer", "Shops online")
94 Container_Boundary(frontend, "Frontend") {
95 Container(spa, "Web App", "React", "Single-page app")
96 Container(bff, "BFF API", "Node.js", "Backend for frontend")
97 }
99 Container_Boundary(services, "Core Services") {
100 Container(order_svc, "Order Service", "Go", "Order processing")
101 Container(catalog_svc, "Product Catalog", "Go", "Product data")
102 Container(user_svc, "User Service", "Go", "Auth and profiles")
103 }
105 Container_Boundary(data, "Data Layer") {
106 ContainerDb(pg, "PostgreSQL", "SQL", "Primary data store")
107 ContainerDb(redis, "Redis", "Cache", "Session and cache")
108 ContainerDb(search, "Elasticsearch", "Search", "Product search")
109 }
111 System_Ext(payment_gw, "Payment Gateway", "Card processing")
112 System_Ext(email_svc, "Email Service", "Transactional email")
114 Rel(customer, spa, "Browses", "HTTPS")
115 Rel(spa, bff, "Calls", "GraphQL")
116 Rel(bff, order_svc, "Places orders", "gRPC")
117 Rel(bff, catalog_svc, "Queries", "gRPC")
118 Rel(bff, user_svc, "Authenticates", "gRPC")
119 Rel(order_svc, pg, "Reads/writes", "SQL")
120 Rel(order_svc, payment_gw, "Charges", "API")
121 Rel(order_svc, email_svc, "Sends", "SMTP")
122 Rel(catalog_svc, search, "Indexes", "REST")
123 Rel(user_svc, redis, "Sessions", "TCP")
124 Rel(catalog_svc, pg, "Reads", "SQL")
126 UpdateRelStyle(customer, spa, $offsetY="-40", $offsetX="-50")
127 UpdateRelStyle(spa, bff, $offsetY="-30", $offsetX="10")
128 UpdateRelStyle(bff, order_svc, $offsetY="-30", $offsetX="-40")
129 UpdateRelStyle(bff, catalog_svc, $offsetY="-30", $offsetX="10")
130 UpdateRelStyle(bff, user_svc, $offsetY="-30", $offsetX="50")
131 UpdateRelStyle(order_svc, pg, $offsetY="-30", $offsetX="-50")
132 UpdateRelStyle(order_svc, payment_gw, $offsetY="-30", $offsetX="10")
133 UpdateRelStyle(order_svc, email_svc, $offsetY="10", $offsetX="10")
134 UpdateRelStyle(catalog_svc, search, $offsetY="-30", $offsetX="10")
135 UpdateRelStyle(user_svc, redis, $offsetY="-30", $offsetX="10")
136 UpdateRelStyle(catalog_svc, pg, $offsetY="10", $offsetX="30")
137```

Complex Example

A C4 Container diagram for an e-commerce platform with 3 Container_Boundary groups, 8 containers, and 2 external systems. Shows how to use boundaries to organize services by layer, with UpdateRelStyle offsets preventing label overlaps.

C4Container
    accTitle: E-Commerce Platform Container View
    accDescr: C4 container diagram showing a web frontend, core backend services, and data stores with external payment and email dependencies

    Person(customer, "Customer", "Shops online")

    Container_Boundary(frontend, "Frontend") {
        Container(spa, "Web App", "React", "Single-page app")
        Container(bff, "BFF API", "Node.js", "Backend for frontend")
    }

    Container_Boundary(services, "Core Services") {
        Container(order_svc, "Order Service", "Go", "Order processing")
        Container(catalog_svc, "Product Catalog", "Go", "Product data")
        Container(user_svc, "User Service", "Go", "Auth and profiles")
    }

    Container_Boundary(data, "Data Layer") {
        ContainerDb(pg, "PostgreSQL", "SQL", "Primary data store")
        ContainerDb(redis, "Redis", "Cache", "Session and cache")
        ContainerDb(search, "Elasticsearch", "Search", "Product search")
    }

    System_Ext(payment_gw, "Payment Gateway", "Card processing")
    System_Ext(email_svc, "Email Service", "Transactional email")

    Rel(customer, spa, "Browses", "HTTPS")
    Rel(spa, bff, "Calls", "GraphQL")
    Rel(bff, order_svc, "Places orders", "gRPC")
    Rel(bff, catalog_svc, "Queries", "gRPC")
    Rel(bff, user_svc, "Authenticates", "gRPC")
    Rel(order_svc, pg, "Reads/writes", "SQL")
    Rel(order_svc, payment_gw, "Charges", "API")
    Rel(order_svc, email_svc, "Sends", "SMTP")
    Rel(catalog_svc, search, "Indexes", "REST")
    Rel(user_svc, redis, "Sessions", "TCP")
    Rel(catalog_svc, pg, "Reads", "SQL")

    UpdateRelStyle(customer, spa, $offsetY="-40", $offsetX="-50")
    UpdateRelStyle(spa, bff, $offsetY="-30", $offsetX="10")
    UpdateRelStyle(bff, order_svc, $offsetY="-30", $offsetX="-40")
    UpdateRelStyle(bff, catalog_svc, $offsetY="-30", $offsetX="10")
    UpdateRelStyle(bff, user_svc, $offsetY="-30", $offsetX="50")
    UpdateRelStyle(order_svc, pg, $offsetY="-30", $offsetX="-50")
    UpdateRelStyle(order_svc, payment_gw, $offsetY="-30", $offsetX="10")
    UpdateRelStyle(order_svc, email_svc, $offsetY="10", $offsetX="10")
    UpdateRelStyle(catalog_svc, search, $offsetY="-30", $offsetX="10")
    UpdateRelStyle(user_svc, redis, $offsetY="-30", $offsetX="10")
    UpdateRelStyle(catalog_svc, pg, $offsetY="10", $offsetX="30")
Raw lines 83 to 138
139### Why this works
141- **Container_Boundary groups map to deployment units** — frontend, core services, and data layer each correspond to real infrastructure boundaries (CDN, Kubernetes namespace, managed databases)
142- **Relationship offsets are example-specific** — adjust `UpdateRelStyle` only after inspecting the current rendering. Reusing offsets in another graph can create overlaps
143- **Descriptions are kept to 1-3 words** — "Card processing", "Session and cache", "Auth and profiles". Long descriptions are the #1 cause of C4 rendering issues
144- **Container types are semantic** — `ContainerDb` for databases gives them the cylinder icon, `Container` for services. The C4 renderer provides its own visual differentiation

Why this works

  • Container_Boundary groups map to deployment units — frontend, core services, and data layer each correspond to real infrastructure boundaries (CDN, Kubernetes namespace, managed databases)
  • Relationship offsets are example-specific — adjust UpdateRelStyle only after inspecting the current rendering. Reusing offsets in another graph can create overlaps
  • Descriptions are kept to 1-3 words — "Card processing", "Session and cache", "Auth and profiles". Long descriptions are the #1 cause of C4 rendering issues
  • Container types are semantic — ContainerDb for databases gives them the cylinder icon, Container for services. The C4 renderer provides its own visual differentiation
Raw lines 139 to 146
147## Verified reference
149Syntax examples reviewed against [official Mermaid documentation](https://mermaid.js.org/syntax/c4.html) and rendered with Mermaid 12.0.0 (2026-10-01). Check the destination version; appearance and accessibility are not guaranteed by a successful parse.

Verified reference

Syntax examples reviewed against official Mermaid documentation and rendered with Mermaid 12.0.0 (2026-10-01). Check the destination version; appearance and accessibility are not guaranteed by a successful parse.

Raw lines 147 to 149