gaia-framework 1.57.0 → 1.57.2
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 +1 -1
- package/bin/gaia-framework.js +27 -19
- package/gaia-install.sh +1 -1
- package/package.json +15 -11
- package/.claude/commands/gaia-a11y-testing.md +0 -17
- package/.claude/commands/gaia-action-items.md +0 -23
- package/.claude/commands/gaia-add-feature.md +0 -17
- package/.claude/commands/gaia-add-stories.md +0 -17
- package/.claude/commands/gaia-advanced-elicitation.md +0 -17
- package/.claude/commands/gaia-adversarial.md +0 -15
- package/.claude/commands/gaia-agent-analyst.md +0 -14
- package/.claude/commands/gaia-agent-architect.md +0 -14
- package/.claude/commands/gaia-agent-brainstorming.md +0 -14
- package/.claude/commands/gaia-agent-data-engineer.md +0 -14
- package/.claude/commands/gaia-agent-design-thinking.md +0 -14
- package/.claude/commands/gaia-agent-dev-angular.md +0 -14
- package/.claude/commands/gaia-agent-dev-flutter.md +0 -14
- package/.claude/commands/gaia-agent-dev-go.md +0 -14
- package/.claude/commands/gaia-agent-dev-java.md +0 -14
- package/.claude/commands/gaia-agent-dev-mobile.md +0 -14
- package/.claude/commands/gaia-agent-dev-python.md +0 -14
- package/.claude/commands/gaia-agent-dev-typescript.md +0 -14
- package/.claude/commands/gaia-agent-devops.md +0 -14
- package/.claude/commands/gaia-agent-innovation.md +0 -14
- package/.claude/commands/gaia-agent-performance.md +0 -14
- package/.claude/commands/gaia-agent-pm.md +0 -14
- package/.claude/commands/gaia-agent-presentation.md +0 -14
- package/.claude/commands/gaia-agent-problem-solver.md +0 -14
- package/.claude/commands/gaia-agent-qa.md +0 -14
- package/.claude/commands/gaia-agent-security.md +0 -14
- package/.claude/commands/gaia-agent-sm.md +0 -14
- package/.claude/commands/gaia-agent-storyteller.md +0 -14
- package/.claude/commands/gaia-agent-tech-writer.md +0 -14
- package/.claude/commands/gaia-agent-test-architect.md +0 -14
- package/.claude/commands/gaia-agent-ux-designer.md +0 -14
- package/.claude/commands/gaia-agent-validator.md +0 -14
- package/.claude/commands/gaia-atdd.md +0 -17
- package/.claude/commands/gaia-brainstorm.md +0 -17
- package/.claude/commands/gaia-brainstorming.md +0 -17
- package/.claude/commands/gaia-brownfield.md +0 -17
- package/.claude/commands/gaia-build-configs.md +0 -22
- package/.claude/commands/gaia-change-request.md +0 -11
- package/.claude/commands/gaia-changelog.md +0 -16
- package/.claude/commands/gaia-check-dod.md +0 -17
- package/.claude/commands/gaia-check-review-gate.md +0 -17
- package/.claude/commands/gaia-ci-setup.md +0 -17
- package/.claude/commands/gaia-code-review.md +0 -17
- package/.claude/commands/gaia-correct-course.md +0 -17
- package/.claude/commands/gaia-create-arch.md +0 -17
- package/.claude/commands/gaia-create-epics.md +0 -17
- package/.claude/commands/gaia-create-prd.md +0 -17
- package/.claude/commands/gaia-create-story.md +0 -23
- package/.claude/commands/gaia-create-ux.md +0 -17
- package/.claude/commands/gaia-creative-sprint.md +0 -17
- package/.claude/commands/gaia-deploy-checklist.md +0 -17
- package/.claude/commands/gaia-design-thinking.md +0 -17
- package/.claude/commands/gaia-dev-story.md +0 -23
- package/.claude/commands/gaia-document-project.md +0 -17
- package/.claude/commands/gaia-domain-research.md +0 -17
- package/.claude/commands/gaia-edge-cases.md +0 -15
- package/.claude/commands/gaia-edit-arch.md +0 -17
- package/.claude/commands/gaia-edit-prd.md +0 -17
- package/.claude/commands/gaia-edit-test-plan.md +0 -17
- package/.claude/commands/gaia-editorial-prose.md +0 -15
- package/.claude/commands/gaia-editorial-structure.md +0 -15
- package/.claude/commands/gaia-epic-status.md +0 -17
- package/.claude/commands/gaia-fix-story.md +0 -17
- package/.claude/commands/gaia-help.md +0 -15
- package/.claude/commands/gaia-index-docs.md +0 -15
- package/.claude/commands/gaia-infra-design.md +0 -17
- package/.claude/commands/gaia-innovation.md +0 -17
- package/.claude/commands/gaia-market-research.md +0 -17
- package/.claude/commands/gaia-memory-hygiene.md +0 -17
- package/.claude/commands/gaia-merge-docs.md +0 -16
- package/.claude/commands/gaia-mobile-testing.md +0 -17
- package/.claude/commands/gaia-nfr.md +0 -17
- package/.claude/commands/gaia-party.md +0 -17
- package/.claude/commands/gaia-perf-testing.md +0 -17
- package/.claude/commands/gaia-performance-review.md +0 -17
- package/.claude/commands/gaia-pitch-deck.md +0 -17
- package/.claude/commands/gaia-post-deploy.md +0 -17
- package/.claude/commands/gaia-problem-solving.md +0 -17
- package/.claude/commands/gaia-product-brief.md +0 -17
- package/.claude/commands/gaia-project-context.md +0 -17
- package/.claude/commands/gaia-qa-tests.md +0 -17
- package/.claude/commands/gaia-quick-dev.md +0 -17
- package/.claude/commands/gaia-quick-spec.md +0 -17
- package/.claude/commands/gaia-readiness-check.md +0 -17
- package/.claude/commands/gaia-refresh-ground-truth.md +0 -17
- package/.claude/commands/gaia-release-plan.md +0 -17
- package/.claude/commands/gaia-resume.md +0 -25
- package/.claude/commands/gaia-retro.md +0 -20
- package/.claude/commands/gaia-review-a11y.md +0 -16
- package/.claude/commands/gaia-review-api.md +0 -16
- package/.claude/commands/gaia-review-deps.md +0 -16
- package/.claude/commands/gaia-review-perf.md +0 -16
- package/.claude/commands/gaia-review-security.md +0 -16
- package/.claude/commands/gaia-rollback-plan.md +0 -17
- package/.claude/commands/gaia-run-all-reviews.md +0 -17
- package/.claude/commands/gaia-security-review.md +0 -17
- package/.claude/commands/gaia-shard-doc.md +0 -15
- package/.claude/commands/gaia-slide-deck.md +0 -17
- package/.claude/commands/gaia-sprint-plan.md +0 -17
- package/.claude/commands/gaia-sprint-status.md +0 -17
- package/.claude/commands/gaia-storytelling.md +0 -17
- package/.claude/commands/gaia-summarize.md +0 -16
- package/.claude/commands/gaia-teach-testing.md +0 -17
- package/.claude/commands/gaia-tech-debt-review.md +0 -20
- package/.claude/commands/gaia-tech-research.md +0 -17
- package/.claude/commands/gaia-test-automate.md +0 -17
- package/.claude/commands/gaia-test-design.md +0 -17
- package/.claude/commands/gaia-test-framework.md +0 -17
- package/.claude/commands/gaia-test-review.md +0 -17
- package/.claude/commands/gaia-threat-model.md +0 -17
- package/.claude/commands/gaia-trace.md +0 -17
- package/.claude/commands/gaia-triage-findings.md +0 -20
- package/.claude/commands/gaia-val-validate-plan.md +0 -17
- package/.claude/commands/gaia-val-validate.md +0 -17
- package/.claude/commands/gaia-validate-framework.md +0 -17
- package/.claude/commands/gaia-validate-prd.md +0 -17
- package/.claude/commands/gaia-validate-story.md +0 -22
- package/.claude/commands/gaia.md +0 -32
- package/CLAUDE.md +0 -165
- package/_gaia/_config/agent-manifest.csv +0 -29
- package/_gaia/_config/agents/CUSTOMIZATION-README.md +0 -117
- package/_gaia/_config/files-manifest.csv +0 -30
- package/_gaia/_config/gaia-help.csv +0 -82
- package/_gaia/_config/global.yaml +0 -45
- package/_gaia/_config/lifecycle-sequence.yaml +0 -593
- package/_gaia/_config/manifest.yaml +0 -24
- package/_gaia/_config/skill-manifest.csv +0 -12
- package/_gaia/_config/task-manifest.csv +0 -17
- package/_gaia/_config/workflow-manifest.csv +0 -73
- package/_gaia/_memory/tier2-results/.gitkeep +0 -0
- package/_gaia/_memory/tier2-results/checkpoint-resume-2026-03-24.yaml +0 -6
- package/_gaia/_memory/tier2-results/engine-scenarios-2026-03-22.yaml +0 -14
- package/_gaia/core/.resolved/.gitkeep +0 -0
- package/_gaia/core/agents/orchestrator.md +0 -303
- package/_gaia/core/config.yaml +0 -8
- package/_gaia/core/engine/error-recovery.xml +0 -28
- package/_gaia/core/engine/protocols/discover-inputs.xml +0 -31
- package/_gaia/core/engine/protocols/handoff.xml +0 -21
- package/_gaia/core/engine/protocols/preflight-check.xml +0 -31
- package/_gaia/core/engine/task-runner.xml +0 -63
- package/_gaia/core/engine/workflow.xml +0 -225
- package/_gaia/core/module-help.csv +0 -21
- package/_gaia/core/protocols/agent-specification-protocol.md +0 -103
- package/_gaia/core/protocols/review-gate-check.xml +0 -29
- package/_gaia/core/protocols/sprint-status-write-safety.xml +0 -35
- package/_gaia/core/protocols/status-sync.xml +0 -49
- package/_gaia/core/tasks/editorial-review-prose.xml +0 -42
- package/_gaia/core/tasks/editorial-review-structure.xml +0 -43
- package/_gaia/core/tasks/generate-changelog.xml +0 -35
- package/_gaia/core/tasks/help.md +0 -45
- package/_gaia/core/tasks/index-docs.xml +0 -46
- package/_gaia/core/tasks/merge-docs.xml +0 -34
- package/_gaia/core/tasks/review-accessibility.xml +0 -47
- package/_gaia/core/tasks/review-adversarial.xml +0 -55
- package/_gaia/core/tasks/review-api-design.xml +0 -38
- package/_gaia/core/tasks/review-dependency-audit.xml +0 -38
- package/_gaia/core/tasks/review-edge-case-hunter.xml +0 -52
- package/_gaia/core/tasks/review-performance.xml +0 -49
- package/_gaia/core/tasks/review-security.xml +0 -37
- package/_gaia/core/tasks/shard-doc.xml +0 -49
- package/_gaia/core/tasks/summarize-doc.xml +0 -33
- package/_gaia/core/tasks/validate-framework.xml +0 -66
- package/_gaia/core/workflows/brainstorming/steps/step-01-session-setup.md +0 -7
- package/_gaia/core/workflows/brainstorming/steps/step-02-technique-selection.md +0 -20
- package/_gaia/core/workflows/brainstorming/steps/step-03-technique-execution.md +0 -11
- package/_gaia/core/workflows/brainstorming/steps/step-04-idea-organization.md +0 -14
- package/_gaia/core/workflows/brainstorming/template.md +0 -38
- package/_gaia/core/workflows/brainstorming/workflow.yaml +0 -26
- package/_gaia/core/workflows/party-mode/steps/step-01-agent-loading.md +0 -11
- package/_gaia/core/workflows/party-mode/steps/step-02-discussion-orchestration.md +0 -16
- package/_gaia/core/workflows/party-mode/steps/step-03-graceful-exit.md +0 -10
- package/_gaia/core/workflows/party-mode/workflow.yaml +0 -23
- package/_gaia/creative/.resolved/.gitkeep +0 -0
- package/_gaia/creative/agents/brainstorming-coach.md +0 -93
- package/_gaia/creative/agents/design-thinking-coach.md +0 -91
- package/_gaia/creative/agents/innovation-strategist.md +0 -89
- package/_gaia/creative/agents/presentation-designer.md +0 -99
- package/_gaia/creative/agents/problem-solver.md +0 -90
- package/_gaia/creative/agents/storyteller.md +0 -90
- package/_gaia/creative/config.yaml +0 -8
- package/_gaia/creative/data/design-methods.csv +0 -28
- package/_gaia/creative/data/innovation-frameworks.csv +0 -15
- package/_gaia/creative/data/solving-methods.csv +0 -14
- package/_gaia/creative/data/story-types.csv +0 -12
- package/_gaia/creative/module-help.csv +0 -8
- package/_gaia/creative/teams/creative-squad.yaml +0 -10
- package/_gaia/creative/workflows/creative-sprint/checklist.md +0 -10
- package/_gaia/creative/workflows/creative-sprint/instructions.xml +0 -40
- package/_gaia/creative/workflows/creative-sprint/workflow.yaml +0 -11
- package/_gaia/creative/workflows/design-thinking/checklist.md +0 -25
- package/_gaia/creative/workflows/design-thinking/instructions.xml +0 -38
- package/_gaia/creative/workflows/design-thinking/workflow.yaml +0 -13
- package/_gaia/creative/workflows/innovation-strategy/checklist.md +0 -26
- package/_gaia/creative/workflows/innovation-strategy/instructions.xml +0 -34
- package/_gaia/creative/workflows/innovation-strategy/workflow.yaml +0 -13
- package/_gaia/creative/workflows/pitch-deck/checklist.md +0 -22
- package/_gaia/creative/workflows/pitch-deck/instructions.xml +0 -49
- package/_gaia/creative/workflows/pitch-deck/workflow.yaml +0 -15
- package/_gaia/creative/workflows/problem-solving/checklist.md +0 -26
- package/_gaia/creative/workflows/problem-solving/instructions.xml +0 -39
- package/_gaia/creative/workflows/problem-solving/workflow.yaml +0 -13
- package/_gaia/creative/workflows/slide-deck/checklist.md +0 -21
- package/_gaia/creative/workflows/slide-deck/instructions.xml +0 -39
- package/_gaia/creative/workflows/slide-deck/workflow.yaml +0 -15
- package/_gaia/creative/workflows/storytelling/checklist.md +0 -26
- package/_gaia/creative/workflows/storytelling/instructions.xml +0 -38
- package/_gaia/creative/workflows/storytelling/workflow.yaml +0 -13
- package/_gaia/dev/agents/_base-dev.md +0 -180
- package/_gaia/dev/agents/angular-dev.md +0 -70
- package/_gaia/dev/agents/flutter-dev.md +0 -70
- package/_gaia/dev/agents/go-dev.md +0 -72
- package/_gaia/dev/agents/java-dev.md +0 -70
- package/_gaia/dev/agents/mobile-dev.md +0 -70
- package/_gaia/dev/agents/python-dev.md +0 -70
- package/_gaia/dev/agents/typescript-dev.md +0 -70
- package/_gaia/dev/config.yaml +0 -11
- package/_gaia/dev/knowledge/_index.csv +0 -25
- package/_gaia/dev/knowledge/angular/angular-conventions.md +0 -119
- package/_gaia/dev/knowledge/angular/angular-patterns.md +0 -126
- package/_gaia/dev/knowledge/angular/ngrx-state.md +0 -124
- package/_gaia/dev/knowledge/angular/rxjs-patterns.md +0 -119
- package/_gaia/dev/knowledge/flutter/dart-conventions.md +0 -143
- package/_gaia/dev/knowledge/flutter/platform-channels.md +0 -144
- package/_gaia/dev/knowledge/flutter/state-management.md +0 -144
- package/_gaia/dev/knowledge/flutter/widget-patterns.md +0 -134
- package/_gaia/dev/knowledge/go/gin-fiber-patterns.md +0 -40
- package/_gaia/dev/knowledge/go/go-conventions.md +0 -54
- package/_gaia/dev/knowledge/go/go-stdlib-patterns.md +0 -39
- package/_gaia/dev/knowledge/go/go-testing-patterns.md +0 -39
- package/_gaia/dev/knowledge/java/jpa-patterns.md +0 -136
- package/_gaia/dev/knowledge/java/maven-gradle.md +0 -189
- package/_gaia/dev/knowledge/java/microservices.md +0 -159
- package/_gaia/dev/knowledge/java/spring-boot-patterns.md +0 -160
- package/_gaia/dev/knowledge/mobile/kotlin-patterns.md +0 -193
- package/_gaia/dev/knowledge/mobile/mobile-testing.md +0 -186
- package/_gaia/dev/knowledge/mobile/react-native-patterns.md +0 -162
- package/_gaia/dev/knowledge/mobile/swift-patterns.md +0 -190
- package/_gaia/dev/knowledge/python/data-pipelines.md +0 -169
- package/_gaia/dev/knowledge/python/django-patterns.md +0 -145
- package/_gaia/dev/knowledge/python/fastapi-patterns.md +0 -164
- package/_gaia/dev/knowledge/python/python-conventions.md +0 -170
- package/_gaia/dev/knowledge/typescript/express-patterns.md +0 -188
- package/_gaia/dev/knowledge/typescript/nextjs-patterns.md +0 -166
- package/_gaia/dev/knowledge/typescript/react-patterns.md +0 -176
- package/_gaia/dev/knowledge/typescript/ts-conventions.md +0 -133
- package/_gaia/dev/module-help.csv +0 -10
- package/_gaia/dev/skills/_skill-index.yaml +0 -55
- package/_gaia/dev/skills/api-design.md +0 -229
- package/_gaia/dev/skills/code-review-standards.md +0 -226
- package/_gaia/dev/skills/database-design.md +0 -172
- package/_gaia/dev/skills/docker-workflow.md +0 -222
- package/_gaia/dev/skills/documentation-standards.md +0 -256
- package/_gaia/dev/skills/git-workflow.md +0 -157
- package/_gaia/dev/skills/security-basics.md +0 -230
- package/_gaia/dev/skills/testing-patterns.md +0 -232
- package/_gaia/lifecycle/.resolved/.gitkeep +0 -0
- package/_gaia/lifecycle/agents/analyst.md +0 -104
- package/_gaia/lifecycle/agents/architect.md +0 -109
- package/_gaia/lifecycle/agents/data-engineer.md +0 -99
- package/_gaia/lifecycle/agents/devops.md +0 -110
- package/_gaia/lifecycle/agents/performance.md +0 -92
- package/_gaia/lifecycle/agents/pm.md +0 -112
- package/_gaia/lifecycle/agents/qa.md +0 -89
- package/_gaia/lifecycle/agents/security.md +0 -108
- package/_gaia/lifecycle/agents/sm.md +0 -119
- package/_gaia/lifecycle/agents/tech-writer.md +0 -94
- package/_gaia/lifecycle/agents/ux-designer.md +0 -94
- package/_gaia/lifecycle/agents/validator.md +0 -189
- package/_gaia/lifecycle/config.yaml +0 -14
- package/_gaia/lifecycle/module-help.csv +0 -39
- package/_gaia/lifecycle/skills/ground-truth-management.md +0 -252
- package/_gaia/lifecycle/skills/memory-management.md +0 -322
- package/_gaia/lifecycle/skills/validation-patterns.md +0 -230
- package/_gaia/lifecycle/teams/team-data-intensive.yaml +0 -12
- package/_gaia/lifecycle/teams/team-enterprise.yaml +0 -16
- package/_gaia/lifecycle/teams/team-full.yaml +0 -13
- package/_gaia/lifecycle/teams/team-implementation.yaml +0 -8
- package/_gaia/lifecycle/teams/team-planning.yaml +0 -9
- package/_gaia/lifecycle/teams/team-quick-ship.yaml +0 -6
- package/_gaia/lifecycle/teams/team-security-focused.yaml +0 -13
- package/_gaia/lifecycle/templates/api-documentation-template.md +0 -112
- package/_gaia/lifecycle/templates/architecture-template.md +0 -65
- package/_gaia/lifecycle/templates/brownfield-architecture-template.md +0 -198
- package/_gaia/lifecycle/templates/brownfield-assessment-template.md +0 -78
- package/_gaia/lifecycle/templates/brownfield-onboarding-template.md +0 -160
- package/_gaia/lifecycle/templates/dependency-map-template.md +0 -73
- package/_gaia/lifecycle/templates/deployment-template.md +0 -52
- package/_gaia/lifecycle/templates/epic-status-template.md +0 -64
- package/_gaia/lifecycle/templates/event-catalog-template.md +0 -78
- package/_gaia/lifecycle/templates/nfr-assessment-template.md +0 -96
- package/_gaia/lifecycle/templates/prd-template.md +0 -83
- package/_gaia/lifecycle/templates/product-brief-template.md +0 -48
- package/_gaia/lifecycle/templates/review-template.md +0 -47
- package/_gaia/lifecycle/templates/sprint-plan-template.md +0 -45
- package/_gaia/lifecycle/templates/story-template.md +0 -118
- package/_gaia/lifecycle/templates/tech-debt-dashboard-template.md +0 -71
- package/_gaia/lifecycle/templates/test-plan-template.md +0 -56
- package/_gaia/lifecycle/templates/ux-design-assessment-template.md +0 -122
- package/_gaia/lifecycle/workflows/1-analysis/advanced-elicitation/instructions.xml +0 -44
- package/_gaia/lifecycle/workflows/1-analysis/advanced-elicitation/methods.csv +0 -9
- package/_gaia/lifecycle/workflows/1-analysis/advanced-elicitation/workflow.yaml +0 -33
- package/_gaia/lifecycle/workflows/1-analysis/brainstorm-project/checklist.md +0 -24
- package/_gaia/lifecycle/workflows/1-analysis/brainstorm-project/instructions.xml +0 -39
- package/_gaia/lifecycle/workflows/1-analysis/brainstorm-project/workflow.yaml +0 -19
- package/_gaia/lifecycle/workflows/1-analysis/create-product-brief/checklist.md +0 -27
- package/_gaia/lifecycle/workflows/1-analysis/create-product-brief/instructions.xml +0 -57
- package/_gaia/lifecycle/workflows/1-analysis/create-product-brief/workflow.yaml +0 -38
- package/_gaia/lifecycle/workflows/1-analysis/domain-research/checklist.md +0 -22
- package/_gaia/lifecycle/workflows/1-analysis/domain-research/instructions.xml +0 -34
- package/_gaia/lifecycle/workflows/1-analysis/domain-research/workflow.yaml +0 -15
- package/_gaia/lifecycle/workflows/1-analysis/market-research/checklist.md +0 -28
- package/_gaia/lifecycle/workflows/1-analysis/market-research/instructions.xml +0 -42
- package/_gaia/lifecycle/workflows/1-analysis/market-research/workflow.yaml +0 -15
- package/_gaia/lifecycle/workflows/1-analysis/technical-research/checklist.md +0 -22
- package/_gaia/lifecycle/workflows/1-analysis/technical-research/instructions.xml +0 -34
- package/_gaia/lifecycle/workflows/1-analysis/technical-research/workflow.yaml +0 -15
- package/_gaia/lifecycle/workflows/2-planning/create-prd/checklist.md +0 -36
- package/_gaia/lifecycle/workflows/2-planning/create-prd/instructions.xml +0 -80
- package/_gaia/lifecycle/workflows/2-planning/create-prd/workflow.yaml +0 -23
- package/_gaia/lifecycle/workflows/2-planning/create-ux-design/checklist.md +0 -26
- package/_gaia/lifecycle/workflows/2-planning/create-ux-design/instructions.xml +0 -49
- package/_gaia/lifecycle/workflows/2-planning/create-ux-design/workflow.yaml +0 -23
- package/_gaia/lifecycle/workflows/2-planning/edit-prd/checklist.md +0 -17
- package/_gaia/lifecycle/workflows/2-planning/edit-prd/instructions.xml +0 -50
- package/_gaia/lifecycle/workflows/2-planning/edit-prd/workflow.yaml +0 -22
- package/_gaia/lifecycle/workflows/2-planning/validate-prd/checklist.md +0 -12
- package/_gaia/lifecycle/workflows/2-planning/validate-prd/instructions.xml +0 -52
- package/_gaia/lifecycle/workflows/2-planning/validate-prd/workflow.yaml +0 -19
- package/_gaia/lifecycle/workflows/3-solutioning/create-architecture/checklist.md +0 -32
- package/_gaia/lifecycle/workflows/3-solutioning/create-architecture/instructions.xml +0 -100
- package/_gaia/lifecycle/workflows/3-solutioning/create-architecture/workflow.yaml +0 -41
- package/_gaia/lifecycle/workflows/3-solutioning/create-epics-stories/checklist.md +0 -30
- package/_gaia/lifecycle/workflows/3-solutioning/create-epics-stories/instructions.xml +0 -86
- package/_gaia/lifecycle/workflows/3-solutioning/create-epics-stories/workflow.yaml +0 -34
- package/_gaia/lifecycle/workflows/3-solutioning/edit-architecture/checklist.md +0 -24
- package/_gaia/lifecycle/workflows/3-solutioning/edit-architecture/instructions.xml +0 -91
- package/_gaia/lifecycle/workflows/3-solutioning/edit-architecture/workflow.yaml +0 -32
- package/_gaia/lifecycle/workflows/3-solutioning/implementation-readiness/checklist.md +0 -66
- package/_gaia/lifecycle/workflows/3-solutioning/implementation-readiness/instructions.xml +0 -160
- package/_gaia/lifecycle/workflows/3-solutioning/implementation-readiness/workflow.yaml +0 -48
- package/_gaia/lifecycle/workflows/3-solutioning/infrastructure-design/checklist.md +0 -24
- package/_gaia/lifecycle/workflows/3-solutioning/infrastructure-design/instructions.xml +0 -44
- package/_gaia/lifecycle/workflows/3-solutioning/infrastructure-design/workflow.yaml +0 -23
- package/_gaia/lifecycle/workflows/3-solutioning/security-threat-model/checklist.md +0 -24
- package/_gaia/lifecycle/workflows/3-solutioning/security-threat-model/instructions.xml +0 -55
- package/_gaia/lifecycle/workflows/3-solutioning/security-threat-model/workflow.yaml +0 -23
- package/_gaia/lifecycle/workflows/4-implementation/action-items/instructions.xml +0 -131
- package/_gaia/lifecycle/workflows/4-implementation/action-items/workflow.yaml +0 -19
- package/_gaia/lifecycle/workflows/4-implementation/add-stories/checklist.md +0 -27
- package/_gaia/lifecycle/workflows/4-implementation/add-stories/instructions.xml +0 -100
- package/_gaia/lifecycle/workflows/4-implementation/add-stories/workflow.yaml +0 -35
- package/_gaia/lifecycle/workflows/4-implementation/change-request/checklist.md +0 -25
- package/_gaia/lifecycle/workflows/4-implementation/change-request/instructions.xml +0 -123
- package/_gaia/lifecycle/workflows/4-implementation/change-request/workflow.yaml +0 -38
- package/_gaia/lifecycle/workflows/4-implementation/check-dod/checklist.md +0 -18
- package/_gaia/lifecycle/workflows/4-implementation/check-dod/instructions.xml +0 -54
- package/_gaia/lifecycle/workflows/4-implementation/check-dod/workflow.yaml +0 -19
- package/_gaia/lifecycle/workflows/4-implementation/check-review-gate/checklist.md +0 -18
- package/_gaia/lifecycle/workflows/4-implementation/check-review-gate/instructions.xml +0 -53
- package/_gaia/lifecycle/workflows/4-implementation/check-review-gate/workflow.yaml +0 -19
- package/_gaia/lifecycle/workflows/4-implementation/code-review/checklist.md +0 -18
- package/_gaia/lifecycle/workflows/4-implementation/code-review/instructions.xml +0 -50
- package/_gaia/lifecycle/workflows/4-implementation/code-review/workflow.yaml +0 -24
- package/_gaia/lifecycle/workflows/4-implementation/correct-course/checklist.md +0 -21
- package/_gaia/lifecycle/workflows/4-implementation/correct-course/instructions.xml +0 -63
- package/_gaia/lifecycle/workflows/4-implementation/correct-course/workflow.yaml +0 -25
- package/_gaia/lifecycle/workflows/4-implementation/create-story/checklist.md +0 -38
- package/_gaia/lifecycle/workflows/4-implementation/create-story/instructions.xml +0 -194
- package/_gaia/lifecycle/workflows/4-implementation/create-story/workflow.yaml +0 -26
- package/_gaia/lifecycle/workflows/4-implementation/dev-story/checklist.md +0 -26
- package/_gaia/lifecycle/workflows/4-implementation/dev-story/instructions.xml +0 -268
- package/_gaia/lifecycle/workflows/4-implementation/dev-story/workflow.yaml +0 -51
- package/_gaia/lifecycle/workflows/4-implementation/epic-status/checklist.md +0 -25
- package/_gaia/lifecycle/workflows/4-implementation/epic-status/instructions.xml +0 -62
- package/_gaia/lifecycle/workflows/4-implementation/epic-status/workflow.yaml +0 -24
- package/_gaia/lifecycle/workflows/4-implementation/fix-story/checklist.md +0 -12
- package/_gaia/lifecycle/workflows/4-implementation/fix-story/instructions.xml +0 -67
- package/_gaia/lifecycle/workflows/4-implementation/fix-story/workflow.yaml +0 -17
- package/_gaia/lifecycle/workflows/4-implementation/qa-generate-tests/checklist.md +0 -19
- package/_gaia/lifecycle/workflows/4-implementation/qa-generate-tests/instructions.xml +0 -52
- package/_gaia/lifecycle/workflows/4-implementation/qa-generate-tests/workflow.yaml +0 -20
- package/_gaia/lifecycle/workflows/4-implementation/retrospective/checklist.md +0 -15
- package/_gaia/lifecycle/workflows/4-implementation/retrospective/instructions.xml +0 -164
- package/_gaia/lifecycle/workflows/4-implementation/retrospective/workflow.yaml +0 -30
- package/_gaia/lifecycle/workflows/4-implementation/run-all-reviews/checklist.md +0 -14
- package/_gaia/lifecycle/workflows/4-implementation/run-all-reviews/instructions.xml +0 -78
- package/_gaia/lifecycle/workflows/4-implementation/run-all-reviews/workflow.yaml +0 -16
- package/_gaia/lifecycle/workflows/4-implementation/security-review/checklist.md +0 -29
- package/_gaia/lifecycle/workflows/4-implementation/security-review/instructions.xml +0 -80
- package/_gaia/lifecycle/workflows/4-implementation/security-review/workflow.yaml +0 -27
- package/_gaia/lifecycle/workflows/4-implementation/sprint-planning/checklist.md +0 -29
- package/_gaia/lifecycle/workflows/4-implementation/sprint-planning/instructions.xml +0 -140
- package/_gaia/lifecycle/workflows/4-implementation/sprint-planning/workflow.yaml +0 -33
- package/_gaia/lifecycle/workflows/4-implementation/sprint-status/checklist.md +0 -18
- package/_gaia/lifecycle/workflows/4-implementation/sprint-status/instructions.xml +0 -36
- package/_gaia/lifecycle/workflows/4-implementation/sprint-status/workflow.yaml +0 -19
- package/_gaia/lifecycle/workflows/4-implementation/tech-debt-review/checklist.md +0 -30
- package/_gaia/lifecycle/workflows/4-implementation/tech-debt-review/instructions.xml +0 -147
- package/_gaia/lifecycle/workflows/4-implementation/tech-debt-review/workflow.yaml +0 -24
- package/_gaia/lifecycle/workflows/4-implementation/triage-findings/checklist.md +0 -17
- package/_gaia/lifecycle/workflows/4-implementation/triage-findings/instructions.xml +0 -124
- package/_gaia/lifecycle/workflows/4-implementation/triage-findings/workflow.yaml +0 -15
- package/_gaia/lifecycle/workflows/4-implementation/val-refresh-ground-truth/checklist.md +0 -48
- package/_gaia/lifecycle/workflows/4-implementation/val-refresh-ground-truth/instructions.xml +0 -125
- package/_gaia/lifecycle/workflows/4-implementation/val-refresh-ground-truth/workflow.yaml +0 -31
- package/_gaia/lifecycle/workflows/4-implementation/val-validate-artifact/checklist.md +0 -54
- package/_gaia/lifecycle/workflows/4-implementation/val-validate-artifact/instructions.xml +0 -147
- package/_gaia/lifecycle/workflows/4-implementation/val-validate-artifact/test-structure.sh +0 -116
- package/_gaia/lifecycle/workflows/4-implementation/val-validate-artifact/workflow.yaml +0 -29
- package/_gaia/lifecycle/workflows/4-implementation/val-validate-plan/checklist.md +0 -34
- package/_gaia/lifecycle/workflows/4-implementation/val-validate-plan/instructions.xml +0 -162
- package/_gaia/lifecycle/workflows/4-implementation/val-validate-plan/workflow.yaml +0 -39
- package/_gaia/lifecycle/workflows/4-implementation/validate-story/checklist.md +0 -23
- package/_gaia/lifecycle/workflows/4-implementation/validate-story/instructions.xml +0 -146
- package/_gaia/lifecycle/workflows/4-implementation/validate-story/workflow.yaml +0 -25
- package/_gaia/lifecycle/workflows/5-deployment/deployment-checklist/checklist.md +0 -29
- package/_gaia/lifecycle/workflows/5-deployment/deployment-checklist/instructions.xml +0 -59
- package/_gaia/lifecycle/workflows/5-deployment/deployment-checklist/workflow.yaml +0 -39
- package/_gaia/lifecycle/workflows/5-deployment/post-deploy-verify/checklist.md +0 -19
- package/_gaia/lifecycle/workflows/5-deployment/post-deploy-verify/instructions.xml +0 -33
- package/_gaia/lifecycle/workflows/5-deployment/post-deploy-verify/workflow.yaml +0 -15
- package/_gaia/lifecycle/workflows/5-deployment/release-plan/checklist.md +0 -20
- package/_gaia/lifecycle/workflows/5-deployment/release-plan/instructions.xml +0 -33
- package/_gaia/lifecycle/workflows/5-deployment/release-plan/workflow.yaml +0 -19
- package/_gaia/lifecycle/workflows/5-deployment/rollback-plan/checklist.md +0 -20
- package/_gaia/lifecycle/workflows/5-deployment/rollback-plan/instructions.xml +0 -33
- package/_gaia/lifecycle/workflows/5-deployment/rollback-plan/workflow.yaml +0 -15
- package/_gaia/lifecycle/workflows/anytime/brownfield-onboarding/checklist.md +0 -52
- package/_gaia/lifecycle/workflows/anytime/brownfield-onboarding/instructions.xml +0 -122
- package/_gaia/lifecycle/workflows/anytime/brownfield-onboarding/test-step7.sh +0 -149
- package/_gaia/lifecycle/workflows/anytime/brownfield-onboarding/workflow.yaml +0 -33
- package/_gaia/lifecycle/workflows/anytime/document-project/checklist.md +0 -11
- package/_gaia/lifecycle/workflows/anytime/document-project/instructions.xml +0 -26
- package/_gaia/lifecycle/workflows/anytime/document-project/workflow.yaml +0 -15
- package/_gaia/lifecycle/workflows/anytime/generate-project-context/checklist.md +0 -11
- package/_gaia/lifecycle/workflows/anytime/generate-project-context/instructions.xml +0 -22
- package/_gaia/lifecycle/workflows/anytime/generate-project-context/workflow.yaml +0 -15
- package/_gaia/lifecycle/workflows/anytime/memory-hygiene/checklist.md +0 -24
- package/_gaia/lifecycle/workflows/anytime/memory-hygiene/instructions.xml +0 -108
- package/_gaia/lifecycle/workflows/anytime/memory-hygiene/workflow.yaml +0 -15
- package/_gaia/lifecycle/workflows/anytime/performance-review/checklist.md +0 -25
- package/_gaia/lifecycle/workflows/anytime/performance-review/instructions.xml +0 -62
- package/_gaia/lifecycle/workflows/anytime/performance-review/workflow.yaml +0 -15
- package/_gaia/lifecycle/workflows/cross-phase/add-feature/checklist.md +0 -30
- package/_gaia/lifecycle/workflows/cross-phase/add-feature/instructions.xml +0 -85
- package/_gaia/lifecycle/workflows/cross-phase/add-feature/workflow.yaml +0 -37
- package/_gaia/lifecycle/workflows/quick-flow/quick-dev/checklist.md +0 -11
- package/_gaia/lifecycle/workflows/quick-flow/quick-dev/instructions.xml +0 -26
- package/_gaia/lifecycle/workflows/quick-flow/quick-dev/workflow.yaml +0 -19
- package/_gaia/lifecycle/workflows/quick-flow/quick-spec/checklist.md +0 -13
- package/_gaia/lifecycle/workflows/quick-flow/quick-spec/instructions.xml +0 -27
- package/_gaia/lifecycle/workflows/quick-flow/quick-spec/workflow.yaml +0 -15
- package/_gaia/testing/.resolved/.gitkeep +0 -0
- package/_gaia/testing/agents/test-architect.md +0 -131
- package/_gaia/testing/config.yaml +0 -8
- package/_gaia/testing/knowledge/_index.csv +0 -22
- package/_gaia/testing/knowledge/accessibility/axe-core-patterns.md +0 -177
- package/_gaia/testing/knowledge/accessibility/wcag-checks.md +0 -191
- package/_gaia/testing/knowledge/core/deterministic-testing.md +0 -167
- package/_gaia/testing/knowledge/core/fixture-architecture.md +0 -131
- package/_gaia/testing/knowledge/core/test-isolation.md +0 -142
- package/_gaia/testing/knowledge/core/test-pyramid.md +0 -129
- package/_gaia/testing/knowledge/extended/api-testing-patterns.md +0 -196
- package/_gaia/testing/knowledge/extended/data-factories.md +0 -158
- package/_gaia/testing/knowledge/extended/risk-governance.md +0 -119
- package/_gaia/testing/knowledge/extended/selector-resilience.md +0 -109
- package/_gaia/testing/knowledge/mobile-testing/appium-patterns.md +0 -164
- package/_gaia/testing/knowledge/mobile-testing/react-native-testing.md +0 -193
- package/_gaia/testing/knowledge/mobile-testing/responsive-testing.md +0 -177
- package/_gaia/testing/knowledge/performance/k6-patterns.md +0 -200
- package/_gaia/testing/knowledge/performance/lighthouse-ci.md +0 -158
- package/_gaia/testing/knowledge/specialized/contract-testing.md +0 -173
- package/_gaia/testing/knowledge/specialized/test-healing.md +0 -129
- package/_gaia/testing/knowledge/specialized/visual-testing.md +0 -129
- package/_gaia/testing/knowledge/unit-testing/jest-vitest-patterns.md +0 -193
- package/_gaia/testing/knowledge/unit-testing/junit5-patterns.md +0 -200
- package/_gaia/testing/knowledge/unit-testing/pytest-patterns.md +0 -185
- package/_gaia/testing/module-help.csv +0 -13
- package/_gaia/testing/workflows/accessibility-testing/checklist.md +0 -12
- package/_gaia/testing/workflows/accessibility-testing/instructions.xml +0 -41
- package/_gaia/testing/workflows/accessibility-testing/workflow.yaml +0 -13
- package/_gaia/testing/workflows/atdd/checklist.md +0 -6
- package/_gaia/testing/workflows/atdd/instructions.xml +0 -36
- package/_gaia/testing/workflows/atdd/workflow.yaml +0 -22
- package/_gaia/testing/workflows/ci-setup/checklist.md +0 -9
- package/_gaia/testing/workflows/ci-setup/instructions.xml +0 -43
- package/_gaia/testing/workflows/ci-setup/workflow.yaml +0 -11
- package/_gaia/testing/workflows/edit-test-plan/checklist.md +0 -20
- package/_gaia/testing/workflows/edit-test-plan/instructions.xml +0 -65
- package/_gaia/testing/workflows/edit-test-plan/workflow.yaml +0 -35
- package/_gaia/testing/workflows/mobile-testing/checklist.md +0 -13
- package/_gaia/testing/workflows/mobile-testing/instructions.xml +0 -41
- package/_gaia/testing/workflows/mobile-testing/workflow.yaml +0 -11
- package/_gaia/testing/workflows/nfr-assessment/checklist.md +0 -7
- package/_gaia/testing/workflows/nfr-assessment/instructions.xml +0 -26
- package/_gaia/testing/workflows/nfr-assessment/workflow.yaml +0 -11
- package/_gaia/testing/workflows/performance-testing/checklist.md +0 -11
- package/_gaia/testing/workflows/performance-testing/instructions.xml +0 -41
- package/_gaia/testing/workflows/performance-testing/workflow.yaml +0 -11
- package/_gaia/testing/workflows/teach-me-testing/checklist.md +0 -6
- package/_gaia/testing/workflows/teach-me-testing/instructions.xml +0 -28
- package/_gaia/testing/workflows/teach-me-testing/workflow.yaml +0 -12
- package/_gaia/testing/workflows/test-automation/checklist.md +0 -6
- package/_gaia/testing/workflows/test-automation/instructions.xml +0 -49
- package/_gaia/testing/workflows/test-automation/workflow.yaml +0 -11
- package/_gaia/testing/workflows/test-design/checklist.md +0 -9
- package/_gaia/testing/workflows/test-design/instructions.xml +0 -47
- package/_gaia/testing/workflows/test-design/workflow.yaml +0 -11
- package/_gaia/testing/workflows/test-framework/checklist.md +0 -8
- package/_gaia/testing/workflows/test-framework/instructions.xml +0 -25
- package/_gaia/testing/workflows/test-framework/workflow.yaml +0 -11
- package/_gaia/testing/workflows/test-review/checklist.md +0 -9
- package/_gaia/testing/workflows/test-review/instructions.xml +0 -51
- package/_gaia/testing/workflows/test-review/workflow.yaml +0 -11
- package/_gaia/testing/workflows/traceability/checklist.md +0 -6
- package/_gaia/testing/workflows/traceability/instructions.xml +0 -49
- package/_gaia/testing/workflows/traceability/workflow.yaml +0 -21
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: Python Conventions and Standards
|
|
3
|
-
stack: python
|
|
4
|
-
version: "1.0"
|
|
5
|
-
focus: [python]
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
# Python Conventions and Standards
|
|
9
|
-
|
|
10
|
-
## Principle
|
|
11
|
-
|
|
12
|
-
Follow PEP 8 for style, use type hints throughout, manage dependencies with virtual environments and `pyproject.toml`, and structure projects with clear module boundaries. Use `ruff` for linting and formatting, `mypy` for type checking, and `pytest` for testing.
|
|
13
|
-
|
|
14
|
-
## Rationale
|
|
15
|
-
|
|
16
|
-
PEP 8 is the universal Python style standard; deviating from it creates friction for contributors and tooling. Type hints enable IDE autocompletion, catch bugs before runtime, and serve as documentation. `pyproject.toml` (PEP 621) consolidates project metadata, dependencies, and tool configuration in a single file, replacing the fragmented `setup.py` + `setup.cfg` + `requirements.txt` approach. Virtual environments isolate dependencies and prevent system-wide conflicts.
|
|
17
|
-
|
|
18
|
-
## Pattern Examples
|
|
19
|
-
|
|
20
|
-
### Pattern 1: Project Structure and pyproject.toml
|
|
21
|
-
|
|
22
|
-
```
|
|
23
|
-
my-project/
|
|
24
|
-
src/
|
|
25
|
-
my_project/
|
|
26
|
-
__init__.py
|
|
27
|
-
models/
|
|
28
|
-
__init__.py
|
|
29
|
-
user.py
|
|
30
|
-
services/
|
|
31
|
-
__init__.py
|
|
32
|
-
user_service.py
|
|
33
|
-
api/
|
|
34
|
-
__init__.py
|
|
35
|
-
routes.py
|
|
36
|
-
core/
|
|
37
|
-
__init__.py
|
|
38
|
-
config.py
|
|
39
|
-
exceptions.py
|
|
40
|
-
tests/
|
|
41
|
-
__init__.py
|
|
42
|
-
conftest.py
|
|
43
|
-
test_user_service.py
|
|
44
|
-
pyproject.toml
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
```toml
|
|
48
|
-
# pyproject.toml
|
|
49
|
-
[project]
|
|
50
|
-
name = "my-project"
|
|
51
|
-
version = "1.0.0"
|
|
52
|
-
requires-python = ">=3.12"
|
|
53
|
-
dependencies = [
|
|
54
|
-
"fastapi>=0.110",
|
|
55
|
-
"sqlalchemy>=2.0",
|
|
56
|
-
"pydantic>=2.0",
|
|
57
|
-
]
|
|
58
|
-
|
|
59
|
-
[project.optional-dependencies]
|
|
60
|
-
dev = [
|
|
61
|
-
"pytest>=8.0",
|
|
62
|
-
"pytest-asyncio>=0.23",
|
|
63
|
-
"ruff>=0.4",
|
|
64
|
-
"mypy>=1.10",
|
|
65
|
-
]
|
|
66
|
-
|
|
67
|
-
[tool.ruff]
|
|
68
|
-
target-version = "py312"
|
|
69
|
-
line-length = 88
|
|
70
|
-
|
|
71
|
-
[tool.ruff.lint]
|
|
72
|
-
select = ["E", "F", "I", "UP", "B", "SIM", "RUF"]
|
|
73
|
-
|
|
74
|
-
[tool.mypy]
|
|
75
|
-
strict = true
|
|
76
|
-
python_version = "3.12"
|
|
77
|
-
|
|
78
|
-
[tool.pytest.ini_options]
|
|
79
|
-
testpaths = ["tests"]
|
|
80
|
-
asyncio_mode = "auto"
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
### Pattern 2: Type Hints and Protocols
|
|
84
|
-
|
|
85
|
-
```python
|
|
86
|
-
from typing import Protocol, TypeVar, Generic
|
|
87
|
-
from datetime import datetime
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
# Protocol for structural typing (duck typing with type safety)
|
|
91
|
-
class Repository(Protocol[T]):
|
|
92
|
-
async def get(self, id: int) -> T | None: ...
|
|
93
|
-
async def save(self, entity: T) -> T: ...
|
|
94
|
-
async def delete(self, id: int) -> bool: ...
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
T = TypeVar("T")
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
class BaseService(Generic[T]):
|
|
101
|
-
"""Generic service with typed repository dependency."""
|
|
102
|
-
|
|
103
|
-
def __init__(self, repo: Repository[T]) -> None:
|
|
104
|
-
self._repo = repo
|
|
105
|
-
|
|
106
|
-
async def get_or_raise(self, id: int) -> T:
|
|
107
|
-
entity = await self._repo.get(id)
|
|
108
|
-
if entity is None:
|
|
109
|
-
raise EntityNotFoundError(f"Entity {id} not found")
|
|
110
|
-
return entity
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
# Concrete implementation
|
|
114
|
-
class UserService(BaseService[User]):
|
|
115
|
-
async def create(self, data: CreateUserRequest) -> User:
|
|
116
|
-
user = User(
|
|
117
|
-
email=data.email,
|
|
118
|
-
name=data.name,
|
|
119
|
-
created_at=datetime.now(),
|
|
120
|
-
)
|
|
121
|
-
return await self._repo.save(user)
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
### Pattern 3: Testing with pytest Fixtures
|
|
125
|
-
|
|
126
|
-
```python
|
|
127
|
-
import pytest
|
|
128
|
-
from unittest.mock import AsyncMock
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
@pytest.fixture
|
|
132
|
-
def mock_user_repo() -> AsyncMock:
|
|
133
|
-
repo = AsyncMock(spec=UserRepository)
|
|
134
|
-
repo.get.return_value = User(id=1, email="test@example.com", name="Test")
|
|
135
|
-
return repo
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
@pytest.fixture
|
|
139
|
-
def user_service(mock_user_repo: AsyncMock) -> UserService:
|
|
140
|
-
return UserService(repo=mock_user_repo)
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
async def test_get_user_returns_user(user_service: UserService) -> None:
|
|
144
|
-
user = await user_service.get_or_raise(1)
|
|
145
|
-
assert user.email == "test@example.com"
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
async def test_get_user_raises_when_not_found(
|
|
149
|
-
user_service: UserService,
|
|
150
|
-
mock_user_repo: AsyncMock,
|
|
151
|
-
) -> None:
|
|
152
|
-
mock_user_repo.get.return_value = None
|
|
153
|
-
with pytest.raises(EntityNotFoundError):
|
|
154
|
-
await user_service.get_or_raise(999)
|
|
155
|
-
```
|
|
156
|
-
|
|
157
|
-
## Anti-Patterns
|
|
158
|
-
|
|
159
|
-
- **No type hints**: Omitting type annotations loses IDE support and prevents `mypy` from catching bugs. Add hints to all function signatures.
|
|
160
|
-
- **`requirements.txt` without pinning**: `requests` instead of `requests==2.31.0` leads to unreproducible builds. Pin all dependencies.
|
|
161
|
-
- **Global mutable state**: Module-level mutable variables (e.g., `db = None`) create testing nightmares. Use dependency injection.
|
|
162
|
-
- **Wildcard imports**: `from module import *` pollutes the namespace and hides where symbols come from. Import explicitly.
|
|
163
|
-
- **No virtual environment**: Installing packages globally causes version conflicts. Always use `venv`, `uv`, or `conda`.
|
|
164
|
-
|
|
165
|
-
## Integration Points
|
|
166
|
-
|
|
167
|
-
- **Django**: Django projects follow these conventions with Django-specific additions; see `django-patterns.md`.
|
|
168
|
-
- **FastAPI**: FastAPI requires type hints for auto-documentation; see `fastapi-patterns.md`.
|
|
169
|
-
- **Data Pipelines**: Pipeline scripts follow the same structure and testing patterns; see `data-pipelines.md`.
|
|
170
|
-
- **CI/CD**: Run `ruff check`, `mypy`, and `pytest` in CI. Use `pre-commit` hooks locally.
|
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: Express.js Application Patterns
|
|
3
|
-
stack: typescript
|
|
4
|
-
version: "1.0"
|
|
5
|
-
focus: [express]
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
# Express.js Application Patterns
|
|
9
|
-
|
|
10
|
-
## Principle
|
|
11
|
-
|
|
12
|
-
Structure Express applications with a clear middleware chain: parsing, authentication, route-specific logic, and centralized error handling. Use typed request/response objects, validation middleware for input sanitization, and async error wrappers to prevent unhandled promise rejections. Organize routes into modular routers by domain.
|
|
13
|
-
|
|
14
|
-
## Rationale
|
|
15
|
-
|
|
16
|
-
Express processes requests through a middleware chain in the order middleware is registered. This linear flow makes it easy to reason about request processing but requires discipline to avoid middleware order bugs. TypeScript types on request/response objects catch shape mismatches at compile time. Centralized error handling via a four-argument middleware ensures consistent error responses and prevents leaked stack traces in production.
|
|
17
|
-
|
|
18
|
-
## Pattern Examples
|
|
19
|
-
|
|
20
|
-
### Pattern 1: Typed Middleware Chain
|
|
21
|
-
|
|
22
|
-
```typescript
|
|
23
|
-
import express, { Request, Response, NextFunction } from 'express';
|
|
24
|
-
import cors from 'cors';
|
|
25
|
-
import helmet from 'helmet';
|
|
26
|
-
|
|
27
|
-
// Extend Express Request with typed properties
|
|
28
|
-
interface AuthenticatedRequest extends Request {
|
|
29
|
-
user: { id: string; role: string };
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// Auth middleware — adds typed user to request
|
|
33
|
-
function authenticate(req: Request, res: Response, next: NextFunction): void {
|
|
34
|
-
const token = req.headers.authorization?.replace('Bearer ', '');
|
|
35
|
-
if (!token) {
|
|
36
|
-
res.status(401).json({ error: 'Authentication required' });
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
try {
|
|
40
|
-
const payload = verifyToken(token);
|
|
41
|
-
(req as AuthenticatedRequest).user = payload;
|
|
42
|
-
next();
|
|
43
|
-
} catch {
|
|
44
|
-
res.status(401).json({ error: 'Invalid token' });
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// Role guard middleware factory
|
|
49
|
-
function requireRole(...roles: string[]) {
|
|
50
|
-
return (req: Request, res: Response, next: NextFunction): void => {
|
|
51
|
-
const user = (req as AuthenticatedRequest).user;
|
|
52
|
-
if (!roles.includes(user.role)) {
|
|
53
|
-
res.status(403).json({ error: 'Insufficient permissions' });
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
next();
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const app = express();
|
|
61
|
-
app.use(helmet());
|
|
62
|
-
app.use(cors());
|
|
63
|
-
app.use(express.json({ limit: '10mb' }));
|
|
64
|
-
app.use('/api', authenticate); // All /api routes require auth
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
### Pattern 2: Modular Router with Validation
|
|
68
|
-
|
|
69
|
-
```typescript
|
|
70
|
-
import { Router } from 'express';
|
|
71
|
-
import { z } from 'zod';
|
|
72
|
-
|
|
73
|
-
const router = Router();
|
|
74
|
-
|
|
75
|
-
// Validation middleware factory
|
|
76
|
-
function validate(schema: z.ZodSchema) {
|
|
77
|
-
return (req: Request, res: Response, next: NextFunction): void => {
|
|
78
|
-
const result = schema.safeParse(req.body);
|
|
79
|
-
if (!result.success) {
|
|
80
|
-
res.status(422).json({
|
|
81
|
-
error: 'Validation failed',
|
|
82
|
-
details: result.error.flatten().fieldErrors,
|
|
83
|
-
});
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
req.body = result.data;
|
|
87
|
-
next();
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const CreateUserSchema = z.object({
|
|
92
|
-
name: z.string().min(1).max(100),
|
|
93
|
-
email: z.string().email(),
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
// Async handler wrapper — catches rejected promises
|
|
97
|
-
function asyncHandler(
|
|
98
|
-
fn: (req: Request, res: Response, next: NextFunction) => Promise<void>
|
|
99
|
-
) {
|
|
100
|
-
return (req: Request, res: Response, next: NextFunction) => {
|
|
101
|
-
fn(req, res, next).catch(next);
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
router.post(
|
|
106
|
-
'/',
|
|
107
|
-
validate(CreateUserSchema),
|
|
108
|
-
asyncHandler(async (req: Request, res: Response) => {
|
|
109
|
-
const user = await userService.create(req.body);
|
|
110
|
-
res.status(201).json(user);
|
|
111
|
-
})
|
|
112
|
-
);
|
|
113
|
-
|
|
114
|
-
router.get(
|
|
115
|
-
'/:id',
|
|
116
|
-
asyncHandler(async (req: Request, res: Response) => {
|
|
117
|
-
const user = await userService.findById(req.params.id);
|
|
118
|
-
if (!user) {
|
|
119
|
-
res.status(404).json({ error: 'User not found' });
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
res.json(user);
|
|
123
|
-
})
|
|
124
|
-
);
|
|
125
|
-
|
|
126
|
-
export const userRouter = router;
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
### Pattern 3: Centralized Error Handling
|
|
130
|
-
|
|
131
|
-
```typescript
|
|
132
|
-
// Custom error classes
|
|
133
|
-
class AppError extends Error {
|
|
134
|
-
constructor(
|
|
135
|
-
public statusCode: number,
|
|
136
|
-
message: string,
|
|
137
|
-
public isOperational = true
|
|
138
|
-
) {
|
|
139
|
-
super(message);
|
|
140
|
-
Object.setPrototypeOf(this, AppError.prototype);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
class NotFoundError extends AppError {
|
|
145
|
-
constructor(resource: string) {
|
|
146
|
-
super(404, `${resource} not found`);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// Error handling middleware — MUST have 4 parameters
|
|
151
|
-
function errorHandler(
|
|
152
|
-
err: Error,
|
|
153
|
-
req: Request,
|
|
154
|
-
res: Response,
|
|
155
|
-
_next: NextFunction
|
|
156
|
-
): void {
|
|
157
|
-
if (err instanceof AppError) {
|
|
158
|
-
res.status(err.statusCode).json({
|
|
159
|
-
error: err.message,
|
|
160
|
-
...(process.env.NODE_ENV === 'development' && { stack: err.stack }),
|
|
161
|
-
});
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
// Unexpected errors — log and return generic message
|
|
166
|
-
console.error('Unhandled error:', err);
|
|
167
|
-
res.status(500).json({ error: 'Internal server error' });
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// Register AFTER all routes
|
|
171
|
-
app.use('/api/users', userRouter);
|
|
172
|
-
app.use('/api/orders', orderRouter);
|
|
173
|
-
app.use(errorHandler); // Must be last
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
## Anti-Patterns
|
|
177
|
-
|
|
178
|
-
- **No async error handling**: Unhandled promise rejections in route handlers crash the process. Always use an async wrapper or express-async-errors.
|
|
179
|
-
- **Error middleware not last**: Registering the error handler before routes means it never catches route errors.
|
|
180
|
-
- **Business logic in route handlers**: Route handlers should validate, delegate to a service, and format the response. Keep them thin.
|
|
181
|
-
- **No input validation**: Trusting `req.body` without validation opens injection and type-mismatch vulnerabilities.
|
|
182
|
-
|
|
183
|
-
## Integration Points
|
|
184
|
-
|
|
185
|
-
- **React/Next.js**: Express APIs are consumed by React client components; see `react-patterns.md` and `nextjs-patterns.md`.
|
|
186
|
-
- **TypeScript**: Strict typing for middleware, requests, and responses; see `ts-conventions.md`.
|
|
187
|
-
- **Testing**: Use `supertest` for HTTP-level integration tests against the Express app.
|
|
188
|
-
- **Docker**: Express apps are containerized with multi-stage builds for production deployment.
|
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: Next.js Application Patterns
|
|
3
|
-
stack: typescript
|
|
4
|
-
version: "1.0"
|
|
5
|
-
focus: [nextjs]
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
# Next.js Application Patterns
|
|
9
|
-
|
|
10
|
-
## Principle
|
|
11
|
-
|
|
12
|
-
Use the App Router with React Server Components (RSC) as the default rendering strategy. Fetch data on the server to reduce client bundle size and improve initial load. Use client components (`'use client'`) only when interactivity (hooks, event handlers, browser APIs) is required. Leverage Next.js caching layers (request memoization, data cache, full route cache) deliberately.
|
|
13
|
-
|
|
14
|
-
## Rationale
|
|
15
|
-
|
|
16
|
-
Server Components eliminate the client-side JavaScript for data display, reducing bundle sizes by 30-50%. The App Router's nested layout system prevents re-rendering shared UI (navigation, sidebars) during navigation. Next.js provides multiple caching layers that must be understood to avoid stale data in production. Route handlers replace API routes with a more natural request/response model.
|
|
17
|
-
|
|
18
|
-
## Pattern Examples
|
|
19
|
-
|
|
20
|
-
### Pattern 1: Server Component with Data Fetching
|
|
21
|
-
|
|
22
|
-
```typescript
|
|
23
|
-
// app/users/page.tsx — Server Component (default, no 'use client')
|
|
24
|
-
import { UserList } from './user-list';
|
|
25
|
-
|
|
26
|
-
interface User {
|
|
27
|
-
id: number;
|
|
28
|
-
name: string;
|
|
29
|
-
email: string;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
async function getUsers(): Promise<User[]> {
|
|
33
|
-
const res = await fetch('https://api.example.com/users', {
|
|
34
|
-
next: { revalidate: 60 }, // ISR: revalidate every 60 seconds
|
|
35
|
-
});
|
|
36
|
-
if (!res.ok) throw new Error('Failed to fetch users');
|
|
37
|
-
return res.json();
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export default async function UsersPage() {
|
|
41
|
-
const users = await getUsers();
|
|
42
|
-
return (
|
|
43
|
-
<main>
|
|
44
|
-
<h1>Users</h1>
|
|
45
|
-
{/* UserList can be a client component for interactivity */}
|
|
46
|
-
<UserList initialUsers={users} />
|
|
47
|
-
</main>
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// app/users/loading.tsx — Automatic Suspense boundary
|
|
52
|
-
export default function Loading() {
|
|
53
|
-
return <UserListSkeleton />;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// app/users/error.tsx — Error boundary
|
|
57
|
-
'use client';
|
|
58
|
-
export default function Error({ error, reset }: {
|
|
59
|
-
error: Error & { digest?: string };
|
|
60
|
-
reset: () => void;
|
|
61
|
-
}) {
|
|
62
|
-
return (
|
|
63
|
-
<div>
|
|
64
|
-
<h2>Something went wrong</h2>
|
|
65
|
-
<button onClick={reset}>Try again</button>
|
|
66
|
-
</div>
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
### Pattern 2: Nested Layouts
|
|
72
|
-
|
|
73
|
-
```typescript
|
|
74
|
-
// app/layout.tsx — Root layout (wraps all pages)
|
|
75
|
-
export default function RootLayout({ children }: { children: React.ReactNode }) {
|
|
76
|
-
return (
|
|
77
|
-
<html lang="en">
|
|
78
|
-
<body>
|
|
79
|
-
<Navbar />
|
|
80
|
-
{children}
|
|
81
|
-
</body>
|
|
82
|
-
</html>
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// app/dashboard/layout.tsx — Dashboard layout (persists across dashboard pages)
|
|
87
|
-
import { Sidebar } from '@/components/sidebar';
|
|
88
|
-
|
|
89
|
-
export default function DashboardLayout({
|
|
90
|
-
children,
|
|
91
|
-
}: {
|
|
92
|
-
children: React.ReactNode;
|
|
93
|
-
}) {
|
|
94
|
-
return (
|
|
95
|
-
<div className="flex">
|
|
96
|
-
<Sidebar />
|
|
97
|
-
<main className="flex-1 p-6">{children}</main>
|
|
98
|
-
</div>
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// app/dashboard/analytics/page.tsx — inherits both layouts
|
|
103
|
-
export default async function AnalyticsPage() {
|
|
104
|
-
const metrics = await getMetrics();
|
|
105
|
-
return <MetricsDashboard data={metrics} />;
|
|
106
|
-
}
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
### Pattern 3: Route Handler with Validation
|
|
110
|
-
|
|
111
|
-
```typescript
|
|
112
|
-
// app/api/users/route.ts
|
|
113
|
-
import { NextRequest, NextResponse } from 'next/server';
|
|
114
|
-
import { z } from 'zod';
|
|
115
|
-
|
|
116
|
-
const CreateUserSchema = z.object({
|
|
117
|
-
name: z.string().min(1).max(100),
|
|
118
|
-
email: z.string().email(),
|
|
119
|
-
role: z.enum(['admin', 'member']).default('member'),
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
export async function POST(request: NextRequest) {
|
|
123
|
-
try {
|
|
124
|
-
const body = await request.json();
|
|
125
|
-
const validated = CreateUserSchema.parse(body);
|
|
126
|
-
const user = await db.user.create({ data: validated });
|
|
127
|
-
return NextResponse.json(user, { status: 201 });
|
|
128
|
-
} catch (error) {
|
|
129
|
-
if (error instanceof z.ZodError) {
|
|
130
|
-
return NextResponse.json(
|
|
131
|
-
{ errors: error.flatten().fieldErrors },
|
|
132
|
-
{ status: 422 }
|
|
133
|
-
);
|
|
134
|
-
}
|
|
135
|
-
return NextResponse.json(
|
|
136
|
-
{ error: 'Internal server error' },
|
|
137
|
-
{ status: 500 }
|
|
138
|
-
);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
export async function GET(request: NextRequest) {
|
|
143
|
-
const { searchParams } = new URL(request.url);
|
|
144
|
-
const page = parseInt(searchParams.get('page') ?? '1');
|
|
145
|
-
const limit = parseInt(searchParams.get('limit') ?? '20');
|
|
146
|
-
const users = await db.user.findMany({
|
|
147
|
-
skip: (page - 1) * limit,
|
|
148
|
-
take: limit,
|
|
149
|
-
});
|
|
150
|
-
return NextResponse.json(users);
|
|
151
|
-
}
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
## Anti-Patterns
|
|
155
|
-
|
|
156
|
-
- **`'use client'` on everything**: Treating the App Router like the Pages Router. Default to server components; opt into client only for interactivity.
|
|
157
|
-
- **Fetching in client components**: Using `useEffect` to fetch data that could be fetched on the server wastes client bandwidth and reveals API details.
|
|
158
|
-
- **Ignoring caching semantics**: Not setting `revalidate` or `cache` options on `fetch` leads to unexpected stale or always-fresh behavior.
|
|
159
|
-
- **Passing functions as props from server to client**: Functions are not serializable across the RSC boundary. Use server actions or route handlers.
|
|
160
|
-
|
|
161
|
-
## Integration Points
|
|
162
|
-
|
|
163
|
-
- **React**: Client components use React hooks and patterns; see `react-patterns.md`.
|
|
164
|
-
- **Express**: Next.js can sit behind an Express server for custom middleware; see `express-patterns.md`.
|
|
165
|
-
- **TypeScript**: Strict typing for route handlers, page props, and metadata; see `ts-conventions.md`.
|
|
166
|
-
- **Testing**: Use `@testing-library/react` with Next.js test utilities for component and integration tests.
|
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: React Component Patterns
|
|
3
|
-
stack: typescript
|
|
4
|
-
version: "1.0"
|
|
5
|
-
focus: [react]
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
# React Component Patterns
|
|
9
|
-
|
|
10
|
-
## Principle
|
|
11
|
-
|
|
12
|
-
Build UIs with functional components and hooks. Use `useState` for local state, `useEffect` for side effects with proper dependency arrays, `useCallback`/`useMemo` for referential stability and expensive computations, and Context for dependency injection of shared services. Compose complex components from simple, focused building blocks.
|
|
13
|
-
|
|
14
|
-
## Rationale
|
|
15
|
-
|
|
16
|
-
React's rendering model re-creates component output on every state change. Understanding when React re-renders and how to prevent unnecessary work is crucial for performance. Hooks provide a composable primitive that replaces class lifecycle methods with a more declarative API. Custom hooks extract and share stateful logic without render props or HOCs. Context avoids prop drilling but should not replace purpose-built state management for frequently changing data.
|
|
17
|
-
|
|
18
|
-
## Pattern Examples
|
|
19
|
-
|
|
20
|
-
### Pattern 1: Custom Hook for Data Fetching
|
|
21
|
-
|
|
22
|
-
```typescript
|
|
23
|
-
interface UseQueryResult<T> {
|
|
24
|
-
data: T | undefined;
|
|
25
|
-
error: Error | null;
|
|
26
|
-
isLoading: boolean;
|
|
27
|
-
refetch: () => void;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function useQuery<T>(url: string): UseQueryResult<T> {
|
|
31
|
-
const [data, setData] = useState<T>();
|
|
32
|
-
const [error, setError] = useState<Error | null>(null);
|
|
33
|
-
const [isLoading, setIsLoading] = useState(true);
|
|
34
|
-
|
|
35
|
-
const fetchData = useCallback(async () => {
|
|
36
|
-
setIsLoading(true);
|
|
37
|
-
setError(null);
|
|
38
|
-
try {
|
|
39
|
-
const response = await fetch(url);
|
|
40
|
-
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
41
|
-
const json = await response.json();
|
|
42
|
-
setData(json);
|
|
43
|
-
} catch (err) {
|
|
44
|
-
setError(err instanceof Error ? err : new Error(String(err)));
|
|
45
|
-
} finally {
|
|
46
|
-
setIsLoading(false);
|
|
47
|
-
}
|
|
48
|
-
}, [url]);
|
|
49
|
-
|
|
50
|
-
useEffect(() => {
|
|
51
|
-
fetchData();
|
|
52
|
-
}, [fetchData]);
|
|
53
|
-
|
|
54
|
-
return { data, error, isLoading, refetch: fetchData };
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// Usage
|
|
58
|
-
function UserList() {
|
|
59
|
-
const { data: users, isLoading, error } = useQuery<User[]>('/api/users');
|
|
60
|
-
if (isLoading) return <Spinner />;
|
|
61
|
-
if (error) return <ErrorMessage error={error} />;
|
|
62
|
-
return <ul>{users?.map(u => <UserCard key={u.id} user={u} />)}</ul>;
|
|
63
|
-
}
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
### Pattern 2: Compound Components with Context
|
|
67
|
-
|
|
68
|
-
```typescript
|
|
69
|
-
interface TabsContextValue {
|
|
70
|
-
activeTab: string;
|
|
71
|
-
setActiveTab: (id: string) => void;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const TabsContext = createContext<TabsContextValue | null>(null);
|
|
75
|
-
|
|
76
|
-
function useTabs(): TabsContextValue {
|
|
77
|
-
const context = useContext(TabsContext);
|
|
78
|
-
if (!context) throw new Error('useTabs must be used within <Tabs>');
|
|
79
|
-
return context;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function Tabs({ defaultTab, children }: { defaultTab: string; children: ReactNode }) {
|
|
83
|
-
const [activeTab, setActiveTab] = useState(defaultTab);
|
|
84
|
-
return (
|
|
85
|
-
<TabsContext.Provider value={{ activeTab, setActiveTab }}>
|
|
86
|
-
<div role="tablist">{children}</div>
|
|
87
|
-
</TabsContext.Provider>
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function TabTrigger({ id, children }: { id: string; children: ReactNode }) {
|
|
92
|
-
const { activeTab, setActiveTab } = useTabs();
|
|
93
|
-
return (
|
|
94
|
-
<button
|
|
95
|
-
role="tab"
|
|
96
|
-
aria-selected={activeTab === id}
|
|
97
|
-
onClick={() => setActiveTab(id)}
|
|
98
|
-
>
|
|
99
|
-
{children}
|
|
100
|
-
</button>
|
|
101
|
-
);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function TabContent({ id, children }: { id: string; children: ReactNode }) {
|
|
105
|
-
const { activeTab } = useTabs();
|
|
106
|
-
if (activeTab !== id) return null;
|
|
107
|
-
return <div role="tabpanel">{children}</div>;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// Usage
|
|
111
|
-
// <Tabs defaultTab="profile">
|
|
112
|
-
// <TabTrigger id="profile">Profile</TabTrigger>
|
|
113
|
-
// <TabTrigger id="settings">Settings</TabTrigger>
|
|
114
|
-
// <TabContent id="profile"><ProfileForm /></TabContent>
|
|
115
|
-
// <TabContent id="settings"><SettingsForm /></TabContent>
|
|
116
|
-
// </Tabs>
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
### Pattern 3: Performance with useMemo and useCallback
|
|
120
|
-
|
|
121
|
-
```typescript
|
|
122
|
-
interface DataTableProps {
|
|
123
|
-
rows: DataRow[];
|
|
124
|
-
filter: string;
|
|
125
|
-
onRowClick: (row: DataRow) => void;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function DataTable({ rows, filter, onRowClick }: DataTableProps) {
|
|
129
|
-
// Expensive filtering — memoize so it only recomputes when inputs change
|
|
130
|
-
const filteredRows = useMemo(
|
|
131
|
-
() => rows.filter(r => r.name.toLowerCase().includes(filter.toLowerCase())),
|
|
132
|
-
[rows, filter]
|
|
133
|
-
);
|
|
134
|
-
|
|
135
|
-
// Stable callback reference for child components
|
|
136
|
-
const handleRowClick = useCallback(
|
|
137
|
-
(row: DataRow) => { onRowClick(row); },
|
|
138
|
-
[onRowClick]
|
|
139
|
-
);
|
|
140
|
-
|
|
141
|
-
return (
|
|
142
|
-
<table>
|
|
143
|
-
<tbody>
|
|
144
|
-
{filteredRows.map(row => (
|
|
145
|
-
<MemoizedRow key={row.id} row={row} onClick={handleRowClick} />
|
|
146
|
-
))}
|
|
147
|
-
</tbody>
|
|
148
|
-
</table>
|
|
149
|
-
);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
const MemoizedRow = memo(function Row({
|
|
153
|
-
row, onClick,
|
|
154
|
-
}: { row: DataRow; onClick: (row: DataRow) => void }) {
|
|
155
|
-
return (
|
|
156
|
-
<tr onClick={() => onClick(row)}>
|
|
157
|
-
<td>{row.name}</td>
|
|
158
|
-
<td>{row.value}</td>
|
|
159
|
-
</tr>
|
|
160
|
-
);
|
|
161
|
-
});
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
## Anti-Patterns
|
|
165
|
-
|
|
166
|
-
- **useEffect as onChange handler**: Using `useEffect` to respond to state changes that should be handled in the event handler itself.
|
|
167
|
-
- **Missing dependency array**: Omitting the dependency array in `useEffect` causes it to run on every render.
|
|
168
|
-
- **Context for high-frequency updates**: Putting rapidly changing state (mouse position, animations) in Context re-renders all consumers.
|
|
169
|
-
- **Premature memoization**: Wrapping everything in `useMemo`/`useCallback` adds complexity. Only memoize when profiling shows a bottleneck.
|
|
170
|
-
|
|
171
|
-
## Integration Points
|
|
172
|
-
|
|
173
|
-
- **Next.js**: React components are used in both server and client contexts; see `nextjs-patterns.md`.
|
|
174
|
-
- **Express**: React apps consume Express APIs; see `express-patterns.md` for API design.
|
|
175
|
-
- **TypeScript**: Strict typing enhances React component props; see `ts-conventions.md`.
|
|
176
|
-
- **Testing**: Use React Testing Library for component tests; test custom hooks with `renderHook`.
|