contextos-agents 2.1.0 → 2.2.0

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 (192) hide show
  1. package/.agents/adapters/aider/export.js +2 -2
  2. package/.agents/adapters/claude/export.js +53 -2
  3. package/.agents/adapters/drift-detector.js +6 -3
  4. package/.agents/adapters/pure-compiler.js +18 -6
  5. package/.agents/ctx.js +13 -8
  6. package/.agents/plugins.js +347 -26
  7. package/.agents/profiles.js +32 -11
  8. package/README.md +38 -3
  9. package/bin/commands/hook.js +50 -12
  10. package/bin/commands/scan.js +10 -3
  11. package/bin/index.js +165 -53
  12. package/bin/lib/git-snapshot.js +70 -43
  13. package/bin/lib/scan.js +108 -27
  14. package/bin/lib/ui.js +140 -0
  15. package/catalog/skills/adapters/EXAMPLES.md +19 -0
  16. package/catalog/skills/adapters/SKILL.md +101 -0
  17. package/catalog/skills/adapters/TROUBLESHOOTING.md +7 -0
  18. package/catalog/skills/adapters/VALIDATION.json +12 -0
  19. package/catalog/skills/adapters/skill.yaml +13 -0
  20. package/catalog/skills/api-design/EXAMPLES.md +91 -0
  21. package/catalog/skills/api-design/SKILL.md +63 -0
  22. package/catalog/skills/api-design/TROUBLESHOOTING.md +54 -0
  23. package/catalog/skills/api-design/VALIDATION.json +11 -0
  24. package/catalog/skills/api-design/skill.yaml +14 -0
  25. package/catalog/skills/architecture-diagrams/SKILL.md +108 -0
  26. package/catalog/skills/architecture-diagrams/VALIDATION.json +12 -0
  27. package/catalog/skills/architecture-diagrams/skill.yaml +9 -0
  28. package/catalog/skills/brutalist-design/EXAMPLES.md +59 -0
  29. package/catalog/skills/brutalist-design/SKILL.md +150 -0
  30. package/catalog/skills/brutalist-design/VALIDATION.json +12 -0
  31. package/catalog/skills/brutalist-design/skill.yaml +10 -0
  32. package/catalog/skills/ci-cd/EXAMPLES.md +79 -0
  33. package/catalog/skills/ci-cd/SKILL.md +69 -0
  34. package/catalog/skills/ci-cd/TROUBLESHOOTING.md +52 -0
  35. package/catalog/skills/ci-cd/VALIDATION.json +11 -0
  36. package/catalog/skills/ci-cd/skill.yaml +13 -0
  37. package/catalog/skills/database/EXAMPLES.md +74 -0
  38. package/catalog/skills/database/SKILL.md +101 -0
  39. package/catalog/skills/database/TROUBLESHOOTING.md +18 -0
  40. package/catalog/skills/database/VALIDATION.json +11 -0
  41. package/catalog/skills/database/skill.yaml +14 -0
  42. package/catalog/skills/ddd/EXAMPLES.md +42 -0
  43. package/catalog/skills/ddd/SKILL.md +247 -0
  44. package/catalog/skills/ddd/TROUBLESHOOTING.md +19 -0
  45. package/catalog/skills/ddd/VALIDATION.json +12 -0
  46. package/catalog/skills/ddd/skill.yaml +14 -0
  47. package/catalog/skills/decisions/EXAMPLES.md +35 -0
  48. package/catalog/skills/decisions/SKILL.md +90 -0
  49. package/catalog/skills/decisions/TROUBLESHOOTING.md +13 -0
  50. package/catalog/skills/decisions/VALIDATION.json +12 -0
  51. package/catalog/skills/decisions/skill.yaml +13 -0
  52. package/catalog/skills/docker/EXAMPLES.md +56 -0
  53. package/catalog/skills/docker/SKILL.md +169 -0
  54. package/catalog/skills/docker/TROUBLESHOOTING.md +18 -0
  55. package/catalog/skills/docker/VALIDATION.json +11 -0
  56. package/catalog/skills/docker/skill.yaml +13 -0
  57. package/catalog/skills/fastapi/EXAMPLES.md +36 -0
  58. package/catalog/skills/fastapi/SKILL.md +171 -0
  59. package/catalog/skills/fastapi/TROUBLESHOOTING.md +19 -0
  60. package/catalog/skills/fastapi/VALIDATION.json +12 -0
  61. package/catalog/skills/fastapi/skill.yaml +14 -0
  62. package/catalog/skills/generators/EXAMPLES.md +19 -0
  63. package/catalog/skills/generators/SKILL.md +110 -0
  64. package/catalog/skills/generators/TROUBLESHOOTING.md +7 -0
  65. package/catalog/skills/generators/VALIDATION.json +12 -0
  66. package/catalog/skills/generators/skill.yaml +22 -0
  67. package/catalog/skills/generators/templates/API.md +77 -0
  68. package/catalog/skills/generators/templates/ARCHITECTURE.md +70 -0
  69. package/catalog/skills/generators/templates/DATABASE.md +42 -0
  70. package/catalog/skills/generators/templates/DECISION.md +46 -0
  71. package/catalog/skills/generators/templates/PRD.md +67 -0
  72. package/catalog/skills/generators/templates/PROJECT_GRAPH.md +56 -0
  73. package/catalog/skills/generators/templates/ROADMAP.md +51 -0
  74. package/catalog/skills/generators/templates/TASKS.md +43 -0
  75. package/catalog/skills/generators/templates/UI.md +73 -0
  76. package/catalog/skills/graphify/EXAMPLES.md +73 -0
  77. package/catalog/skills/graphify/SKILL.md +130 -0
  78. package/catalog/skills/graphify/VALIDATION.json +12 -0
  79. package/catalog/skills/graphify/skill.yaml +13 -0
  80. package/catalog/skills/impeccable-design/EXAMPLES.md +26 -0
  81. package/catalog/skills/impeccable-design/SKILL.md +201 -0
  82. package/catalog/skills/impeccable-design/TROUBLESHOOTING.md +19 -0
  83. package/catalog/skills/impeccable-design/VALIDATION.json +12 -0
  84. package/catalog/skills/impeccable-design/skill.yaml +15 -0
  85. package/catalog/skills/interview-me/SKILL.md +97 -0
  86. package/catalog/skills/interview-me/VALIDATION.json +12 -0
  87. package/catalog/skills/interview-me/skill.yaml +9 -0
  88. package/catalog/skills/microservices/EXAMPLES.md +38 -0
  89. package/catalog/skills/microservices/SKILL.md +164 -0
  90. package/catalog/skills/microservices/TROUBLESHOOTING.md +19 -0
  91. package/catalog/skills/microservices/VALIDATION.json +12 -0
  92. package/catalog/skills/microservices/skill.yaml +14 -0
  93. package/catalog/skills/minimalist-design/EXAMPLES.md +58 -0
  94. package/catalog/skills/minimalist-design/SKILL.md +113 -0
  95. package/catalog/skills/minimalist-design/VALIDATION.json +12 -0
  96. package/catalog/skills/minimalist-design/skill.yaml +10 -0
  97. package/catalog/skills/nestjs/EXAMPLES.md +40 -0
  98. package/catalog/skills/nestjs/SKILL.md +139 -0
  99. package/catalog/skills/nestjs/TROUBLESHOOTING.md +19 -0
  100. package/catalog/skills/nestjs/VALIDATION.json +12 -0
  101. package/catalog/skills/nestjs/skill.yaml +14 -0
  102. package/catalog/skills/nextjs/EXAMPLES.md +40 -0
  103. package/catalog/skills/nextjs/SKILL.md +163 -0
  104. package/catalog/skills/nextjs/TROUBLESHOOTING.md +19 -0
  105. package/catalog/skills/nextjs/VALIDATION.json +12 -0
  106. package/catalog/skills/nextjs/skill.yaml +14 -0
  107. package/catalog/skills/node/EXAMPLES.md +80 -0
  108. package/catalog/skills/node/SKILL.md +128 -0
  109. package/catalog/skills/node/TROUBLESHOOTING.md +19 -0
  110. package/catalog/skills/node/VALIDATION.json +12 -0
  111. package/catalog/skills/node/skill.yaml +14 -0
  112. package/catalog/skills/performance/EXAMPLES.md +30 -0
  113. package/catalog/skills/performance/SKILL.md +75 -0
  114. package/catalog/skills/performance/TROUBLESHOOTING.md +19 -0
  115. package/catalog/skills/performance/VALIDATION.json +12 -0
  116. package/catalog/skills/performance/skill.yaml +14 -0
  117. package/catalog/skills/react/EXAMPLES.md +79 -0
  118. package/catalog/skills/react/SKILL.md +132 -0
  119. package/catalog/skills/react/TROUBLESHOOTING.md +19 -0
  120. package/catalog/skills/react/VALIDATION.json +12 -0
  121. package/catalog/skills/react/skill.yaml +14 -0
  122. package/catalog/skills/react-best-practices/SKILL.md +158 -0
  123. package/catalog/skills/react-best-practices/VALIDATION.json +12 -0
  124. package/catalog/skills/react-best-practices/skill.yaml +13 -0
  125. package/catalog/skills/redesign-audit/SKILL.md +117 -0
  126. package/catalog/skills/redesign-audit/VALIDATION.json +12 -0
  127. package/catalog/skills/redesign-audit/skill.yaml +9 -0
  128. package/catalog/skills/security-audit/EXAMPLES.md +79 -0
  129. package/catalog/skills/security-audit/SKILL.md +91 -0
  130. package/catalog/skills/security-audit/TROUBLESHOOTING.md +46 -0
  131. package/catalog/skills/security-audit/VALIDATION.json +11 -0
  132. package/catalog/skills/security-audit/skill.yaml +14 -0
  133. package/catalog/skills/soft-design/EXAMPLES.md +51 -0
  134. package/catalog/skills/soft-design/SKILL.md +108 -0
  135. package/catalog/skills/soft-design/VALIDATION.json +12 -0
  136. package/catalog/skills/soft-design/skill.yaml +10 -0
  137. package/catalog/skills/state-management/EXAMPLES.md +56 -0
  138. package/catalog/skills/state-management/SKILL.md +168 -0
  139. package/catalog/skills/state-management/TROUBLESHOOTING.md +18 -0
  140. package/catalog/skills/state-management/VALIDATION.json +11 -0
  141. package/catalog/skills/state-management/skill.yaml +14 -0
  142. package/catalog/skills/subagent-orchestrator/SKILL.md +117 -0
  143. package/catalog/skills/subagent-orchestrator/VALIDATION.json +12 -0
  144. package/catalog/skills/subagent-orchestrator/skill.yaml +9 -0
  145. package/catalog/skills/system-design/EXAMPLES.md +75 -0
  146. package/catalog/skills/system-design/SKILL.md +419 -0
  147. package/catalog/skills/system-design/TROUBLESHOOTING.md +19 -0
  148. package/catalog/skills/system-design/VALIDATION.json +12 -0
  149. package/catalog/skills/system-design/skill.yaml +14 -0
  150. package/catalog/skills/terraform/EXAMPLES.md +74 -0
  151. package/catalog/skills/terraform/SKILL.md +55 -0
  152. package/catalog/skills/terraform/TROUBLESHOOTING.md +53 -0
  153. package/catalog/skills/terraform/VALIDATION.json +11 -0
  154. package/catalog/skills/terraform/skill.yaml +14 -0
  155. package/catalog/skills/testing/EXAMPLES.md +122 -0
  156. package/catalog/skills/testing/SKILL.md +70 -0
  157. package/catalog/skills/testing/TROUBLESHOOTING.md +18 -0
  158. package/catalog/skills/testing/VALIDATION.json +11 -0
  159. package/catalog/skills/testing/skill.yaml +14 -0
  160. package/catalog/skills/typescript/EXAMPLES.md +64 -0
  161. package/catalog/skills/typescript/SKILL.md +112 -0
  162. package/catalog/skills/typescript/TROUBLESHOOTING.md +19 -0
  163. package/catalog/skills/typescript/VALIDATION.json +12 -0
  164. package/catalog/skills/typescript/skill.yaml +14 -0
  165. package/catalog/skills/ui-design/EXAMPLES.md +21 -0
  166. package/catalog/skills/ui-design/SKILL.md +124 -0
  167. package/catalog/skills/ui-design/TROUBLESHOOTING.md +19 -0
  168. package/catalog/skills/ui-design/VALIDATION.json +12 -0
  169. package/catalog/skills/ui-design/skill.yaml +16 -0
  170. package/catalog/skills/ui-ux-pro/EXAMPLES.md +62 -0
  171. package/catalog/skills/ui-ux-pro/SKILL.md +418 -0
  172. package/catalog/skills/ui-ux-pro/TROUBLESHOOTING.md +19 -0
  173. package/catalog/skills/ui-ux-pro/VALIDATION.json +12 -0
  174. package/catalog/skills/ui-ux-pro/skill.yaml +14 -0
  175. package/catalog/skills/ux-design/EXAMPLES.md +36 -0
  176. package/catalog/skills/ux-design/SKILL.md +116 -0
  177. package/catalog/skills/ux-design/TROUBLESHOOTING.md +19 -0
  178. package/catalog/skills/ux-design/VALIDATION.json +12 -0
  179. package/catalog/skills/ux-design/skill.yaml +16 -0
  180. package/catalog/skills/vercel-optimize/SKILL.md +83 -0
  181. package/catalog/skills/vercel-optimize/VALIDATION.json +12 -0
  182. package/catalog/skills/vercel-optimize/scripts/collect-signals.mjs +131 -0
  183. package/catalog/skills/vercel-optimize/scripts/gate-investigations.mjs +142 -0
  184. package/catalog/skills/vercel-optimize/scripts/merge-signals.mjs +143 -0
  185. package/catalog/skills/vercel-optimize/scripts/scan-codebase.mjs +174 -0
  186. package/catalog/skills/vercel-optimize/skill.yaml +15 -0
  187. package/catalog/skills/web-accessibility/EXAMPLES.md +39 -0
  188. package/catalog/skills/web-accessibility/SKILL.md +151 -0
  189. package/catalog/skills/web-accessibility/TROUBLESHOOTING.md +19 -0
  190. package/catalog/skills/web-accessibility/VALIDATION.json +12 -0
  191. package/catalog/skills/web-accessibility/skill.yaml +14 -0
  192. package/package.json +3 -2
@@ -0,0 +1,247 @@
1
+ ---
2
+ name: Domain-Driven Design
3
+ description: >
4
+ ContextOS skill for Domain-Driven Design
5
+ ---
6
+
7
+ # Domain-Driven Design
8
+
9
+ ## Overview
10
+
11
+ Domain-Driven Design standard for robust business software. Enforces separation between domain logic (Entities, Value Objects, Aggregates, Domain Events) and infrastructure frameworks, preventing leaky abstractions.
12
+
13
+ ## When to Use
14
+
15
+ Activate when designing core business domain models, transactional consistency boundaries, enterprise APIs, or complex aggregate hierarchies.
16
+
17
+ ## Rules & Patterns
18
+ <!-- Source: ddd.md -->
19
+
20
+ ## Domain-Driven Design - Patterns & Practices
21
+
22
+ ## When to Use DDD
23
+
24
+ **Use when:**
25
+
26
+ - Complex business logic that goes beyond CRUD
27
+ - Multiple domain experts with different vocabularies
28
+ - The domain model is the competitive advantage
29
+ - Enterprise-grade applications
30
+
31
+ **Don't use when:**
32
+
33
+ - Simple CRUD applications
34
+ - Hackathon/MVP (overkill)
35
+ - No domain expert available
36
+
37
+ ## Strategic Design
38
+
39
+ ### Bounded Contexts
40
+
41
+ The single most important DDD concept. A Bounded Context is a boundary within which a particular model is defined and applicable.
42
+
43
+ **Example - E-Commerce:**
44
+
45
+ ```
46
+ [Order Context] [Payment Context] [Shipping Context]
47
+ - Order - Payment - Shipment
48
+ - OrderItem - Transaction - TrackingNumber
49
+ - Customer (ref) - Refund - Address
50
+ - Address (value) - Invoice - Carrier
51
+ ```
52
+
53
+ `Customer` means different things in each context:
54
+
55
+ - Order Context: name, email, shipping preference
56
+ - Payment Context: billing info, payment methods
57
+ - Support Context: ticket history, satisfaction score
58
+
59
+ ### Context Map
60
+
61
+ ```
62
+ [Order] ←→ [Payment] # Partnership
63
+ [Order] → [Shipping] # Customer-Supplier
64
+ [Order] → [Legacy CRM] # Anti-Corruption Layer
65
+ ```
66
+
67
+ ## Tactical Design
68
+
69
+ ### Entities
70
+
71
+ Objects with identity. Two entities with the same attributes but different IDs are different.
72
+
73
+ ```typescript
74
+ class User {
75
+ readonly id: UserId;
76
+ name: string;
77
+ email: Email; // Value Object
78
+ }
79
+ ```
80
+
81
+ ### Value Objects
82
+
83
+ Objects defined by their attributes, not identity. Immutable.
84
+
85
+ ```typescript
86
+ class Email {
87
+ constructor(readonly value: string) {
88
+ if (!isValidEmail(value)) throw new InvalidEmailError(value);
89
+ }
90
+ equals(other: Email): boolean {
91
+ return this.value === other.value;
92
+ }
93
+ }
94
+ ```
95
+
96
+ ### Aggregates
97
+
98
+ A cluster of entities and value objects with a single root entity (Aggregate Root). All access goes through the root.
99
+
100
+ ```typescript
101
+ class Order { // Aggregate Root
102
+ private items: OrderItem[] = [];
103
+
104
+ addItem(product: ProductRef, quantity: number): void {
105
+ // Business logic HERE, not in a service
106
+ if (quantity <= 0) throw new InvalidQuantityError();
107
+ this.items.push(new OrderItem(product, quantity));
108
+ }
109
+
110
+ get total(): Money {
111
+ return this.items.reduce((sum, item) => sum.add(item.subtotal), Money.zero());
112
+ }
113
+ }
114
+ ```
115
+
116
+ **Aggregate Rules:**
117
+
118
+ 1. Reference other aggregates by ID only
119
+ 2. One aggregate per transaction
120
+ 3. Eventual consistency between aggregates
121
+
122
+ ### Domain Events
123
+
124
+ Something that happened in the domain that domain experts care about.
125
+
126
+ ```typescript
127
+ class OrderPlaced implements DomainEvent {
128
+ constructor(
129
+ readonly orderId: OrderId,
130
+ readonly customerId: CustomerId,
131
+ readonly total: Money,
132
+ readonly occurredAt: Date
133
+ ) {}
134
+ }
135
+ ```
136
+
137
+ ### Domain Services
138
+
139
+ Business logic that doesn't naturally belong to an entity or value object.
140
+
141
+ ```typescript
142
+ class PricingService {
143
+ calculatePrice(order: Order, customer: Customer, promotions: Promotion[]): Money {
144
+ // Complex pricing logic involving multiple aggregates
145
+ }
146
+ }
147
+ ```
148
+
149
+ ### Repositories
150
+
151
+ Abstraction over data access. One repository per aggregate root.
152
+
153
+ ```typescript
154
+ interface OrderRepository {
155
+ findById(id: OrderId): Promise<Order | null>;
156
+ save(order: Order): Promise<void>;
157
+ delete(id: OrderId): Promise<void>;
158
+ }
159
+ ```
160
+
161
+ ## Directory Structure (DDD)
162
+
163
+ ```
164
+ src/
165
+ ├── modules/
166
+ │ └── orders/ # Bounded Context
167
+ │ ├── domain/
168
+ │ │ ├── entities/
169
+ │ │ │ └── order.ts # Aggregate Root
170
+ │ │ ├── value-objects/
171
+ │ │ │ └── money.ts
172
+ │ │ ├── events/
173
+ │ │ │ └── order-placed.ts
174
+ │ │ ├── services/
175
+ │ │ │ └── pricing.ts
176
+ │ │ └── repositories/
177
+ │ │ └── order.repository.ts # Interface
178
+ │ ├── application/
179
+ │ │ ├── commands/
180
+ │ │ │ └── place-order.ts
181
+ │ │ ├── queries/
182
+ │ │ │ └── get-order.ts
183
+ │ │ └── handlers/
184
+ │ │ └── place-order.handler.ts
185
+ │ └── infrastructure/
186
+ │ ├── persistence/
187
+ │ │ └── order.repository.impl.ts # Implementation
188
+ │ └── api/
189
+ │ └── orders.controller.ts
190
+ ```
191
+
192
+ ### The Clean Architecture Dependency Rule
193
+
194
+ In DDD, dependencies **MUST strictly point inward**:
195
+
196
+ ```
197
+ [ Frameworks & Drivers (Web, DB, UI) ]
198
+ └──▶ [ Interface Adapters (Controllers, Gateways) ]
199
+ └──▶ [ Application (Use Cases, CQRS Handlers) ]
200
+ └──▶ [ Domain (Entities, Value Objects) ]
201
+ ```
202
+
203
+ - The **Domain layer** has ZERO dependencies on ORMs (Prisma, TypeORM), HTTP frameworks (Express, NestJS), or external SDKs.
204
+ - Repositories are defined as interfaces in the domain/application layer and implemented in the infrastructure layer.
205
+
206
+ ### Domain Events vs Integration Events
207
+
208
+ 1. **Domain Events**: Represent state changes inside a single Bounded Context.
209
+ - Raised directly inside the Aggregate Root (`order.addItem(...)` raises `OrderItemAdded`).
210
+ - Dispatched in-process before transaction commit.
211
+ 2. **Integration Events**: Published across Bounded Context boundaries to communicate with other services.
212
+ - Dispatched via Transactional Outbox pattern to message brokers.
213
+ - Must use backward-compatible schemas with versioning.
214
+
215
+ ### Anti-Corruption Layer (ACL)
216
+
217
+ When consuming data from an external bounded context or 3rd-party vendor API (e.g. Stripe, Salesforce):
218
+
219
+ - NEVER import external domain models directly into your domain.
220
+ - Create an **ACL Translator / Adapter** in the infrastructure layer to convert external DTOs into your own Value Objects and Entities.
221
+
222
+ ---
223
+
224
+ ## Anti-Patterns
225
+
226
+ - [FAIL] Anemic domain model - entities with only getters/setters, all logic in services
227
+ - [FAIL] Big aggregate - aggregates should be small, focused on invariants
228
+ - [FAIL] Cross-aggregate transactions - use eventual consistency
229
+ - [FAIL] DDD everywhere - use DDD only where complexity justifies it
230
+ - [FAIL] ORM entities leaking into Domain - domain entities must not depend on `@Entity()` or ORM decorators
231
+
232
+
233
+ ## Code Examples
234
+
235
+ See `EXAMPLES.md` for detailed code examples.
236
+
237
+ ## Validation Checklist
238
+
239
+ What to verify during the review phase before completing the task.
240
+
241
+ ## Common Mistakes
242
+
243
+ Anti-patterns and things to explicitly avoid. See `TROUBLESHOOTING.md`.
244
+
245
+ ## Integration Notes
246
+
247
+ How this skill interacts with other skills.
@@ -0,0 +1,19 @@
1
+ # ddd Troubleshooting & Common Mistakes
2
+
3
+ ## 1. God Aggregates
4
+
5
+ - **Symptom**: Aggregate Root contains 20 child entities and loading it requires joining dozens of tables.
6
+ - **Root Cause**: Treating ERD tables as aggregate boundaries rather than transactional consistency units.
7
+ - **Fix**: Design small aggregates. Reference other aggregates by ID only, not by object reference.
8
+
9
+ ## 2. Leaking Infrastructure into Domain Layer
10
+
11
+ - **Symptom**: Domain entities import Prisma, TypeORM decorators, or Express Request objects.
12
+ - **Root Cause**: Inverting Clean Architecture boundaries.
13
+ - **Fix**: The Domain layer must be pure TypeScript with zero external framework dependencies.
14
+
15
+ ## 3. Transaction Spanning Multiple Aggregates
16
+
17
+ - **Symptom**: High database lock contention and deadlocks under concurrent transactions.
18
+ - **Root Cause**: Modifying multiple aggregate roots within the same database transaction.
19
+ - **Fix**: Rule of thumb: Exactly one Aggregate Root modified per transaction. Use Domain Events for eventual consistency across other aggregates.
@@ -0,0 +1,12 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "type": "object",
4
+ "properties": {
5
+ "rules_followed": {
6
+ "type": "boolean"
7
+ }
8
+ },
9
+ "required": [
10
+ "rules_followed"
11
+ ]
12
+ }
@@ -0,0 +1,14 @@
1
+ schemaVersion: 2
2
+ id: ddd
3
+ name: Domain-Driven Design
4
+ category: architecture
5
+ type: instruction-only
6
+ requires: []
7
+ optional: [microservices, system-design]
8
+ conflicts: []
9
+ weight: 6
10
+ resources:
11
+ - EXAMPLES.md
12
+ - SKILL.md
13
+ - TROUBLESHOOTING.md
14
+ - VALIDATION.json
@@ -0,0 +1,35 @@
1
+ # decisions Examples - Anti-patterns vs ContextOS Standard
2
+
3
+ ## Example 1: Documenting Tech Choices
4
+
5
+ ### Anti-pattern: Tribal Knowledge & Undocumented Decisions
6
+
7
+ ```text
8
+ "We switched to Redis for session storage last month because Dan said so on Slack."
9
+ Three months later, Dan leaves and nobody knows why the config is set up this way.
10
+ ```
11
+
12
+ ### Best practice: ContextOS Standard (MADR Architecture Decision Record)
13
+
14
+ ```markdown
15
+ # ADR 0003: Use Redis for Distributed Session Storage
16
+
17
+ ## Context and Problem Statement
18
+ Our application is transitioning from a single server to horizontally auto-scaled instances.
19
+ Sticky sessions on load balancer cause uneven distribution and drop sessions on node recycling.
20
+
21
+ ## Considered Options
22
+ 1. PostgreSQL session table
23
+ 2. Redis cluster
24
+ 3. JWT stateless tokens in cookies
25
+
26
+ ## Decision Outcome
27
+ Chosen option: "Redis cluster", because:
28
+ - Sub-millisecond read/write latency compared to relational DB queries.
29
+ - Built-in TTL automatically handles session expiration without cron cleanup.
30
+ - Avoids security risks of client-stored JWT revocation.
31
+
32
+ ## Consequences
33
+ - Positive: Stateless web tier, zero session drops on deployment.
34
+ - Negative: Adds operational dependency on Redis cluster infrastructure.
35
+ ```
@@ -0,0 +1,90 @@
1
+ ---
2
+ name: decision-engine
3
+ description: >
4
+ Architecture Decision Records (ADR) management. Creates, tracks, and queries
5
+ decisions so the AI agent understands WHY choices were made, not just WHAT was chosen.
6
+ ---
7
+
8
+ # decision-engine
9
+
10
+ ## Overview
11
+
12
+ Architecture Decision Record (ADR) system following Michael Nygard format. Captures context, options considered, tradeoffs, and consequences to prevent architectural regression and knowledge loss across AI sessions.
13
+
14
+ ## When to Use
15
+
16
+ Activate when choosing or switching database engines, authentication strategies, state libraries, or significant architectural patterns.
17
+
18
+ ## Rules & Patterns
19
+
20
+ You manage **Architecture Decision Records** (ADRs).
21
+
22
+ ## Why Decisions Matter
23
+
24
+ Without ADRs, the AI agent sees:
25
+
26
+ - "Database: PostgreSQL" - but doesn't know WHY
27
+ - "Auth: JWT" - but doesn't know what alternatives were considered
28
+ - "Framework: Next.js" - but doesn't know the tradeoffs
29
+
30
+ With ADRs, the agent understands the reasoning and won't accidentally contradict prior decisions.
31
+
32
+ ## Commands
33
+
34
+ ### Create a Decision
35
+
36
+ When an architectural choice is made during any pipeline stage:
37
+
38
+ 1. Auto-increment the decision number
39
+ 2. Use the template from `generators/templates/DECISION.md`
40
+ 3. Save to `docs/decisions/NNNN-decision-name.md`
41
+ 4. Update the Project Graph if the decision affects modules
42
+
43
+ **Naming convention:** `docs/decisions/0001-use-postgresql.md`
44
+
45
+ ### Query Decisions
46
+
47
+ Before making changes that touch architecture:
48
+
49
+ 1. Check `docs/decisions/` for related decisions
50
+ 2. If a decision exists, follow it
51
+ 3. If a decision needs to change, create a new ADR that **supersedes** the old one
52
+
53
+ ### Decision Lifecycle
54
+
55
+ ```
56
+ proposed → accepted → [deprecated | superseded]
57
+ ```
58
+
59
+ - **proposed**: Under discussion, not yet committed
60
+ - **accepted**: The team agreed, this is the standard
61
+ - **deprecated**: No longer relevant (project evolved)
62
+ - **superseded**: Replaced by a newer decision (link to it)
63
+
64
+ ## Auto-Detection
65
+
66
+ The Decision Engine should suggest creating an ADR when it detects:
67
+
68
+ - A new database/ORM is introduced
69
+ - A new framework is added
70
+ - Authentication strategy changes
71
+ - API versioning approach is chosen
72
+ - Deployment strategy is decided
73
+ - A significant library is added (state management, testing framework, etc.)
74
+
75
+
76
+ ## Code Examples
77
+
78
+ See `EXAMPLES.md` for detailed code examples.
79
+
80
+ ## Validation Checklist
81
+
82
+ What to verify during the review phase before completing the task.
83
+
84
+ ## Common Mistakes
85
+
86
+ Anti-patterns and things to explicitly avoid. See `TROUBLESHOOTING.md`.
87
+
88
+ ## Integration Notes
89
+
90
+ How this skill interacts with other skills.
@@ -0,0 +1,13 @@
1
+ # decisions Troubleshooting & Common Mistakes
2
+
3
+ ## 1. Post-Hoc Justifications
4
+
5
+ - **Symptom**: ADR written weeks after code is merged, omitting all rejected options.
6
+ - **Root Cause**: Treating ADRs as paperwork rather than decision-making tools.
7
+ - **Fix**: Write the ADR during the PLAN phase _before_ implementing the decision.
8
+
9
+ ## 2. Omitting Trade-offs
10
+
11
+ - **Symptom**: ADR lists only benefits, claiming the chosen tech has zero downsides.
12
+ - **Root Cause**: Confirmation bias.
13
+ - **Fix**: Every architecture decision has costs. Explicitly document negative trade-offs and operational overhead.
@@ -0,0 +1,12 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "type": "object",
4
+ "properties": {
5
+ "rules_followed": {
6
+ "type": "boolean"
7
+ }
8
+ },
9
+ "required": [
10
+ "rules_followed"
11
+ ]
12
+ }
@@ -0,0 +1,13 @@
1
+ schemaVersion: 2
2
+ name: decisions
3
+ category: architecture
4
+ type: instruction-only
5
+ description: >
6
+ Architecture Decision Records (ADR) management. Creates, tracks, and queries
7
+ architectural decisions so AI assistants understand why choices were made.
8
+ version: 1.0.0
9
+ resources:
10
+ - EXAMPLES.md
11
+ - SKILL.md
12
+ - TROUBLESHOOTING.md
13
+ - VALIDATION.json
@@ -0,0 +1,56 @@
1
+ # Docker Examples - Anti-patterns vs ContextOS Standard
2
+
3
+ ## Example 1: Multi-Stage Build & Layer Caching
4
+
5
+ ### Anti-pattern: Anti-pattern (Fat single-stage image running as root)
6
+
7
+ ```dockerfile
8
+ # BAD: 1.2GB image, runs as root, breaks caching on every file edit
9
+ FROM node:latest
10
+ WORKDIR /app
11
+ COPY . .
12
+ RUN npm install
13
+ RUN npm run build
14
+ EXPOSE 3000
15
+ CMD ["npm", "start"]
16
+ ```
17
+
18
+ ### Best practice: ContextOS Standard (Slim multi-stage build with non-root user)
19
+
20
+ ```dockerfile
21
+ # GOOD: 95MB image, non-root user, optimized layer caching
22
+ FROM node:20.12.2-alpine3.19 AS builder
23
+ WORKDIR /app
24
+ COPY package.json package-lock.json ./
25
+ RUN npm ci
26
+ COPY . .
27
+ RUN npm run build && npm prune --production
28
+
29
+ FROM node:20.12.2-alpine3.19 AS runner
30
+ WORKDIR /app
31
+ ENV NODE_ENV=production
32
+ RUN addgroup -S -g 1001 appgroup && adduser -S -u 1001 appuser -G appgroup
33
+ COPY --from=builder --chown=appuser:appgroup /app/dist ./dist
34
+ COPY --from=builder --chown=appuser:appgroup /app/node_modules ./node_modules
35
+ USER appuser
36
+ CMD ["node", "dist/main.js"]
37
+ ```
38
+
39
+ ---
40
+
41
+ ## Example 2: Docker Ignore File (`.dockerignore`)
42
+
43
+ ### Best practice: ContextOS Standard `.dockerignore`
44
+
45
+ ```gitignore
46
+ node_modules
47
+ npm-debug.log
48
+ .git
49
+ .gitignore
50
+ .env
51
+ .env.*
52
+ dist
53
+ coverage
54
+ .DS_Store
55
+ *.md
56
+ ```
@@ -0,0 +1,169 @@
1
+ ---
2
+ name: docker
3
+ description: Docker containerization, multi-stage builds, non-root security, layer caching optimization, and docker-compose standards.
4
+ ---
5
+
6
+ # Docker
7
+
8
+ ## Overview
9
+
10
+ Containerization, Dockerfile architecture, multi-stage compilation, security hardening, and container orchestration for production workloads.
11
+
12
+ ## When to Use
13
+
14
+ Activate when creating or optimizing Dockerfiles, docker-compose configurations, container security audits, CI/CD container build stages, or production container deployments.
15
+
16
+ ## Rules & Patterns
17
+
18
+ ### Negative Constraints (What NOT to Do)
19
+
20
+ 1. **NEVER run containers as `root` in production**: Always create and switch to an unprivileged non-root user (e.g. `USER node` or `USER nonroot`).
21
+ 2. **NEVER use the `latest` tag**: Always pin base images to specific immutable version digests or explicit minor tags (e.g. `node:22-alpine3.20` or `python:3.12-slim-bookworm`).
22
+ 3. **NEVER copy source code before dependency manifests**: Always copy package manifests (`package.json`, `pnpm-lock.yaml`, `pyproject.toml`) and install dependencies first to maximize Docker layer cache hits.
23
+ 4. **NEVER bake secrets, API keys, or `.env` files into image layers**: Pass secrets via build-time secret mounts (`--mount=type=secret`) or runtime environment variables injected by the orchestrator.
24
+ 5. **NEVER include build tools or devDependencies in the final runner image**: Always use multi-stage builds to discard compilers, package managers, and temporary build caches from production images.
25
+ 6. **NEVER run without a `.dockerignore` file**: Always exclude `.git`, `node_modules`, `.env*`, and build outputs from the Docker build context.
26
+
27
+ ---
28
+
29
+ ### Pattern 1: Node.js / Next.js Standalone Multi-Stage Dockerfile
30
+
31
+ Optimized multi-stage build producing minimal production images (<120MB) with non-root security:
32
+
33
+ ```dockerfile
34
+ # ── Stage 1: Dependencies ─────────────────────────────────────────────
35
+ FROM node:22-alpine3.20 AS deps
36
+ RUN apk add --no-cache libc6-compat
37
+ WORKDIR /app
38
+
39
+ COPY package.json pnpm-lock.yaml* package-lock.json* yarn.lock* ./
40
+ RUN \
41
+ if [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \
42
+ elif [ -f package-lock.json ]; then npm ci; \
43
+ else yarn --frozen-lockfile; \
44
+ fi
45
+
46
+ # ── Stage 2: Builder ──────────────────────────────────────────────────
47
+ FROM node:22-alpine3.20 AS builder
48
+ WORKDIR /app
49
+ COPY --from=deps /app/node_modules ./node_modules
50
+ COPY . .
51
+
52
+ ENV NEXT_TELEMETRY_DISABLED=1
53
+ ENV NODE_ENV=production
54
+ RUN npm run build
55
+
56
+ # ── Stage 3: Production Runner ────────────────────────────────────────
57
+ FROM node:22-alpine3.20 AS runner
58
+ WORKDIR /app
59
+
60
+ ENV NODE_ENV=production
61
+ ENV PORT=3000
62
+ ENV HOSTNAME="0.0.0.0"
63
+
64
+ RUN addgroup --system --gid 1001 nodejs && \
65
+ adduser --system --uid 1001 nextjs
66
+
67
+ # Copy standalone output and static assets
68
+ COPY --from=builder /app/public ./public
69
+ COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
70
+ COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
71
+
72
+ USER nextjs
73
+ EXPOSE 3000
74
+
75
+ HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
76
+ CMD wget --no-verbose --tries=1 --spider http://127.0.0.1:3000/api/health || exit 1
77
+
78
+ CMD ["node", "server.js"]
79
+ ```
80
+
81
+ ---
82
+
83
+ ### Pattern 2: Python / FastAPI Multi-Stage Dockerfile (uv)
84
+
85
+ High-performance Python build utilizing `uv` for sub-second installs and slim final layers:
86
+
87
+ ```dockerfile
88
+ # ── Stage 1: Build virtual environment ────────────────────────────────
89
+ FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim AS builder
90
+ WORKDIR /app
91
+
92
+ ENV UV_COMPILE_BYTECODE=1
93
+ ENV UV_LINK_MODE=copy
94
+
95
+ # Install dependencies before code to leverage layer cache
96
+ RUN --mount=type=cache,target=/root/.cache/uv \
97
+ --mount=type=bind,source=uv.lock,target=uv.lock \
98
+ --mount=type=bind,source=pyproject.toml,target=pyproject.toml \
99
+ uv sync --frozen --no-install-project --no-dev
100
+
101
+ COPY . /app
102
+ RUN --mount=type=cache,target=/root/.cache/uv \
103
+ uv sync --frozen --no-dev
104
+
105
+ # ── Stage 2: Runtime Runner ───────────────────────────────────────────
106
+ FROM python:3.12-slim-bookworm AS runner
107
+ WORKDIR /app
108
+
109
+ # Create unprivileged application user
110
+ RUN groupadd -r appgroup && useradd -r -g appgroup appuser
111
+
112
+ COPY --from=builder --chown=appuser:appgroup /app /app
113
+
114
+ ENV PATH="/app/.venv/bin:$PATH"
115
+ ENV PYTHONUNBUFFERED=1
116
+
117
+ USER appuser
118
+ EXPOSE 8000
119
+
120
+ HEALTHCHECK --interval=30s --timeout=3s --retries=3 \
121
+ CMD python -c "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8000/health').read()" || exit 1
122
+
123
+ CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "2"]
124
+ ```
125
+
126
+ ---
127
+
128
+ ### Pattern 3: Essential `.dockerignore` Template
129
+
130
+ Every repository must include a `.dockerignore` to prevent uploading secrets and heavy cache folders:
131
+
132
+ ```text
133
+ .git
134
+ .github
135
+ node_modules
136
+ npm-debug.log
137
+ .env
138
+ .env.*
139
+ !.env.example
140
+ dist
141
+ build
142
+ .next
143
+ .cache
144
+ coverage
145
+ *.md
146
+ Dockerfile*
147
+ docker-compose*.yml
148
+ ```
149
+
150
+ ---
151
+
152
+ ## Validation Checklist
153
+
154
+ - [ ] Multi-stage build separates build compilers from production runtime.
155
+ - [ ] Non-root `USER` directive is active in the final image stage.
156
+ - [ ] Base images are pinned to explicit, immutable release tags.
157
+ - [ ] `HEALTHCHECK` directive is defined with reasonable interval and timeout.
158
+ - [ ] `.dockerignore` prevents leaking local `.env` files and `node_modules`.
159
+ - [ ] Dependencies are copied and installed before copying source code.
160
+
161
+ ## Common Mistakes
162
+
163
+ - **Running as root**: Leaves the host system vulnerable if a container breakout vulnerability occurs.
164
+ - **Copying entire source before install**: Invalidates the Docker layer cache on every code edit, slowing CI builds.
165
+ - **Omitting HEALTHCHECK**: Orchestrators cannot detect frozen or zombie worker processes.
166
+
167
+ ## Integration Notes
168
+
169
+ Interacts with `security` (container hardening) and `node` / `nextjs` / `fastapi`.