@zigrivers/scaffold 2.1.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.
- package/LICENSE +21 -0
- package/README.md +477 -0
- package/dist/cli/commands/adopt.d.ts +12 -0
- package/dist/cli/commands/adopt.d.ts.map +1 -0
- package/dist/cli/commands/adopt.js +107 -0
- package/dist/cli/commands/adopt.js.map +1 -0
- package/dist/cli/commands/adopt.test.d.ts +2 -0
- package/dist/cli/commands/adopt.test.d.ts.map +1 -0
- package/dist/cli/commands/adopt.test.js +277 -0
- package/dist/cli/commands/adopt.test.js.map +1 -0
- package/dist/cli/commands/build.d.ts +12 -0
- package/dist/cli/commands/build.d.ts.map +1 -0
- package/dist/cli/commands/build.js +105 -0
- package/dist/cli/commands/build.js.map +1 -0
- package/dist/cli/commands/build.test.d.ts +2 -0
- package/dist/cli/commands/build.test.d.ts.map +1 -0
- package/dist/cli/commands/build.test.js +272 -0
- package/dist/cli/commands/build.test.js.map +1 -0
- package/dist/cli/commands/dashboard.d.ts +14 -0
- package/dist/cli/commands/dashboard.d.ts.map +1 -0
- package/dist/cli/commands/dashboard.js +102 -0
- package/dist/cli/commands/dashboard.js.map +1 -0
- package/dist/cli/commands/dashboard.test.d.ts +2 -0
- package/dist/cli/commands/dashboard.test.d.ts.map +1 -0
- package/dist/cli/commands/dashboard.test.js +142 -0
- package/dist/cli/commands/dashboard.test.js.map +1 -0
- package/dist/cli/commands/decisions.d.ts +13 -0
- package/dist/cli/commands/decisions.d.ts.map +1 -0
- package/dist/cli/commands/decisions.js +62 -0
- package/dist/cli/commands/decisions.js.map +1 -0
- package/dist/cli/commands/decisions.test.d.ts +2 -0
- package/dist/cli/commands/decisions.test.d.ts.map +1 -0
- package/dist/cli/commands/decisions.test.js +154 -0
- package/dist/cli/commands/decisions.test.js.map +1 -0
- package/dist/cli/commands/info.d.ts +12 -0
- package/dist/cli/commands/info.d.ts.map +1 -0
- package/dist/cli/commands/info.js +110 -0
- package/dist/cli/commands/info.js.map +1 -0
- package/dist/cli/commands/info.test.d.ts +2 -0
- package/dist/cli/commands/info.test.d.ts.map +1 -0
- package/dist/cli/commands/info.test.js +392 -0
- package/dist/cli/commands/info.test.js.map +1 -0
- package/dist/cli/commands/init.d.ts +13 -0
- package/dist/cli/commands/init.d.ts.map +1 -0
- package/dist/cli/commands/init.js +46 -0
- package/dist/cli/commands/init.js.map +1 -0
- package/dist/cli/commands/init.test.d.ts +2 -0
- package/dist/cli/commands/init.test.d.ts.map +1 -0
- package/dist/cli/commands/init.test.js +156 -0
- package/dist/cli/commands/init.test.js.map +1 -0
- package/dist/cli/commands/knowledge.d.ts +4 -0
- package/dist/cli/commands/knowledge.d.ts.map +1 -0
- package/dist/cli/commands/knowledge.js +346 -0
- package/dist/cli/commands/knowledge.js.map +1 -0
- package/dist/cli/commands/knowledge.test.d.ts +2 -0
- package/dist/cli/commands/knowledge.test.d.ts.map +1 -0
- package/dist/cli/commands/knowledge.test.js +293 -0
- package/dist/cli/commands/knowledge.test.js.map +1 -0
- package/dist/cli/commands/list.d.ts +12 -0
- package/dist/cli/commands/list.d.ts.map +1 -0
- package/dist/cli/commands/list.js +73 -0
- package/dist/cli/commands/list.js.map +1 -0
- package/dist/cli/commands/list.test.d.ts +2 -0
- package/dist/cli/commands/list.test.d.ts.map +1 -0
- package/dist/cli/commands/list.test.js +166 -0
- package/dist/cli/commands/list.test.js.map +1 -0
- package/dist/cli/commands/next.d.ts +12 -0
- package/dist/cli/commands/next.d.ts.map +1 -0
- package/dist/cli/commands/next.js +75 -0
- package/dist/cli/commands/next.js.map +1 -0
- package/dist/cli/commands/next.test.d.ts +2 -0
- package/dist/cli/commands/next.test.d.ts.map +1 -0
- package/dist/cli/commands/next.test.js +236 -0
- package/dist/cli/commands/next.test.js.map +1 -0
- package/dist/cli/commands/reset.d.ts +13 -0
- package/dist/cli/commands/reset.d.ts.map +1 -0
- package/dist/cli/commands/reset.js +105 -0
- package/dist/cli/commands/reset.js.map +1 -0
- package/dist/cli/commands/reset.test.d.ts +2 -0
- package/dist/cli/commands/reset.test.d.ts.map +1 -0
- package/dist/cli/commands/reset.test.js +211 -0
- package/dist/cli/commands/reset.test.js.map +1 -0
- package/dist/cli/commands/run.d.ts +14 -0
- package/dist/cli/commands/run.d.ts.map +1 -0
- package/dist/cli/commands/run.js +379 -0
- package/dist/cli/commands/run.js.map +1 -0
- package/dist/cli/commands/run.test.d.ts +2 -0
- package/dist/cli/commands/run.test.d.ts.map +1 -0
- package/dist/cli/commands/run.test.js +535 -0
- package/dist/cli/commands/run.test.js.map +1 -0
- package/dist/cli/commands/skip.d.ts +13 -0
- package/dist/cli/commands/skip.d.ts.map +1 -0
- package/dist/cli/commands/skip.js +123 -0
- package/dist/cli/commands/skip.js.map +1 -0
- package/dist/cli/commands/skip.test.d.ts +2 -0
- package/dist/cli/commands/skip.test.d.ts.map +1 -0
- package/dist/cli/commands/skip.test.js +339 -0
- package/dist/cli/commands/skip.test.js.map +1 -0
- package/dist/cli/commands/status.d.ts +12 -0
- package/dist/cli/commands/status.d.ts.map +1 -0
- package/dist/cli/commands/status.js +79 -0
- package/dist/cli/commands/status.js.map +1 -0
- package/dist/cli/commands/status.test.d.ts +2 -0
- package/dist/cli/commands/status.test.d.ts.map +1 -0
- package/dist/cli/commands/status.test.js +245 -0
- package/dist/cli/commands/status.test.js.map +1 -0
- package/dist/cli/commands/update.d.ts +11 -0
- package/dist/cli/commands/update.d.ts.map +1 -0
- package/dist/cli/commands/update.js +159 -0
- package/dist/cli/commands/update.js.map +1 -0
- package/dist/cli/commands/update.test.d.ts +2 -0
- package/dist/cli/commands/update.test.d.ts.map +1 -0
- package/dist/cli/commands/update.test.js +140 -0
- package/dist/cli/commands/update.test.js.map +1 -0
- package/dist/cli/commands/validate.d.ts +12 -0
- package/dist/cli/commands/validate.d.ts.map +1 -0
- package/dist/cli/commands/validate.js +65 -0
- package/dist/cli/commands/validate.js.map +1 -0
- package/dist/cli/commands/validate.test.d.ts +2 -0
- package/dist/cli/commands/validate.test.d.ts.map +1 -0
- package/dist/cli/commands/validate.test.js +159 -0
- package/dist/cli/commands/validate.test.js.map +1 -0
- package/dist/cli/commands/version.d.ts +13 -0
- package/dist/cli/commands/version.d.ts.map +1 -0
- package/dist/cli/commands/version.js +89 -0
- package/dist/cli/commands/version.js.map +1 -0
- package/dist/cli/commands/version.test.d.ts +2 -0
- package/dist/cli/commands/version.test.d.ts.map +1 -0
- package/dist/cli/commands/version.test.js +63 -0
- package/dist/cli/commands/version.test.js.map +1 -0
- package/dist/cli/index.d.ts +4 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +72 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/index.test.d.ts +2 -0
- package/dist/cli/index.test.d.ts.map +1 -0
- package/dist/cli/index.test.js +8 -0
- package/dist/cli/index.test.js.map +1 -0
- package/dist/cli/middleware/output-mode.d.ts +21 -0
- package/dist/cli/middleware/output-mode.d.ts.map +1 -0
- package/dist/cli/middleware/output-mode.js +27 -0
- package/dist/cli/middleware/output-mode.js.map +1 -0
- package/dist/cli/middleware/output-mode.test.d.ts +2 -0
- package/dist/cli/middleware/output-mode.test.d.ts.map +1 -0
- package/dist/cli/middleware/output-mode.test.js +41 -0
- package/dist/cli/middleware/output-mode.test.js.map +1 -0
- package/dist/cli/middleware/project-root.d.ts +21 -0
- package/dist/cli/middleware/project-root.d.ts.map +1 -0
- package/dist/cli/middleware/project-root.js +54 -0
- package/dist/cli/middleware/project-root.js.map +1 -0
- package/dist/cli/middleware/project-root.test.d.ts +2 -0
- package/dist/cli/middleware/project-root.test.d.ts.map +1 -0
- package/dist/cli/middleware/project-root.test.js +112 -0
- package/dist/cli/middleware/project-root.test.js.map +1 -0
- package/dist/cli/output/auto.d.ts +18 -0
- package/dist/cli/output/auto.d.ts.map +1 -0
- package/dist/cli/output/auto.js +43 -0
- package/dist/cli/output/auto.js.map +1 -0
- package/dist/cli/output/context.d.ts +19 -0
- package/dist/cli/output/context.d.ts.map +1 -0
- package/dist/cli/output/context.js +15 -0
- package/dist/cli/output/context.js.map +1 -0
- package/dist/cli/output/context.test.d.ts +2 -0
- package/dist/cli/output/context.test.d.ts.map +1 -0
- package/dist/cli/output/context.test.js +335 -0
- package/dist/cli/output/context.test.js.map +1 -0
- package/dist/cli/output/error-display.d.ts +31 -0
- package/dist/cli/output/error-display.d.ts.map +1 -0
- package/dist/cli/output/error-display.js +79 -0
- package/dist/cli/output/error-display.js.map +1 -0
- package/dist/cli/output/error-display.test.d.ts +2 -0
- package/dist/cli/output/error-display.test.d.ts.map +1 -0
- package/dist/cli/output/error-display.test.js +230 -0
- package/dist/cli/output/error-display.test.js.map +1 -0
- package/dist/cli/output/interactive.d.ts +22 -0
- package/dist/cli/output/interactive.d.ts.map +1 -0
- package/dist/cli/output/interactive.js +126 -0
- package/dist/cli/output/interactive.js.map +1 -0
- package/dist/cli/output/json.d.ts +17 -0
- package/dist/cli/output/json.d.ts.map +1 -0
- package/dist/cli/output/json.js +62 -0
- package/dist/cli/output/json.js.map +1 -0
- package/dist/cli/types.d.ts +11 -0
- package/dist/cli/types.d.ts.map +1 -0
- package/dist/cli/types.js +2 -0
- package/dist/cli/types.js.map +1 -0
- package/dist/config/loader.d.ts +22 -0
- package/dist/config/loader.d.ts.map +1 -0
- package/dist/config/loader.js +159 -0
- package/dist/config/loader.js.map +1 -0
- package/dist/config/loader.test.d.ts +2 -0
- package/dist/config/loader.test.d.ts.map +1 -0
- package/dist/config/loader.test.js +226 -0
- package/dist/config/loader.test.js.map +1 -0
- package/dist/config/migration.d.ts +15 -0
- package/dist/config/migration.d.ts.map +1 -0
- package/dist/config/migration.js +39 -0
- package/dist/config/migration.js.map +1 -0
- package/dist/config/migration.test.d.ts +2 -0
- package/dist/config/migration.test.d.ts.map +1 -0
- package/dist/config/migration.test.js +44 -0
- package/dist/config/migration.test.js.map +1 -0
- package/dist/config/schema.d.ts +121 -0
- package/dist/config/schema.d.ts.map +1 -0
- package/dist/config/schema.js +22 -0
- package/dist/config/schema.js.map +1 -0
- package/dist/config/schema.test.d.ts +2 -0
- package/dist/config/schema.test.d.ts.map +1 -0
- package/dist/config/schema.test.js +126 -0
- package/dist/config/schema.test.js.map +1 -0
- package/dist/core/adapters/adapter.d.ts +64 -0
- package/dist/core/adapters/adapter.d.ts.map +1 -0
- package/dist/core/adapters/adapter.js +25 -0
- package/dist/core/adapters/adapter.js.map +1 -0
- package/dist/core/adapters/adapter.test.d.ts +2 -0
- package/dist/core/adapters/adapter.test.d.ts.map +1 -0
- package/dist/core/adapters/adapter.test.js +175 -0
- package/dist/core/adapters/adapter.test.js.map +1 -0
- package/dist/core/adapters/claude-code.d.ts +9 -0
- package/dist/core/adapters/claude-code.d.ts.map +1 -0
- package/dist/core/adapters/claude-code.js +34 -0
- package/dist/core/adapters/claude-code.js.map +1 -0
- package/dist/core/adapters/claude-code.test.d.ts +2 -0
- package/dist/core/adapters/claude-code.test.d.ts.map +1 -0
- package/dist/core/adapters/claude-code.test.js +100 -0
- package/dist/core/adapters/claude-code.test.js.map +1 -0
- package/dist/core/adapters/codex.d.ts +10 -0
- package/dist/core/adapters/codex.d.ts.map +1 -0
- package/dist/core/adapters/codex.js +61 -0
- package/dist/core/adapters/codex.js.map +1 -0
- package/dist/core/adapters/codex.test.d.ts +2 -0
- package/dist/core/adapters/codex.test.d.ts.map +1 -0
- package/dist/core/adapters/codex.test.js +122 -0
- package/dist/core/adapters/codex.test.js.map +1 -0
- package/dist/core/adapters/universal.d.ts +10 -0
- package/dist/core/adapters/universal.d.ts.map +1 -0
- package/dist/core/adapters/universal.js +45 -0
- package/dist/core/adapters/universal.js.map +1 -0
- package/dist/core/adapters/universal.test.d.ts +2 -0
- package/dist/core/adapters/universal.test.d.ts.map +1 -0
- package/dist/core/adapters/universal.test.js +121 -0
- package/dist/core/adapters/universal.test.js.map +1 -0
- package/dist/core/assembly/context-gatherer.d.ts +17 -0
- package/dist/core/assembly/context-gatherer.d.ts.map +1 -0
- package/dist/core/assembly/context-gatherer.js +49 -0
- package/dist/core/assembly/context-gatherer.js.map +1 -0
- package/dist/core/assembly/context-gatherer.test.d.ts +2 -0
- package/dist/core/assembly/context-gatherer.test.d.ts.map +1 -0
- package/dist/core/assembly/context-gatherer.test.js +252 -0
- package/dist/core/assembly/context-gatherer.test.js.map +1 -0
- package/dist/core/assembly/depth-resolver.d.ts +11 -0
- package/dist/core/assembly/depth-resolver.d.ts.map +1 -0
- package/dist/core/assembly/depth-resolver.js +23 -0
- package/dist/core/assembly/depth-resolver.js.map +1 -0
- package/dist/core/assembly/depth-resolver.test.d.ts +2 -0
- package/dist/core/assembly/depth-resolver.test.d.ts.map +1 -0
- package/dist/core/assembly/depth-resolver.test.js +100 -0
- package/dist/core/assembly/depth-resolver.test.js.map +1 -0
- package/dist/core/assembly/engine.d.ts +22 -0
- package/dist/core/assembly/engine.d.ts.map +1 -0
- package/dist/core/assembly/engine.js +215 -0
- package/dist/core/assembly/engine.js.map +1 -0
- package/dist/core/assembly/engine.test.d.ts +2 -0
- package/dist/core/assembly/engine.test.d.ts.map +1 -0
- package/dist/core/assembly/engine.test.js +462 -0
- package/dist/core/assembly/engine.test.js.map +1 -0
- package/dist/core/assembly/instruction-loader.d.ts +16 -0
- package/dist/core/assembly/instruction-loader.d.ts.map +1 -0
- package/dist/core/assembly/instruction-loader.js +40 -0
- package/dist/core/assembly/instruction-loader.js.map +1 -0
- package/dist/core/assembly/instruction-loader.test.d.ts +2 -0
- package/dist/core/assembly/instruction-loader.test.d.ts.map +1 -0
- package/dist/core/assembly/instruction-loader.test.js +109 -0
- package/dist/core/assembly/instruction-loader.test.js.map +1 -0
- package/dist/core/assembly/knowledge-loader.d.ts +34 -0
- package/dist/core/assembly/knowledge-loader.d.ts.map +1 -0
- package/dist/core/assembly/knowledge-loader.js +204 -0
- package/dist/core/assembly/knowledge-loader.js.map +1 -0
- package/dist/core/assembly/knowledge-loader.test.d.ts +2 -0
- package/dist/core/assembly/knowledge-loader.test.d.ts.map +1 -0
- package/dist/core/assembly/knowledge-loader.test.js +205 -0
- package/dist/core/assembly/knowledge-loader.test.js.map +1 -0
- package/dist/core/assembly/meta-prompt-loader.d.ts +13 -0
- package/dist/core/assembly/meta-prompt-loader.d.ts.map +1 -0
- package/dist/core/assembly/meta-prompt-loader.js +91 -0
- package/dist/core/assembly/meta-prompt-loader.js.map +1 -0
- package/dist/core/assembly/meta-prompt-loader.test.d.ts +2 -0
- package/dist/core/assembly/meta-prompt-loader.test.d.ts.map +1 -0
- package/dist/core/assembly/meta-prompt-loader.test.js +232 -0
- package/dist/core/assembly/meta-prompt-loader.test.js.map +1 -0
- package/dist/core/assembly/methodology-change.d.ts +27 -0
- package/dist/core/assembly/methodology-change.d.ts.map +1 -0
- package/dist/core/assembly/methodology-change.js +41 -0
- package/dist/core/assembly/methodology-change.js.map +1 -0
- package/dist/core/assembly/methodology-change.test.d.ts +2 -0
- package/dist/core/assembly/methodology-change.test.d.ts.map +1 -0
- package/dist/core/assembly/methodology-change.test.js +145 -0
- package/dist/core/assembly/methodology-change.test.js.map +1 -0
- package/dist/core/assembly/methodology-resolver.d.ts +11 -0
- package/dist/core/assembly/methodology-resolver.d.ts.map +1 -0
- package/dist/core/assembly/methodology-resolver.js +19 -0
- package/dist/core/assembly/methodology-resolver.js.map +1 -0
- package/dist/core/assembly/methodology-resolver.test.d.ts +2 -0
- package/dist/core/assembly/methodology-resolver.test.d.ts.map +1 -0
- package/dist/core/assembly/methodology-resolver.test.js +87 -0
- package/dist/core/assembly/methodology-resolver.test.js.map +1 -0
- package/dist/core/assembly/preset-loader.d.ts +26 -0
- package/dist/core/assembly/preset-loader.d.ts.map +1 -0
- package/dist/core/assembly/preset-loader.js +146 -0
- package/dist/core/assembly/preset-loader.js.map +1 -0
- package/dist/core/assembly/preset-loader.test.d.ts +2 -0
- package/dist/core/assembly/preset-loader.test.d.ts.map +1 -0
- package/dist/core/assembly/preset-loader.test.js +107 -0
- package/dist/core/assembly/preset-loader.test.js.map +1 -0
- package/dist/core/assembly/update-mode.d.ts +25 -0
- package/dist/core/assembly/update-mode.d.ts.map +1 -0
- package/dist/core/assembly/update-mode.js +70 -0
- package/dist/core/assembly/update-mode.js.map +1 -0
- package/dist/core/assembly/update-mode.test.d.ts +2 -0
- package/dist/core/assembly/update-mode.test.d.ts.map +1 -0
- package/dist/core/assembly/update-mode.test.js +235 -0
- package/dist/core/assembly/update-mode.test.js.map +1 -0
- package/dist/core/dependency/dependency.d.ts +20 -0
- package/dist/core/dependency/dependency.d.ts.map +1 -0
- package/dist/core/dependency/dependency.js +104 -0
- package/dist/core/dependency/dependency.js.map +1 -0
- package/dist/core/dependency/dependency.test.d.ts +2 -0
- package/dist/core/dependency/dependency.test.d.ts.map +1 -0
- package/dist/core/dependency/dependency.test.js +166 -0
- package/dist/core/dependency/dependency.test.js.map +1 -0
- package/dist/core/dependency/eligibility.d.ts +17 -0
- package/dist/core/dependency/eligibility.d.ts.map +1 -0
- package/dist/core/dependency/eligibility.js +60 -0
- package/dist/core/dependency/eligibility.js.map +1 -0
- package/dist/core/dependency/eligibility.test.d.ts +2 -0
- package/dist/core/dependency/eligibility.test.d.ts.map +1 -0
- package/dist/core/dependency/eligibility.test.js +198 -0
- package/dist/core/dependency/eligibility.test.js.map +1 -0
- package/dist/core/dependency/graph.d.ts +12 -0
- package/dist/core/dependency/graph.d.ts.map +1 -0
- package/dist/core/dependency/graph.js +34 -0
- package/dist/core/dependency/graph.js.map +1 -0
- package/dist/core/knowledge/knowledge-update-assembler.d.ts +24 -0
- package/dist/core/knowledge/knowledge-update-assembler.d.ts.map +1 -0
- package/dist/core/knowledge/knowledge-update-assembler.js +46 -0
- package/dist/core/knowledge/knowledge-update-assembler.js.map +1 -0
- package/dist/core/knowledge/knowledge-update-assembler.test.d.ts +2 -0
- package/dist/core/knowledge/knowledge-update-assembler.test.d.ts.map +1 -0
- package/dist/core/knowledge/knowledge-update-assembler.test.js +93 -0
- package/dist/core/knowledge/knowledge-update-assembler.test.js.map +1 -0
- package/dist/core/knowledge/knowledge-update-template.md +55 -0
- package/dist/dashboard/generator.d.ts +37 -0
- package/dist/dashboard/generator.d.ts.map +1 -0
- package/dist/dashboard/generator.js +42 -0
- package/dist/dashboard/generator.js.map +1 -0
- package/dist/dashboard/generator.test.d.ts +2 -0
- package/dist/dashboard/generator.test.d.ts.map +1 -0
- package/dist/dashboard/generator.test.js +186 -0
- package/dist/dashboard/generator.test.js.map +1 -0
- package/dist/dashboard/template.d.ts +4 -0
- package/dist/dashboard/template.d.ts.map +1 -0
- package/dist/dashboard/template.js +190 -0
- package/dist/dashboard/template.js.map +1 -0
- package/dist/e2e/commands.test.d.ts +9 -0
- package/dist/e2e/commands.test.d.ts.map +1 -0
- package/dist/e2e/commands.test.js +499 -0
- package/dist/e2e/commands.test.js.map +1 -0
- package/dist/e2e/init.test.d.ts +10 -0
- package/dist/e2e/init.test.d.ts.map +1 -0
- package/dist/e2e/init.test.js +180 -0
- package/dist/e2e/init.test.js.map +1 -0
- package/dist/e2e/knowledge.test.d.ts +2 -0
- package/dist/e2e/knowledge.test.d.ts.map +1 -0
- package/dist/e2e/knowledge.test.js +103 -0
- package/dist/e2e/knowledge.test.js.map +1 -0
- package/dist/e2e/pipeline.test.d.ts +8 -0
- package/dist/e2e/pipeline.test.d.ts.map +1 -0
- package/dist/e2e/pipeline.test.js +295 -0
- package/dist/e2e/pipeline.test.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/project/adopt.d.ts +28 -0
- package/dist/project/adopt.d.ts.map +1 -0
- package/dist/project/adopt.js +49 -0
- package/dist/project/adopt.js.map +1 -0
- package/dist/project/adopt.test.d.ts +2 -0
- package/dist/project/adopt.test.d.ts.map +1 -0
- package/dist/project/adopt.test.js +220 -0
- package/dist/project/adopt.test.js.map +1 -0
- package/dist/project/claude-md.d.ts +33 -0
- package/dist/project/claude-md.d.ts.map +1 -0
- package/dist/project/claude-md.js +112 -0
- package/dist/project/claude-md.js.map +1 -0
- package/dist/project/claude-md.test.d.ts +2 -0
- package/dist/project/claude-md.test.d.ts.map +1 -0
- package/dist/project/claude-md.test.js +151 -0
- package/dist/project/claude-md.test.js.map +1 -0
- package/dist/project/detector.d.ts +7 -0
- package/dist/project/detector.d.ts.map +1 -0
- package/dist/project/detector.js +78 -0
- package/dist/project/detector.js.map +1 -0
- package/dist/project/detector.test.d.ts +2 -0
- package/dist/project/detector.test.d.ts.map +1 -0
- package/dist/project/detector.test.js +137 -0
- package/dist/project/detector.test.js.map +1 -0
- package/dist/project/frontmatter.d.ts +17 -0
- package/dist/project/frontmatter.d.ts.map +1 -0
- package/dist/project/frontmatter.js +236 -0
- package/dist/project/frontmatter.js.map +1 -0
- package/dist/project/frontmatter.test.d.ts +2 -0
- package/dist/project/frontmatter.test.d.ts.map +1 -0
- package/dist/project/frontmatter.test.js +218 -0
- package/dist/project/frontmatter.test.js.map +1 -0
- package/dist/project/signals.d.ts +12 -0
- package/dist/project/signals.d.ts.map +1 -0
- package/dist/project/signals.js +2 -0
- package/dist/project/signals.js.map +1 -0
- package/dist/state/completion.d.ts +22 -0
- package/dist/state/completion.d.ts.map +1 -0
- package/dist/state/completion.js +82 -0
- package/dist/state/completion.js.map +1 -0
- package/dist/state/completion.test.d.ts +2 -0
- package/dist/state/completion.test.d.ts.map +1 -0
- package/dist/state/completion.test.js +246 -0
- package/dist/state/completion.test.js.map +1 -0
- package/dist/state/decision-logger.d.ts +16 -0
- package/dist/state/decision-logger.d.ts.map +1 -0
- package/dist/state/decision-logger.js +80 -0
- package/dist/state/decision-logger.js.map +1 -0
- package/dist/state/decision-logger.test.d.ts +2 -0
- package/dist/state/decision-logger.test.d.ts.map +1 -0
- package/dist/state/decision-logger.test.js +182 -0
- package/dist/state/decision-logger.test.js.map +1 -0
- package/dist/state/lock-manager.d.ts +18 -0
- package/dist/state/lock-manager.d.ts.map +1 -0
- package/dist/state/lock-manager.js +134 -0
- package/dist/state/lock-manager.js.map +1 -0
- package/dist/state/lock-manager.test.d.ts +2 -0
- package/dist/state/lock-manager.test.d.ts.map +1 -0
- package/dist/state/lock-manager.test.js +190 -0
- package/dist/state/lock-manager.test.js.map +1 -0
- package/dist/state/state-manager.d.ts +37 -0
- package/dist/state/state-manager.d.ts.map +1 -0
- package/dist/state/state-manager.js +125 -0
- package/dist/state/state-manager.js.map +1 -0
- package/dist/state/state-manager.test.d.ts +2 -0
- package/dist/state/state-manager.test.d.ts.map +1 -0
- package/dist/state/state-manager.test.js +240 -0
- package/dist/state/state-manager.test.js.map +1 -0
- package/dist/types/adapter.d.ts +24 -0
- package/dist/types/adapter.d.ts.map +1 -0
- package/dist/types/adapter.js +2 -0
- package/dist/types/adapter.js.map +1 -0
- package/dist/types/assembly.d.ts +89 -0
- package/dist/types/assembly.d.ts.map +1 -0
- package/dist/types/assembly.js +2 -0
- package/dist/types/assembly.js.map +1 -0
- package/dist/types/claude-md.d.ts +11 -0
- package/dist/types/claude-md.d.ts.map +1 -0
- package/dist/types/claude-md.js +2 -0
- package/dist/types/claude-md.js.map +1 -0
- package/dist/types/cli.d.ts +15 -0
- package/dist/types/cli.d.ts.map +1 -0
- package/dist/types/cli.js +2 -0
- package/dist/types/cli.js.map +1 -0
- package/dist/types/config.d.ts +40 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/config.js +2 -0
- package/dist/types/config.js.map +1 -0
- package/dist/types/decision.d.ts +14 -0
- package/dist/types/decision.d.ts.map +1 -0
- package/dist/types/decision.js +2 -0
- package/dist/types/decision.js.map +1 -0
- package/dist/types/dependency.d.ts +12 -0
- package/dist/types/dependency.d.ts.map +1 -0
- package/dist/types/dependency.js +2 -0
- package/dist/types/dependency.js.map +1 -0
- package/dist/types/enums.d.ts +23 -0
- package/dist/types/enums.d.ts.map +1 -0
- package/dist/types/enums.js +11 -0
- package/dist/types/enums.js.map +1 -0
- package/dist/types/enums.test.d.ts +2 -0
- package/dist/types/enums.test.d.ts.map +1 -0
- package/dist/types/enums.test.js +13 -0
- package/dist/types/enums.test.js.map +1 -0
- package/dist/types/errors.d.ts +24 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/errors.js +2 -0
- package/dist/types/errors.js.map +1 -0
- package/dist/types/frontmatter.d.ts +43 -0
- package/dist/types/frontmatter.d.ts.map +1 -0
- package/dist/types/frontmatter.js +2 -0
- package/dist/types/frontmatter.js.map +1 -0
- package/dist/types/index.d.ts +14 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +14 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/lock.d.ts +10 -0
- package/dist/types/lock.d.ts.map +1 -0
- package/dist/types/lock.js +2 -0
- package/dist/types/lock.js.map +1 -0
- package/dist/types/state.d.ts +49 -0
- package/dist/types/state.d.ts.map +1 -0
- package/dist/types/state.js +2 -0
- package/dist/types/state.js.map +1 -0
- package/dist/types/wizard.d.ts +14 -0
- package/dist/types/wizard.d.ts.map +1 -0
- package/dist/types/wizard.js +2 -0
- package/dist/types/wizard.js.map +1 -0
- package/dist/utils/errors.d.ts +42 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +232 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/errors.test.d.ts +2 -0
- package/dist/utils/errors.test.d.ts.map +1 -0
- package/dist/utils/errors.test.js +91 -0
- package/dist/utils/errors.test.js.map +1 -0
- package/dist/utils/fs.d.ts +11 -0
- package/dist/utils/fs.d.ts.map +1 -0
- package/dist/utils/fs.js +20 -0
- package/dist/utils/fs.js.map +1 -0
- package/dist/utils/fs.test.d.ts +2 -0
- package/dist/utils/fs.test.d.ts.map +1 -0
- package/dist/utils/fs.test.js +93 -0
- package/dist/utils/fs.test.js.map +1 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +4 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/levenshtein.d.ts +11 -0
- package/dist/utils/levenshtein.d.ts.map +1 -0
- package/dist/utils/levenshtein.js +37 -0
- package/dist/utils/levenshtein.js.map +1 -0
- package/dist/utils/levenshtein.test.d.ts +2 -0
- package/dist/utils/levenshtein.test.d.ts.map +1 -0
- package/dist/utils/levenshtein.test.js +34 -0
- package/dist/utils/levenshtein.test.js.map +1 -0
- package/dist/validation/config-validator.d.ts +10 -0
- package/dist/validation/config-validator.d.ts.map +1 -0
- package/dist/validation/config-validator.js +11 -0
- package/dist/validation/config-validator.js.map +1 -0
- package/dist/validation/dependency-validator.d.ts +10 -0
- package/dist/validation/dependency-validator.d.ts.map +1 -0
- package/dist/validation/dependency-validator.js +34 -0
- package/dist/validation/dependency-validator.js.map +1 -0
- package/dist/validation/frontmatter-validator.d.ts +12 -0
- package/dist/validation/frontmatter-validator.d.ts.map +1 -0
- package/dist/validation/frontmatter-validator.js +50 -0
- package/dist/validation/frontmatter-validator.js.map +1 -0
- package/dist/validation/index.d.ts +19 -0
- package/dist/validation/index.d.ts.map +1 -0
- package/dist/validation/index.js +64 -0
- package/dist/validation/index.js.map +1 -0
- package/dist/validation/index.test.d.ts +2 -0
- package/dist/validation/index.test.d.ts.map +1 -0
- package/dist/validation/index.test.js +241 -0
- package/dist/validation/index.test.js.map +1 -0
- package/dist/validation/state-validator.d.ts +15 -0
- package/dist/validation/state-validator.d.ts.map +1 -0
- package/dist/validation/state-validator.js +104 -0
- package/dist/validation/state-validator.js.map +1 -0
- package/dist/wizard/questions.d.ts +18 -0
- package/dist/wizard/questions.d.ts.map +1 -0
- package/dist/wizard/questions.js +46 -0
- package/dist/wizard/questions.js.map +1 -0
- package/dist/wizard/suggestion.d.ts +10 -0
- package/dist/wizard/suggestion.d.ts.map +1 -0
- package/dist/wizard/suggestion.js +17 -0
- package/dist/wizard/suggestion.js.map +1 -0
- package/dist/wizard/wizard.d.ts +19 -0
- package/dist/wizard/wizard.d.ts.map +1 -0
- package/dist/wizard/wizard.js +104 -0
- package/dist/wizard/wizard.js.map +1 -0
- package/dist/wizard/wizard.test.d.ts +2 -0
- package/dist/wizard/wizard.test.d.ts.map +1 -0
- package/dist/wizard/wizard.test.js +167 -0
- package/dist/wizard/wizard.test.js.map +1 -0
- package/knowledge/core/adr-craft.md +281 -0
- package/knowledge/core/api-design.md +501 -0
- package/knowledge/core/database-design.md +380 -0
- package/knowledge/core/domain-modeling.md +317 -0
- package/knowledge/core/operations-runbook.md +513 -0
- package/knowledge/core/security-review.md +523 -0
- package/knowledge/core/system-architecture.md +402 -0
- package/knowledge/core/task-decomposition.md +372 -0
- package/knowledge/core/testing-strategy.md +409 -0
- package/knowledge/core/user-stories.md +337 -0
- package/knowledge/core/user-story-innovation.md +171 -0
- package/knowledge/core/ux-specification.md +380 -0
- package/knowledge/finalization/apply-fixes-and-freeze.md +93 -0
- package/knowledge/finalization/developer-onboarding.md +376 -0
- package/knowledge/finalization/implementation-playbook.md +404 -0
- package/knowledge/product/gap-analysis.md +305 -0
- package/knowledge/product/prd-craft.md +324 -0
- package/knowledge/product/prd-innovation.md +204 -0
- package/knowledge/review/review-adr.md +203 -0
- package/knowledge/review/review-api-contracts.md +233 -0
- package/knowledge/review/review-database-schema.md +229 -0
- package/knowledge/review/review-domain-modeling.md +288 -0
- package/knowledge/review/review-implementation-tasks.md +202 -0
- package/knowledge/review/review-methodology.md +215 -0
- package/knowledge/review/review-operations.md +212 -0
- package/knowledge/review/review-prd.md +235 -0
- package/knowledge/review/review-security.md +213 -0
- package/knowledge/review/review-system-architecture.md +296 -0
- package/knowledge/review/review-testing-strategy.md +176 -0
- package/knowledge/review/review-user-stories.md +172 -0
- package/knowledge/review/review-ux-spec.md +208 -0
- package/knowledge/validation/critical-path-analysis.md +203 -0
- package/knowledge/validation/cross-phase-consistency.md +181 -0
- package/knowledge/validation/decision-completeness.md +218 -0
- package/knowledge/validation/dependency-validation.md +233 -0
- package/knowledge/validation/implementability-review.md +252 -0
- package/knowledge/validation/scope-management.md +223 -0
- package/knowledge/validation/traceability.md +198 -0
- package/methodology/custom-defaults.yml +43 -0
- package/methodology/deep.yml +42 -0
- package/methodology/mvp.yml +42 -0
- package/package.json +58 -0
- package/pipeline/architecture/review-architecture.md +44 -0
- package/pipeline/architecture/system-architecture.md +45 -0
- package/pipeline/decisions/adrs.md +45 -0
- package/pipeline/decisions/review-adrs.md +39 -0
- package/pipeline/finalization/apply-fixes-and-freeze.md +39 -0
- package/pipeline/finalization/developer-onboarding-guide.md +36 -0
- package/pipeline/finalization/implementation-playbook.md +45 -0
- package/pipeline/modeling/domain-modeling.md +57 -0
- package/pipeline/modeling/review-domain-modeling.md +41 -0
- package/pipeline/planning/implementation-tasks.md +57 -0
- package/pipeline/planning/review-tasks.md +38 -0
- package/pipeline/pre/create-prd.md +45 -0
- package/pipeline/pre/innovate-prd.md +47 -0
- package/pipeline/pre/innovate-user-stories.md +47 -0
- package/pipeline/pre/review-prd.md +44 -0
- package/pipeline/pre/review-user-stories.md +43 -0
- package/pipeline/pre/user-stories.md +48 -0
- package/pipeline/quality/operations.md +42 -0
- package/pipeline/quality/review-operations.md +37 -0
- package/pipeline/quality/review-security.md +40 -0
- package/pipeline/quality/review-testing.md +39 -0
- package/pipeline/quality/security.md +44 -0
- package/pipeline/quality/testing-strategy.md +42 -0
- package/pipeline/specification/api-contracts.md +44 -0
- package/pipeline/specification/database-schema.md +41 -0
- package/pipeline/specification/review-api.md +40 -0
- package/pipeline/specification/review-database.md +39 -0
- package/pipeline/specification/review-ux.md +38 -0
- package/pipeline/specification/ux-spec.md +43 -0
- package/pipeline/validation/critical-path-walkthrough.md +37 -0
- package/pipeline/validation/cross-phase-consistency.md +35 -0
- package/pipeline/validation/decision-completeness.md +36 -0
- package/pipeline/validation/dependency-graph-validation.md +36 -0
- package/pipeline/validation/implementability-dry-run.md +36 -0
- package/pipeline/validation/scope-creep-check.md +38 -0
- package/pipeline/validation/traceability-matrix.md +36 -0
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: database-design
|
|
3
|
+
description: Database schema design, normalization, indexing, and migration patterns
|
|
4
|
+
topics: [database, schema, sql, nosql, migrations, indexing, data-modeling]
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## From Domain Models to Schema
|
|
8
|
+
|
|
9
|
+
The domain model defines what the business cares about. The database schema defines how that information is stored. The mapping between them is deliberate, not automatic.
|
|
10
|
+
|
|
11
|
+
### Mapping Entities to Tables
|
|
12
|
+
|
|
13
|
+
Each entity in the domain model typically maps to a database table. The entity's attributes become columns. The entity's identity becomes the primary key.
|
|
14
|
+
|
|
15
|
+
**Identity columns:**
|
|
16
|
+
|
|
17
|
+
- **UUID/ULID:** Best for distributed systems, no coordination needed. ULIDs add time-ordering which helps with index locality. Use `uuid` or `text` column type.
|
|
18
|
+
- **Auto-increment integer:** Simpler, smaller, faster joins. Leaks information (total count, creation order). Requires a single sequence source.
|
|
19
|
+
- **Natural key:** Use the business identifier if one exists and is truly immutable (ISBN, country code). Rarely appropriate for mutable business concepts.
|
|
20
|
+
|
|
21
|
+
**Recommendation:** Default to UUIDs for new projects. They work everywhere, don't leak information, and avoid coordination issues in multi-agent development (two agents can create records simultaneously without ID conflicts).
|
|
22
|
+
|
|
23
|
+
### Handling Aggregates
|
|
24
|
+
|
|
25
|
+
An aggregate's internal structure doesn't necessarily map to a single table. Common patterns:
|
|
26
|
+
|
|
27
|
+
**Single table per aggregate** — When the aggregate is simple (root entity + value objects), store everything in one table with column groups or JSON columns for value objects.
|
|
28
|
+
|
|
29
|
+
```sql
|
|
30
|
+
CREATE TABLE orders (
|
|
31
|
+
id UUID PRIMARY KEY,
|
|
32
|
+
customer_id UUID NOT NULL REFERENCES customers(id),
|
|
33
|
+
status TEXT NOT NULL DEFAULT 'draft',
|
|
34
|
+
-- Shipping address (value object) stored as columns
|
|
35
|
+
shipping_street TEXT,
|
|
36
|
+
shipping_city TEXT,
|
|
37
|
+
shipping_state TEXT,
|
|
38
|
+
shipping_zip TEXT,
|
|
39
|
+
shipping_country TEXT,
|
|
40
|
+
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
|
41
|
+
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
|
42
|
+
);
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
**Multiple tables per aggregate** — When the aggregate has internal entities (e.g., Order with OrderLines), use a parent table and child tables. The child table's foreign key to the parent enforces the aggregate boundary.
|
|
46
|
+
|
|
47
|
+
```sql
|
|
48
|
+
CREATE TABLE order_lines (
|
|
49
|
+
id UUID PRIMARY KEY,
|
|
50
|
+
order_id UUID NOT NULL REFERENCES orders(id) ON DELETE CASCADE,
|
|
51
|
+
product_id UUID NOT NULL REFERENCES products(id),
|
|
52
|
+
quantity INTEGER NOT NULL CHECK (quantity > 0),
|
|
53
|
+
unit_price_cents INTEGER NOT NULL CHECK (unit_price_cents >= 0),
|
|
54
|
+
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
|
55
|
+
);
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
The `ON DELETE CASCADE` expresses that order lines have no lifecycle independent of their order — they're internal to the aggregate.
|
|
59
|
+
|
|
60
|
+
### Representing Value Objects
|
|
61
|
+
|
|
62
|
+
Value objects have no identity. Storage options:
|
|
63
|
+
|
|
64
|
+
**Embedded columns** — Store the value object's attributes as columns in the parent entity's table. Best when the value object is always loaded with the entity.
|
|
65
|
+
|
|
66
|
+
```sql
|
|
67
|
+
-- Money value object embedded in order_lines
|
|
68
|
+
unit_price_cents INTEGER NOT NULL,
|
|
69
|
+
unit_price_currency TEXT NOT NULL DEFAULT 'USD'
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
**JSON/JSONB column** — Store the value object as a JSON document. Best when the value object is complex, rarely queried directly, or has a variable structure.
|
|
73
|
+
|
|
74
|
+
```sql
|
|
75
|
+
metadata JSONB NOT NULL DEFAULT '{}'
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
**Lookup table** — Store value objects with limited valid values in a reference table. Best for enums with associated data (status codes with descriptions, country codes with names).
|
|
79
|
+
|
|
80
|
+
### Modeling Relationships
|
|
81
|
+
|
|
82
|
+
**One-to-one:** Use a foreign key in either table (typically the dependent side). Consider: could this be columns in the same table instead?
|
|
83
|
+
|
|
84
|
+
**One-to-many:** Foreign key on the "many" side referencing the "one" side. The most common relationship type.
|
|
85
|
+
|
|
86
|
+
**Many-to-many:** Junction table with two foreign keys. Include created_at to track when the relationship was established. Consider whether the junction table needs its own identity (entity) or is purely a relationship (value).
|
|
87
|
+
|
|
88
|
+
```sql
|
|
89
|
+
-- Junction table for many-to-many
|
|
90
|
+
CREATE TABLE user_roles (
|
|
91
|
+
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
|
92
|
+
role_id UUID NOT NULL REFERENCES roles(id) ON DELETE CASCADE,
|
|
93
|
+
granted_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
|
94
|
+
granted_by UUID REFERENCES users(id),
|
|
95
|
+
PRIMARY KEY (user_id, role_id)
|
|
96
|
+
);
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
**Self-referencing:** An entity that relates to other instances of itself (organizational hierarchy, comment threads, category trees). Use a nullable foreign key to the same table.
|
|
100
|
+
|
|
101
|
+
```sql
|
|
102
|
+
CREATE TABLE categories (
|
|
103
|
+
id UUID PRIMARY KEY,
|
|
104
|
+
name TEXT NOT NULL,
|
|
105
|
+
parent_id UUID REFERENCES categories(id) ON DELETE SET NULL,
|
|
106
|
+
sort_order INTEGER NOT NULL DEFAULT 0
|
|
107
|
+
);
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Normalization Decisions
|
|
111
|
+
|
|
112
|
+
### Normal Forms in Practice
|
|
113
|
+
|
|
114
|
+
**First normal form (1NF):** Each column holds atomic values (no arrays, no comma-separated lists). In SQL databases, this is usually enforced by the type system. Exception: PostgreSQL arrays and JSON columns deliberately violate 1NF for good reasons.
|
|
115
|
+
|
|
116
|
+
**Second normal form (2NF):** Every non-key column depends on the entire primary key, not just part of it. Violations typically appear in tables with composite primary keys.
|
|
117
|
+
|
|
118
|
+
**Third normal form (3NF):** Every non-key column depends on the primary key, not on another non-key column. Example violation: storing both `zip_code` and `city` when city is determined by zip code.
|
|
119
|
+
|
|
120
|
+
**Practical rule:** Normalize to 3NF by default. Denormalize deliberately with documented rationale.
|
|
121
|
+
|
|
122
|
+
### When to Denormalize
|
|
123
|
+
|
|
124
|
+
Denormalization trades data integrity for read performance. Only do it when:
|
|
125
|
+
|
|
126
|
+
- You have measured a performance problem (not assumed one)
|
|
127
|
+
- The read-to-write ratio strongly favors reads (>10:1)
|
|
128
|
+
- The denormalized data has a clear update strategy (triggers, application logic, async sync)
|
|
129
|
+
- The inconsistency window is acceptable for the use case
|
|
130
|
+
|
|
131
|
+
**Common denormalization patterns:**
|
|
132
|
+
|
|
133
|
+
**Computed columns:** Store a calculated value (order total, item count, average rating) instead of computing it on every read.
|
|
134
|
+
|
|
135
|
+
```sql
|
|
136
|
+
ALTER TABLE orders ADD COLUMN total_cents INTEGER;
|
|
137
|
+
-- Updated by application logic when order lines change
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
**Duplicated attributes:** Copy frequently-joined data into the table that reads it. Store `customer_name` in the orders table to avoid joining to customers on every order list query.
|
|
141
|
+
|
|
142
|
+
**Materialized views / read models:** Create a dedicated read-optimized table (or materialized view) that denormalizes across multiple source tables. Updated asynchronously when source data changes.
|
|
143
|
+
|
|
144
|
+
### Read Model vs. Write Model Separation
|
|
145
|
+
|
|
146
|
+
In complex domains, the shape of data for writing (enforcing invariants) differs from the shape for reading (displaying to users). Separating these concerns:
|
|
147
|
+
|
|
148
|
+
- **Write model:** Normalized, invariant-enforcing, aggregate-aligned. Optimized for correctness.
|
|
149
|
+
- **Read model:** Denormalized, query-optimized, possibly pre-aggregated. Optimized for speed.
|
|
150
|
+
|
|
151
|
+
This doesn't require full CQRS — it can be as simple as a materialized view or a denormalized table refreshed by triggers.
|
|
152
|
+
|
|
153
|
+
## Indexing Strategy
|
|
154
|
+
|
|
155
|
+
### Primary Keys
|
|
156
|
+
|
|
157
|
+
Every table must have a primary key. The primary key automatically gets a unique index.
|
|
158
|
+
|
|
159
|
+
- Use UUID or ULID for application-generated IDs
|
|
160
|
+
- Use `SERIAL`/`BIGSERIAL` only for internal sequences (migration version numbers, internal counters)
|
|
161
|
+
- Composite primary keys are appropriate for junction tables; avoid them for entity tables
|
|
162
|
+
|
|
163
|
+
### Foreign Keys
|
|
164
|
+
|
|
165
|
+
Every foreign key should reference a primary key or unique constraint on the target table. Foreign keys automatically enforce referential integrity.
|
|
166
|
+
|
|
167
|
+
**Cascade behavior decisions:**
|
|
168
|
+
|
|
169
|
+
- `ON DELETE CASCADE` — When the parent is deleted, delete the children. Appropriate for aggregate internals (order lines deleted with order).
|
|
170
|
+
- `ON DELETE SET NULL` — When the parent is deleted, null out the reference. Appropriate for optional relationships.
|
|
171
|
+
- `ON DELETE RESTRICT` (default) — Prevent parent deletion if children exist. Appropriate when orphaned children would be a data integrity problem.
|
|
172
|
+
|
|
173
|
+
Foreign key columns should almost always be indexed. Without an index, any operation on the parent table requires a full scan of the child table to check for references.
|
|
174
|
+
|
|
175
|
+
### Covering Indexes
|
|
176
|
+
|
|
177
|
+
A covering index contains all columns needed to satisfy a query, eliminating the need to access the table's heap. Useful for frequently-executed queries with predictable column access patterns.
|
|
178
|
+
|
|
179
|
+
```sql
|
|
180
|
+
-- Covers: SELECT id, status, created_at FROM orders WHERE customer_id = ? ORDER BY created_at DESC
|
|
181
|
+
CREATE INDEX idx_orders_customer_status ON orders (customer_id, created_at DESC)
|
|
182
|
+
INCLUDE (status);
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Partial Indexes
|
|
186
|
+
|
|
187
|
+
An index on a subset of rows, defined by a WHERE clause. Smaller, faster, and more specific than a full-table index.
|
|
188
|
+
|
|
189
|
+
```sql
|
|
190
|
+
-- Only index active subscriptions (most queries filter for active)
|
|
191
|
+
CREATE INDEX idx_active_subscriptions ON subscriptions (user_id, plan_id)
|
|
192
|
+
WHERE status = 'active';
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### Composite Indexes
|
|
196
|
+
|
|
197
|
+
Multi-column indexes follow the "leftmost prefix" rule: the index on `(a, b, c)` can satisfy queries filtering on `a`, `a + b`, or `a + b + c`, but not `b` or `c` alone.
|
|
198
|
+
|
|
199
|
+
**Column order matters:** Put the most selective column first (the one that eliminates the most rows). For range queries, put the equality column first, then the range column.
|
|
200
|
+
|
|
201
|
+
```sql
|
|
202
|
+
-- For queries: WHERE tenant_id = ? AND created_at > ?
|
|
203
|
+
-- tenant_id (equality) comes before created_at (range)
|
|
204
|
+
CREATE INDEX idx_events_tenant_date ON events (tenant_id, created_at);
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
### Deriving Index Needs from Query Patterns
|
|
208
|
+
|
|
209
|
+
Before creating indexes, enumerate the application's query patterns:
|
|
210
|
+
|
|
211
|
+
| Query | Used By | Frequency | Current Performance |
|
|
212
|
+
|-------|---------|-----------|-------------------|
|
|
213
|
+
| Orders by customer, newest first | Order list page | High | Needs index |
|
|
214
|
+
| Active subscriptions by user | Auth middleware | Every request | Critical path |
|
|
215
|
+
| Products by category with price range | Browse page | High | Needs composite index |
|
|
216
|
+
|
|
217
|
+
Create indexes to cover the high-frequency and critical-path queries. Resist creating indexes for every possible query — each index slows down writes and consumes storage.
|
|
218
|
+
|
|
219
|
+
### Index Anti-Patterns
|
|
220
|
+
|
|
221
|
+
- **Over-indexing:** An index for every column. Slows writes, wastes storage, confuses the query planner.
|
|
222
|
+
- **Redundant indexes:** An index on `(a)` when an index on `(a, b)` already exists. The composite index covers single-column queries on `a`.
|
|
223
|
+
- **Unused indexes:** Indexes created during development that no query uses. Audit with `pg_stat_user_indexes` (PostgreSQL) or equivalent.
|
|
224
|
+
|
|
225
|
+
## Constraint Design
|
|
226
|
+
|
|
227
|
+
### CHECK Constraints from Domain Invariants
|
|
228
|
+
|
|
229
|
+
Every domain invariant that can be expressed as a column-level or row-level constraint should be:
|
|
230
|
+
|
|
231
|
+
```sql
|
|
232
|
+
-- Domain invariant: quantity must be positive
|
|
233
|
+
quantity INTEGER NOT NULL CHECK (quantity > 0)
|
|
234
|
+
|
|
235
|
+
-- Domain invariant: end date must be after start date
|
|
236
|
+
CHECK (end_date > start_date)
|
|
237
|
+
|
|
238
|
+
-- Domain invariant: status must be one of defined values
|
|
239
|
+
status TEXT NOT NULL CHECK (status IN ('draft', 'active', 'suspended', 'cancelled'))
|
|
240
|
+
|
|
241
|
+
-- Domain invariant: discount percentage between 0 and 100
|
|
242
|
+
discount_percent NUMERIC NOT NULL CHECK (discount_percent >= 0 AND discount_percent <= 100)
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
### Unique Constraints from Business Rules
|
|
246
|
+
|
|
247
|
+
Business rules that require uniqueness should be enforced at the database level, not just the application level:
|
|
248
|
+
|
|
249
|
+
```sql
|
|
250
|
+
-- Business rule: email must be unique per tenant
|
|
251
|
+
ALTER TABLE users ADD CONSTRAINT uq_users_tenant_email
|
|
252
|
+
UNIQUE (tenant_id, email);
|
|
253
|
+
|
|
254
|
+
-- Business rule: only one active subscription per user
|
|
255
|
+
CREATE UNIQUE INDEX uq_one_active_sub ON subscriptions (user_id)
|
|
256
|
+
WHERE status = 'active';
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
### Foreign Key Constraints from Relationships
|
|
260
|
+
|
|
261
|
+
Every relationship in the domain model should have a corresponding foreign key constraint. Unconstrained references allow orphaned data.
|
|
262
|
+
|
|
263
|
+
### NOT NULL Discipline
|
|
264
|
+
|
|
265
|
+
Default to `NOT NULL` for every column. Allow NULL only when the domain explicitly models the absence of a value (e.g., "user has not set a phone number"). If NULL is allowed, document what it means.
|
|
266
|
+
|
|
267
|
+
**Anti-pattern: NULL as a default.** Columns that allow NULL because nobody thought about whether the value is optional. This leads to unexpected NULLs propagating through queries and application logic.
|
|
268
|
+
|
|
269
|
+
## Migration Patterns
|
|
270
|
+
|
|
271
|
+
### Schema Versioning
|
|
272
|
+
|
|
273
|
+
Every schema change is a migration with a unique version identifier. Migrations are ordered and applied sequentially. Common approaches:
|
|
274
|
+
|
|
275
|
+
- **Timestamp-based:** `20260314120000_create_users.sql` — prevents ordering conflicts between developers
|
|
276
|
+
- **Sequential:** `001_create_users.sql`, `002_add_orders.sql` — simpler but conflicts when two developers create the next migration simultaneously
|
|
277
|
+
|
|
278
|
+
### Backwards-Compatible Migrations
|
|
279
|
+
|
|
280
|
+
Migrations that can be applied without breaking the running application:
|
|
281
|
+
|
|
282
|
+
**Safe operations:**
|
|
283
|
+
- Adding a column with a default value or allowing NULL
|
|
284
|
+
- Adding a new table
|
|
285
|
+
- Adding an index (CONCURRENTLY in PostgreSQL)
|
|
286
|
+
- Adding a CHECK constraint (NOT VALID initially, then VALIDATE separately)
|
|
287
|
+
|
|
288
|
+
**Unsafe operations (require coordination):**
|
|
289
|
+
- Dropping a column (application may still reference it)
|
|
290
|
+
- Renaming a column (breaks existing queries)
|
|
291
|
+
- Changing a column type (may fail if data can't be converted)
|
|
292
|
+
- Adding a NOT NULL constraint to an existing column with NULL values
|
|
293
|
+
|
|
294
|
+
### Data Migrations
|
|
295
|
+
|
|
296
|
+
Schema changes that also require data transformation:
|
|
297
|
+
|
|
298
|
+
```sql
|
|
299
|
+
-- Schema migration: add new column
|
|
300
|
+
ALTER TABLE users ADD COLUMN full_name TEXT;
|
|
301
|
+
|
|
302
|
+
-- Data migration: populate from existing columns
|
|
303
|
+
UPDATE users SET full_name = first_name || ' ' || last_name;
|
|
304
|
+
|
|
305
|
+
-- Schema migration: make it non-nullable after population
|
|
306
|
+
ALTER TABLE users ALTER COLUMN full_name SET NOT NULL;
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
Data migrations should be idempotent (safe to run twice) and tested with production-like data volumes. A migration that runs in 1 second on 1000 rows may take 30 minutes on 10 million rows.
|
|
310
|
+
|
|
311
|
+
### Rollback Strategies
|
|
312
|
+
|
|
313
|
+
Every migration should have a reverse migration (down migration). Test rollbacks before deploying:
|
|
314
|
+
|
|
315
|
+
```sql
|
|
316
|
+
-- Up: add status column
|
|
317
|
+
ALTER TABLE orders ADD COLUMN status TEXT NOT NULL DEFAULT 'draft';
|
|
318
|
+
|
|
319
|
+
-- Down: remove status column (data loss — document this)
|
|
320
|
+
ALTER TABLE orders DROP COLUMN status;
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
Some migrations are irreversible (dropping a column deletes data permanently). Document these clearly and ensure backups exist before running.
|
|
324
|
+
|
|
325
|
+
### Zero-Downtime Migrations
|
|
326
|
+
|
|
327
|
+
For production systems that cannot tolerate downtime:
|
|
328
|
+
|
|
329
|
+
1. **Expand:** Add new column/table without removing old one
|
|
330
|
+
2. **Migrate:** Dual-write to both old and new. Backfill historical data.
|
|
331
|
+
3. **Contract:** Remove old column/table after verification
|
|
332
|
+
|
|
333
|
+
This three-phase approach prevents data loss and allows rollback at each step.
|
|
334
|
+
|
|
335
|
+
## NoSQL Considerations
|
|
336
|
+
|
|
337
|
+
### When to Use NoSQL
|
|
338
|
+
|
|
339
|
+
- **Document databases (MongoDB, DynamoDB):** When the data is naturally document-shaped, schema varies between records, or you need horizontal scaling for simple key-value or key-document access patterns.
|
|
340
|
+
- **Key-value stores (Redis, Memcached):** Caching, session storage, rate limiting. Not a primary data store.
|
|
341
|
+
- **Wide-column stores (Cassandra, ScyllaDB):** Time-series data, write-heavy workloads, multi-region replication.
|
|
342
|
+
- **Graph databases (Neo4j):** When the primary queries traverse relationships (social networks, recommendation engines, fraud detection).
|
|
343
|
+
|
|
344
|
+
### Document Design
|
|
345
|
+
|
|
346
|
+
In document databases, design around query patterns rather than entity relationships:
|
|
347
|
+
|
|
348
|
+
**Embedding vs. referencing:**
|
|
349
|
+
|
|
350
|
+
- **Embed** when the child data is always read with the parent, has a bounded size, and doesn't need independent access. Example: embed OrderLines within an Order document.
|
|
351
|
+
- **Reference** when the child data has its own lifecycle, is accessed independently, or could grow unboundedly. Example: reference User from Order by ID.
|
|
352
|
+
|
|
353
|
+
**Denormalization by default:** Document databases expect denormalized data. Duplicating data across documents is normal and expected. The trade-off: faster reads, more complex writes (must update all copies).
|
|
354
|
+
|
|
355
|
+
### Partition Key Selection
|
|
356
|
+
|
|
357
|
+
For distributed databases (DynamoDB, Cassandra), the partition key determines data distribution and query capability:
|
|
358
|
+
|
|
359
|
+
- Choose a partition key with high cardinality (many distinct values) for even distribution
|
|
360
|
+
- Queries must include the partition key — design around your access patterns
|
|
361
|
+
- Avoid hot partitions (one key receiving disproportionate traffic)
|
|
362
|
+
- Common choices: tenant_id, user_id, date-based for time-series
|
|
363
|
+
|
|
364
|
+
## Common Pitfalls
|
|
365
|
+
|
|
366
|
+
**Over-normalization.** Splitting every concept into its own table produces a schema that requires 10 joins to answer a simple question. The join cost exceeds any benefit from reduced data duplication. Fix: denormalize when read patterns consistently need the joined data.
|
|
367
|
+
|
|
368
|
+
**Missing indexes for common queries.** Every page load runs a full table scan because nobody added an index for the query that drives it. Fix: enumerate query patterns before deployment. Add indexes for high-frequency queries.
|
|
369
|
+
|
|
370
|
+
**Migration ordering issues.** Two developers create migrations that conflict — both add a column with the same name, or one depends on a table the other creates. Fix: use timestamp-based migration names. Review migration PRs for conflicts. In parallel agent development, sequence migrations through task dependencies.
|
|
371
|
+
|
|
372
|
+
**Not testing rollbacks.** A migration runs successfully in development but the rollback fails in staging, leaving the database in an inconsistent state. Fix: every migration must have a tested rollback. Include rollback testing in CI.
|
|
373
|
+
|
|
374
|
+
**Storing money as floating point.** `FLOAT` and `DOUBLE` cannot represent all decimal values exactly. `19.99` becomes `19.989999999999998`. Fix: store money as integer cents or use `DECIMAL`/`NUMERIC` types.
|
|
375
|
+
|
|
376
|
+
**Missing timestamps.** Tables without `created_at` and `updated_at` columns. When something goes wrong, you can't tell when the data was created or last changed. Fix: add timestamp columns to every table, populated automatically by defaults or triggers.
|
|
377
|
+
|
|
378
|
+
**Allowing unbounded growth in aggregate tables.** An events or logs table that grows without limit, eventually consuming all storage and degrading query performance. Fix: define a retention policy and implement it (archival, partitioning, or deletion).
|
|
379
|
+
|
|
380
|
+
**Using the database as a message queue.** Polling a table for new rows to process. This creates lock contention, wastes resources, and scales poorly. Fix: use a proper message queue (Redis, RabbitMQ, SQS) for event-driven processing.
|