agile-context-engineering 0.5.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/.claude-plugin/marketplace.json +18 -0
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/CHANGELOG.md +7 -1
  4. package/README.md +16 -12
  5. package/agents/ace-code-discovery-analyst.md +245 -245
  6. package/agents/ace-code-integration-analyst.md +248 -248
  7. package/agents/ace-code-reviewer.md +375 -375
  8. package/agents/ace-product-owner.md +365 -361
  9. package/agents/ace-project-researcher.md +606 -606
  10. package/agents/ace-technical-application-architect.md +315 -315
  11. package/bin/install.js +587 -173
  12. package/hooks/ace-check-update.js +15 -14
  13. package/hooks/ace-statusline.js +30 -12
  14. package/hooks/hooks.json +14 -0
  15. package/package.json +3 -2
  16. package/shared/lib/ace-core.js +53 -0
  17. package/shared/lib/ace-core.test.js +308 -308
  18. package/shared/lib/ace-story.test.js +250 -250
  19. package/skills/execute-story/SKILL.md +116 -110
  20. package/skills/execute-story/script.js +13 -27
  21. package/skills/execute-story/script.test.js +261 -261
  22. package/skills/execute-story/story-template.xml +451 -451
  23. package/skills/execute-story/workflow.xml +3 -1
  24. package/skills/help/SKILL.md +71 -69
  25. package/skills/help/script.js +32 -35
  26. package/skills/help/script.test.js +183 -183
  27. package/skills/help/workflow.xml +14 -3
  28. package/skills/init-coding-standards/SKILL.md +91 -72
  29. package/skills/init-coding-standards/coding-standards-template.xml +531 -531
  30. package/skills/init-coding-standards/script.js +50 -59
  31. package/skills/init-coding-standards/script.test.js +70 -70
  32. package/skills/init-coding-standards/workflow.xml +1 -1
  33. package/skills/map-cross-cutting/SKILL.md +126 -89
  34. package/skills/map-cross-cutting/workflow.xml +1 -1
  35. package/skills/map-guide/SKILL.md +126 -89
  36. package/skills/map-guide/workflow.xml +1 -1
  37. package/skills/map-pattern/SKILL.md +125 -89
  38. package/skills/map-pattern/workflow.xml +1 -1
  39. package/skills/map-story/SKILL.md +180 -127
  40. package/skills/map-story/templates/tech-debt-index.xml +125 -125
  41. package/skills/map-story/workflow.xml +2 -2
  42. package/skills/map-subsystem/SKILL.md +155 -111
  43. package/skills/map-subsystem/script.js +51 -60
  44. package/skills/map-subsystem/script.test.js +68 -68
  45. package/skills/map-subsystem/templates/subsystem-architecture.xml +343 -343
  46. package/skills/map-subsystem/templates/subsystem-structure.xml +234 -234
  47. package/skills/map-subsystem/workflow.xml +1173 -1173
  48. package/skills/map-sys-doc/SKILL.md +125 -90
  49. package/skills/map-sys-doc/workflow.xml +1 -1
  50. package/skills/map-system/SKILL.md +103 -85
  51. package/skills/map-system/script.js +75 -84
  52. package/skills/map-system/script.test.js +73 -73
  53. package/skills/map-system/templates/system-structure.xml +177 -177
  54. package/skills/map-system/templates/testing-framework.xml +283 -283
  55. package/skills/map-system/workflow.xml +667 -667
  56. package/skills/map-walkthrough/SKILL.md +140 -92
  57. package/skills/map-walkthrough/workflow.xml +457 -457
  58. package/skills/plan-backlog/SKILL.md +93 -75
  59. package/skills/plan-backlog/script.js +121 -136
  60. package/skills/plan-backlog/script.test.js +83 -83
  61. package/skills/plan-backlog/workflow.xml +1348 -1348
  62. package/skills/plan-feature/SKILL.md +99 -76
  63. package/skills/plan-feature/feature-template.xml +361 -361
  64. package/skills/plan-feature/script.js +131 -148
  65. package/skills/plan-feature/script.test.js +80 -80
  66. package/skills/plan-feature/workflow.xml +1 -1
  67. package/skills/plan-product-vision/SKILL.md +91 -75
  68. package/skills/plan-product-vision/product-vision-template.xml +227 -227
  69. package/skills/plan-product-vision/script.js +51 -60
  70. package/skills/plan-product-vision/script.test.js +69 -69
  71. package/skills/plan-product-vision/workflow.xml +337 -337
  72. package/skills/plan-story/SKILL.md +125 -102
  73. package/skills/plan-story/script.js +18 -49
  74. package/skills/plan-story/story-template.xml +8 -1
  75. package/skills/plan-story/workflow.xml +17 -1
  76. package/skills/research-external-solution/SKILL.md +120 -107
  77. package/skills/research-external-solution/external-solution-template.xml +832 -832
  78. package/skills/research-external-solution/script.js +229 -238
  79. package/skills/research-external-solution/script.test.js +134 -134
  80. package/skills/research-external-solution/workflow.xml +657 -657
  81. package/skills/research-integration-solution/SKILL.md +121 -98
  82. package/skills/research-integration-solution/integration-solution-template.xml +1015 -1015
  83. package/skills/research-integration-solution/script.js +223 -231
  84. package/skills/research-integration-solution/script.test.js +134 -134
  85. package/skills/research-integration-solution/workflow.xml +711 -711
  86. package/skills/research-story-wiki/SKILL.md +101 -92
  87. package/skills/research-story-wiki/script.js +223 -231
  88. package/skills/research-story-wiki/script.test.js +138 -138
  89. package/skills/research-story-wiki/story-wiki-template.xml +194 -194
  90. package/skills/research-story-wiki/workflow.xml +473 -473
  91. package/skills/research-technical-solution/SKILL.md +131 -103
  92. package/skills/research-technical-solution/script.js +223 -231
  93. package/skills/research-technical-solution/script.test.js +134 -134
  94. package/skills/research-technical-solution/technical-solution-template.xml +1025 -1025
  95. package/skills/research-technical-solution/workflow.xml +761 -761
  96. package/skills/review-story/SKILL.md +99 -100
  97. package/skills/review-story/script.js +8 -16
  98. package/skills/review-story/script.test.js +169 -169
  99. package/skills/review-story/story-template.xml +451 -451
  100. package/skills/review-story/workflow.xml +1 -1
  101. package/skills/update/SKILL.md +65 -53
  102. package/skills/update/workflow.xml +21 -5
@@ -1,343 +1,343 @@
1
- <subsystem-architecture>
2
- <purpose>
3
- Template for `.docs/wiki/subsystems/[subsystem-name]/architecture.md` — the internal
4
- architecture view of a single subsystem. Captures component structure (C4 L3), internal
5
- flows, dependency contracts, data ownership, and subsystem-specific decisions.
6
-
7
- Complements system-architecture.md (which shows system-wide L1/L2 views).
8
- Complements subsystem-structure.md (which shows physical file/folder layout).
9
-
10
- One instance per subsystem — each gets its own architecture doc.
11
-
12
- A "subsystem" is any cohesive code unit with a clear responsibility boundary —
13
- whether deployed as a microservice, a monolith module, or a library package.
14
- </purpose>
15
-
16
- <template>
17
- <subsystem-context>
18
- ## [Subsystem Name]
19
-
20
- **Responsibility:** [One-line — what this subsystem owns and does]
21
- **Root:** `[path from project root]`
22
-
23
- ### System Context
24
-
25
- How this subsystem connects to the rest of the system:
26
-
27
- | Relationship | Counterpart | Pattern | What Flows |
28
- |-------------|-------------|---------|------------|
29
- | Inbound | [Caller subsystem / external] | [Sync/Async, HTTP/gRPC/event] | [Data/command description] |
30
- | Outbound | [Callee subsystem / external] | [Sync/Async, HTTP/gRPC/event] | [Data/command description] |
31
- </subsystem-context>
32
-
33
- <architectural-pattern>
34
- ## Architectural Pattern
35
-
36
- **Pattern:** [N-Tier / Clean Architecture / Onion / Hexagonal / Vertical Slice / CQRS / MVC / Simple Layered / Other]
37
- **Detected from:** [e.g., "Domain/, Application/, Infrastructure/ folder hierarchy", "IRepository interfaces in core project", "Feature-first directory layout with per-slice handlers"]
38
-
39
- [1-2 sentences: how the pattern manifests in this subsystem — what the layers are called,
40
- how dependencies flow, and any notable deviations from the canonical pattern.]
41
- </architectural-pattern>
42
-
43
- <c4-l3-component>
44
- ## L3: Internal Components
45
-
46
- Shape this diagram to match the detected architectural pattern. Use the reference diagrams
47
- in the guidelines section. Below is the Clean Architecture default — replace with the
48
- appropriate structure for the actual pattern.
49
-
50
- ```mermaid
51
- flowchart TD
52
- subgraph Entry["Entry Point(s)"]
53
- api["[API Layer]<br/><small>[Router/Controller/Handler]</small>"]
54
- end
55
-
56
- subgraph App["Application Layer"]
57
- svc["[Service / Use Case]<br/><small>[Orchestrates domain]</small>"]
58
- end
59
-
60
- subgraph Domain["Domain"]
61
- entity["[Domain Entity / Aggregate]<br/><small>[Core business logic]</small>"]
62
- end
63
-
64
- subgraph Infra["Infrastructure"]
65
- repo["[Repository]<br/><small>[Data access]</small>"]
66
- client["[External Client]<br/><small>[3rd-party / other subsystem]</small>"]
67
- end
68
-
69
- subgraph Data["Data"]
70
- db[("Data Store")]
71
- end
72
-
73
- api --> svc
74
- svc --> entity
75
- svc --> repo
76
- svc --> client
77
- repo --> db
78
- ```
79
-
80
- ### Component Responsibilities
81
-
82
- | Component | Responsibility | Key Files |
83
- |-----------|---------------|-----------|
84
- | [API Layer] | [Receives and validates requests, maps to use cases] | `[path]` |
85
- | [Service] | [Orchestrates domain logic and infrastructure] | `[path]` |
86
- | [Domain] | [Business rules, entities, value objects] | `[path]` |
87
- | [Repository] | [Persists and retrieves domain objects] | `[path]` |
88
- | [External Client] | [Communicates with external system/subsystem] | `[path]` |
89
- </c4-l3-component>
90
-
91
- <internal-flows>
92
- ## Key Internal Flows
93
-
94
- The flows that define this subsystem's core operations.
95
-
96
- ### Flow: [Flow Name]
97
-
98
- [One sentence: what this achieves and when it triggers.]
99
-
100
- ```mermaid
101
- sequenceDiagram
102
- participant Caller as [Caller / Entry]
103
- participant Svc as [Service]
104
- participant Domain as [Domain]
105
- participant Repo as [Repository]
106
- participant DB as [Data Store]
107
-
108
- Caller->>Svc: [Request / command]
109
- Svc->>Domain: [What is passed]
110
- Domain-->>Svc: [Result / validated object]
111
- Svc->>Repo: [Persist / query]
112
- Repo->>DB: [SQL / query]
113
- DB-->>Repo: [Result]
114
- Repo-->>Svc: [Domain object]
115
- Svc-->>Caller: [Response]
116
- ```
117
- </internal-flows>
118
-
119
- <dependency-inventory>
120
- ## Dependency Inventory
121
-
122
- ### Inbound (Who calls this subsystem)
123
-
124
- | Caller | Call Type | Contract | Notes |
125
- |--------|-----------|----------|-------|
126
- | [Subsystem / External] | [HTTP GET /path, Event: topic-name] | [OpenAPI / schema / event type] | [e.g., "authenticated calls only"] |
127
-
128
- ### Outbound (What this subsystem calls)
129
-
130
- | Dependency | Call Type | Contract | Failure Handling |
131
- |------------|-----------|----------|-----------------|
132
- | [Subsystem / External] | [HTTP / gRPC / SQL / event publish] | [OpenAPI / schema / event type] | [Retry, fallback, fail fast] |
133
- </dependency-inventory>
134
-
135
- <data-ownership>
136
- ## Data Ownership
137
-
138
- This subsystem owns the following data stores and schemas. Other subsystems MUST NOT
139
- write directly — they interact through this subsystem's API or events.
140
-
141
- | Store | Type | Schema / Namespace | Key Entities |
142
- |-------|------|--------------------|--------------|
143
- | [Table/collection/topic] | [Postgres/Mongo/Kafka] | [Schema name or prefix] | [Primary entities stored] |
144
-
145
- **Data NOT owned here:** [Any data this subsystem reads but doesn't own, with note of true owner]
146
- </data-ownership>
147
-
148
- <subsystem-architectural-decisions>
149
- ## Subsystem Architectural Decisions
150
-
151
- Decisions specific to this subsystem. System-wide decisions live in system-architecture.md.
152
-
153
- | Decision | Rationale |
154
- |----------|-----------|
155
- | [e.g., CQRS for this service] | [High read/write asymmetry — separate models] |
156
- | [e.g., Repository pattern over direct ORM] | [Testability, ability to swap data store] |
157
- </subsystem-architectural-decisions>
158
- </template>
159
-
160
- <guidelines>
161
-
162
- **ALL visual representations of architecture, dependencies, flows, or relationships MUST be ```mermaid fenced code blocks. NO ASCII arrows (->), NO dependency trees, NO PlantUML. Only mermaid. The ONLY ASCII exception is file trees.**
163
-
164
- **Architectural Pattern — How to Detect:**
165
-
166
- Examine folder structure, namespaces, class names, and dependency directions. Match against
167
- these signals — the first clear match wins. When signals overlap, note the hybrid.
168
-
169
- - **N-Tier / Simple Layered** — Folders named `Controllers/`, `Services/` (or `BLL/`),
170
- `Repositories/` (or `DAL/`). Direct downward dependencies: controller → service → repo.
171
- No interface inversion — concrete classes reference each other directly.
172
-
173
- - **MVC** — Framework-scaffolded `Models/`, `Views/`, `Controllers/` (or `Pages/` for
174
- Razor Pages). Route handlers return views or JSON directly. Thin or no service layer.
175
-
176
- - **Clean Architecture** — Explicit `Domain/`, `Application/`, `Infrastructure/`,
177
- `Presentation/` (or `Web/`, `API/`) projects or folders. Domain has zero outgoing
178
- dependencies. Application references Domain only. Infrastructure implements interfaces
179
- defined in Application or Domain. Dependency rule strictly inward.
180
-
181
- - **Onion Architecture** — Similar signals to Clean but layered as concentric rings:
182
- `Core/` (domain model + domain services + application services), `Infrastructure/`,
183
- optional `UI/`. Interfaces (ports) defined in Core; implementations in outer rings.
184
-
185
- - **Hexagonal / Ports & Adapters** — Explicit `ports/` or `interfaces/` alongside
186
- `adapters/` or `infrastructure/`. Primary adapters (HTTP, CLI) on one side; secondary
187
- adapters (DB, messaging) on the other. Domain core has no framework imports.
188
-
189
- - **Vertical Slice / Feature-First** — Feature-named top-level folders:
190
- `Features/CreateOrder/`, `Features/ListOrders/`. Each slice contains its own handler,
191
- validator, model, and tests. No shared service layer across features. Often uses a
192
- mediator (MediatR, similar) — look for `IRequest`/`IRequestHandler` or equivalent.
193
-
194
- - **CQRS** — Separate `Commands/` and `Queries/` (or `Read/` and `Write/`) directories.
195
- Distinct models for reads vs. writes. May be combined with Event Sourcing
196
- (`Events/`, `EventStore`, `Projections/`).
197
-
198
- **Architectural Pattern — Diagram shapes per pattern:**
199
-
200
- Use the reference below to choose the right diagram structure. Replace the default
201
- Clean Architecture diagram in the template with the one matching the detected pattern.
202
-
203
- *N-Tier:*
204
- ```
205
- flowchart TD
206
- ctrl["Controller / Presenter"] --> svc["Service / Business Logic"]
207
- svc --> repo["Repository / DAO"]
208
- repo --> db[("Data Store")]
209
- ```
210
-
211
- *Clean Architecture / Onion:*
212
- ```
213
- flowchart TD
214
- subgraph Presentation; api["Controller / Handler"]; end
215
- subgraph Application; uc["Use Case / App Service"]; end
216
- subgraph Domain; ent["Entity / Aggregate"]; port["Port Interface"]; end
217
- subgraph Infrastructure; impl["Repository Impl"]; adapter["External Adapter"]; end
218
- api --> uc
219
- uc --> ent
220
- uc --> port
221
- impl -.->|implements| port
222
- adapter -.->|implements| port
223
- ```
224
-
225
- *Hexagonal / Ports & Adapters:*
226
- ```
227
- flowchart LR
228
- subgraph Primary["Primary Adapters (Driving)"]
229
- http["HTTP Controller"]
230
- cli["CLI Handler"]
231
- end
232
- subgraph Core["Domain Core"]
233
- domain["Domain Logic"]
234
- inport["Input Port"]
235
- outport["Output Port"]
236
- end
237
- subgraph Secondary["Secondary Adapters (Driven)"]
238
- dbrepo["DB Repository"]
239
- msgclient["Messaging Client"]
240
- end
241
- http --> inport
242
- cli --> inport
243
- inport --> domain
244
- domain --> outport
245
- outport -.->|implements| dbrepo
246
- outport -.->|implements| msgclient
247
- ```
248
-
249
- *Vertical Slice / Feature-First:*
250
- ```
251
- flowchart LR
252
- subgraph SliceA["Feature: [Name A]"]
253
- ha["Handler A"] --> va["Validator A"]
254
- ha --> dba[("DB")]
255
- end
256
- subgraph SliceB["Feature: [Name B]"]
257
- hb["Handler B"] --> vb["Validator B"]
258
- hb --> dbb[("DB")]
259
- end
260
- entry["Entry / Mediator"] --> ha
261
- entry --> hb
262
- ```
263
-
264
- *CQRS:*
265
- ```
266
- flowchart TD
267
- entry["Entry / Mediator"]
268
- subgraph Commands
269
- ch["Command Handler"] --> domain["Domain / Aggregate"]
270
- domain --> writedb[("Write Store")]
271
- end
272
- subgraph Queries
273
- qh["Query Handler"] --> readdb[("Read Store / Projection")]
274
- end
275
- entry --> ch
276
- entry --> qh
277
- ```
278
-
279
- **Subsystem Context:**
280
- - One-line responsibility — NOT a paragraph. If you need more words, the boundary is wrong
281
- - System context table: only show DIRECT inbound/outbound. No transitive dependencies
282
- - Keep it brief — the full system view is in system-architecture.md
283
-
284
- **L3 Component Diagram:**
285
- - Layered top-to-bottom (entry → application → domain → infrastructure → data)
286
- - Each box = a logical component, NOT a file or class
287
- - Use `flowchart TD` for layered architectures (Clean Architecture, DDD) or `flowchart LR`
288
- for pipeline/stream-processing subsystems
289
- - Do NOT show method calls — this is component-level, not code-level
290
- - Component table: key files must be actual paths within the subsystem
291
-
292
- **Internal Flows:**
293
- - 1-3 flows maximum. Choose flows a NEW DEVELOPER must understand to add a feature
294
- - Component-level only — no method names, no line numbers, no class details
295
- - Sequence diagram participants = components from the L3 diagram, not files
296
- - If more than 3 flows are needed, this subsystem likely has multiple bounded operations —
297
- consider separate docs per operation or split the subsystem
298
-
299
- **Dependency Inventory:**
300
- - Inbound: every caller of this subsystem, even if it's just one other subsystem
301
- - Outbound: every dependency this subsystem calls — including data stores, caches, queues
302
- - "Failure Handling" for outbound: what happens when that dependency is unavailable?
303
-
304
- **Data Ownership:**
305
- - Strict — document who OWNS the data, not just who reads it
306
- - Include ALL data stores: relational tables, document collections, cache keys, message topics
307
- - "Data NOT owned here" prevents confusion when a subsystem reads across ownership boundaries
308
-
309
- **Subsystem Architectural Decisions:**
310
- - Only decisions that deviate from system-wide defaults or are significant within the subsystem
311
- - Skip obvious choices (e.g., don't document "we use async/await" in a Node.js service)
312
- - Decision + Rationale only. No status tracking, no dates
313
-
314
- **What does NOT belong here:**
315
- - Physical file layout (that's subsystem-structure.md)
316
- - System-wide tech stack (that's system-architecture.md)
317
- - L1/L2 diagrams (that's system-architecture.md)
318
- - Code-level detail like class signatures, method contracts (L4 — in code comments/docs)
319
-
320
- </guidelines>
321
-
322
- <evolution>
323
-
324
- Update when this subsystem's internal architecture changes.
325
-
326
- **Update triggers:**
327
- - Architectural pattern changed (e.g., N-Tier refactored to Clean Architecture)
328
- - New component layer added (e.g., adding CQRS, adding a cache layer)
329
- - New inbound integration (new caller, new event type consumed)
330
- - New outbound dependency (new API called, new data store added)
331
- - Data ownership changes (new table, new schema, new topic)
332
- - New subsystem-specific architectural decision made
333
- - Core internal flow fundamentally changed (not just a new step in an existing flow)
334
-
335
- **NOT an update trigger:**
336
- - New feature following existing patterns
337
- - Bug fixes or refactoring within existing components
338
- - New API endpoint within existing handler
339
- - New fields on existing entities
340
-
341
- </evolution>
342
-
343
- </subsystem-architecture>
1
+ <subsystem-architecture>
2
+ <purpose>
3
+ Template for `.docs/wiki/subsystems/[subsystem-name]/architecture.md` — the internal
4
+ architecture view of a single subsystem. Captures component structure (C4 L3), internal
5
+ flows, dependency contracts, data ownership, and subsystem-specific decisions.
6
+
7
+ Complements system-architecture.md (which shows system-wide L1/L2 views).
8
+ Complements subsystem-structure.md (which shows physical file/folder layout).
9
+
10
+ One instance per subsystem — each gets its own architecture doc.
11
+
12
+ A "subsystem" is any cohesive code unit with a clear responsibility boundary —
13
+ whether deployed as a microservice, a monolith module, or a library package.
14
+ </purpose>
15
+
16
+ <template>
17
+ <subsystem-context>
18
+ ## [Subsystem Name]
19
+
20
+ **Responsibility:** [One-line — what this subsystem owns and does]
21
+ **Root:** `[path from project root]`
22
+
23
+ ### System Context
24
+
25
+ How this subsystem connects to the rest of the system:
26
+
27
+ | Relationship | Counterpart | Pattern | What Flows |
28
+ |-------------|-------------|---------|------------|
29
+ | Inbound | [Caller subsystem / external] | [Sync/Async, HTTP/gRPC/event] | [Data/command description] |
30
+ | Outbound | [Callee subsystem / external] | [Sync/Async, HTTP/gRPC/event] | [Data/command description] |
31
+ </subsystem-context>
32
+
33
+ <architectural-pattern>
34
+ ## Architectural Pattern
35
+
36
+ **Pattern:** [N-Tier / Clean Architecture / Onion / Hexagonal / Vertical Slice / CQRS / MVC / Simple Layered / Other]
37
+ **Detected from:** [e.g., "Domain/, Application/, Infrastructure/ folder hierarchy", "IRepository interfaces in core project", "Feature-first directory layout with per-slice handlers"]
38
+
39
+ [1-2 sentences: how the pattern manifests in this subsystem — what the layers are called,
40
+ how dependencies flow, and any notable deviations from the canonical pattern.]
41
+ </architectural-pattern>
42
+
43
+ <c4-l3-component>
44
+ ## L3: Internal Components
45
+
46
+ Shape this diagram to match the detected architectural pattern. Use the reference diagrams
47
+ in the guidelines section. Below is the Clean Architecture default — replace with the
48
+ appropriate structure for the actual pattern.
49
+
50
+ ```mermaid
51
+ flowchart TD
52
+ subgraph Entry["Entry Point(s)"]
53
+ api["[API Layer]<br/><small>[Router/Controller/Handler]</small>"]
54
+ end
55
+
56
+ subgraph App["Application Layer"]
57
+ svc["[Service / Use Case]<br/><small>[Orchestrates domain]</small>"]
58
+ end
59
+
60
+ subgraph Domain["Domain"]
61
+ entity["[Domain Entity / Aggregate]<br/><small>[Core business logic]</small>"]
62
+ end
63
+
64
+ subgraph Infra["Infrastructure"]
65
+ repo["[Repository]<br/><small>[Data access]</small>"]
66
+ client["[External Client]<br/><small>[3rd-party / other subsystem]</small>"]
67
+ end
68
+
69
+ subgraph Data["Data"]
70
+ db[("Data Store")]
71
+ end
72
+
73
+ api --> svc
74
+ svc --> entity
75
+ svc --> repo
76
+ svc --> client
77
+ repo --> db
78
+ ```
79
+
80
+ ### Component Responsibilities
81
+
82
+ | Component | Responsibility | Key Files |
83
+ |-----------|---------------|-----------|
84
+ | [API Layer] | [Receives and validates requests, maps to use cases] | `[path]` |
85
+ | [Service] | [Orchestrates domain logic and infrastructure] | `[path]` |
86
+ | [Domain] | [Business rules, entities, value objects] | `[path]` |
87
+ | [Repository] | [Persists and retrieves domain objects] | `[path]` |
88
+ | [External Client] | [Communicates with external system/subsystem] | `[path]` |
89
+ </c4-l3-component>
90
+
91
+ <internal-flows>
92
+ ## Key Internal Flows
93
+
94
+ The flows that define this subsystem's core operations.
95
+
96
+ ### Flow: [Flow Name]
97
+
98
+ [One sentence: what this achieves and when it triggers.]
99
+
100
+ ```mermaid
101
+ sequenceDiagram
102
+ participant Caller as [Caller / Entry]
103
+ participant Svc as [Service]
104
+ participant Domain as [Domain]
105
+ participant Repo as [Repository]
106
+ participant DB as [Data Store]
107
+
108
+ Caller->>Svc: [Request / command]
109
+ Svc->>Domain: [What is passed]
110
+ Domain-->>Svc: [Result / validated object]
111
+ Svc->>Repo: [Persist / query]
112
+ Repo->>DB: [SQL / query]
113
+ DB-->>Repo: [Result]
114
+ Repo-->>Svc: [Domain object]
115
+ Svc-->>Caller: [Response]
116
+ ```
117
+ </internal-flows>
118
+
119
+ <dependency-inventory>
120
+ ## Dependency Inventory
121
+
122
+ ### Inbound (Who calls this subsystem)
123
+
124
+ | Caller | Call Type | Contract | Notes |
125
+ |--------|-----------|----------|-------|
126
+ | [Subsystem / External] | [HTTP GET /path, Event: topic-name] | [OpenAPI / schema / event type] | [e.g., "authenticated calls only"] |
127
+
128
+ ### Outbound (What this subsystem calls)
129
+
130
+ | Dependency | Call Type | Contract | Failure Handling |
131
+ |------------|-----------|----------|-----------------|
132
+ | [Subsystem / External] | [HTTP / gRPC / SQL / event publish] | [OpenAPI / schema / event type] | [Retry, fallback, fail fast] |
133
+ </dependency-inventory>
134
+
135
+ <data-ownership>
136
+ ## Data Ownership
137
+
138
+ This subsystem owns the following data stores and schemas. Other subsystems MUST NOT
139
+ write directly — they interact through this subsystem's API or events.
140
+
141
+ | Store | Type | Schema / Namespace | Key Entities |
142
+ |-------|------|--------------------|--------------|
143
+ | [Table/collection/topic] | [Postgres/Mongo/Kafka] | [Schema name or prefix] | [Primary entities stored] |
144
+
145
+ **Data NOT owned here:** [Any data this subsystem reads but doesn't own, with note of true owner]
146
+ </data-ownership>
147
+
148
+ <subsystem-architectural-decisions>
149
+ ## Subsystem Architectural Decisions
150
+
151
+ Decisions specific to this subsystem. System-wide decisions live in system-architecture.md.
152
+
153
+ | Decision | Rationale |
154
+ |----------|-----------|
155
+ | [e.g., CQRS for this service] | [High read/write asymmetry — separate models] |
156
+ | [e.g., Repository pattern over direct ORM] | [Testability, ability to swap data store] |
157
+ </subsystem-architectural-decisions>
158
+ </template>
159
+
160
+ <guidelines>
161
+
162
+ **ALL visual representations of architecture, dependencies, flows, or relationships MUST be ```mermaid fenced code blocks. NO ASCII arrows (->), NO dependency trees, NO PlantUML. Only mermaid. The ONLY ASCII exception is file trees.**
163
+
164
+ **Architectural Pattern — How to Detect:**
165
+
166
+ Examine folder structure, namespaces, class names, and dependency directions. Match against
167
+ these signals — the first clear match wins. When signals overlap, note the hybrid.
168
+
169
+ - **N-Tier / Simple Layered** — Folders named `Controllers/`, `Services/` (or `BLL/`),
170
+ `Repositories/` (or `DAL/`). Direct downward dependencies: controller → service → repo.
171
+ No interface inversion — concrete classes reference each other directly.
172
+
173
+ - **MVC** — Framework-scaffolded `Models/`, `Views/`, `Controllers/` (or `Pages/` for
174
+ Razor Pages). Route handlers return views or JSON directly. Thin or no service layer.
175
+
176
+ - **Clean Architecture** — Explicit `Domain/`, `Application/`, `Infrastructure/`,
177
+ `Presentation/` (or `Web/`, `API/`) projects or folders. Domain has zero outgoing
178
+ dependencies. Application references Domain only. Infrastructure implements interfaces
179
+ defined in Application or Domain. Dependency rule strictly inward.
180
+
181
+ - **Onion Architecture** — Similar signals to Clean but layered as concentric rings:
182
+ `Core/` (domain model + domain services + application services), `Infrastructure/`,
183
+ optional `UI/`. Interfaces (ports) defined in Core; implementations in outer rings.
184
+
185
+ - **Hexagonal / Ports & Adapters** — Explicit `ports/` or `interfaces/` alongside
186
+ `adapters/` or `infrastructure/`. Primary adapters (HTTP, CLI) on one side; secondary
187
+ adapters (DB, messaging) on the other. Domain core has no framework imports.
188
+
189
+ - **Vertical Slice / Feature-First** — Feature-named top-level folders:
190
+ `Features/CreateOrder/`, `Features/ListOrders/`. Each slice contains its own handler,
191
+ validator, model, and tests. No shared service layer across features. Often uses a
192
+ mediator (MediatR, similar) — look for `IRequest`/`IRequestHandler` or equivalent.
193
+
194
+ - **CQRS** — Separate `Commands/` and `Queries/` (or `Read/` and `Write/`) directories.
195
+ Distinct models for reads vs. writes. May be combined with Event Sourcing
196
+ (`Events/`, `EventStore`, `Projections/`).
197
+
198
+ **Architectural Pattern — Diagram shapes per pattern:**
199
+
200
+ Use the reference below to choose the right diagram structure. Replace the default
201
+ Clean Architecture diagram in the template with the one matching the detected pattern.
202
+
203
+ *N-Tier:*
204
+ ```
205
+ flowchart TD
206
+ ctrl["Controller / Presenter"] --> svc["Service / Business Logic"]
207
+ svc --> repo["Repository / DAO"]
208
+ repo --> db[("Data Store")]
209
+ ```
210
+
211
+ *Clean Architecture / Onion:*
212
+ ```
213
+ flowchart TD
214
+ subgraph Presentation; api["Controller / Handler"]; end
215
+ subgraph Application; uc["Use Case / App Service"]; end
216
+ subgraph Domain; ent["Entity / Aggregate"]; port["Port Interface"]; end
217
+ subgraph Infrastructure; impl["Repository Impl"]; adapter["External Adapter"]; end
218
+ api --> uc
219
+ uc --> ent
220
+ uc --> port
221
+ impl -.->|implements| port
222
+ adapter -.->|implements| port
223
+ ```
224
+
225
+ *Hexagonal / Ports & Adapters:*
226
+ ```
227
+ flowchart LR
228
+ subgraph Primary["Primary Adapters (Driving)"]
229
+ http["HTTP Controller"]
230
+ cli["CLI Handler"]
231
+ end
232
+ subgraph Core["Domain Core"]
233
+ domain["Domain Logic"]
234
+ inport["Input Port"]
235
+ outport["Output Port"]
236
+ end
237
+ subgraph Secondary["Secondary Adapters (Driven)"]
238
+ dbrepo["DB Repository"]
239
+ msgclient["Messaging Client"]
240
+ end
241
+ http --> inport
242
+ cli --> inport
243
+ inport --> domain
244
+ domain --> outport
245
+ outport -.->|implements| dbrepo
246
+ outport -.->|implements| msgclient
247
+ ```
248
+
249
+ *Vertical Slice / Feature-First:*
250
+ ```
251
+ flowchart LR
252
+ subgraph SliceA["Feature: [Name A]"]
253
+ ha["Handler A"] --> va["Validator A"]
254
+ ha --> dba[("DB")]
255
+ end
256
+ subgraph SliceB["Feature: [Name B]"]
257
+ hb["Handler B"] --> vb["Validator B"]
258
+ hb --> dbb[("DB")]
259
+ end
260
+ entry["Entry / Mediator"] --> ha
261
+ entry --> hb
262
+ ```
263
+
264
+ *CQRS:*
265
+ ```
266
+ flowchart TD
267
+ entry["Entry / Mediator"]
268
+ subgraph Commands
269
+ ch["Command Handler"] --> domain["Domain / Aggregate"]
270
+ domain --> writedb[("Write Store")]
271
+ end
272
+ subgraph Queries
273
+ qh["Query Handler"] --> readdb[("Read Store / Projection")]
274
+ end
275
+ entry --> ch
276
+ entry --> qh
277
+ ```
278
+
279
+ **Subsystem Context:**
280
+ - One-line responsibility — NOT a paragraph. If you need more words, the boundary is wrong
281
+ - System context table: only show DIRECT inbound/outbound. No transitive dependencies
282
+ - Keep it brief — the full system view is in system-architecture.md
283
+
284
+ **L3 Component Diagram:**
285
+ - Layered top-to-bottom (entry → application → domain → infrastructure → data)
286
+ - Each box = a logical component, NOT a file or class
287
+ - Use `flowchart TD` for layered architectures (Clean Architecture, DDD) or `flowchart LR`
288
+ for pipeline/stream-processing subsystems
289
+ - Do NOT show method calls — this is component-level, not code-level
290
+ - Component table: key files must be actual paths within the subsystem
291
+
292
+ **Internal Flows:**
293
+ - 1-3 flows maximum. Choose flows a NEW DEVELOPER must understand to add a feature
294
+ - Component-level only — no method names, no line numbers, no class details
295
+ - Sequence diagram participants = components from the L3 diagram, not files
296
+ - If more than 3 flows are needed, this subsystem likely has multiple bounded operations —
297
+ consider separate docs per operation or split the subsystem
298
+
299
+ **Dependency Inventory:**
300
+ - Inbound: every caller of this subsystem, even if it's just one other subsystem
301
+ - Outbound: every dependency this subsystem calls — including data stores, caches, queues
302
+ - "Failure Handling" for outbound: what happens when that dependency is unavailable?
303
+
304
+ **Data Ownership:**
305
+ - Strict — document who OWNS the data, not just who reads it
306
+ - Include ALL data stores: relational tables, document collections, cache keys, message topics
307
+ - "Data NOT owned here" prevents confusion when a subsystem reads across ownership boundaries
308
+
309
+ **Subsystem Architectural Decisions:**
310
+ - Only decisions that deviate from system-wide defaults or are significant within the subsystem
311
+ - Skip obvious choices (e.g., don't document "we use async/await" in a Node.js service)
312
+ - Decision + Rationale only. No status tracking, no dates
313
+
314
+ **What does NOT belong here:**
315
+ - Physical file layout (that's subsystem-structure.md)
316
+ - System-wide tech stack (that's system-architecture.md)
317
+ - L1/L2 diagrams (that's system-architecture.md)
318
+ - Code-level detail like class signatures, method contracts (L4 — in code comments/docs)
319
+
320
+ </guidelines>
321
+
322
+ <evolution>
323
+
324
+ Update when this subsystem's internal architecture changes.
325
+
326
+ **Update triggers:**
327
+ - Architectural pattern changed (e.g., N-Tier refactored to Clean Architecture)
328
+ - New component layer added (e.g., adding CQRS, adding a cache layer)
329
+ - New inbound integration (new caller, new event type consumed)
330
+ - New outbound dependency (new API called, new data store added)
331
+ - Data ownership changes (new table, new schema, new topic)
332
+ - New subsystem-specific architectural decision made
333
+ - Core internal flow fundamentally changed (not just a new step in an existing flow)
334
+
335
+ **NOT an update trigger:**
336
+ - New feature following existing patterns
337
+ - Bug fixes or refactoring within existing components
338
+ - New API endpoint within existing handler
339
+ - New fields on existing entities
340
+
341
+ </evolution>
342
+
343
+ </subsystem-architecture>