Guest User

c4-guide.md

a guest
Feb 26th, 2026
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.59 KB | None | 0 0
  1. # C4 Model — Quick Reference for EARS Plans
  2.  
  3. ## Depth Selection
  4.  
  5. Pick the **shallowest level that makes the change legible**. Going deeper than necessary adds noise.
  6.  
  7. ### Decision tree
  8.  
  9. ```
  10. Does the change cross service/deployment boundaries?
  11. ├─ Yes → Start at L2 (Container), drill to L3 if needed
  12. └─ No
  13. Does it affect external actors or system boundaries?
  14. ├─ Yes → L1 (Context) + relevant inner level
  15. └─ No
  16. Does it involve 2+ internal modules/packages?
  17. ├─ Yes → L3 (Component)
  18. └─ No
  19. Is class/function-level design ambiguous?
  20. ├─ Yes → L4 (Code) or pseudo-breakdown
  21. └─ No → Skip C4, the plan is self-explanatory
  22. ```
  23.  
  24. ## Level Definitions
  25.  
  26. ### L1 — System Context
  27. Shows the system as a black box, its users, and external systems it integrates with.
  28.  
  29. ```mermaid
  30. C4Context
  31. title System Context — <SystemName>
  32. Person(user, "End User", "Interacts via web UI")
  33. System(sys, "SystemName", "Core platform")
  34. System_Ext(ext, "ExternalAPI", "Third-party service")
  35. Rel(user, sys, "Uses")
  36. Rel(sys, ext, "Calls")
  37. ```
  38.  
  39. Use when: the change alters who/what the system talks to.
  40.  
  41. ### L2 — Container
  42. Decomposes the system into deployable units (services, databases, SPAs, queues).
  43.  
  44. ```mermaid
  45. C4Container
  46. title Container — <SystemName>
  47. Container(api, "API Service", "Node.js", "Handles HTTP requests")
  48. ContainerDb(db, "PostgreSQL", "Relational DB", "Persistent storage")
  49. Container(worker, "Background Worker", "Python", "Async job processing")
  50. ContainerQueue(q, "RabbitMQ", "Message broker")
  51. Rel(api, db, "Reads/writes")
  52. Rel(api, q, "Enqueues jobs")
  53. Rel(worker, q, "Consumes jobs")
  54. ```
  55.  
  56. Use when: the change spans services or introduces a new deployable unit.
  57.  
  58. ### L3 — Component
  59. Shows internal modules/packages within a single container and their relationships.
  60.  
  61. ```mermaid
  62. C4Component
  63. title Component — API Service
  64. Component(ctrl, "RequestController", "Handles routing")
  65. Component(auth, "AuthModule", "Token validation")
  66. Component(rate, "RateLimiter", "Request throttling")
  67. Component(repo, "UserRepository", "Data access")
  68. Rel(ctrl, auth, "Validates tokens")
  69. Rel(ctrl, rate, "Checks limits")
  70. Rel(ctrl, repo, "Queries users")
  71. ```
  72.  
  73. Use when: the change involves interactions between 2+ modules within a container.
  74.  
  75. ### L4 — Code
  76. Class/function-level detail. Rarely needed in plans — pseudo-structural breakdown is usually clearer.
  77.  
  78. Use when: the design is ambiguous at the function level and the team needs to agree on signatures/types before implementation.
  79.  
  80. ## Pseudo-Structural Breakdown (preferred for most Standard-tier plans)
  81.  
  82. When a Mermaid diagram would be overkill:
  83.  
  84. ```
  85. Component: <Name>
  86. Responsibilities: <comma-separated list>
  87. Dependencies: <what it imports/calls>
  88. Exposes: <public API surface>
  89. Change: <what's being modified — omit if new>
  90. ```
  91.  
  92. Rules:
  93. - One block per component touched by the plan.
  94. - Dependencies MUST form a DAG — flag cycles immediately.
  95. - "Exposes" = the contract other components depend on. If this changes, it affects blast radius.
  96.  
  97. ## Combining with EARS
  98.  
  99. Map C4 components to EARS requirements:
  100. - Each component's "Exposes" surface suggests ubiquitous requirements (invariants of the contract).
  101. - Each "Dependencies" edge suggests event-driven or state-driven requirements at the boundary.
  102. - Each "Change" annotation maps to one or more R# IDs.
  103.  
  104. This traceability — from architecture to requirements to implementation to verification — is the core value of the EARS planning method.
Advertisement
Add Comment
Please, Sign In to add comment