contextos-agents 1.7.0 → 2.0.0-beta.3
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.
- package/.agents/AGENTS.md +16 -50
- package/.agents/adapters/aider/export.js +117 -99
- package/.agents/adapters/claude/export.js +68 -26
- package/.agents/adapters/copilot/export.js +90 -53
- package/.agents/adapters/cursor/export.js +100 -104
- package/.agents/adapters/drift-detector.js +196 -0
- package/.agents/adapters/gemini/export.js +76 -45
- package/.agents/adapters/pure-compiler.js +443 -0
- package/.agents/adapters/zed/export.js +104 -96
- package/.agents/compiled/registry.v2.json +504 -0
- package/.agents/compiled/registry.v2.sha256 +1 -0
- package/.agents/compiler/manifest-compiler.js +963 -0
- package/.agents/compiler/vendor/yaml.LICENSE.txt +13 -0
- package/.agents/compiler/vendor/yaml.SBOM.json +6 -0
- package/.agents/compiler/vendor/yaml.js +139 -0
- package/.agents/core/profiles/init.yaml +25 -0
- package/.agents/core/skills/context-manager/skill.yaml +3 -5
- package/.agents/core/skills/context-os/SKILL.md +3 -6
- package/.agents/core/skills/context-os/skill.yaml +3 -8
- package/.agents/core/skills/engineering-workflow/skill.yaml +1 -7
- package/.agents/core/skills/gemini-precision/skill.yaml +1 -6
- package/.agents/core/skills/gstack-roles/skill.yaml +3 -6
- package/.agents/core/skills/ponytail-mindset/skill.yaml +1 -7
- package/.agents/core/skills/security/skill.yaml +15 -3
- package/.agents/ctx.js +537 -112
- package/.agents/customization-dx.js +282 -0
- package/.agents/doctor.js +855 -66
- package/.agents/filesystem/index.js +71 -0
- package/.agents/filesystem/journaled-transaction.js +451 -0
- package/.agents/filesystem/lockfile-v2.js +275 -0
- package/.agents/filesystem/platform-hardening.js +222 -0
- package/.agents/filesystem/project-lock.js +218 -0
- package/.agents/filesystem/safe-path.js +256 -0
- package/.agents/generated/claude/skills/context-os/SKILL.md +1 -1
- package/.agents/generated/gemini/skills/context-os/SKILL.md +2 -2
- package/.agents/plugins/contextos/plugin.json +1 -1
- package/.agents/plugins.js +278 -64
- package/.agents/profiles.js +486 -51
- package/.agents/resolver/canonical-resolver.js +1348 -0
- package/.agents/resolver.js +50 -534
- package/.agents/rules/rule-catalog.js +525 -0
- package/.agents/schemas/attestation.review.v1.json +111 -0
- package/.agents/schemas/attestation.verification.v1.json +85 -0
- package/.agents/schemas/lockfile.v2.schema.json +134 -0
- package/.agents/schemas/profile.v2.schema.json +114 -0
- package/.agents/schemas/runtime.thread.v1.json +192 -0
- package/.agents/schemas/skill.manifest.v2.json +177 -0
- package/.agents/schemas/verification.spec.v1.json +39 -0
- package/.agents/schemas/workspace.graph.schema.json +106 -0
- package/.agents/skills-index.json +6 -166
- package/.agents/stats.js +9 -9
- package/.agents/transaction-core/event-store.js +288 -0
- package/.agents/transaction-core/idempotency.js +129 -0
- package/.agents/transaction-core/ipc-lock.js +311 -0
- package/.agents/transaction-core/plugin-supply-chain-bundle.js +436 -0
- package/.agents/validate.js +44 -1
- package/.agents/watch.js +354 -102
- package/.agents/workspace/workspace-graph.js +778 -0
- package/README.md +59 -387
- package/benchmarks/v2/analysis/statistics.js +140 -0
- package/benchmarks/v2/analysis/stats.js +69 -0
- package/benchmarks/v2/arms/arm-definitions.js +79 -0
- package/benchmarks/v2/dataset.schema.json +34 -0
- package/benchmarks/v2/evaluators/index.js +25 -0
- package/benchmarks/v2/evaluators/verified-success.js +116 -0
- package/benchmarks/v2/harness/runner.js +88 -0
- package/benchmarks/v2/pilot-tasks.json +392 -0
- package/bin/commands/recover.js +88 -0
- package/bin/commands/update.js +80 -17
- package/bin/commands.js +62 -25
- package/bin/index.js +138 -81
- package/bin/lib/lockfile.js +5 -3
- package/bin/lib/safe-writer.js +34 -3
- package/package.json +87 -72
- package/registry.json +2 -2
- package/registry.v2.schema.json +86 -0
- package/.agents/core/profiles/backend.yaml +0 -47
- package/.agents/core/profiles/enterprise.yaml +0 -46
- package/.agents/core/profiles/frontend.yaml +0 -46
- package/.agents/core/profiles/hackathon.yaml +0 -45
- package/.agents/core/profiles/mvp.yaml +0 -44
- package/.agents/core/profiles/startup.yaml +0 -48
- package/.agents/core/skills/adapters/EXAMPLES.md +0 -19
- package/.agents/core/skills/adapters/SKILL.md +0 -105
- package/.agents/core/skills/adapters/TROUBLESHOOTING.md +0 -7
- package/.agents/core/skills/adapters/VALIDATION.json +0 -12
- package/.agents/core/skills/adapters/skill.yaml +0 -16
- package/.agents/core/skills/architecture-diagrams/SKILL.md +0 -108
- package/.agents/core/skills/architecture-diagrams/VALIDATION.json +0 -12
- package/.agents/core/skills/architecture-diagrams/skill.yaml +0 -12
- package/.agents/core/skills/brutalist-design/SKILL.md +0 -150
- package/.agents/core/skills/brutalist-design/VALIDATION.json +0 -12
- package/.agents/core/skills/brutalist-design/skill.yaml +0 -12
- package/.agents/core/skills/database/EXAMPLES.md +0 -74
- package/.agents/core/skills/database/SKILL.md +0 -101
- package/.agents/core/skills/database/TROUBLESHOOTING.md +0 -18
- package/.agents/core/skills/database/VALIDATION.json +0 -11
- package/.agents/core/skills/database/skill.yaml +0 -31
- package/.agents/core/skills/ddd/EXAMPLES.md +0 -42
- package/.agents/core/skills/ddd/SKILL.md +0 -247
- package/.agents/core/skills/ddd/TROUBLESHOOTING.md +0 -19
- package/.agents/core/skills/ddd/VALIDATION.json +0 -12
- package/.agents/core/skills/ddd/ddd.md +0 -178
- package/.agents/core/skills/ddd/skill.yaml +0 -17
- package/.agents/core/skills/decisions/EXAMPLES.md +0 -35
- package/.agents/core/skills/decisions/SKILL.md +0 -90
- package/.agents/core/skills/decisions/TROUBLESHOOTING.md +0 -13
- package/.agents/core/skills/decisions/VALIDATION.json +0 -12
- package/.agents/core/skills/decisions/skill.yaml +0 -16
- package/.agents/core/skills/docker/EXAMPLES.md +0 -56
- package/.agents/core/skills/docker/SKILL.md +0 -63
- package/.agents/core/skills/docker/TROUBLESHOOTING.md +0 -18
- package/.agents/core/skills/docker/VALIDATION.json +0 -11
- package/.agents/core/skills/docker/skill.yaml +0 -29
- package/.agents/core/skills/fastapi/EXAMPLES.md +0 -36
- package/.agents/core/skills/fastapi/SKILL.md +0 -148
- package/.agents/core/skills/fastapi/TROUBLESHOOTING.md +0 -19
- package/.agents/core/skills/fastapi/VALIDATION.json +0 -12
- package/.agents/core/skills/fastapi/fastapi.md +0 -112
- package/.agents/core/skills/fastapi/skill.yaml +0 -17
- package/.agents/core/skills/generators/EXAMPLES.md +0 -19
- package/.agents/core/skills/generators/SKILL.md +0 -112
- package/.agents/core/skills/generators/TROUBLESHOOTING.md +0 -7
- package/.agents/core/skills/generators/VALIDATION.json +0 -12
- package/.agents/core/skills/generators/skill.yaml +0 -25
- package/.agents/core/skills/generators/templates/API.md +0 -77
- package/.agents/core/skills/generators/templates/ARCHITECTURE.md +0 -70
- package/.agents/core/skills/generators/templates/DATABASE.md +0 -42
- package/.agents/core/skills/generators/templates/DECISION.md +0 -46
- package/.agents/core/skills/generators/templates/PRD.md +0 -67
- package/.agents/core/skills/generators/templates/PROJECT_GRAPH.md +0 -56
- package/.agents/core/skills/generators/templates/ROADMAP.md +0 -51
- package/.agents/core/skills/generators/templates/TASKS.md +0 -43
- package/.agents/core/skills/generators/templates/UI.md +0 -73
- package/.agents/core/skills/graphify/EXAMPLES.md +0 -73
- package/.agents/core/skills/graphify/SKILL.md +0 -130
- package/.agents/core/skills/graphify/VALIDATION.json +0 -12
- package/.agents/core/skills/graphify/skill.yaml +0 -18
- package/.agents/core/skills/impeccable-design/EXAMPLES.md +0 -26
- package/.agents/core/skills/impeccable-design/SKILL.md +0 -201
- package/.agents/core/skills/impeccable-design/TROUBLESHOOTING.md +0 -19
- package/.agents/core/skills/impeccable-design/VALIDATION.json +0 -12
- package/.agents/core/skills/impeccable-design/skill.yaml +0 -20
- package/.agents/core/skills/interview-me/SKILL.md +0 -97
- package/.agents/core/skills/interview-me/VALIDATION.json +0 -12
- package/.agents/core/skills/interview-me/skill.yaml +0 -12
- package/.agents/core/skills/microservices/EXAMPLES.md +0 -38
- package/.agents/core/skills/microservices/SKILL.md +0 -164
- package/.agents/core/skills/microservices/TROUBLESHOOTING.md +0 -19
- package/.agents/core/skills/microservices/VALIDATION.json +0 -12
- package/.agents/core/skills/microservices/microservices.md +0 -119
- package/.agents/core/skills/microservices/skill.yaml +0 -17
- package/.agents/core/skills/minimalist-design/SKILL.md +0 -113
- package/.agents/core/skills/minimalist-design/VALIDATION.json +0 -12
- package/.agents/core/skills/minimalist-design/skill.yaml +0 -12
- package/.agents/core/skills/nestjs/EXAMPLES.md +0 -40
- package/.agents/core/skills/nestjs/SKILL.md +0 -139
- package/.agents/core/skills/nestjs/TROUBLESHOOTING.md +0 -19
- package/.agents/core/skills/nestjs/VALIDATION.json +0 -12
- package/.agents/core/skills/nestjs/nestjs.md +0 -103
- package/.agents/core/skills/nestjs/skill.yaml +0 -17
- package/.agents/core/skills/nextjs/EXAMPLES.md +0 -40
- package/.agents/core/skills/nextjs/SKILL.md +0 -163
- package/.agents/core/skills/nextjs/TROUBLESHOOTING.md +0 -19
- package/.agents/core/skills/nextjs/VALIDATION.json +0 -12
- package/.agents/core/skills/nextjs/nextjs.md +0 -67
- package/.agents/core/skills/nextjs/skill.yaml +0 -17
- package/.agents/core/skills/node/EXAMPLES.md +0 -80
- package/.agents/core/skills/node/SKILL.md +0 -128
- package/.agents/core/skills/node/TROUBLESHOOTING.md +0 -19
- package/.agents/core/skills/node/VALIDATION.json +0 -12
- package/.agents/core/skills/node/node.md +0 -87
- package/.agents/core/skills/node/skill.yaml +0 -17
- package/.agents/core/skills/performance/EXAMPLES.md +0 -30
- package/.agents/core/skills/performance/SKILL.md +0 -75
- package/.agents/core/skills/performance/TROUBLESHOOTING.md +0 -19
- package/.agents/core/skills/performance/VALIDATION.json +0 -12
- package/.agents/core/skills/performance/performance.md +0 -52
- package/.agents/core/skills/performance/skill.yaml +0 -17
- package/.agents/core/skills/react/EXAMPLES.md +0 -79
- package/.agents/core/skills/react/SKILL.md +0 -132
- package/.agents/core/skills/react/TROUBLESHOOTING.md +0 -19
- package/.agents/core/skills/react/VALIDATION.json +0 -12
- package/.agents/core/skills/react/react.md +0 -93
- package/.agents/core/skills/react/skill.yaml +0 -17
- package/.agents/core/skills/react-best-practices/SKILL.md +0 -155
- package/.agents/core/skills/react-best-practices/VALIDATION.json +0 -12
- package/.agents/core/skills/react-best-practices/skill.yaml +0 -14
- package/.agents/core/skills/redesign-audit/SKILL.md +0 -117
- package/.agents/core/skills/redesign-audit/VALIDATION.json +0 -12
- package/.agents/core/skills/redesign-audit/skill.yaml +0 -12
- package/.agents/core/skills/soft-design/SKILL.md +0 -108
- package/.agents/core/skills/soft-design/VALIDATION.json +0 -12
- package/.agents/core/skills/soft-design/skill.yaml +0 -12
- package/.agents/core/skills/state-management/EXAMPLES.md +0 -56
- package/.agents/core/skills/state-management/SKILL.md +0 -48
- package/.agents/core/skills/state-management/TROUBLESHOOTING.md +0 -18
- package/.agents/core/skills/state-management/VALIDATION.json +0 -11
- package/.agents/core/skills/state-management/skill.yaml +0 -28
- package/.agents/core/skills/subagent-orchestrator/SKILL.md +0 -117
- package/.agents/core/skills/subagent-orchestrator/VALIDATION.json +0 -12
- package/.agents/core/skills/subagent-orchestrator/skill.yaml +0 -12
- package/.agents/core/skills/system-design/EXAMPLES.md +0 -75
- package/.agents/core/skills/system-design/SKILL.md +0 -419
- package/.agents/core/skills/system-design/TROUBLESHOOTING.md +0 -19
- package/.agents/core/skills/system-design/VALIDATION.json +0 -12
- package/.agents/core/skills/system-design/skill.yaml +0 -20
- package/.agents/core/skills/system-design/system-design.md +0 -112
- package/.agents/core/skills/testing/EXAMPLES.md +0 -71
- package/.agents/core/skills/testing/SKILL.md +0 -70
- package/.agents/core/skills/testing/TROUBLESHOOTING.md +0 -18
- package/.agents/core/skills/testing/VALIDATION.json +0 -11
- package/.agents/core/skills/testing/skill.yaml +0 -32
- package/.agents/core/skills/typescript/EXAMPLES.md +0 -64
- package/.agents/core/skills/typescript/SKILL.md +0 -112
- package/.agents/core/skills/typescript/TROUBLESHOOTING.md +0 -19
- package/.agents/core/skills/typescript/VALIDATION.json +0 -12
- package/.agents/core/skills/typescript/skill.yaml +0 -17
- package/.agents/core/skills/typescript/typescript.md +0 -71
- package/.agents/core/skills/ui-design/EXAMPLES.md +0 -21
- package/.agents/core/skills/ui-design/SKILL.md +0 -124
- package/.agents/core/skills/ui-design/TROUBLESHOOTING.md +0 -19
- package/.agents/core/skills/ui-design/VALIDATION.json +0 -12
- package/.agents/core/skills/ui-design/skill.yaml +0 -17
- package/.agents/core/skills/ui-design/ui.md +0 -88
- package/.agents/core/skills/ui-ux-pro/EXAMPLES.md +0 -62
- package/.agents/core/skills/ui-ux-pro/SKILL.md +0 -375
- package/.agents/core/skills/ui-ux-pro/TROUBLESHOOTING.md +0 -19
- package/.agents/core/skills/ui-ux-pro/VALIDATION.json +0 -12
- package/.agents/core/skills/ui-ux-pro/skill.yaml +0 -19
- package/.agents/core/skills/ux-design/EXAMPLES.md +0 -36
- package/.agents/core/skills/ux-design/SKILL.md +0 -116
- package/.agents/core/skills/ux-design/TROUBLESHOOTING.md +0 -19
- package/.agents/core/skills/ux-design/VALIDATION.json +0 -12
- package/.agents/core/skills/ux-design/skill.yaml +0 -17
- package/.agents/core/skills/ux-design/ux.md +0 -80
- package/.agents/core/skills/vercel-optimize/SKILL.md +0 -83
- package/.agents/core/skills/vercel-optimize/VALIDATION.json +0 -12
- package/.agents/core/skills/vercel-optimize/scripts/collect-signals.mjs +0 -131
- package/.agents/core/skills/vercel-optimize/scripts/gate-investigations.mjs +0 -142
- package/.agents/core/skills/vercel-optimize/scripts/merge-signals.mjs +0 -143
- package/.agents/core/skills/vercel-optimize/scripts/scan-codebase.mjs +0 -174
- package/.agents/core/skills/vercel-optimize/skill.yaml +0 -18
- package/.agents/core/skills/web-accessibility/EXAMPLES.md +0 -39
- package/.agents/core/skills/web-accessibility/SKILL.md +0 -170
- package/.agents/core/skills/web-accessibility/TROUBLESHOOTING.md +0 -19
- package/.agents/core/skills/web-accessibility/VALIDATION.json +0 -12
- package/.agents/core/skills/web-accessibility/accessibility.md +0 -63
- package/.agents/core/skills/web-accessibility/skill.yaml +0 -17
- package/.agents/generated/claude/skills/adapters/SKILL.md +0 -126
- package/.agents/generated/claude/skills/architecture-diagrams/SKILL.md +0 -101
- package/.agents/generated/claude/skills/brutalist-design/SKILL.md +0 -145
- package/.agents/generated/claude/skills/database/SKILL.md +0 -191
- package/.agents/generated/claude/skills/ddd/SKILL.md +0 -305
- package/.agents/generated/claude/skills/decisions/SKILL.md +0 -134
- package/.agents/generated/claude/skills/docker/SKILL.md +0 -135
- package/.agents/generated/claude/skills/fastapi/SKILL.md +0 -200
- package/.agents/generated/claude/skills/generators/SKILL.md +0 -133
- package/.agents/generated/claude/skills/graphify/SKILL.md +0 -198
- package/.agents/generated/claude/skills/impeccable-design/SKILL.md +0 -241
- package/.agents/generated/claude/skills/interview-me/SKILL.md +0 -90
- package/.agents/generated/claude/skills/microservices/SKILL.md +0 -218
- package/.agents/generated/claude/skills/minimalist-design/SKILL.md +0 -108
- package/.agents/generated/claude/skills/nestjs/SKILL.md +0 -195
- package/.agents/generated/claude/skills/nextjs/SKILL.md +0 -219
- package/.agents/generated/claude/skills/node/SKILL.md +0 -224
- package/.agents/generated/claude/skills/performance/SKILL.md +0 -121
- package/.agents/generated/claude/skills/react/SKILL.md +0 -227
- package/.agents/generated/claude/skills/react-best-practices/SKILL.md +0 -146
- package/.agents/generated/claude/skills/redesign-audit/SKILL.md +0 -112
- package/.agents/generated/claude/skills/soft-design/SKILL.md +0 -103
- package/.agents/generated/claude/skills/state-management/SKILL.md +0 -120
- package/.agents/generated/claude/skills/subagent-orchestrator/SKILL.md +0 -110
- package/.agents/generated/claude/skills/system-design/SKILL.md +0 -507
- package/.agents/generated/claude/skills/testing/SKILL.md +0 -157
- package/.agents/generated/claude/skills/typescript/SKILL.md +0 -192
- package/.agents/generated/claude/skills/ui-design/SKILL.md +0 -161
- package/.agents/generated/claude/skills/ui-ux-pro/SKILL.md +0 -451
- package/.agents/generated/claude/skills/ux-design/SKILL.md +0 -168
- package/.agents/generated/claude/skills/vercel-optimize/SKILL.md +0 -76
- package/.agents/generated/claude/skills/web-accessibility/SKILL.md +0 -225
- package/.agents/generated/gemini/skills/adapters/SKILL.md +0 -135
- package/.agents/generated/gemini/skills/architecture-diagrams/SKILL.md +0 -107
- package/.agents/generated/gemini/skills/brutalist-design/SKILL.md +0 -151
- package/.agents/generated/gemini/skills/database/SKILL.md +0 -200
- package/.agents/generated/gemini/skills/ddd/SKILL.md +0 -314
- package/.agents/generated/gemini/skills/decisions/SKILL.md +0 -143
- package/.agents/generated/gemini/skills/docker/SKILL.md +0 -144
- package/.agents/generated/gemini/skills/fastapi/SKILL.md +0 -209
- package/.agents/generated/gemini/skills/generators/SKILL.md +0 -142
- package/.agents/generated/gemini/skills/graphify/SKILL.md +0 -205
- package/.agents/generated/gemini/skills/impeccable-design/SKILL.md +0 -250
- package/.agents/generated/gemini/skills/interview-me/SKILL.md +0 -96
- package/.agents/generated/gemini/skills/microservices/SKILL.md +0 -227
- package/.agents/generated/gemini/skills/minimalist-design/SKILL.md +0 -114
- package/.agents/generated/gemini/skills/nestjs/SKILL.md +0 -204
- package/.agents/generated/gemini/skills/nextjs/SKILL.md +0 -298
- package/.agents/generated/gemini/skills/node/SKILL.md +0 -323
- package/.agents/generated/gemini/skills/performance/SKILL.md +0 -185
- package/.agents/generated/gemini/skills/react/SKILL.md +0 -332
- package/.agents/generated/gemini/skills/react-best-practices/SKILL.md +0 -152
- package/.agents/generated/gemini/skills/redesign-audit/SKILL.md +0 -118
- package/.agents/generated/gemini/skills/soft-design/SKILL.md +0 -109
- package/.agents/generated/gemini/skills/state-management/SKILL.md +0 -129
- package/.agents/generated/gemini/skills/subagent-orchestrator/SKILL.md +0 -116
- package/.agents/generated/gemini/skills/system-design/SKILL.md +0 -631
- package/.agents/generated/gemini/skills/testing/SKILL.md +0 -166
- package/.agents/generated/gemini/skills/typescript/SKILL.md +0 -275
- package/.agents/generated/gemini/skills/ui-design/SKILL.md +0 -170
- package/.agents/generated/gemini/skills/ui-ux-pro/SKILL.md +0 -460
- package/.agents/generated/gemini/skills/ux-design/SKILL.md +0 -177
- package/.agents/generated/gemini/skills/vercel-optimize/SKILL.md +0 -82
- package/.agents/generated/gemini/skills/web-accessibility/SKILL.md +0 -300
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: database
|
|
3
|
-
description: >
|
|
4
|
-
Database architecture, schema design, Prisma, Drizzle ORM, indexing strategies, migrations, and N+1 query resolution.
|
|
5
|
-
---
|
|
6
|
-
# database
|
|
7
|
-
|
|
8
|
-
## Overview
|
|
9
|
-
|
|
10
|
-
Relational database design, query optimization, migration safety, connection pooling in serverless environments, and ORM usage across PostgreSQL, Prisma, and Drizzle.
|
|
11
|
-
|
|
12
|
-
## When to Use
|
|
13
|
-
|
|
14
|
-
Activate for tasks involving database schema design, migrations, indexing, relational models, ORM queries, transactions, or query performance tuning.
|
|
15
|
-
|
|
16
|
-
## Rules & Patterns
|
|
17
|
-
|
|
18
|
-
### Negative Constraints (What NOT to Do)
|
|
19
|
-
|
|
20
|
-
1. **NEVER do `SELECT *` in production**: Always select explicit columns required by the caller to minimize memory bandwidth and lock footprint.
|
|
21
|
-
2. **NEVER run destructive migrations without backward compatibility**: Always follow expand-and-contract (Phase 1: add new column as nullable; Phase 2: backfill; Phase 3: make non-nullable & remove old column).
|
|
22
|
-
3. **NEVER execute queries in loops (The N+1 Anti-Pattern)**: Always use batch loading (`inArray`, `DataLoader`, or relational `include` / `JOIN`).
|
|
23
|
-
4. **NEVER leave foreign keys without indexes**: In PostgreSQL/MySQL, child foreign key columns must always have an index to prevent table-level locking on cascade deletes.
|
|
24
|
-
5. **NEVER perform multi-entity writes without a database transaction**: Any operation touching multiple records must use `prisma.$transaction` or `db.transaction`.
|
|
25
|
-
6. **NEVER open unpooled database connections in Serverless / Edge functions**: Serverless scale-outs will instantly exhaust PostgreSQL's `max_connections`.
|
|
26
|
-
|
|
27
|
-
---
|
|
28
|
-
|
|
29
|
-
### Zero-Downtime Migrations (Expand-and-Contract)
|
|
30
|
-
|
|
31
|
-
When modifying schemas with zero downtime:
|
|
32
|
-
|
|
33
|
-
1. **Phase 1 (Expand)**: Add the new column as `NULLABLE` (or with a default value). Deploy the application code that reads from old column and writes to both old and new.
|
|
34
|
-
2. **Phase 2 (Backfill)**: Run an asynchronous batch migration job in chunks (e.g. 1000 rows at a time) to populate data from old column to new column.
|
|
35
|
-
3. **Phase 3 (Contract)**: Update application code to read and write exclusively from the new column.
|
|
36
|
-
4. **Phase 4 (Cleanup)**: Once traffic is fully shifted, remove the old column and mark the new column as `NOT NULL` in a separate migration.
|
|
37
|
-
|
|
38
|
-
---
|
|
39
|
-
|
|
40
|
-
### Serverless & Edge Connection Pooling
|
|
41
|
-
|
|
42
|
-
In serverless environments (AWS Lambda, Vercel Functions):
|
|
43
|
-
|
|
44
|
-
- Always connect via a connection pooler:
|
|
45
|
-
- **Prisma**: Use Prisma Accelerate or configure transaction mode connection URLs.
|
|
46
|
-
- **Drizzle / Node-Postgres**: Use `@neondatabase/serverless` or connect to PgBouncer pooler port (`6543`) with `max: 1` per serverless container.
|
|
47
|
-
- Set strict statement timeouts (e.g. `statement_timeout = '5000'`) to prevent hanging queries from exhausting pool capacity.
|
|
48
|
-
|
|
49
|
-
---
|
|
50
|
-
|
|
51
|
-
### Indexing & Performance Rules
|
|
52
|
-
|
|
53
|
-
- **B-Tree Indexes**: For high-cardinality filters (`status`, `user_id`, `created_at`).
|
|
54
|
-
- **Composite Indexes**: When querying multiple columns together (`WHERE organization_id = ? AND status = ?`), order columns in index by equality first, range second.
|
|
55
|
-
- **Partial Indexes**: For sparse boolean flags (`WHERE is_processed = false`).
|
|
56
|
-
- **Covering Indexes**: Include frequently selected columns (`INCLUDE (title, created_at)`) to enable index-only scans without table heap access.
|
|
57
|
-
|
|
58
|
-
---
|
|
59
|
-
|
|
60
|
-
## Code Examples
|
|
61
|
-
|
|
62
|
-
### Zero-Downtime Column Rename (Drizzle ORM)
|
|
63
|
-
|
|
64
|
-
```typescript
|
|
65
|
-
// Step 1 (Expand): Keep old column, add new column
|
|
66
|
-
export const users = pgTable('users', {
|
|
67
|
-
id: uuid('id').primaryKey().defaultRandom(),
|
|
68
|
-
fullName: varchar('full_name', { length: 255 }), // new column
|
|
69
|
-
name: varchar('name', { length: 255 }), // old column kept during transition
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
// App write logic during transition:
|
|
73
|
-
await db.insert(users).values({
|
|
74
|
-
name: input.name,
|
|
75
|
-
fullName: input.name
|
|
76
|
-
});
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
---
|
|
80
|
-
|
|
81
|
-
## Validation Checklist
|
|
82
|
-
|
|
83
|
-
- [ ] All database queries select explicit required columns (no `SELECT *`).
|
|
84
|
-
- [ ] Foreign keys have matching indexes on child tables.
|
|
85
|
-
- [ ] Multi-table writes wrapped in ACID transactions.
|
|
86
|
-
- [ ] No N+1 queries in loops.
|
|
87
|
-
- [ ] Schema migrations tested against expand-and-contract pattern.
|
|
88
|
-
- [ ] Serverless database connection string uses pooling proxy.
|
|
89
|
-
|
|
90
|
-
---
|
|
91
|
-
|
|
92
|
-
## Common Mistakes
|
|
93
|
-
|
|
94
|
-
- **Missing pagination limits**: Unbounded `findMany()` calls leading to Out-Of-Memory crashes under production volume.
|
|
95
|
-
- **Locking entire tables**: Adding `NOT NULL` columns with heavy compute defaults in PostgreSQL without concurrent index creation.
|
|
96
|
-
|
|
97
|
-
---
|
|
98
|
-
|
|
99
|
-
## Integration Notes
|
|
100
|
-
|
|
101
|
-
- Interacts with `system-design`, `ddd`, and `security` (multi-tenant tenantId scoping).
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
<!-- Source: EXAMPLES.md -->
|
|
105
|
-
|
|
106
|
-
# Database Examples — Anti-patterns vs ContextOS Standard
|
|
107
|
-
|
|
108
|
-
## Example 1: Solving the N+1 Query Problem
|
|
109
|
-
|
|
110
|
-
### Anti-pattern: Anti-pattern (N+1 database queries in a loop)
|
|
111
|
-
|
|
112
|
-
```typescript
|
|
113
|
-
// BAD: 1 query for users + N queries for posts!
|
|
114
|
-
const users = await prisma.user.findMany();
|
|
115
|
-
const usersWithPosts = [];
|
|
116
|
-
for (const user of users) {
|
|
117
|
-
const posts = await prisma.post.findMany({ where: { userId: user.id } }); // N queries!
|
|
118
|
-
usersWithPosts.push({ ...user, posts });
|
|
119
|
-
}
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
### Best practice: ContextOS Standard (Batch query or relational include)
|
|
123
|
-
|
|
124
|
-
```typescript
|
|
125
|
-
// GOOD: 1 single optimized batch query
|
|
126
|
-
const usersWithPosts = await prisma.user.findMany({
|
|
127
|
-
where: { isActive: true },
|
|
128
|
-
select: {
|
|
129
|
-
id: true,
|
|
130
|
-
name: true,
|
|
131
|
-
email: true,
|
|
132
|
-
posts: {
|
|
133
|
-
where: { published: true },
|
|
134
|
-
select: { id: true, title: true, createdAt: true },
|
|
135
|
-
take: 5
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
```
|
|
140
|
-
|
|
141
|
-
---
|
|
142
|
-
|
|
143
|
-
## Example 2: Safe Atomic Transactions with Locking
|
|
144
|
-
|
|
145
|
-
### Anti-pattern: Anti-pattern (Unprotected read-modify-write race condition)
|
|
146
|
-
|
|
147
|
-
```typescript
|
|
148
|
-
// BAD: race condition between reading balance and updating
|
|
149
|
-
const account = await prisma.account.findUnique({ where: { id } });
|
|
150
|
-
if (account.balance >= amount) {
|
|
151
|
-
await prisma.account.update({
|
|
152
|
-
where: { id },
|
|
153
|
-
data: { balance: account.balance - amount }
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
### Best practice: ContextOS Standard (Atomic conditional update in transaction)
|
|
159
|
-
|
|
160
|
-
```typescript
|
|
161
|
-
// GOOD: atomic database transaction with invariant check
|
|
162
|
-
export async function deductBalance(accountId: string, amount: number) {
|
|
163
|
-
return await prisma.$transaction(async (tx) => {
|
|
164
|
-
const updated = await tx.account.updateMany({
|
|
165
|
-
where: {
|
|
166
|
-
id: accountId,
|
|
167
|
-
balance: { gte: amount }
|
|
168
|
-
},
|
|
169
|
-
data: {
|
|
170
|
-
balance: { decrement: amount }
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
if (updated.count === 0) {
|
|
175
|
-
throw new InsufficientFundsError(accountId);
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
```
|
|
180
|
-
|
|
181
|
-
<!-- Source: TROUBLESHOOTING.md -->
|
|
182
|
-
|
|
183
|
-
# Database Troubleshooting Guide
|
|
184
|
-
|
|
185
|
-
## Common Issues & Fixes
|
|
186
|
-
|
|
187
|
-
### 1. Connection Pool Exhaustion in Serverless / Edge
|
|
188
|
-
|
|
189
|
-
- **Cause**: Creating a new PrismaClient / DB connection instance on every serverless function invocation.
|
|
190
|
-
- **Fix**: Declare PrismaClient as a global singleton across warm lambdas, and enable PgBouncer or Prisma Accelerate.
|
|
191
|
-
|
|
192
|
-
### 2. Slow Queries on Large Tables
|
|
193
|
-
|
|
194
|
-
- **Cause**: Missing composite index on filtered and ordered columns.
|
|
195
|
-
- **Fix**: Run `EXPLAIN ANALYZE <query>` and add targeted indexes matching the WHERE and ORDER BY columns.
|
|
196
|
-
|
|
197
|
-
### 3. Database Deadlocks during Concurrent Transactions
|
|
198
|
-
|
|
199
|
-
- **Cause**: Different transactions updating resources in different orders.
|
|
200
|
-
- **Fix**: Always acquire locks and update entities in a deterministic alphabetical or ID-ordered sequence.
|
|
@@ -1,314 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: Domain-Driven Design
|
|
3
|
-
description: >
|
|
4
|
-
ContextOS skill for Domain-Driven Design
|
|
5
|
-
---
|
|
6
|
-
# Domain-Driven Design
|
|
7
|
-
|
|
8
|
-
## Overview
|
|
9
|
-
|
|
10
|
-
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.
|
|
11
|
-
|
|
12
|
-
## When to Use
|
|
13
|
-
|
|
14
|
-
Activate when designing core business domain models, transactional consistency boundaries, enterprise APIs, or complex aggregate hierarchies.
|
|
15
|
-
|
|
16
|
-
## Rules & Patterns
|
|
17
|
-
<!-- Source: ddd.md -->
|
|
18
|
-
|
|
19
|
-
## Domain-Driven Design — Patterns & Practices
|
|
20
|
-
|
|
21
|
-
## When to Use DDD
|
|
22
|
-
|
|
23
|
-
**Use when:**
|
|
24
|
-
|
|
25
|
-
- Complex business logic that goes beyond CRUD
|
|
26
|
-
- Multiple domain experts with different vocabularies
|
|
27
|
-
- The domain model is the competitive advantage
|
|
28
|
-
- Enterprise-grade applications
|
|
29
|
-
|
|
30
|
-
**Don't use when:**
|
|
31
|
-
|
|
32
|
-
- Simple CRUD applications
|
|
33
|
-
- Hackathon/MVP (overkill)
|
|
34
|
-
- No domain expert available
|
|
35
|
-
|
|
36
|
-
## Strategic Design
|
|
37
|
-
|
|
38
|
-
### Bounded Contexts
|
|
39
|
-
|
|
40
|
-
The single most important DDD concept. A Bounded Context is a boundary within which a particular model is defined and applicable.
|
|
41
|
-
|
|
42
|
-
**Example — E-Commerce:**
|
|
43
|
-
|
|
44
|
-
```
|
|
45
|
-
[Order Context] [Payment Context] [Shipping Context]
|
|
46
|
-
- Order - Payment - Shipment
|
|
47
|
-
- OrderItem - Transaction - TrackingNumber
|
|
48
|
-
- Customer (ref) - Refund - Address
|
|
49
|
-
- Address (value) - Invoice - Carrier
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
`Customer` means different things in each context:
|
|
53
|
-
|
|
54
|
-
- Order Context: name, email, shipping preference
|
|
55
|
-
- Payment Context: billing info, payment methods
|
|
56
|
-
- Support Context: ticket history, satisfaction score
|
|
57
|
-
|
|
58
|
-
### Context Map
|
|
59
|
-
|
|
60
|
-
```
|
|
61
|
-
[Order] ←→ [Payment] # Partnership
|
|
62
|
-
[Order] → [Shipping] # Customer-Supplier
|
|
63
|
-
[Order] → [Legacy CRM] # Anti-Corruption Layer
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
## Tactical Design
|
|
67
|
-
|
|
68
|
-
### Entities
|
|
69
|
-
|
|
70
|
-
Objects with identity. Two entities with the same attributes but different IDs are different.
|
|
71
|
-
|
|
72
|
-
```typescript
|
|
73
|
-
class User {
|
|
74
|
-
readonly id: UserId;
|
|
75
|
-
name: string;
|
|
76
|
-
email: Email; // Value Object
|
|
77
|
-
}
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
### Value Objects
|
|
81
|
-
|
|
82
|
-
Objects defined by their attributes, not identity. Immutable.
|
|
83
|
-
|
|
84
|
-
```typescript
|
|
85
|
-
class Email {
|
|
86
|
-
constructor(readonly value: string) {
|
|
87
|
-
if (!isValidEmail(value)) throw new InvalidEmailError(value);
|
|
88
|
-
}
|
|
89
|
-
equals(other: Email): boolean {
|
|
90
|
-
return this.value === other.value;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
### Aggregates
|
|
96
|
-
|
|
97
|
-
A cluster of entities and value objects with a single root entity (Aggregate Root). All access goes through the root.
|
|
98
|
-
|
|
99
|
-
```typescript
|
|
100
|
-
class Order { // Aggregate Root
|
|
101
|
-
private items: OrderItem[] = [];
|
|
102
|
-
|
|
103
|
-
addItem(product: ProductRef, quantity: number): void {
|
|
104
|
-
// Business logic HERE, not in a service
|
|
105
|
-
if (quantity <= 0) throw new InvalidQuantityError();
|
|
106
|
-
this.items.push(new OrderItem(product, quantity));
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
get total(): Money {
|
|
110
|
-
return this.items.reduce((sum, item) => sum.add(item.subtotal), Money.zero());
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
**Aggregate Rules:**
|
|
116
|
-
|
|
117
|
-
1. Reference other aggregates by ID only
|
|
118
|
-
2. One aggregate per transaction
|
|
119
|
-
3. Eventual consistency between aggregates
|
|
120
|
-
|
|
121
|
-
### Domain Events
|
|
122
|
-
|
|
123
|
-
Something that happened in the domain that domain experts care about.
|
|
124
|
-
|
|
125
|
-
```typescript
|
|
126
|
-
class OrderPlaced implements DomainEvent {
|
|
127
|
-
constructor(
|
|
128
|
-
readonly orderId: OrderId,
|
|
129
|
-
readonly customerId: CustomerId,
|
|
130
|
-
readonly total: Money,
|
|
131
|
-
readonly occurredAt: Date
|
|
132
|
-
) {}
|
|
133
|
-
}
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
### Domain Services
|
|
137
|
-
|
|
138
|
-
Business logic that doesn't naturally belong to an entity or value object.
|
|
139
|
-
|
|
140
|
-
```typescript
|
|
141
|
-
class PricingService {
|
|
142
|
-
calculatePrice(order: Order, customer: Customer, promotions: Promotion[]): Money {
|
|
143
|
-
// Complex pricing logic involving multiple aggregates
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
```
|
|
147
|
-
|
|
148
|
-
### Repositories
|
|
149
|
-
|
|
150
|
-
Abstraction over data access. One repository per aggregate root.
|
|
151
|
-
|
|
152
|
-
```typescript
|
|
153
|
-
interface OrderRepository {
|
|
154
|
-
findById(id: OrderId): Promise<Order | null>;
|
|
155
|
-
save(order: Order): Promise<void>;
|
|
156
|
-
delete(id: OrderId): Promise<void>;
|
|
157
|
-
}
|
|
158
|
-
```
|
|
159
|
-
|
|
160
|
-
## Directory Structure (DDD)
|
|
161
|
-
|
|
162
|
-
```
|
|
163
|
-
src/
|
|
164
|
-
├── modules/
|
|
165
|
-
│ └── orders/ # Bounded Context
|
|
166
|
-
│ ├── domain/
|
|
167
|
-
│ │ ├── entities/
|
|
168
|
-
│ │ │ └── order.ts # Aggregate Root
|
|
169
|
-
│ │ ├── value-objects/
|
|
170
|
-
│ │ │ └── money.ts
|
|
171
|
-
│ │ ├── events/
|
|
172
|
-
│ │ │ └── order-placed.ts
|
|
173
|
-
│ │ ├── services/
|
|
174
|
-
│ │ │ └── pricing.ts
|
|
175
|
-
│ │ └── repositories/
|
|
176
|
-
│ │ └── order.repository.ts # Interface
|
|
177
|
-
│ ├── application/
|
|
178
|
-
│ │ ├── commands/
|
|
179
|
-
│ │ │ └── place-order.ts
|
|
180
|
-
│ │ ├── queries/
|
|
181
|
-
│ │ │ └── get-order.ts
|
|
182
|
-
│ │ └── handlers/
|
|
183
|
-
│ │ └── place-order.handler.ts
|
|
184
|
-
│ └── infrastructure/
|
|
185
|
-
│ ├── persistence/
|
|
186
|
-
│ │ └── order.repository.impl.ts # Implementation
|
|
187
|
-
│ └── api/
|
|
188
|
-
│ └── orders.controller.ts
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
### The Clean Architecture Dependency Rule
|
|
192
|
-
|
|
193
|
-
In DDD, dependencies **MUST strictly point inward**:
|
|
194
|
-
|
|
195
|
-
```
|
|
196
|
-
[ Frameworks & Drivers (Web, DB, UI) ]
|
|
197
|
-
└──▶ [ Interface Adapters (Controllers, Gateways) ]
|
|
198
|
-
└──▶ [ Application (Use Cases, CQRS Handlers) ]
|
|
199
|
-
└──▶ [ Domain (Entities, Value Objects) ]
|
|
200
|
-
```
|
|
201
|
-
|
|
202
|
-
- The **Domain layer** has ZERO dependencies on ORMs (Prisma, TypeORM), HTTP frameworks (Express, NestJS), or external SDKs.
|
|
203
|
-
- Repositories are defined as interfaces in the domain/application layer and implemented in the infrastructure layer.
|
|
204
|
-
|
|
205
|
-
### Domain Events vs Integration Events
|
|
206
|
-
|
|
207
|
-
1. **Domain Events**: Represent state changes inside a single Bounded Context.
|
|
208
|
-
- Raised directly inside the Aggregate Root (`order.addItem(...)` raises `OrderItemAdded`).
|
|
209
|
-
- Dispatched in-process before transaction commit.
|
|
210
|
-
2. **Integration Events**: Published across Bounded Context boundaries to communicate with other services.
|
|
211
|
-
- Dispatched via Transactional Outbox pattern to message brokers.
|
|
212
|
-
- Must use backward-compatible schemas with versioning.
|
|
213
|
-
|
|
214
|
-
### Anti-Corruption Layer (ACL)
|
|
215
|
-
|
|
216
|
-
When consuming data from an external bounded context or 3rd-party vendor API (e.g. Stripe, Salesforce):
|
|
217
|
-
|
|
218
|
-
- NEVER import external domain models directly into your domain.
|
|
219
|
-
- Create an **ACL Translator / Adapter** in the infrastructure layer to convert external DTOs into your own Value Objects and Entities.
|
|
220
|
-
|
|
221
|
-
---
|
|
222
|
-
|
|
223
|
-
## Anti-Patterns
|
|
224
|
-
|
|
225
|
-
- [FAIL] Anemic domain model — entities with only getters/setters, all logic in services
|
|
226
|
-
- [FAIL] Big aggregate — aggregates should be small, focused on invariants
|
|
227
|
-
- [FAIL] Cross-aggregate transactions — use eventual consistency
|
|
228
|
-
- [FAIL] DDD everywhere — use DDD only where complexity justifies it
|
|
229
|
-
- [FAIL] ORM entities leaking into Domain — domain entities must not depend on `@Entity()` or ORM decorators
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
## Code Examples
|
|
233
|
-
|
|
234
|
-
See `EXAMPLES.md` for detailed code examples.
|
|
235
|
-
|
|
236
|
-
## Validation Checklist
|
|
237
|
-
|
|
238
|
-
What to verify during the review phase before completing the task.
|
|
239
|
-
|
|
240
|
-
## Common Mistakes
|
|
241
|
-
|
|
242
|
-
Anti-patterns and things to explicitly avoid. See `TROUBLESHOOTING.md`.
|
|
243
|
-
|
|
244
|
-
## Integration Notes
|
|
245
|
-
|
|
246
|
-
How this skill interacts with other skills.
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
<!-- Source: EXAMPLES.md -->
|
|
250
|
-
|
|
251
|
-
# ddd Examples — Anti-patterns vs ContextOS Standard
|
|
252
|
-
|
|
253
|
-
## Example 1: Domain Entities vs Anemic Models
|
|
254
|
-
|
|
255
|
-
### Anti-pattern: Anemic Domain Model with Leaky Setters
|
|
256
|
-
|
|
257
|
-
```typescript
|
|
258
|
-
// BAD: Zero business invariants; any caller can corrupt state
|
|
259
|
-
class BankAccount {
|
|
260
|
-
public balance: number = 0;
|
|
261
|
-
public isFrozen: boolean = false;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
// Logic leaked into controller or service
|
|
265
|
-
account.balance -= 500; // Overdraft not checked!
|
|
266
|
-
```
|
|
267
|
-
|
|
268
|
-
### Best practice: ContextOS Standard (Rich Domain Model with Guarded Invariants)
|
|
269
|
-
|
|
270
|
-
```typescript
|
|
271
|
-
// GOOD: Invariants strictly enforced inside Aggregate Root
|
|
272
|
-
class BankAccount {
|
|
273
|
-
private _balance: number;
|
|
274
|
-
private _isFrozen: boolean;
|
|
275
|
-
|
|
276
|
-
constructor(id: string, initialDeposit: Money) {
|
|
277
|
-
this._balance = initialDeposit.amount;
|
|
278
|
-
this._isFrozen = false;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
public withdraw(amount: Money): void {
|
|
282
|
-
if (this._isFrozen) {
|
|
283
|
-
throw new AccountFrozenException('Cannot withdraw from a frozen account');
|
|
284
|
-
}
|
|
285
|
-
if (this._balance < amount.amount) {
|
|
286
|
-
throw new InsufficientFundsException('Insufficient funds for withdrawal');
|
|
287
|
-
}
|
|
288
|
-
this._balance -= amount.amount;
|
|
289
|
-
this.addDomainEvent(new MoneyWithdrawnEvent(this.id, amount));
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
```
|
|
293
|
-
|
|
294
|
-
<!-- Source: TROUBLESHOOTING.md -->
|
|
295
|
-
|
|
296
|
-
# ddd Troubleshooting & Common Mistakes
|
|
297
|
-
|
|
298
|
-
## 1. God Aggregates
|
|
299
|
-
|
|
300
|
-
- **Symptom**: Aggregate Root contains 20 child entities and loading it requires joining dozens of tables.
|
|
301
|
-
- **Root Cause**: Treating ERD tables as aggregate boundaries rather than transactional consistency units.
|
|
302
|
-
- **Fix**: Design small aggregates. Reference other aggregates by ID only, not by object reference.
|
|
303
|
-
|
|
304
|
-
## 2. Leaking Infrastructure into Domain Layer
|
|
305
|
-
|
|
306
|
-
- **Symptom**: Domain entities import Prisma, TypeORM decorators, or Express Request objects.
|
|
307
|
-
- **Root Cause**: Inverting Clean Architecture boundaries.
|
|
308
|
-
- **Fix**: The Domain layer must be pure TypeScript with zero external framework dependencies.
|
|
309
|
-
|
|
310
|
-
## 3. Transaction Spanning Multiple Aggregates
|
|
311
|
-
|
|
312
|
-
- **Symptom**: High database lock contention and deadlocks under concurrent transactions.
|
|
313
|
-
- **Root Cause**: Modifying multiple aggregate roots within the same database transaction.
|
|
314
|
-
- **Fix**: Rule of thumb: Exactly one Aggregate Root modified per transaction. Use Domain Events for eventual consistency across other aggregates.
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: decisions
|
|
3
|
-
description: >
|
|
4
|
-
Architecture Decision Records (ADR) management. Creates, tracks, and queries architectural decisions so AI assistants understand why choices were made.
|
|
5
|
-
---
|
|
6
|
-
# decision-engine
|
|
7
|
-
|
|
8
|
-
## Overview
|
|
9
|
-
|
|
10
|
-
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.
|
|
11
|
-
|
|
12
|
-
## When to Use
|
|
13
|
-
|
|
14
|
-
Activate when choosing or switching database engines, authentication strategies, state libraries, or significant architectural patterns.
|
|
15
|
-
|
|
16
|
-
## Rules & Patterns
|
|
17
|
-
|
|
18
|
-
You manage **Architecture Decision Records** (ADRs).
|
|
19
|
-
|
|
20
|
-
## Why Decisions Matter
|
|
21
|
-
|
|
22
|
-
Without ADRs, the AI agent sees:
|
|
23
|
-
|
|
24
|
-
- "Database: PostgreSQL" — but doesn't know WHY
|
|
25
|
-
- "Auth: JWT" — but doesn't know what alternatives were considered
|
|
26
|
-
- "Framework: Next.js" — but doesn't know the tradeoffs
|
|
27
|
-
|
|
28
|
-
With ADRs, the agent understands the reasoning and won't accidentally contradict prior decisions.
|
|
29
|
-
|
|
30
|
-
## Commands
|
|
31
|
-
|
|
32
|
-
### Create a Decision
|
|
33
|
-
|
|
34
|
-
When an architectural choice is made during any pipeline stage:
|
|
35
|
-
|
|
36
|
-
1. Auto-increment the decision number
|
|
37
|
-
2. Use the template from `generators/templates/DECISION.md`
|
|
38
|
-
3. Save to `docs/decisions/NNNN-decision-name.md`
|
|
39
|
-
4. Update the Project Graph if the decision affects modules
|
|
40
|
-
|
|
41
|
-
**Naming convention:** `docs/decisions/0001-use-postgresql.md`
|
|
42
|
-
|
|
43
|
-
### Query Decisions
|
|
44
|
-
|
|
45
|
-
Before making changes that touch architecture:
|
|
46
|
-
|
|
47
|
-
1. Check `docs/decisions/` for related decisions
|
|
48
|
-
2. If a decision exists, follow it
|
|
49
|
-
3. If a decision needs to change, create a new ADR that **supersedes** the old one
|
|
50
|
-
|
|
51
|
-
### Decision Lifecycle
|
|
52
|
-
|
|
53
|
-
```
|
|
54
|
-
proposed → accepted → [deprecated | superseded]
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
- **proposed**: Under discussion, not yet committed
|
|
58
|
-
- **accepted**: The team agreed, this is the standard
|
|
59
|
-
- **deprecated**: No longer relevant (project evolved)
|
|
60
|
-
- **superseded**: Replaced by a newer decision (link to it)
|
|
61
|
-
|
|
62
|
-
## Auto-Detection
|
|
63
|
-
|
|
64
|
-
The Decision Engine should suggest creating an ADR when it detects:
|
|
65
|
-
|
|
66
|
-
- A new database/ORM is introduced
|
|
67
|
-
- A new framework is added
|
|
68
|
-
- Authentication strategy changes
|
|
69
|
-
- API versioning approach is chosen
|
|
70
|
-
- Deployment strategy is decided
|
|
71
|
-
- A significant library is added (state management, testing framework, etc.)
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
## Code Examples
|
|
75
|
-
|
|
76
|
-
See `EXAMPLES.md` for detailed code examples.
|
|
77
|
-
|
|
78
|
-
## Validation Checklist
|
|
79
|
-
|
|
80
|
-
What to verify during the review phase before completing the task.
|
|
81
|
-
|
|
82
|
-
## Common Mistakes
|
|
83
|
-
|
|
84
|
-
Anti-patterns and things to explicitly avoid. See `TROUBLESHOOTING.md`.
|
|
85
|
-
|
|
86
|
-
## Integration Notes
|
|
87
|
-
|
|
88
|
-
How this skill interacts with other skills.
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
<!-- Source: EXAMPLES.md -->
|
|
92
|
-
|
|
93
|
-
# decisions Examples — Anti-patterns vs ContextOS Standard
|
|
94
|
-
|
|
95
|
-
## Example 1: Documenting Tech Choices
|
|
96
|
-
|
|
97
|
-
### Anti-pattern: Tribal Knowledge & Undocumented Decisions
|
|
98
|
-
|
|
99
|
-
```text
|
|
100
|
-
"We switched to Redis for session storage last month because Dan said so on Slack."
|
|
101
|
-
Three months later, Dan leaves and nobody knows why the config is set up this way.
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
### Best practice: ContextOS Standard (MADR Architecture Decision Record)
|
|
105
|
-
|
|
106
|
-
```markdown
|
|
107
|
-
# ADR 0003: Use Redis for Distributed Session Storage
|
|
108
|
-
|
|
109
|
-
## Context and Problem Statement
|
|
110
|
-
Our application is transitioning from a single server to horizontally auto-scaled instances.
|
|
111
|
-
Sticky sessions on load balancer cause uneven distribution and drop sessions on node recycling.
|
|
112
|
-
|
|
113
|
-
## Considered Options
|
|
114
|
-
1. PostgreSQL session table
|
|
115
|
-
2. Redis cluster
|
|
116
|
-
3. JWT stateless tokens in cookies
|
|
117
|
-
|
|
118
|
-
## Decision Outcome
|
|
119
|
-
Chosen option: "Redis cluster", because:
|
|
120
|
-
- Sub-millisecond read/write latency compared to relational DB queries.
|
|
121
|
-
- Built-in TTL automatically handles session expiration without cron cleanup.
|
|
122
|
-
- Avoids security risks of client-stored JWT revocation.
|
|
123
|
-
|
|
124
|
-
## Consequences
|
|
125
|
-
- Positive: Stateless web tier, zero session drops on deployment.
|
|
126
|
-
- Negative: Adds operational dependency on Redis cluster infrastructure.
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
<!-- Source: TROUBLESHOOTING.md -->
|
|
130
|
-
|
|
131
|
-
# decisions Troubleshooting & Common Mistakes
|
|
132
|
-
|
|
133
|
-
## 1. Post-Hoc Justifications
|
|
134
|
-
|
|
135
|
-
- **Symptom**: ADR written weeks after code is merged, omitting all rejected options.
|
|
136
|
-
- **Root Cause**: Treating ADRs as paperwork rather than decision-making tools.
|
|
137
|
-
- **Fix**: Write the ADR during the PLAN phase _before_ implementing the decision.
|
|
138
|
-
|
|
139
|
-
## 2. Omitting Trade-offs
|
|
140
|
-
|
|
141
|
-
- **Symptom**: ADR lists only benefits, claiming the chosen tech has zero downsides.
|
|
142
|
-
- **Root Cause**: Confirmation bias.
|
|
143
|
-
- **Fix**: Every architecture decision has costs. Explicitly document negative trade-offs and operational overhead.
|