@zigrivers/scaffold 2.1.2 → 2.38.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/README.md +505 -119
- package/dist/cli/commands/build.d.ts.map +1 -1
- package/dist/cli/commands/build.js +94 -14
- package/dist/cli/commands/build.js.map +1 -1
- package/dist/cli/commands/build.test.js +30 -5
- package/dist/cli/commands/build.test.js.map +1 -1
- package/dist/cli/commands/check.d.ts +12 -0
- package/dist/cli/commands/check.d.ts.map +1 -0
- package/dist/cli/commands/check.js +311 -0
- package/dist/cli/commands/check.js.map +1 -0
- package/dist/cli/commands/check.test.d.ts +2 -0
- package/dist/cli/commands/check.test.d.ts.map +1 -0
- package/dist/cli/commands/check.test.js +412 -0
- package/dist/cli/commands/check.test.js.map +1 -0
- package/dist/cli/commands/complete.d.ts +12 -0
- package/dist/cli/commands/complete.d.ts.map +1 -0
- package/dist/cli/commands/complete.js +101 -0
- package/dist/cli/commands/complete.js.map +1 -0
- package/dist/cli/commands/complete.test.d.ts +2 -0
- package/dist/cli/commands/complete.test.d.ts.map +1 -0
- package/dist/cli/commands/complete.test.js +133 -0
- package/dist/cli/commands/complete.test.js.map +1 -0
- package/dist/cli/commands/dashboard.d.ts.map +1 -1
- package/dist/cli/commands/dashboard.js +12 -8
- package/dist/cli/commands/dashboard.js.map +1 -1
- package/dist/cli/commands/info.d.ts.map +1 -1
- package/dist/cli/commands/info.js +4 -0
- package/dist/cli/commands/info.js.map +1 -1
- package/dist/cli/commands/knowledge.d.ts.map +1 -1
- package/dist/cli/commands/knowledge.js +6 -2
- package/dist/cli/commands/knowledge.js.map +1 -1
- package/dist/cli/commands/knowledge.test.js +16 -11
- package/dist/cli/commands/knowledge.test.js.map +1 -1
- package/dist/cli/commands/next.d.ts.map +1 -1
- package/dist/cli/commands/next.js +41 -13
- package/dist/cli/commands/next.js.map +1 -1
- package/dist/cli/commands/next.test.js +3 -0
- package/dist/cli/commands/next.test.js.map +1 -1
- package/dist/cli/commands/reset.d.ts +1 -0
- package/dist/cli/commands/reset.d.ts.map +1 -1
- package/dist/cli/commands/reset.js +179 -67
- package/dist/cli/commands/reset.js.map +1 -1
- package/dist/cli/commands/reset.test.js +360 -0
- package/dist/cli/commands/reset.test.js.map +1 -1
- package/dist/cli/commands/rework.d.ts +20 -0
- package/dist/cli/commands/rework.d.ts.map +1 -0
- package/dist/cli/commands/rework.js +332 -0
- package/dist/cli/commands/rework.js.map +1 -0
- package/dist/cli/commands/rework.test.d.ts +2 -0
- package/dist/cli/commands/rework.test.d.ts.map +1 -0
- package/dist/cli/commands/rework.test.js +297 -0
- package/dist/cli/commands/rework.test.js.map +1 -0
- package/dist/cli/commands/run.d.ts.map +1 -1
- package/dist/cli/commands/run.js +59 -31
- package/dist/cli/commands/run.js.map +1 -1
- package/dist/cli/commands/run.test.js +288 -6
- package/dist/cli/commands/run.test.js.map +1 -1
- package/dist/cli/commands/skill.d.ts +12 -0
- package/dist/cli/commands/skill.d.ts.map +1 -0
- package/dist/cli/commands/skill.js +123 -0
- package/dist/cli/commands/skill.js.map +1 -0
- package/dist/cli/commands/skill.test.d.ts +2 -0
- package/dist/cli/commands/skill.test.d.ts.map +1 -0
- package/dist/cli/commands/skill.test.js +297 -0
- package/dist/cli/commands/skill.test.js.map +1 -0
- package/dist/cli/commands/skip.d.ts +1 -1
- package/dist/cli/commands/skip.d.ts.map +1 -1
- package/dist/cli/commands/skip.js +123 -57
- package/dist/cli/commands/skip.js.map +1 -1
- package/dist/cli/commands/skip.test.js +91 -0
- package/dist/cli/commands/skip.test.js.map +1 -1
- package/dist/cli/commands/status.d.ts +1 -0
- package/dist/cli/commands/status.d.ts.map +1 -1
- package/dist/cli/commands/status.js +57 -10
- package/dist/cli/commands/status.js.map +1 -1
- package/dist/cli/commands/status.test.js +81 -0
- package/dist/cli/commands/status.test.js.map +1 -1
- package/dist/cli/commands/update.test.js +252 -0
- package/dist/cli/commands/update.test.js.map +1 -1
- package/dist/cli/commands/version.test.js +171 -1
- package/dist/cli/commands/version.test.js.map +1 -1
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +8 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/core/adapters/adapter.d.ts +14 -0
- package/dist/core/adapters/adapter.d.ts.map +1 -1
- package/dist/core/adapters/adapter.js.map +1 -1
- package/dist/core/adapters/adapter.test.js +10 -0
- package/dist/core/adapters/adapter.test.js.map +1 -1
- package/dist/core/adapters/claude-code.d.ts.map +1 -1
- package/dist/core/adapters/claude-code.js +47 -10
- package/dist/core/adapters/claude-code.js.map +1 -1
- package/dist/core/adapters/claude-code.test.js +41 -20
- package/dist/core/adapters/claude-code.test.js.map +1 -1
- package/dist/core/adapters/codex.d.ts.map +1 -1
- package/dist/core/adapters/codex.js +5 -1
- package/dist/core/adapters/codex.js.map +1 -1
- package/dist/core/adapters/codex.test.js +5 -0
- package/dist/core/adapters/codex.test.js.map +1 -1
- package/dist/core/adapters/universal.d.ts.map +1 -1
- package/dist/core/adapters/universal.js +0 -1
- package/dist/core/adapters/universal.js.map +1 -1
- package/dist/core/adapters/universal.test.js +5 -0
- package/dist/core/adapters/universal.test.js.map +1 -1
- package/dist/core/assembly/context-gatherer.d.ts.map +1 -1
- package/dist/core/assembly/context-gatherer.js +5 -2
- package/dist/core/assembly/context-gatherer.js.map +1 -1
- package/dist/core/assembly/engine.d.ts.map +1 -1
- package/dist/core/assembly/engine.js +10 -2
- package/dist/core/assembly/engine.js.map +1 -1
- package/dist/core/assembly/engine.test.js +19 -0
- package/dist/core/assembly/engine.test.js.map +1 -1
- package/dist/core/assembly/knowledge-loader.d.ts +25 -0
- package/dist/core/assembly/knowledge-loader.d.ts.map +1 -1
- package/dist/core/assembly/knowledge-loader.js +75 -2
- package/dist/core/assembly/knowledge-loader.js.map +1 -1
- package/dist/core/assembly/knowledge-loader.test.js +388 -1
- package/dist/core/assembly/knowledge-loader.test.js.map +1 -1
- package/dist/core/assembly/meta-prompt-loader.d.ts +6 -0
- package/dist/core/assembly/meta-prompt-loader.d.ts.map +1 -1
- package/dist/core/assembly/meta-prompt-loader.js +41 -25
- package/dist/core/assembly/meta-prompt-loader.js.map +1 -1
- package/dist/core/assembly/preset-loader.d.ts +10 -0
- package/dist/core/assembly/preset-loader.d.ts.map +1 -1
- package/dist/core/assembly/preset-loader.js +26 -1
- package/dist/core/assembly/preset-loader.js.map +1 -1
- package/dist/core/assembly/preset-loader.test.js +65 -1
- package/dist/core/assembly/preset-loader.test.js.map +1 -1
- package/dist/core/assembly/update-mode.d.ts.map +1 -1
- package/dist/core/assembly/update-mode.js +10 -4
- package/dist/core/assembly/update-mode.js.map +1 -1
- package/dist/core/assembly/update-mode.test.js +47 -0
- package/dist/core/assembly/update-mode.test.js.map +1 -1
- package/dist/core/dependency/dependency.d.ts.map +1 -1
- package/dist/core/dependency/dependency.js +3 -2
- package/dist/core/dependency/dependency.js.map +1 -1
- package/dist/core/dependency/dependency.test.js +2 -0
- package/dist/core/dependency/dependency.test.js.map +1 -1
- package/dist/core/dependency/eligibility.js +3 -3
- package/dist/core/dependency/eligibility.js.map +1 -1
- package/dist/core/dependency/eligibility.test.js +2 -0
- package/dist/core/dependency/eligibility.test.js.map +1 -1
- package/dist/core/dependency/graph.d.ts.map +1 -1
- package/dist/core/dependency/graph.js +4 -0
- package/dist/core/dependency/graph.js.map +1 -1
- package/dist/core/dependency/graph.test.d.ts +2 -0
- package/dist/core/dependency/graph.test.d.ts.map +1 -0
- package/dist/core/dependency/graph.test.js +262 -0
- package/dist/core/dependency/graph.test.js.map +1 -0
- package/dist/core/rework/phase-selector.d.ts +24 -0
- package/dist/core/rework/phase-selector.d.ts.map +1 -0
- package/dist/core/rework/phase-selector.js +98 -0
- package/dist/core/rework/phase-selector.js.map +1 -0
- package/dist/core/rework/phase-selector.test.d.ts +2 -0
- package/dist/core/rework/phase-selector.test.d.ts.map +1 -0
- package/dist/core/rework/phase-selector.test.js +138 -0
- package/dist/core/rework/phase-selector.test.js.map +1 -0
- package/dist/dashboard/generator.d.ts +48 -17
- package/dist/dashboard/generator.d.ts.map +1 -1
- package/dist/dashboard/generator.js +75 -5
- package/dist/dashboard/generator.js.map +1 -1
- package/dist/dashboard/generator.test.js +213 -5
- package/dist/dashboard/generator.test.js.map +1 -1
- package/dist/dashboard/template.d.ts +1 -1
- package/dist/dashboard/template.d.ts.map +1 -1
- package/dist/dashboard/template.js +755 -114
- package/dist/dashboard/template.js.map +1 -1
- package/dist/e2e/knowledge.test.js +4 -3
- package/dist/e2e/knowledge.test.js.map +1 -1
- package/dist/e2e/pipeline.test.js +2 -0
- package/dist/e2e/pipeline.test.js.map +1 -1
- package/dist/e2e/rework.test.d.ts +6 -0
- package/dist/e2e/rework.test.d.ts.map +1 -0
- package/dist/e2e/rework.test.js +226 -0
- package/dist/e2e/rework.test.js.map +1 -0
- package/dist/index.js +0 -0
- package/dist/project/adopt.test.js +2 -0
- package/dist/project/adopt.test.js.map +1 -1
- package/dist/project/claude-md.js +2 -2
- package/dist/project/claude-md.js.map +1 -1
- package/dist/project/claude-md.test.js +4 -4
- package/dist/project/claude-md.test.js.map +1 -1
- package/dist/project/detector.d.ts.map +1 -1
- package/dist/project/detector.js +4 -1
- package/dist/project/detector.js.map +1 -1
- package/dist/project/frontmatter.d.ts.map +1 -1
- package/dist/project/frontmatter.js +54 -15
- package/dist/project/frontmatter.js.map +1 -1
- package/dist/project/frontmatter.test.js +2 -2
- package/dist/project/frontmatter.test.js.map +1 -1
- package/dist/state/rework-manager.d.ts +16 -0
- package/dist/state/rework-manager.d.ts.map +1 -0
- package/dist/state/rework-manager.js +126 -0
- package/dist/state/rework-manager.js.map +1 -0
- package/dist/state/rework-manager.test.d.ts +2 -0
- package/dist/state/rework-manager.test.d.ts.map +1 -0
- package/dist/state/rework-manager.test.js +191 -0
- package/dist/state/rework-manager.test.js.map +1 -0
- package/dist/state/state-manager.d.ts +13 -0
- package/dist/state/state-manager.d.ts.map +1 -1
- package/dist/state/state-manager.js +39 -2
- package/dist/state/state-manager.js.map +1 -1
- package/dist/state/state-manager.test.js +74 -1
- package/dist/state/state-manager.test.js.map +1 -1
- package/dist/state/state-migration.d.ts +23 -0
- package/dist/state/state-migration.d.ts.map +1 -0
- package/dist/state/state-migration.js +144 -0
- package/dist/state/state-migration.js.map +1 -0
- package/dist/state/state-migration.test.d.ts +2 -0
- package/dist/state/state-migration.test.d.ts.map +1 -0
- package/dist/state/state-migration.test.js +451 -0
- package/dist/state/state-migration.test.js.map +1 -0
- package/dist/types/assembly.d.ts +2 -0
- package/dist/types/assembly.d.ts.map +1 -1
- package/dist/types/dependency.d.ts +2 -2
- package/dist/types/dependency.d.ts.map +1 -1
- package/dist/types/frontmatter.d.ts +100 -7
- package/dist/types/frontmatter.d.ts.map +1 -1
- package/dist/types/frontmatter.js +89 -1
- package/dist/types/frontmatter.js.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/lock.d.ts +1 -1
- package/dist/types/lock.d.ts.map +1 -1
- package/dist/types/rework.d.ts +36 -0
- package/dist/types/rework.d.ts.map +1 -0
- package/dist/types/rework.js +2 -0
- package/dist/types/rework.js.map +1 -0
- package/dist/utils/errors.d.ts +1 -0
- package/dist/utils/errors.d.ts.map +1 -1
- package/dist/utils/errors.js +8 -0
- package/dist/utils/errors.js.map +1 -1
- package/dist/utils/fs.d.ts +6 -0
- package/dist/utils/fs.d.ts.map +1 -1
- package/dist/utils/fs.js +13 -0
- package/dist/utils/fs.js.map +1 -1
- package/dist/validation/config-validator.test.d.ts +2 -0
- package/dist/validation/config-validator.test.d.ts.map +1 -0
- package/dist/validation/config-validator.test.js +210 -0
- package/dist/validation/config-validator.test.js.map +1 -0
- package/dist/validation/dependency-validator.test.d.ts +2 -0
- package/dist/validation/dependency-validator.test.d.ts.map +1 -0
- package/dist/validation/dependency-validator.test.js +215 -0
- package/dist/validation/dependency-validator.test.js.map +1 -0
- package/dist/validation/frontmatter-validator.test.d.ts +2 -0
- package/dist/validation/frontmatter-validator.test.d.ts.map +1 -0
- package/dist/validation/frontmatter-validator.test.js +371 -0
- package/dist/validation/frontmatter-validator.test.js.map +1 -0
- package/dist/validation/state-validator.test.d.ts +2 -0
- package/dist/validation/state-validator.test.d.ts.map +1 -0
- package/dist/validation/state-validator.test.js +325 -0
- package/dist/validation/state-validator.test.js.map +1 -0
- package/dist/wizard/suggestion.test.d.ts +2 -0
- package/dist/wizard/suggestion.test.d.ts.map +1 -0
- package/dist/wizard/suggestion.test.js +115 -0
- package/dist/wizard/suggestion.test.js.map +1 -0
- package/dist/wizard/wizard.d.ts.map +1 -1
- package/dist/wizard/wizard.js +34 -1
- package/dist/wizard/wizard.js.map +1 -1
- package/knowledge/core/adr-craft.md +57 -0
- package/knowledge/core/ai-memory-management.md +246 -0
- package/knowledge/core/api-design.md +8 -0
- package/knowledge/core/automated-review-tooling.md +203 -0
- package/knowledge/core/claude-md-patterns.md +254 -0
- package/knowledge/core/coding-conventions.md +246 -0
- package/knowledge/core/database-design.md +8 -0
- package/knowledge/core/design-system-tokens.md +469 -0
- package/knowledge/core/dev-environment.md +223 -0
- package/knowledge/core/domain-modeling.md +8 -0
- package/knowledge/core/eval-craft.md +1008 -0
- package/knowledge/core/git-workflow-patterns.md +200 -0
- package/knowledge/core/multi-model-review-dispatch.md +250 -0
- package/knowledge/core/operations-runbook.md +40 -225
- package/knowledge/core/project-structure-patterns.md +231 -0
- package/knowledge/core/review-step-template.md +247 -0
- package/knowledge/core/{security-review.md → security-best-practices.md} +9 -1
- package/knowledge/core/system-architecture.md +5 -1
- package/knowledge/core/task-decomposition.md +174 -36
- package/knowledge/core/task-tracking.md +225 -0
- package/knowledge/core/tech-stack-selection.md +214 -0
- package/knowledge/core/testing-strategy.md +63 -70
- package/knowledge/core/user-stories.md +69 -60
- package/knowledge/core/user-story-innovation.md +70 -0
- package/knowledge/core/ux-specification.md +18 -148
- package/knowledge/execution/enhancement-workflow.md +201 -0
- package/knowledge/execution/task-claiming-strategy.md +130 -0
- package/knowledge/execution/tdd-execution-loop.md +172 -0
- package/knowledge/execution/worktree-management.md +205 -0
- package/knowledge/finalization/apply-fixes-and-freeze.md +177 -14
- package/knowledge/finalization/developer-onboarding.md +4 -0
- package/knowledge/finalization/implementation-playbook.md +83 -5
- package/knowledge/product/gap-analysis.md +5 -1
- package/knowledge/product/prd-craft.md +55 -34
- package/knowledge/product/prd-innovation.md +12 -0
- package/knowledge/product/vision-craft.md +213 -0
- package/knowledge/review/review-adr.md +44 -0
- package/knowledge/review/{review-api-contracts.md → review-api-design.md} +47 -1
- package/knowledge/review/{review-database-schema.md → review-database-design.md} +40 -1
- package/knowledge/review/review-domain-modeling.md +38 -1
- package/knowledge/review/review-implementation-tasks.md +108 -1
- package/knowledge/review/review-methodology.md +11 -0
- package/knowledge/review/review-operations.md +67 -0
- package/knowledge/review/review-prd.md +46 -0
- package/knowledge/review/review-security.md +65 -0
- package/knowledge/review/review-system-architecture.md +32 -2
- package/knowledge/review/review-testing-strategy.md +62 -0
- package/knowledge/review/review-user-stories.md +65 -0
- package/knowledge/review/{review-ux-spec.md → review-ux-specification.md} +50 -2
- package/knowledge/review/review-vision.md +255 -0
- package/knowledge/tools/release-management.md +222 -0
- package/knowledge/tools/session-analysis.md +215 -0
- package/knowledge/tools/version-strategy.md +200 -0
- package/knowledge/validation/critical-path-analysis.md +1 -1
- package/knowledge/validation/cross-phase-consistency.md +12 -0
- package/knowledge/validation/decision-completeness.md +13 -1
- package/knowledge/validation/dependency-validation.md +12 -0
- package/knowledge/validation/scope-management.md +12 -0
- package/knowledge/validation/traceability.md +12 -0
- package/methodology/README.md +37 -0
- package/methodology/custom-defaults.yml +44 -4
- package/methodology/deep.yml +43 -3
- package/methodology/mvp.yml +43 -3
- package/package.json +4 -3
- package/pipeline/architecture/review-architecture.md +36 -13
- package/pipeline/architecture/system-architecture.md +24 -9
- package/pipeline/build/multi-agent-resume.md +245 -0
- package/pipeline/build/multi-agent-start.md +236 -0
- package/pipeline/build/new-enhancement.md +456 -0
- package/pipeline/build/quick-task.md +381 -0
- package/pipeline/build/single-agent-resume.md +210 -0
- package/pipeline/build/single-agent-start.md +207 -0
- package/pipeline/consolidation/claude-md-optimization.md +76 -0
- package/pipeline/consolidation/workflow-audit.md +77 -0
- package/pipeline/decisions/adrs.md +21 -7
- package/pipeline/decisions/review-adrs.md +32 -11
- package/pipeline/environment/ai-memory-setup.md +76 -0
- package/pipeline/environment/automated-pr-review.md +76 -0
- package/pipeline/environment/design-system.md +75 -0
- package/pipeline/environment/dev-env-setup.md +68 -0
- package/pipeline/environment/git-workflow.md +73 -0
- package/pipeline/finalization/apply-fixes-and-freeze.md +17 -6
- package/pipeline/finalization/developer-onboarding-guide.md +23 -9
- package/pipeline/finalization/implementation-playbook.md +43 -14
- package/pipeline/foundation/beads.md +71 -0
- package/pipeline/foundation/coding-standards.md +71 -0
- package/pipeline/foundation/project-structure.md +73 -0
- package/pipeline/foundation/tdd.md +64 -0
- package/pipeline/foundation/tech-stack.md +74 -0
- package/pipeline/integration/add-e2e-testing.md +80 -0
- package/pipeline/modeling/domain-modeling.md +23 -8
- package/pipeline/modeling/review-domain-modeling.md +35 -11
- package/pipeline/parity/platform-parity-review.md +90 -0
- package/pipeline/planning/implementation-plan-review.md +67 -0
- package/pipeline/planning/implementation-plan.md +110 -0
- package/pipeline/pre/create-prd.md +34 -10
- package/pipeline/pre/innovate-prd.md +46 -15
- package/pipeline/pre/innovate-user-stories.md +47 -14
- package/pipeline/pre/review-prd.md +29 -8
- package/pipeline/pre/review-user-stories.md +34 -8
- package/pipeline/pre/user-stories.md +23 -8
- package/pipeline/quality/create-evals.md +106 -0
- package/pipeline/quality/operations.md +46 -17
- package/pipeline/quality/review-operations.md +32 -11
- package/pipeline/quality/review-security.md +34 -12
- package/pipeline/quality/review-testing.md +37 -14
- package/pipeline/quality/security.md +36 -10
- package/pipeline/quality/story-tests.md +75 -0
- package/pipeline/specification/api-contracts.md +28 -8
- package/pipeline/specification/database-schema.md +29 -8
- package/pipeline/specification/review-api.md +32 -11
- package/pipeline/specification/review-database.md +32 -11
- package/pipeline/specification/review-ux.md +34 -12
- package/pipeline/specification/ux-spec.md +35 -13
- package/pipeline/validation/critical-path-walkthrough.md +45 -11
- package/pipeline/validation/cross-phase-consistency.md +45 -11
- package/pipeline/validation/decision-completeness.md +45 -11
- package/pipeline/validation/dependency-graph-validation.md +46 -11
- package/pipeline/validation/implementability-dry-run.md +46 -11
- package/pipeline/validation/scope-creep-check.md +46 -11
- package/pipeline/validation/traceability-matrix.md +51 -11
- package/pipeline/vision/create-vision.md +267 -0
- package/pipeline/vision/innovate-vision.md +157 -0
- package/pipeline/vision/review-vision.md +149 -0
- package/skills/multi-model-dispatch/SKILL.md +326 -0
- package/skills/scaffold-pipeline/SKILL.md +210 -0
- package/skills/scaffold-runner/SKILL.md +619 -0
- package/pipeline/planning/implementation-tasks.md +0 -57
- package/pipeline/planning/review-tasks.md +0 -38
- package/pipeline/quality/testing-strategy.md +0 -42
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: claude-md-patterns
|
|
3
|
+
description: Patterns for structuring CLAUDE.md files including section organization, rule authoring, pointer patterns, and merge strategies
|
|
4
|
+
topics: [claude-md, ai-configuration, rule-files, memory-management, project-setup]
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# CLAUDE.md Patterns
|
|
8
|
+
|
|
9
|
+
CLAUDE.md is the primary instruction file for AI coding agents. It is loaded at the start of every session and defines how the agent should behave within a project. A well-structured CLAUDE.md dramatically improves agent adherence; a poorly structured one gets ignored or causes conflicts. This knowledge covers structure, authoring, the pointer pattern, and the merge strategy for multi-step pipeline updates.
|
|
10
|
+
|
|
11
|
+
## Summary
|
|
12
|
+
|
|
13
|
+
### Purpose
|
|
14
|
+
|
|
15
|
+
CLAUDE.md is a project-level instruction file that AI agents (Claude Code, Codex, etc.) read at session start. It answers three questions:
|
|
16
|
+
1. **What are the rules?** — Coding conventions, git workflow, testing requirements
|
|
17
|
+
2. **How do I do common tasks?** — Key commands, PR workflow, deployment
|
|
18
|
+
3. **What should I avoid?** — Anti-patterns, forbidden operations, common pitfalls
|
|
19
|
+
|
|
20
|
+
### Section Organization
|
|
21
|
+
|
|
22
|
+
A well-structured CLAUDE.md follows this order, from most-referenced to least:
|
|
23
|
+
|
|
24
|
+
| Section | Purpose | Example Content |
|
|
25
|
+
|---------|---------|-----------------|
|
|
26
|
+
| **Core Principles** | 3-5 non-negotiable tenets | TDD, simplicity, no laziness |
|
|
27
|
+
| **Project Overview** | What this project is (1-2 sentences) | "Prompt pipeline for scaffolding projects" |
|
|
28
|
+
| **Key Commands** | Commands the agent runs constantly | `make check`, `make test`, `npm run dev` |
|
|
29
|
+
| **Workflow** | How to do common operations | Branch, commit, PR, merge flow |
|
|
30
|
+
| **Structure Quick Reference** | Where files go | Directory table with purpose |
|
|
31
|
+
| **Environment** | Dev setup specifics | Build tool, test runner, linter |
|
|
32
|
+
| **Rules** | Specific do/don't instructions | "Never push to main directly" |
|
|
33
|
+
| **Self-Improvement** | Learning feedback loop | Lessons file, correction capture |
|
|
34
|
+
| **Autonomous Behavior** | What the agent should do proactively | Fix bugs on sight, use subagents |
|
|
35
|
+
| **Doc Lookup Table** | Where to find detailed docs | Question-to-document mapping |
|
|
36
|
+
|
|
37
|
+
### Rule Authoring Best Practices
|
|
38
|
+
|
|
39
|
+
Rules must be specific, actionable, and testable:
|
|
40
|
+
|
|
41
|
+
**Good rules:**
|
|
42
|
+
- "Run `make check` before every commit"
|
|
43
|
+
- "Never push directly to main — always use branch + PR"
|
|
44
|
+
- "Every commit message starts with `[BD-xxx]` task ID"
|
|
45
|
+
|
|
46
|
+
**Bad rules:**
|
|
47
|
+
- "Write clean code" — what does clean mean?
|
|
48
|
+
- "Be careful with git" — what specific actions to take/avoid?
|
|
49
|
+
- "Follow best practices" — which ones?
|
|
50
|
+
|
|
51
|
+
### The Pointer Pattern
|
|
52
|
+
|
|
53
|
+
Reference external docs instead of duplicating content inline:
|
|
54
|
+
|
|
55
|
+
```markdown
|
|
56
|
+
## Coding Conventions
|
|
57
|
+
See `docs/coding-standards.md` for full reference. Key rules in `.claude/rules/code-style.md`.
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
This keeps CLAUDE.md under 200 lines (the empirically-validated adherence threshold) while preserving access to detailed docs. The agent reads referenced docs on demand rather than processing everything at session start.
|
|
61
|
+
|
|
62
|
+
## Deep Guidance
|
|
63
|
+
|
|
64
|
+
### Section Organization — Extended
|
|
65
|
+
|
|
66
|
+
#### Front-Loading Critical Information
|
|
67
|
+
|
|
68
|
+
Agents skim CLAUDE.md. The first 50 lines get the most attention. Place the most violated rules and most-used commands at the top. Core Principles and Key Commands should appear before any detailed documentation.
|
|
69
|
+
|
|
70
|
+
#### The 200-Line Threshold
|
|
71
|
+
|
|
72
|
+
Research and practical experience show that agent adherence drops sharply when CLAUDE.md exceeds ~200 lines. Beyond that length, agents start selectively ignoring instructions — particularly those in the middle or bottom of the file.
|
|
73
|
+
|
|
74
|
+
Strategies to stay under 200 lines:
|
|
75
|
+
- Use the pointer pattern for anything longer than 5 lines
|
|
76
|
+
- Move path-scoped conventions to `.claude/rules/` files
|
|
77
|
+
- Keep tables compact (no verbose descriptions)
|
|
78
|
+
- Eliminate redundancy (same rule stated multiple ways)
|
|
79
|
+
|
|
80
|
+
#### Section Templates
|
|
81
|
+
|
|
82
|
+
**Core Principles** — 3-5 tenets, each a single sentence with a bold label:
|
|
83
|
+
```markdown
|
|
84
|
+
## Core Principles
|
|
85
|
+
- **Simplicity First**: Make every change as simple as possible.
|
|
86
|
+
- **TDD Always**: Write failing tests first, then make them pass.
|
|
87
|
+
- **Prove It Works**: Never mark a task complete without demonstrating correctness.
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
**Key Commands** — Table format, sorted by frequency of use:
|
|
91
|
+
```markdown
|
|
92
|
+
## Key Commands
|
|
93
|
+
| Command | Purpose |
|
|
94
|
+
|---------|---------|
|
|
95
|
+
| `make check` | Run all quality gates |
|
|
96
|
+
| `make test` | Run test suite |
|
|
97
|
+
| `make lint` | Run linters |
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
**Doc Lookup Table** — Question-to-document mapping:
|
|
101
|
+
```markdown
|
|
102
|
+
## When to Consult Other Docs
|
|
103
|
+
| Question | Document |
|
|
104
|
+
|----------|----------|
|
|
105
|
+
| How do I branch and commit? | `docs/git-workflow.md` |
|
|
106
|
+
| What are the coding conventions? | `docs/coding-standards.md` |
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Rule Authoring — Extended
|
|
110
|
+
|
|
111
|
+
#### The Testability Criterion
|
|
112
|
+
|
|
113
|
+
Every rule should be verifiable. If you cannot check whether the rule was followed, the rule is too vague.
|
|
114
|
+
|
|
115
|
+
| Rule | Testable? | Fix |
|
|
116
|
+
|------|-----------|-----|
|
|
117
|
+
| "Write good tests" | No | "Every new function has at least one unit test" |
|
|
118
|
+
| "Use proper naming" | No | "Use camelCase for variables, PascalCase for types" |
|
|
119
|
+
| "Run `make check` before commits" | Yes | — |
|
|
120
|
+
| "Never commit `.env` files" | Yes | — |
|
|
121
|
+
|
|
122
|
+
#### Conflict Resolution
|
|
123
|
+
|
|
124
|
+
Rules can conflict. When they do, the resolution order is:
|
|
125
|
+
1. CLAUDE.md rules override general conventions
|
|
126
|
+
2. More specific rules override more general rules
|
|
127
|
+
3. Later rules override earlier rules (if truly contradictory)
|
|
128
|
+
4. Project-specific rules override ecosystem defaults
|
|
129
|
+
|
|
130
|
+
Document known conflicts explicitly: "This project uses tabs despite the TypeScript convention of spaces — see `.editorconfig`."
|
|
131
|
+
|
|
132
|
+
#### Negative Rules vs. Positive Rules
|
|
133
|
+
|
|
134
|
+
Prefer positive rules ("always do X") over negative rules ("never do Y") when possible. Positive rules tell the agent what to do; negative rules only eliminate one option from an infinite set.
|
|
135
|
+
|
|
136
|
+
Exception: safety-critical negative rules are valuable. "Never push to main directly" and "Never commit secrets" are clearer as negatives.
|
|
137
|
+
|
|
138
|
+
### Pointer Pattern — Extended
|
|
139
|
+
|
|
140
|
+
#### When to Inline vs. Point
|
|
141
|
+
|
|
142
|
+
| Content Type | Inline in CLAUDE.md | Point to External Doc |
|
|
143
|
+
|-------------|--------------------|-----------------------|
|
|
144
|
+
| Core principles | Yes | No |
|
|
145
|
+
| Key commands table | Yes | No |
|
|
146
|
+
| Workflow summary (5-10 lines) | Yes | Detailed version elsewhere |
|
|
147
|
+
| Coding conventions (full) | No | `docs/coding-standards.md` |
|
|
148
|
+
| Git workflow (full) | No | `docs/git-workflow.md` |
|
|
149
|
+
| Project structure (full) | No | `docs/project-structure.md` |
|
|
150
|
+
| Design system rules | No | `docs/design-system.md` |
|
|
151
|
+
|
|
152
|
+
The rule: if the content is referenced multiple times per session, inline a summary. If it is referenced occasionally, point to it.
|
|
153
|
+
|
|
154
|
+
#### Cross-Reference Format
|
|
155
|
+
|
|
156
|
+
Use consistent pointer format throughout:
|
|
157
|
+
```markdown
|
|
158
|
+
See `docs/coding-standards.md` for full reference.
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Not:
|
|
162
|
+
```markdown
|
|
163
|
+
Refer to the coding standards document for more details.
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
The first format gives the agent an exact file path to read. The second requires the agent to search for the file.
|
|
167
|
+
|
|
168
|
+
### Merge Strategy for Multi-Step Pipeline Updates
|
|
169
|
+
|
|
170
|
+
Seven pipeline steps modify CLAUDE.md during project scaffolding. Each step owns specific sections and must not overwrite sections owned by other steps. This section ownership model prevents destructive overwrites when steps execute sequentially.
|
|
171
|
+
|
|
172
|
+
#### Section Ownership Map
|
|
173
|
+
|
|
174
|
+
| Pipeline Step | CLAUDE.md Sections Owned | Operation |
|
|
175
|
+
|--------------|-------------------------|-----------|
|
|
176
|
+
| **beads** | Core Principles, Task Management (Beads commands), Self-Improvement, Autonomous Behavior | Creates initial skeleton |
|
|
177
|
+
| **project-structure** | Project Structure Quick Reference | Adds/updates directory table |
|
|
178
|
+
| **dev-env-setup** | Key Commands, Dev Environment | Adds/updates command table and env section |
|
|
179
|
+
| **git-workflow** | Committing and Creating PRs, Parallel Sessions (Worktrees) | Adds/updates workflow sections |
|
|
180
|
+
| **design-system** | Design System, Browser Testing | Adds/updates design system section |
|
|
181
|
+
| **ai-memory-setup** | Pointer restructuring (cross-cutting) | Replaces inline content with pointers to `.claude/rules/` |
|
|
182
|
+
| **automated-pr-review** | Code Review workflow | Adds/updates review workflow section |
|
|
183
|
+
|
|
184
|
+
#### Merge Rules
|
|
185
|
+
|
|
186
|
+
1. **Additive by default.** Each step adds its sections without modifying sections owned by other steps. If a section does not exist, create it. If it exists and belongs to this step, update it in-place.
|
|
187
|
+
|
|
188
|
+
2. **Never delete unrecognized sections.** If CLAUDE.md contains sections not in the ownership map (user customizations, project-specific sections), preserve them. Move them to the end if they conflict with the expected layout, but never remove them.
|
|
189
|
+
|
|
190
|
+
3. **Beads goes first.** The `beads` step creates the initial CLAUDE.md skeleton. All subsequent steps add to this skeleton. If `beads` was skipped (project does not use Beads), subsequent steps must still create their sections — they just skip the Beads-specific content.
|
|
191
|
+
|
|
192
|
+
4. **ai-memory-setup is cross-cutting.** Unlike other steps that add sections, `ai-memory-setup` restructures existing sections by replacing inline content blocks with pointer references to `.claude/rules/` files. It operates across sections owned by other steps but only changes the representation (inline → pointer), not the substance.
|
|
193
|
+
|
|
194
|
+
5. **claude-md-optimization consolidates.** The final consolidation step (`claude-md-optimization`) reviews the accumulated CLAUDE.md, removes redundancy introduced by incremental additions, fixes inconsistencies in terminology, and reorders for scannability. It operates on all sections but does not add new workflow steps or rules — only consolidates and clarifies what exists.
|
|
195
|
+
|
|
196
|
+
6. **Preserve tracking comments.** Steps that add tracking comments (`<!-- scaffold:step-name v1 YYYY-MM-DD -->`) must preserve comments from other steps. These comments enable update detection.
|
|
197
|
+
|
|
198
|
+
7. **Update mode is the norm.** After initial creation by `beads`, all subsequent steps operate in update mode. They check for existing content, preserve customizations, and update in-place rather than replacing.
|
|
199
|
+
|
|
200
|
+
#### Conflict Scenarios
|
|
201
|
+
|
|
202
|
+
**Two steps reference the same command.** Example: `dev-env-setup` adds `make check` to Key Commands and `git-workflow` references `make check` in the PR workflow. Resolution: the Key Commands table (owned by `dev-env-setup`) is the single source of truth for command definitions. Other sections reference commands but do not redefine them.
|
|
203
|
+
|
|
204
|
+
**ai-memory-setup restructures a section another step just added.** This is expected and by design. The `ai-memory-setup` step runs after environment steps and converts verbose inline blocks to compact pointer references. The referenced docs must exist before the pointer is valid.
|
|
205
|
+
|
|
206
|
+
**User adds custom sections between pipeline runs.** Subsequent pipeline steps must detect and preserve custom sections. Use the tracking comment (`<!-- scaffold:step-name -->`) to identify pipeline-managed sections vs. user-added sections.
|
|
207
|
+
|
|
208
|
+
### Update Mode Handling
|
|
209
|
+
|
|
210
|
+
#### Detecting Existing Content
|
|
211
|
+
|
|
212
|
+
Every pipeline step that modifies CLAUDE.md implements mode detection:
|
|
213
|
+
- If the file does not exist → create mode (write full skeleton)
|
|
214
|
+
- If the file exists → update mode (modify owned sections in-place)
|
|
215
|
+
|
|
216
|
+
Update mode is the common case. After the first `beads` run, every subsequent step encounters an existing CLAUDE.md.
|
|
217
|
+
|
|
218
|
+
#### Preserving Custom Sections
|
|
219
|
+
|
|
220
|
+
Users customize CLAUDE.md between pipeline runs. Common customizations:
|
|
221
|
+
- Adding project-specific rules
|
|
222
|
+
- Adding custom command aliases
|
|
223
|
+
- Adding team-specific workflow notes
|
|
224
|
+
- Adding integration-specific sections (deployment, monitoring)
|
|
225
|
+
|
|
226
|
+
Pipeline steps must preserve all content they do not own. The safest pattern is:
|
|
227
|
+
1. Read the existing CLAUDE.md
|
|
228
|
+
2. Identify sections owned by this step (by heading or tracking comment)
|
|
229
|
+
3. Replace only those sections with updated content
|
|
230
|
+
4. Leave everything else untouched
|
|
231
|
+
|
|
232
|
+
#### Additive Updates
|
|
233
|
+
|
|
234
|
+
When updating a section, prefer additive changes over destructive ones:
|
|
235
|
+
- Add new table rows rather than replacing the entire table
|
|
236
|
+
- Add new subsections rather than rewriting the section
|
|
237
|
+
- Append to lists rather than replacing them
|
|
238
|
+
- Only remove content if it is demonstrably wrong or duplicated
|
|
239
|
+
|
|
240
|
+
### Common Anti-Patterns
|
|
241
|
+
|
|
242
|
+
**Inline everything.** CLAUDE.md becomes 500+ lines with full coding standards, complete git workflow, entire project structure. Agent adherence drops, load time increases, signal drowns in noise. Fix: use the pointer pattern. Keep CLAUDE.md under 200 lines.
|
|
243
|
+
|
|
244
|
+
**Stale commands.** Key Commands table references `npm test` but the project switched to `bun test` two months ago. The agent runs the wrong command and wastes a cycle. Fix: keep Key Commands in sync with actual build tool configuration. The `claude-md-optimization` step verifies this.
|
|
245
|
+
|
|
246
|
+
**Conflicting rules.** CLAUDE.md says "always use conventional commits" in one section and "use `[BD-xxx]` prefix" in another, with no guidance on which takes precedence. Fix: consolidate commit message rules in one place. If both apply, show the combined format: `[BD-42] feat(api): implement endpoint`.
|
|
247
|
+
|
|
248
|
+
**Redundant instructions.** The same rule appears in Core Principles, Workflow, and Rules sections with slightly different wording. The agent may follow one version and violate another. Fix: state each rule once in its canonical section. Other sections reference it.
|
|
249
|
+
|
|
250
|
+
**Missing doc lookup.** CLAUDE.md references "the git workflow" but does not specify the file path. The agent searches, guesses, or ignores the reference. Fix: always include exact file paths in references.
|
|
251
|
+
|
|
252
|
+
**No update mode.** A pipeline step blindly writes a complete CLAUDE.md, overwriting sections added by earlier steps. Fix: every step that modifies CLAUDE.md must read it first, identify its owned sections, and update only those sections.
|
|
253
|
+
|
|
254
|
+
**Over-specifying autonomous behavior.** CLAUDE.md micro-manages every agent decision: "If you see a typo, fix it. If you see a missing import, add it. If you see..." This wastes lines on things the agent would do anyway. Fix: autonomous behavior should cover non-obvious expectations — "fix bugs on sight," "use subagents for research," "re-plan when stuck." Skip obvious behaviors.
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: coding-conventions
|
|
3
|
+
description: Universal coding standards patterns across languages and linter/formatter configuration
|
|
4
|
+
topics: [coding-standards, linting, formatting, naming, error-handling, code-style]
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Coding Conventions
|
|
8
|
+
|
|
9
|
+
Coding conventions eliminate decision fatigue, reduce code review friction, and make codebases navigable by any team member. Good conventions are enforced by tooling, not willpower. This knowledge covers universal patterns across languages, language-specific catalogs, and the tooling that makes conventions stick.
|
|
10
|
+
|
|
11
|
+
## Summary
|
|
12
|
+
|
|
13
|
+
### Categories of Standards
|
|
14
|
+
|
|
15
|
+
Coding standards fall into six categories, each requiring different enforcement strategies:
|
|
16
|
+
|
|
17
|
+
1. **Naming Conventions** — Variable, function, class, file, and directory naming patterns. Language-specific (camelCase in JS/TS, snake_case in Python/Go). Enforced by linters.
|
|
18
|
+
2. **Formatting** — Indentation, line length, brace placement, trailing commas, semicolons. Enforced by formatters (Prettier, Black, gofmt). Never debated in code review.
|
|
19
|
+
3. **Error Handling** — How errors are created, propagated, caught, and reported. Language-specific patterns (try/catch, Result types, error returns). Enforced by linters + adherence evals.
|
|
20
|
+
4. **Import Organization** — Ordering (stdlib, third-party, local), grouping, path aliasing. Enforced by linters (eslint-plugin-import, isort).
|
|
21
|
+
5. **Comment Philosophy** — When to comment (why, not what), documentation comments vs inline, TODO format, deprecation markers. Partially enforced by linters.
|
|
22
|
+
6. **Code Structure** — Function length limits, file length guidelines, single responsibility, early returns. Enforced by linters + code review.
|
|
23
|
+
|
|
24
|
+
### Linter/Formatter Selection
|
|
25
|
+
|
|
26
|
+
**Rule**: Formatters handle style. Linters handle correctness and patterns. Never configure linter rules that a formatter already handles.
|
|
27
|
+
|
|
28
|
+
| Language | Formatter | Linter | Config Location |
|
|
29
|
+
|----------|-----------|--------|----------------|
|
|
30
|
+
| TypeScript | Prettier | ESLint (flat config) | `eslint.config.js`, `.prettierrc` |
|
|
31
|
+
| Python | Black / Ruff format | Ruff | `pyproject.toml` |
|
|
32
|
+
| Go | gofmt (built-in) | golangci-lint | `.golangci.yml` |
|
|
33
|
+
| Shell | shfmt | ShellCheck | `.shellcheckrc`, `.editorconfig` |
|
|
34
|
+
| Rust | rustfmt | clippy | `rustfmt.toml`, `clippy.toml` |
|
|
35
|
+
|
|
36
|
+
### The Golden Rule
|
|
37
|
+
|
|
38
|
+
If a convention cannot be checked by a tool, it will not be followed consistently. Prefer conventions that can be automated. Document the rest, but accept lower compliance.
|
|
39
|
+
|
|
40
|
+
### Comment Philosophy at a Glance
|
|
41
|
+
|
|
42
|
+
Comments explain **why**, not **what**. If you need a comment to explain what code does, the code is too complex — refactor first. Extract well-named functions, use descriptive variables, replace magic numbers with constants. TODOs must include a task ID: `// TODO [BD-123]: Reason`. Bare TODOs are not allowed.
|
|
43
|
+
|
|
44
|
+
## Deep Guidance
|
|
45
|
+
|
|
46
|
+
### Language-Specific Convention Catalogs
|
|
47
|
+
|
|
48
|
+
#### TypeScript / JavaScript
|
|
49
|
+
|
|
50
|
+
**Naming**: Variables and functions use `camelCase`. Types, interfaces, and classes use `PascalCase`. True constants use `UPPER_SNAKE_CASE`. File names use `kebab-case.ts` for modules, `PascalCase.tsx` for React components. Booleans prefix with `is`, `has`, `can`, `should`. Private class fields use `#` prefix.
|
|
51
|
+
|
|
52
|
+
**Error handling**: Never catch and swallow — `catch (e) {}` is forbidden. Use custom error classes for domain errors. Never use `any` as a catch-all; use `unknown` and narrow. No `@ts-ignore` without a comment explaining why and linking to an issue.
|
|
53
|
+
|
|
54
|
+
**Imports**: Order as Node builtins, third-party, path-aliased local (`@/`), relative local. One blank line between groups. Prefer named exports over default exports. Use path aliases over deep relative paths.
|
|
55
|
+
|
|
56
|
+
**Key ESLint rules**: `no-explicit-any: error`, `no-unused-vars` (with `^_` pattern ignored), `prefer-const: error`, `no-var: error`, `eqeqeq: always`.
|
|
57
|
+
|
|
58
|
+
#### Python
|
|
59
|
+
|
|
60
|
+
**Naming**: Variables, functions, methods use `snake_case`. Classes use `PascalCase`. Constants use `UPPER_SNAKE_CASE`. Modules and packages use short `snake_case` names. Type variables use `T`, `K`, `V` or descriptive `UserT`.
|
|
61
|
+
|
|
62
|
+
**Error handling**: Never bare `except:` — always catch specific exceptions. Use custom exceptions inheriting from a project base exception. Use context managers for resource cleanup. Avoid `assert` in production code (stripped with `-O`).
|
|
63
|
+
|
|
64
|
+
**Imports**: Order as stdlib, third-party, local (enforced by isort/ruff). No `from module import *`. Absolute imports preferred; relative imports acceptable within a package.
|
|
65
|
+
|
|
66
|
+
**Ruff config**: Select rules `E, F, W, I, N, UP, B, SIM, T20` covering pycodestyle, pyflakes, isort, naming, pyupgrade, bugbear, simplify, and no-print.
|
|
67
|
+
|
|
68
|
+
#### Go
|
|
69
|
+
|
|
70
|
+
**Naming**: Exported identifiers use `PascalCase`, unexported use `camelCase`. Acronyms are all caps (`ID`, `HTTP`, `URL`). Single-method interfaces use method name + `er` suffix (`Reader`, `Writer`). Package names are short, lowercase, no underscores.
|
|
71
|
+
|
|
72
|
+
**Error handling**: Always check error returns — never discard with `_`. Wrap errors with context: `fmt.Errorf("fetch user %s: %w", id, err)`. Use sentinel errors for expected conditions. Use `errors.Is()` and `errors.As()`, never string comparison. Return errors, don't panic.
|
|
73
|
+
|
|
74
|
+
**Formatting**: `gofmt` is non-negotiable. Run on save. No style discussions in Go.
|
|
75
|
+
|
|
76
|
+
**Linter**: Enable `errcheck`, `govet`, `staticcheck`, `unused`, `gosimple`, `ineffassign`, `gocritic` via golangci-lint.
|
|
77
|
+
|
|
78
|
+
#### Shell (Bash)
|
|
79
|
+
|
|
80
|
+
**Naming**: Variables use `snake_case`. Constants/environment use `UPPER_SNAKE_CASE`. Functions use `snake_case`. Script files use `kebab-case.sh`.
|
|
81
|
+
|
|
82
|
+
**Error handling**: Every script starts with `set -euo pipefail`. Use `trap` for cleanup. Quote all variable expansions. Use `[[ ]]` over `[ ]`. Check command existence before use.
|
|
83
|
+
|
|
84
|
+
**ShellCheck**: Run on all `.sh` files. Address warnings; if a directive is needed, comment why.
|
|
85
|
+
|
|
86
|
+
### Naming Convention Matrix
|
|
87
|
+
|
|
88
|
+
| Context | TypeScript | Python | Go |
|
|
89
|
+
|---------|-----------|--------|-----|
|
|
90
|
+
| Local variable | `camelCase` | `snake_case` | `camelCase` |
|
|
91
|
+
| Function/method | `camelCase` | `snake_case` | `PascalCase` (exported) |
|
|
92
|
+
| Class/type | `PascalCase` | `PascalCase` | `PascalCase` |
|
|
93
|
+
| Constant | `UPPER_SNAKE` | `UPPER_SNAKE` | `PascalCase` (exported) |
|
|
94
|
+
| File name | `kebab-case` | `snake_case` | `snake_case` |
|
|
95
|
+
| Database column | `snake_case` | `snake_case` | `snake_case` |
|
|
96
|
+
| Environment var | `UPPER_SNAKE` | `UPPER_SNAKE` | `UPPER_SNAKE` |
|
|
97
|
+
| URL path | `kebab-case` | `kebab-case` | `kebab-case` |
|
|
98
|
+
|
|
99
|
+
**The context rule**: Follow the convention of the domain you are writing in, not the language you are writing with. Database columns are `snake_case` regardless of whether your ORM is in TypeScript or Go.
|
|
100
|
+
|
|
101
|
+
### Comment and Documentation Standards
|
|
102
|
+
|
|
103
|
+
**When to comment**: Explain intent, constraints, and non-obvious decisions. Never narrate code. Bad: `// increment counter` before `counter++`. Good: `// Retry up to 3 times — upstream API has transient 503s during deployments`.
|
|
104
|
+
|
|
105
|
+
**When code should self-document**: Extract well-named functions instead of commenting blocks. Use descriptive variable names instead of commenting values. Use enums/constants instead of commenting magic numbers.
|
|
106
|
+
|
|
107
|
+
**Documentation comments**: Public APIs always need documentation comments. TypeScript uses JSDoc `/** */`. Python uses docstrings. Go uses comments above exported identifiers starting with the identifier name.
|
|
108
|
+
|
|
109
|
+
**TODO format**: `// TODO [BD-123]: Reason for the TODO`. Also `FIXME [BD-456]` and `HACK [BD-789]`. Bare TODOs without task IDs accumulate without accountability and are not allowed.
|
|
110
|
+
|
|
111
|
+
### Error Handling Patterns by Language
|
|
112
|
+
|
|
113
|
+
The error handling strategy must be consistent within each architectural layer and documented in `docs/coding-standards.md`.
|
|
114
|
+
|
|
115
|
+
#### TypeScript Error Pattern
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
// Domain errors with discriminated unions
|
|
119
|
+
class AppError extends Error {
|
|
120
|
+
constructor(message: string, public readonly code: string) {
|
|
121
|
+
super(message);
|
|
122
|
+
this.name = 'AppError';
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
class NotFoundError extends AppError {
|
|
126
|
+
constructor(resource: string, id: string) {
|
|
127
|
+
super(`${resource} not found: ${id}`, 'NOT_FOUND');
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Service layer: throw domain errors
|
|
132
|
+
async function getUser(id: string): Promise<User> {
|
|
133
|
+
const user = await userRepo.findById(id);
|
|
134
|
+
if (!user) throw new NotFoundError('User', id);
|
|
135
|
+
return user;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Controller layer: catch and map to HTTP responses
|
|
139
|
+
app.get('/users/:id', async (req, res) => {
|
|
140
|
+
try {
|
|
141
|
+
const user = await getUser(req.params.id);
|
|
142
|
+
res.json(user);
|
|
143
|
+
} catch (err) {
|
|
144
|
+
if (err instanceof NotFoundError) return res.status(404).json({ error: err.message });
|
|
145
|
+
throw err; // re-throw unexpected errors for global handler
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
#### Python Error Pattern
|
|
151
|
+
|
|
152
|
+
```python
|
|
153
|
+
class AppError(Exception):
|
|
154
|
+
"""Base exception for the application."""
|
|
155
|
+
def __init__(self, message: str, code: str = "INTERNAL"):
|
|
156
|
+
super().__init__(message)
|
|
157
|
+
self.code = code
|
|
158
|
+
|
|
159
|
+
class NotFoundError(AppError):
|
|
160
|
+
def __init__(self, resource: str, id: str):
|
|
161
|
+
super().__init__(f"{resource} not found: {id}", "NOT_FOUND")
|
|
162
|
+
|
|
163
|
+
# FastAPI exception handler
|
|
164
|
+
@app.exception_handler(NotFoundError)
|
|
165
|
+
async def not_found_handler(request, exc):
|
|
166
|
+
return JSONResponse(status_code=404, content={"error": str(exc)})
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
#### Go Error Pattern
|
|
170
|
+
|
|
171
|
+
```go
|
|
172
|
+
var ErrNotFound = errors.New("not found")
|
|
173
|
+
|
|
174
|
+
func (r *UserRepo) FindByID(ctx context.Context, id string) (*User, error) {
|
|
175
|
+
user, err := r.db.QueryRow(ctx, "SELECT ... WHERE id = $1", id)
|
|
176
|
+
if err != nil {
|
|
177
|
+
if errors.Is(err, sql.ErrNoRows) {
|
|
178
|
+
return nil, fmt.Errorf("user %s: %w", id, ErrNotFound)
|
|
179
|
+
}
|
|
180
|
+
return nil, fmt.Errorf("query user %s: %w", id, err)
|
|
181
|
+
}
|
|
182
|
+
return user, nil
|
|
183
|
+
}
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### Import Organization Details
|
|
187
|
+
|
|
188
|
+
Consistent import ordering makes files scannable and diffs cleaner. Every language has an established convention:
|
|
189
|
+
|
|
190
|
+
**TypeScript** (enforced by `eslint-plugin-import`):
|
|
191
|
+
```typescript
|
|
192
|
+
// 1. Node built-ins
|
|
193
|
+
import { readFileSync } from 'fs';
|
|
194
|
+
import path from 'path';
|
|
195
|
+
|
|
196
|
+
// 2. Third-party packages
|
|
197
|
+
import express from 'express';
|
|
198
|
+
import { z } from 'zod';
|
|
199
|
+
|
|
200
|
+
// 3. Path-aliased local imports
|
|
201
|
+
import { config } from '@/config/env';
|
|
202
|
+
import { UserService } from '@/features/auth';
|
|
203
|
+
|
|
204
|
+
// 4. Relative imports
|
|
205
|
+
import { validateInput } from './helpers';
|
|
206
|
+
import type { RequestContext } from './types';
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
**Python** (enforced by `isort` or `ruff`):
|
|
210
|
+
```python
|
|
211
|
+
# 1. Standard library
|
|
212
|
+
import os
|
|
213
|
+
from pathlib import Path
|
|
214
|
+
|
|
215
|
+
# 2. Third-party
|
|
216
|
+
from fastapi import Depends
|
|
217
|
+
from sqlalchemy.orm import Session
|
|
218
|
+
|
|
219
|
+
# 3. Local
|
|
220
|
+
from app.core.config import settings
|
|
221
|
+
from app.services.auth import AuthService
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
### Linter Configuration Strategies
|
|
225
|
+
|
|
226
|
+
**Strict from Day One**: Enable all rules at project start. Zero warnings policy. Best for new projects and small teams.
|
|
227
|
+
|
|
228
|
+
**Progressive Adoption**: Start with formatter + critical rules only. Add rules incrementally. Track `eslint-disable-next-line` counts as a health metric — they should decrease over time, not increase. Best for existing projects and large teams.
|
|
229
|
+
|
|
230
|
+
**The Warning Trap**: Never leave linter rules as warnings long-term. Warnings are ignored. Either a rule is an error (enforced) or off (not enforced). Warnings create noise without value.
|
|
231
|
+
|
|
232
|
+
**Monorepo inheritance**: Root config has shared rules. Package configs extend root with package-specific additions. Override blocks handle per-directory exceptions (test files get relaxed rules).
|
|
233
|
+
|
|
234
|
+
### Common Anti-Patterns
|
|
235
|
+
|
|
236
|
+
**Inconsistent Naming**: Same concept has different names — `userId`, `user_id`, `UserID`, `uid` in one codebase. Fix: define a naming glossary in `docs/coding-standards.md`. One name for one concept.
|
|
237
|
+
|
|
238
|
+
**Swallowed Errors**: `catch (e) {}` or `except: pass` discards errors silently. Fix: lint rules that forbid empty catch blocks. If truly intentional, require a justification comment.
|
|
239
|
+
|
|
240
|
+
**Magic Numbers**: `if (retries > 3)` or `setTimeout(fn, 86400000)` with no context. Fix: extract to named constants. Lint rules can flag numeric literals in conditionals.
|
|
241
|
+
|
|
242
|
+
**Over-Commenting**: Every line has a comment restating what the code does. Fix: delete comments that restate code. Keep only "why" comments.
|
|
243
|
+
|
|
244
|
+
**Inconsistent Error Handling**: Some functions throw, some return null, some return error codes. Fix: document one error strategy per architectural layer. Controllers throw HTTP errors. Services return Result types. Repositories throw data access errors.
|
|
245
|
+
|
|
246
|
+
**Import Chaos**: No ordering, mixed styles, deep relative paths. Fix: configure import-ordering tools (`eslint-plugin-import`, `isort`) and path aliases. Run formatter on save.
|
|
@@ -4,6 +4,8 @@ description: Database schema design, normalization, indexing, and migration patt
|
|
|
4
4
|
topics: [database, schema, sql, nosql, migrations, indexing, data-modeling]
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
+
## Summary
|
|
8
|
+
|
|
7
9
|
## From Domain Models to Schema
|
|
8
10
|
|
|
9
11
|
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.
|
|
@@ -77,6 +79,8 @@ metadata JSONB NOT NULL DEFAULT '{}'
|
|
|
77
79
|
|
|
78
80
|
**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
81
|
|
|
82
|
+
## Deep Guidance
|
|
83
|
+
|
|
80
84
|
### Modeling Relationships
|
|
81
85
|
|
|
82
86
|
**One-to-one:** Use a foreign key in either table (typically the dependent side). Consider: could this be columns in the same table instead?
|
|
@@ -378,3 +382,7 @@ For distributed databases (DynamoDB, Cassandra), the partition key determines da
|
|
|
378
382
|
**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
383
|
|
|
380
384
|
**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.
|
|
385
|
+
|
|
386
|
+
## See Also
|
|
387
|
+
|
|
388
|
+
- [domain-modeling](../core/domain-modeling.md) — Domain entities map to database schema
|