@comfanion/workflow 4.36.39 → 4.36.41

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.
@@ -1,11 +1,11 @@
1
1
  ---
2
2
  name: architecture-design
3
- description: How to design system architecture following hexagonal/DDD patterns with proper module boundaries
3
+ description: Use when designing new system architecture, defining module boundaries, choosing architectural patterns (CQRS, Event Sourcing), or making technology decisions
4
4
  license: MIT
5
5
  compatibility: opencode
6
6
  metadata:
7
7
  domain: software-architecture
8
- patterns: hexagonal, ddd, modular-monolith
8
+ patterns: hexagonal, ddd, cqrs, event-sourcing, saga
9
9
  artifacts: docs/architecture.md
10
10
  ---
11
11
 
@@ -18,6 +18,8 @@ Use this skill when you need to:
18
18
  - Define module/service boundaries
19
19
  - Create data ownership model
20
20
  - Design integration points
21
+ - Choose architectural patterns (CQRS, Event Sourcing, Saga)
22
+ - Make technology trade-off decisions
21
23
  - Document architectural decisions
22
24
 
23
25
  ## Reference
@@ -43,8 +45,10 @@ Brief prose with:
43
45
 
44
46
  | Category | Decision | Rationale |
45
47
  |----------|----------|-----------|
46
- | Architecture | Hexagonal | Organizational standard |
47
- | Database | PostgreSQL per module | Service isolation |
48
+ | Architecture | {{pattern}} | {{why_chosen}} |
49
+ | Database | {{db_choice}} | {{why_chosen}} |
50
+
51
+ *Choose pattern based on project needs — see "Architecture Style Selection" below*
48
52
 
49
53
  ### 3. System Context
50
54
 
@@ -124,9 +128,40 @@ Reference in architecture:
124
128
  → Unit: `Task`
125
129
  ```
126
130
 
127
- ## Architecture Principles
131
+ ## Architecture Style Selection
132
+
133
+ **Choose based on project context — no default!**
134
+
135
+ ### Style Comparison
136
+
137
+ | Style | Best For | Team Size | Complexity |
138
+ |-------|----------|-----------|------------|
139
+ | **Layered** | Simple CRUD apps, MVPs | 1-3 devs | Low |
140
+ | **Hexagonal** | Testable business logic, many integrations | 3-10 devs | Medium |
141
+ | **Clean Architecture** | Complex domain, long-term maintainability | 5+ devs | Medium-High |
142
+ | **Microservices** | Independent scaling, multiple teams | 10+ devs | High |
143
+ | **Vertical Slices** | Feature teams, rapid iteration | Any | Medium |
144
+
145
+ ### Layered Architecture
146
+
147
+ ```
148
+ ┌─────────────────────────────┐
149
+ │ Presentation │ ← Controllers, Views
150
+ ├─────────────────────────────┤
151
+ │ Application │ ← Services, DTOs
152
+ ├─────────────────────────────┤
153
+ │ Domain │ ← Entities, Business Logic
154
+ ├─────────────────────────────┤
155
+ │ Infrastructure │ ← DB, External APIs
156
+ └─────────────────────────────┘
157
+
158
+ Dependencies: Top → Bottom (each layer depends on layer below)
159
+ ```
160
+
161
+ **Use when:** Simple CRUD, small team, fast delivery needed
162
+ **Avoid when:** Complex business rules, many external integrations
128
163
 
129
- ### Hexagonal Architecture
164
+ ### Hexagonal (Ports & Adapters)
130
165
 
131
166
  ```
132
167
  ┌─────────────────────────────────────────────────────┐
@@ -142,16 +177,284 @@ Reference in architecture:
142
177
  │ Adapters (HTTP, DB, Kafka, External) │
143
178
  └─────────────────────────────────────────────────────┘
144
179
 
145
- Dependency Direction: Infrastructure → Application → Domain
180
+ Dependencies: Outside → Inside (Infrastructure → Application → Domain)
181
+ ```
182
+
183
+ **Use when:** Many integrations, need to swap implementations, testability critical
184
+ **Avoid when:** Simple apps, overhead not justified
185
+
186
+ ### Clean Architecture
187
+
188
+ ```
189
+ ┌─────────────────────────────────────────────────────┐
190
+ │ Frameworks & Drivers │
191
+ │ ┌───────────────────────────────────────────────┐ │
192
+ │ │ Interface Adapters │ │
193
+ │ │ ┌───────────────────────────────────────┐ │ │
194
+ │ │ │ Application Business │ │ │
195
+ │ │ │ ┌─────────────────────────────────┐ │ │ │
196
+ │ │ │ │ Enterprise Business Rules │ │ │ │
197
+ │ │ │ │ (Entities) │ │ │ │
198
+ │ │ │ └─────────────────────────────────┘ │ │ │
199
+ │ │ │ (Use Cases) │ │ │
200
+ │ │ └───────────────────────────────────────┘ │ │
201
+ │ │ Controllers, Gateways, Presenters │ │
202
+ │ └───────────────────────────────────────────────┘ │
203
+ │ Web, DB, UI, External │
204
+ └─────────────────────────────────────────────────────┘
205
+
206
+ Dependency Rule: Source code dependencies point INWARD only
146
207
  ```
147
208
 
148
- ### Module Boundaries
209
+ **Use when:** Complex domain, multiple UIs, long-term project
210
+ **Avoid when:** MVP, tight deadlines
211
+
212
+ ### Vertical Slices
213
+
214
+ ```
215
+ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐
216
+ │ Feature A │ │ Feature B │ │ Feature C │
217
+ │ ┌─────────┐ │ │ ┌─────────┐ │ │ ┌─────────┐ │
218
+ │ │ Handler │ │ │ │ Handler │ │ │ │ Handler │ │
219
+ │ │ Logic │ │ │ │ Logic │ │ │ │ Logic │ │
220
+ │ │ Data │ │ │ │ Data │ │ │ │ Data │ │
221
+ │ └─────────┘ │ │ └─────────┘ │ │ └─────────┘ │
222
+ └─────────────┘ └─────────────┘ └─────────────┘
223
+ │ │ │
224
+ └───────────────┴───────────────┘
225
+ Shared Kernel
226
+ ```
227
+
228
+ **Use when:** Feature teams, CQRS, rapid delivery
229
+ **Avoid when:** Heavy cross-feature dependencies
230
+
231
+ ---
232
+
233
+ ## Module Boundaries
234
+
235
+ Regardless of architecture style, each module must have:
149
236
 
150
- Each module must have:
151
237
  - **Single responsibility** - One business capability
152
238
  - **Explicit data ownership** - Clear which entities it owns
153
239
  - **Defined interfaces** - API contracts for communication
154
- - **No cross-module imports** - Communicate via Kafka/HTTP only
240
+ - **Loose coupling** - Communicate via events/APIs, not direct imports
241
+
242
+ **Communication patterns:**
243
+
244
+ | Pattern | Use When | Example |
245
+ |---------|----------|---------|
246
+ | Direct call (in-process) | Same deployment, sync needed | Service → Repository |
247
+ | REST/gRPC | Cross-service, request-response | Order → Inventory check |
248
+ | Events (Kafka/RabbitMQ) | Async, decoupled, eventual consistency | OrderPlaced → Notification |
249
+ | Shared DB (avoid) | Legacy, temporary | — migrate away |
250
+
251
+ ---
252
+
253
+ ## Architectural Patterns
254
+
255
+ ### Pattern Selection Matrix
256
+
257
+ | Pattern | Use When | Avoid When |
258
+ |---------|----------|------------|
259
+ | **Modular Monolith** | MVP, small team, unclear boundaries | High scale needs, multiple teams |
260
+ | **Microservices** | Clear boundaries, independent scaling | Small team, shared data |
261
+ | **CQRS** | Different read/write models, complex queries | Simple CRUD |
262
+ | **Event Sourcing** | Audit trail critical, temporal queries | Simple state, storage concerns |
263
+ | **Saga** | Distributed transactions, compensation needed | Single DB, simple workflows |
264
+
265
+ ### CQRS (Command Query Responsibility Segregation)
266
+
267
+ ```
268
+ ┌─────────────┐ ┌─────────────┐
269
+ │ Command │ │ Query │
270
+ │ (Write) │ │ (Read) │
271
+ └──────┬──────┘ └──────┬──────┘
272
+ │ │
273
+ ▼ ▼
274
+ ┌─────────────┐ ┌─────────────┐
275
+ │ Write Model │ │ Read Model │
276
+ │ (normalized)│ │(denormalized│
277
+ └──────┬──────┘ └──────┬──────┘
278
+ │ Sync/Event │
279
+ └────────────────────┘
280
+ ```
281
+
282
+ **When to use:**
283
+ - Read/write ratio > 10:1
284
+ - Complex query requirements
285
+ - Different consistency needs
286
+
287
+ **Trade-offs:**
288
+ | Benefit | Cost |
289
+ |---------|------|
290
+ | Optimized read performance | Eventual consistency |
291
+ | Independent scaling | Data sync complexity |
292
+ | Simpler query logic | More infrastructure |
293
+
294
+ ### Event Sourcing
295
+
296
+ ```
297
+ ┌──────────┐ ┌──────────┐ ┌──────────┐
298
+ │ Command │───►│ Event │───►│ State │
299
+ │ │ │ Store │ │ (derived)│
300
+ └──────────┘ └──────────┘ └──────────┘
301
+
302
+ ▼ Replay
303
+ ┌──────────┐
304
+ │Projection│
305
+ └──────────┘
306
+ ```
307
+
308
+ **When to use:**
309
+ - Full audit trail required
310
+ - Temporal queries ("state at time X")
311
+ - Complex domain with many state transitions
312
+
313
+ **Trade-offs:**
314
+ | Benefit | Cost |
315
+ |---------|------|
316
+ | Complete audit history | Storage growth |
317
+ | Time-travel queries | Query complexity |
318
+ | Event replay for debugging | Schema evolution |
319
+
320
+ ### Saga Pattern (Distributed Transactions)
321
+
322
+ ```
323
+ ┌────────┐ ┌────────┐ ┌────────┐
324
+ │ Step 1 │───►│ Step 2 │───►│ Step 3 │
325
+ └────────┘ └────────┘ └────────┘
326
+ │ │ │
327
+ ▼ ▼ ▼
328
+ Compensate 1 Compensate 2 Compensate 3
329
+ ▲ ▲ │
330
+ └─────────────┴─────────────┘
331
+ (on failure)
332
+ ```
333
+
334
+ **Types:**
335
+ | Type | Coordination | Use When |
336
+ |------|--------------|----------|
337
+ | Choreography | Events | Simple flows, few services |
338
+ | Orchestration | Central orchestrator | Complex flows, many services |
339
+
340
+ **Example: Order Saga**
341
+ 1. Reserve inventory → (compensate: release inventory)
342
+ 2. Charge payment → (compensate: refund)
343
+ 3. Ship order → (compensate: cancel shipment)
344
+
345
+ ### Resilience Patterns
346
+
347
+ | Pattern | Problem Solved | Implementation |
348
+ |---------|----------------|----------------|
349
+ | **Circuit Breaker** | Cascading failures | Open after N failures, half-open retry |
350
+ | **Retry with Backoff** | Transient failures | Exponential backoff + jitter |
351
+ | **Bulkhead** | Resource exhaustion | Isolate thread pools/connections |
352
+ | **Timeout** | Hanging requests | Set max wait time |
353
+ | **Fallback** | Service unavailable | Default response, cached data |
354
+
355
+ **Circuit Breaker States:**
356
+ ```
357
+ success
358
+ ┌───────────────┐
359
+ │ │
360
+ ▼ N failures │
361
+ ┌────────┐ ┌────────┐
362
+ │ CLOSED │────►│ OPEN │
363
+ └────────┘ └────────┘
364
+ ▲ │
365
+ │ timeout ▼
366
+ │ ┌─────────┐
367
+ └──────────│HALF-OPEN│
368
+ success └─────────┘
369
+ ```
370
+
371
+ ---
372
+
373
+ ## Trade-off Analysis
374
+
375
+ ### Decision Matrix Template
376
+
377
+ When choosing between options, use weighted scoring:
378
+
379
+ | Criteria | Weight | Option A | Option B | Option C |
380
+ |----------|--------|----------|----------|----------|
381
+ | Performance | 30% | 4 (1.2) | 3 (0.9) | 5 (1.5) |
382
+ | Complexity | 25% | 3 (0.75) | 5 (1.25) | 2 (0.5) |
383
+ | Team expertise | 20% | 5 (1.0) | 3 (0.6) | 2 (0.4) |
384
+ | Maintainability | 15% | 4 (0.6) | 4 (0.6) | 3 (0.45) |
385
+ | Cost | 10% | 3 (0.3) | 4 (0.4) | 5 (0.5) |
386
+ | **Total** | | **3.85** | **3.75** | **3.35** |
387
+
388
+ *Scores: 1-5, higher is better*
389
+
390
+ ### Common Trade-offs
391
+
392
+ | Decision | Option A | Option B | Key Factor |
393
+ |----------|----------|----------|------------|
394
+ | Monolith vs Microservices | Simple ops, shared DB | Independent deploy, complexity | Team size, scale needs |
395
+ | SQL vs NoSQL | ACID, complex queries | Flexible schema, horizontal scale | Data structure, consistency |
396
+ | Sync vs Async | Simple, immediate | Resilient, decoupled | Latency tolerance |
397
+ | REST vs gRPC | Universal, cacheable | Performance, streaming | Client types |
398
+ | Polling vs Webhooks | Simple, reliable | Real-time, efficient | Latency requirements |
399
+
400
+ ---
401
+
402
+ ## Quality Attribute Scenarios
403
+
404
+ ### Performance Scenario Template
405
+
406
+ ```
407
+ Source: [Who/what triggers]
408
+ Stimulus: [What happens]
409
+ Environment: [Under what conditions]
410
+ Artifact: [What part of system]
411
+ Response: [What system does]
412
+ Measure: [How to verify]
413
+ ```
414
+
415
+ ### Example Scenarios
416
+
417
+ **Performance:**
418
+ | Element | Value |
419
+ |---------|-------|
420
+ | Source | 1000 concurrent users |
421
+ | Stimulus | Submit search query |
422
+ | Environment | Normal operation |
423
+ | Artifact | Search API |
424
+ | Response | Return results |
425
+ | Measure | 95th percentile < 200ms |
426
+
427
+ **Availability:**
428
+ | Element | Value |
429
+ |---------|-------|
430
+ | Source | Any user |
431
+ | Stimulus | Request any API |
432
+ | Environment | Peak load |
433
+ | Artifact | Core services |
434
+ | Response | Respond successfully |
435
+ | Measure | 99.9% uptime monthly |
436
+
437
+ **Security:**
438
+ | Element | Value |
439
+ |---------|-------|
440
+ | Source | Unauthenticated user |
441
+ | Stimulus | Access protected resource |
442
+ | Environment | Normal operation |
443
+ | Artifact | API Gateway |
444
+ | Response | Return 401, log attempt |
445
+ | Measure | 100% unauthorized blocked |
446
+
447
+ ### NFR → Architecture Mapping
448
+
449
+ | NFR Type | Architectural Tactics |
450
+ |----------|----------------------|
451
+ | **Performance** | Caching, CDN, read replicas, async processing |
452
+ | **Scalability** | Horizontal scaling, sharding, queue-based load leveling |
453
+ | **Availability** | Redundancy, health checks, circuit breakers, multi-AZ |
454
+ | **Security** | Auth gateway, encryption, WAF, rate limiting |
455
+ | **Maintainability** | Modular design, clear interfaces, documentation |
456
+
457
+ ---
155
458
 
156
459
  ### Reference Format
157
460
 
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: architecture-validation
3
- description: How to validate architecture for PRD coverage, NFR compliance, and QA artifact presence
3
+ description: Use when validating architecture document before creating epics - checks PRD coverage, NFR compliance, module boundaries, and QA artifacts
4
4
  license: MIT
5
5
  compatibility: opencode
6
6
  metadata:
@@ -61,9 +61,9 @@ For each module:
61
61
 
62
62
  ### Pattern Compliance
63
63
 
64
- - [ ] Follows hexagonal architecture
65
- - [ ] Domain layer has no infrastructure imports
66
- - [ ] Use case pattern (4 files) documented
64
+ - [ ] Architecture style is documented and justified (ADR)
65
+ - [ ] Dependency direction follows chosen pattern
66
+ - [ ] Business logic isolated from infrastructure
67
67
  - [ ] Aligns with CLAUDE.md standards
68
68
 
69
69
  ### ADR Checks