@djm204/agent-skills 1.0.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 +597 -0
- package/bin/cli.js +8 -0
- package/package.json +55 -0
- package/src/index.js +1817 -0
- package/src/index.test.js +1264 -0
- package/templates/_shared/code-quality.mdc +52 -0
- package/templates/_shared/communication.mdc +43 -0
- package/templates/_shared/core-principles.mdc +67 -0
- package/templates/_shared/git-workflow.mdc +48 -0
- package/templates/_shared/security-fundamentals.mdc +41 -0
- package/templates/agents/utility-agent/.cursor/rules/action-control.mdc +71 -0
- package/templates/agents/utility-agent/.cursor/rules/context-management.mdc +61 -0
- package/templates/agents/utility-agent/.cursor/rules/hallucination-prevention.mdc +58 -0
- package/templates/agents/utility-agent/.cursor/rules/overview.mdc +34 -0
- package/templates/agents/utility-agent/.cursor/rules/token-optimization.mdc +71 -0
- package/templates/agents/utility-agent/CLAUDE.md +513 -0
- package/templates/business/market-intelligence/.cursor/rules/data-sources.mdc +62 -0
- package/templates/business/market-intelligence/.cursor/rules/overview.mdc +55 -0
- package/templates/business/market-intelligence/.cursor/rules/reporting.mdc +59 -0
- package/templates/business/market-intelligence/.cursor/rules/risk-signals.mdc +63 -0
- package/templates/business/market-intelligence/.cursor/rules/sentiment-analysis.mdc +70 -0
- package/templates/business/market-intelligence/.cursor/rules/trend-detection.mdc +72 -0
- package/templates/business/market-intelligence/CLAUDE.md +371 -0
- package/templates/business/marketing-expert/.cursor/rules/brand-strategy.mdc +74 -0
- package/templates/business/marketing-expert/.cursor/rules/campaign-planning.mdc +60 -0
- package/templates/business/marketing-expert/.cursor/rules/growth-frameworks.mdc +69 -0
- package/templates/business/marketing-expert/.cursor/rules/market-analysis.mdc +70 -0
- package/templates/business/marketing-expert/.cursor/rules/marketing-analytics.mdc +71 -0
- package/templates/business/marketing-expert/.cursor/rules/overview.mdc +56 -0
- package/templates/business/marketing-expert/CLAUDE.md +567 -0
- package/templates/business/predictive-maintenance/.cursor/rules/alerting.mdc +56 -0
- package/templates/business/predictive-maintenance/.cursor/rules/asset-lifecycle.mdc +71 -0
- package/templates/business/predictive-maintenance/.cursor/rules/failure-prediction.mdc +65 -0
- package/templates/business/predictive-maintenance/.cursor/rules/maintenance-scheduling.mdc +61 -0
- package/templates/business/predictive-maintenance/.cursor/rules/overview.mdc +55 -0
- package/templates/business/predictive-maintenance/.cursor/rules/sensor-analytics.mdc +66 -0
- package/templates/business/predictive-maintenance/CLAUDE.md +529 -0
- package/templates/business/product-manager/.cursor/rules/communication.mdc +77 -0
- package/templates/business/product-manager/.cursor/rules/discovery.mdc +79 -0
- package/templates/business/product-manager/.cursor/rules/metrics.mdc +75 -0
- package/templates/business/product-manager/.cursor/rules/overview.mdc +47 -0
- package/templates/business/product-manager/.cursor/rules/prioritization.mdc +66 -0
- package/templates/business/product-manager/.cursor/rules/requirements.mdc +79 -0
- package/templates/business/product-manager/CLAUDE.md +593 -0
- package/templates/business/project-manager/.cursor/rules/overview.mdc +53 -0
- package/templates/business/project-manager/.cursor/rules/reporting.mdc +68 -0
- package/templates/business/project-manager/.cursor/rules/risk-management.mdc +71 -0
- package/templates/business/project-manager/.cursor/rules/scheduling.mdc +67 -0
- package/templates/business/project-manager/.cursor/rules/scope-management.mdc +66 -0
- package/templates/business/project-manager/.cursor/rules/stakeholder-management.mdc +70 -0
- package/templates/business/project-manager/CLAUDE.md +540 -0
- package/templates/business/regulatory-sentinel/.cursor/rules/compliance-tracking.mdc +74 -0
- package/templates/business/regulatory-sentinel/.cursor/rules/impact-assessment.mdc +62 -0
- package/templates/business/regulatory-sentinel/.cursor/rules/monitoring.mdc +67 -0
- package/templates/business/regulatory-sentinel/.cursor/rules/overview.mdc +55 -0
- package/templates/business/regulatory-sentinel/.cursor/rules/reporting.mdc +61 -0
- package/templates/business/regulatory-sentinel/.cursor/rules/risk-classification.mdc +73 -0
- package/templates/business/regulatory-sentinel/CLAUDE.md +572 -0
- package/templates/business/resource-allocator/.cursor/rules/capacity-modeling.mdc +65 -0
- package/templates/business/resource-allocator/.cursor/rules/coordination.mdc +67 -0
- package/templates/business/resource-allocator/.cursor/rules/crisis-management.mdc +64 -0
- package/templates/business/resource-allocator/.cursor/rules/demand-prediction.mdc +52 -0
- package/templates/business/resource-allocator/.cursor/rules/overview.mdc +76 -0
- package/templates/business/resource-allocator/.cursor/rules/scheduling.mdc +63 -0
- package/templates/business/resource-allocator/CLAUDE.md +525 -0
- package/templates/business/strategic-negotiator/.cursor/rules/contract-analysis.mdc +60 -0
- package/templates/business/strategic-negotiator/.cursor/rules/deal-structuring.mdc +66 -0
- package/templates/business/strategic-negotiator/.cursor/rules/game-theory.mdc +64 -0
- package/templates/business/strategic-negotiator/.cursor/rules/overview.mdc +55 -0
- package/templates/business/strategic-negotiator/.cursor/rules/preparation.mdc +79 -0
- package/templates/business/strategic-negotiator/.cursor/rules/scenario-modeling.mdc +66 -0
- package/templates/business/strategic-negotiator/CLAUDE.md +640 -0
- package/templates/business/supply-chain/.cursor/rules/cost-modeling.mdc +67 -0
- package/templates/business/supply-chain/.cursor/rules/demand-forecasting.mdc +67 -0
- package/templates/business/supply-chain/.cursor/rules/inventory-management.mdc +69 -0
- package/templates/business/supply-chain/.cursor/rules/logistics.mdc +61 -0
- package/templates/business/supply-chain/.cursor/rules/overview.mdc +64 -0
- package/templates/business/supply-chain/.cursor/rules/supplier-evaluation.mdc +66 -0
- package/templates/business/supply-chain/CLAUDE.md +590 -0
- package/templates/business/supply-chain-harmonizer/.cursor/rules/disruption-response.mdc +67 -0
- package/templates/business/supply-chain-harmonizer/.cursor/rules/inventory-rebalancing.mdc +63 -0
- package/templates/business/supply-chain-harmonizer/.cursor/rules/overview.mdc +65 -0
- package/templates/business/supply-chain-harmonizer/.cursor/rules/rerouting.mdc +64 -0
- package/templates/business/supply-chain-harmonizer/.cursor/rules/scenario-simulation.mdc +68 -0
- package/templates/business/supply-chain-harmonizer/.cursor/rules/stakeholder-notifications.mdc +61 -0
- package/templates/business/supply-chain-harmonizer/CLAUDE.md +600 -0
- package/templates/creative/brand-guardian/.cursor/rules/brand-voice.mdc +64 -0
- package/templates/creative/brand-guardian/.cursor/rules/content-review.mdc +47 -0
- package/templates/creative/brand-guardian/.cursor/rules/ethical-guidelines.mdc +47 -0
- package/templates/creative/brand-guardian/.cursor/rules/multi-channel.mdc +49 -0
- package/templates/creative/brand-guardian/.cursor/rules/overview.mdc +58 -0
- package/templates/creative/brand-guardian/.cursor/rules/visual-identity.mdc +64 -0
- package/templates/creative/brand-guardian/CLAUDE.md +634 -0
- package/templates/creative/content-creation-expert/.cursor/rules/content-strategy.mdc +65 -0
- package/templates/creative/content-creation-expert/.cursor/rules/copywriting.mdc +59 -0
- package/templates/creative/content-creation-expert/.cursor/rules/editorial-operations.mdc +65 -0
- package/templates/creative/content-creation-expert/.cursor/rules/multimedia-production.mdc +64 -0
- package/templates/creative/content-creation-expert/.cursor/rules/overview.mdc +58 -0
- package/templates/creative/content-creation-expert/.cursor/rules/seo-content.mdc +75 -0
- package/templates/creative/content-creation-expert/CLAUDE.md +568 -0
- package/templates/creative/narrative-architect/.cursor/rules/collaboration.mdc +62 -0
- package/templates/creative/narrative-architect/.cursor/rules/continuity-tracking.mdc +56 -0
- package/templates/creative/narrative-architect/.cursor/rules/overview.mdc +68 -0
- package/templates/creative/narrative-architect/.cursor/rules/story-bible.mdc +77 -0
- package/templates/creative/narrative-architect/.cursor/rules/timeline-management.mdc +60 -0
- package/templates/creative/narrative-architect/.cursor/rules/world-building.mdc +78 -0
- package/templates/creative/narrative-architect/CLAUDE.md +737 -0
- package/templates/creative/social-media-expert/.cursor/rules/audience-growth.mdc +62 -0
- package/templates/creative/social-media-expert/.cursor/rules/community-management.mdc +67 -0
- package/templates/creative/social-media-expert/.cursor/rules/content-strategy.mdc +60 -0
- package/templates/creative/social-media-expert/.cursor/rules/overview.mdc +48 -0
- package/templates/creative/social-media-expert/.cursor/rules/platform-strategy.mdc +64 -0
- package/templates/creative/social-media-expert/.cursor/rules/social-analytics.mdc +64 -0
- package/templates/creative/social-media-expert/CLAUDE.md +624 -0
- package/templates/creative/trend-forecaster/.cursor/rules/cultural-analysis.mdc +59 -0
- package/templates/creative/trend-forecaster/.cursor/rules/forecasting-methods.mdc +63 -0
- package/templates/creative/trend-forecaster/.cursor/rules/overview.mdc +58 -0
- package/templates/creative/trend-forecaster/.cursor/rules/reporting.mdc +61 -0
- package/templates/creative/trend-forecaster/.cursor/rules/signal-analysis.mdc +74 -0
- package/templates/creative/trend-forecaster/.cursor/rules/trend-lifecycle.mdc +75 -0
- package/templates/creative/trend-forecaster/CLAUDE.md +717 -0
- package/templates/creative/ux-designer/.cursor/rules/accessibility.mdc +69 -0
- package/templates/creative/ux-designer/.cursor/rules/emotional-design.mdc +59 -0
- package/templates/creative/ux-designer/.cursor/rules/handoff.mdc +73 -0
- package/templates/creative/ux-designer/.cursor/rules/information-architecture.mdc +62 -0
- package/templates/creative/ux-designer/.cursor/rules/interaction-design.mdc +66 -0
- package/templates/creative/ux-designer/.cursor/rules/overview.mdc +61 -0
- package/templates/creative/ux-designer/.cursor/rules/research.mdc +61 -0
- package/templates/creative/ux-designer/.cursor/rules/visual-design.mdc +68 -0
- package/templates/creative/ux-designer/CLAUDE.md +124 -0
- package/templates/dogfood/project-overview.mdc +12 -0
- package/templates/dogfood/project-structure.mdc +82 -0
- package/templates/dogfood/rules-creation-best-practices.mdc +45 -0
- package/templates/education/educator/.cursor/rules/accessibility.mdc +67 -0
- package/templates/education/educator/.cursor/rules/assessment.mdc +68 -0
- package/templates/education/educator/.cursor/rules/curriculum.mdc +57 -0
- package/templates/education/educator/.cursor/rules/engagement.mdc +65 -0
- package/templates/education/educator/.cursor/rules/instructional-design.mdc +69 -0
- package/templates/education/educator/.cursor/rules/overview.mdc +57 -0
- package/templates/education/educator/.cursor/rules/retention.mdc +64 -0
- package/templates/education/educator/CLAUDE.md +338 -0
- package/templates/engineering/blockchain/.cursor/rules/defi-patterns.mdc +48 -0
- package/templates/engineering/blockchain/.cursor/rules/gas-optimization.mdc +77 -0
- package/templates/engineering/blockchain/.cursor/rules/overview.mdc +41 -0
- package/templates/engineering/blockchain/.cursor/rules/security.mdc +61 -0
- package/templates/engineering/blockchain/.cursor/rules/smart-contracts.mdc +64 -0
- package/templates/engineering/blockchain/.cursor/rules/testing.mdc +77 -0
- package/templates/engineering/blockchain/.cursor/rules/web3-integration.mdc +47 -0
- package/templates/engineering/blockchain/CLAUDE.md +389 -0
- package/templates/engineering/cli-tools/.cursor/rules/architecture.mdc +76 -0
- package/templates/engineering/cli-tools/.cursor/rules/arguments.mdc +65 -0
- package/templates/engineering/cli-tools/.cursor/rules/distribution.mdc +40 -0
- package/templates/engineering/cli-tools/.cursor/rules/error-handling.mdc +67 -0
- package/templates/engineering/cli-tools/.cursor/rules/overview.mdc +58 -0
- package/templates/engineering/cli-tools/.cursor/rules/testing.mdc +42 -0
- package/templates/engineering/cli-tools/.cursor/rules/user-experience.mdc +43 -0
- package/templates/engineering/cli-tools/CLAUDE.md +356 -0
- package/templates/engineering/data-engineering/.cursor/rules/data-modeling.mdc +71 -0
- package/templates/engineering/data-engineering/.cursor/rules/data-quality.mdc +78 -0
- package/templates/engineering/data-engineering/.cursor/rules/overview.mdc +49 -0
- package/templates/engineering/data-engineering/.cursor/rules/performance.mdc +71 -0
- package/templates/engineering/data-engineering/.cursor/rules/pipeline-design.mdc +79 -0
- package/templates/engineering/data-engineering/.cursor/rules/security.mdc +79 -0
- package/templates/engineering/data-engineering/.cursor/rules/testing.mdc +75 -0
- package/templates/engineering/data-engineering/CLAUDE.md +974 -0
- package/templates/engineering/devops-sre/.cursor/rules/capacity-planning.mdc +49 -0
- package/templates/engineering/devops-sre/.cursor/rules/change-management.mdc +51 -0
- package/templates/engineering/devops-sre/.cursor/rules/chaos-engineering.mdc +50 -0
- package/templates/engineering/devops-sre/.cursor/rules/disaster-recovery.mdc +54 -0
- package/templates/engineering/devops-sre/.cursor/rules/incident-management.mdc +56 -0
- package/templates/engineering/devops-sre/.cursor/rules/observability.mdc +50 -0
- package/templates/engineering/devops-sre/.cursor/rules/overview.mdc +76 -0
- package/templates/engineering/devops-sre/.cursor/rules/postmortems.mdc +49 -0
- package/templates/engineering/devops-sre/.cursor/rules/runbooks.mdc +49 -0
- package/templates/engineering/devops-sre/.cursor/rules/slo-sli.mdc +46 -0
- package/templates/engineering/devops-sre/.cursor/rules/toil-reduction.mdc +52 -0
- package/templates/engineering/devops-sre/CLAUDE.md +1007 -0
- package/templates/engineering/fullstack/.cursor/rules/api-contracts.mdc +79 -0
- package/templates/engineering/fullstack/.cursor/rules/architecture.mdc +79 -0
- package/templates/engineering/fullstack/.cursor/rules/overview.mdc +61 -0
- package/templates/engineering/fullstack/.cursor/rules/shared-types.mdc +77 -0
- package/templates/engineering/fullstack/.cursor/rules/testing.mdc +72 -0
- package/templates/engineering/fullstack/CLAUDE.md +349 -0
- package/templates/engineering/ml-ai/.cursor/rules/data-engineering.mdc +71 -0
- package/templates/engineering/ml-ai/.cursor/rules/deployment.mdc +43 -0
- package/templates/engineering/ml-ai/.cursor/rules/model-development.mdc +44 -0
- package/templates/engineering/ml-ai/.cursor/rules/monitoring.mdc +45 -0
- package/templates/engineering/ml-ai/.cursor/rules/overview.mdc +42 -0
- package/templates/engineering/ml-ai/.cursor/rules/security.mdc +51 -0
- package/templates/engineering/ml-ai/.cursor/rules/testing.mdc +44 -0
- package/templates/engineering/ml-ai/CLAUDE.md +1136 -0
- package/templates/engineering/mobile/.cursor/rules/navigation.mdc +75 -0
- package/templates/engineering/mobile/.cursor/rules/offline-first.mdc +68 -0
- package/templates/engineering/mobile/.cursor/rules/overview.mdc +76 -0
- package/templates/engineering/mobile/.cursor/rules/performance.mdc +78 -0
- package/templates/engineering/mobile/.cursor/rules/testing.mdc +77 -0
- package/templates/engineering/mobile/CLAUDE.md +233 -0
- package/templates/engineering/platform-engineering/.cursor/rules/ci-cd.mdc +51 -0
- package/templates/engineering/platform-engineering/.cursor/rules/developer-experience.mdc +48 -0
- package/templates/engineering/platform-engineering/.cursor/rules/infrastructure-as-code.mdc +62 -0
- package/templates/engineering/platform-engineering/.cursor/rules/kubernetes.mdc +51 -0
- package/templates/engineering/platform-engineering/.cursor/rules/observability.mdc +52 -0
- package/templates/engineering/platform-engineering/.cursor/rules/overview.mdc +44 -0
- package/templates/engineering/platform-engineering/.cursor/rules/security.mdc +74 -0
- package/templates/engineering/platform-engineering/.cursor/rules/testing.mdc +59 -0
- package/templates/engineering/platform-engineering/CLAUDE.md +850 -0
- package/templates/engineering/qa-engineering/.cursor/rules/automation.mdc +71 -0
- package/templates/engineering/qa-engineering/.cursor/rules/metrics.mdc +68 -0
- package/templates/engineering/qa-engineering/.cursor/rules/overview.mdc +45 -0
- package/templates/engineering/qa-engineering/.cursor/rules/quality-gates.mdc +54 -0
- package/templates/engineering/qa-engineering/.cursor/rules/test-design.mdc +59 -0
- package/templates/engineering/qa-engineering/.cursor/rules/test-strategy.mdc +62 -0
- package/templates/engineering/qa-engineering/CLAUDE.md +726 -0
- package/templates/engineering/testing/.cursor/rules/advanced-techniques.mdc +44 -0
- package/templates/engineering/testing/.cursor/rules/ci-cd-integration.mdc +43 -0
- package/templates/engineering/testing/.cursor/rules/overview.mdc +61 -0
- package/templates/engineering/testing/.cursor/rules/performance-testing.mdc +39 -0
- package/templates/engineering/testing/.cursor/rules/quality-metrics.mdc +74 -0
- package/templates/engineering/testing/.cursor/rules/reliability.mdc +39 -0
- package/templates/engineering/testing/.cursor/rules/tdd-methodology.mdc +52 -0
- package/templates/engineering/testing/.cursor/rules/test-data.mdc +46 -0
- package/templates/engineering/testing/.cursor/rules/test-design.mdc +45 -0
- package/templates/engineering/testing/.cursor/rules/test-types.mdc +71 -0
- package/templates/engineering/testing/CLAUDE.md +1134 -0
- package/templates/engineering/unity-dev-expert/.cursor/rules/csharp-architecture.mdc +61 -0
- package/templates/engineering/unity-dev-expert/.cursor/rules/multiplayer-networking.mdc +67 -0
- package/templates/engineering/unity-dev-expert/.cursor/rules/overview.mdc +56 -0
- package/templates/engineering/unity-dev-expert/.cursor/rules/performance-optimization.mdc +76 -0
- package/templates/engineering/unity-dev-expert/.cursor/rules/physics-rendering.mdc +59 -0
- package/templates/engineering/unity-dev-expert/.cursor/rules/ui-systems.mdc +59 -0
- package/templates/engineering/unity-dev-expert/CLAUDE.md +534 -0
- package/templates/engineering/web-backend/.cursor/rules/api-design.mdc +64 -0
- package/templates/engineering/web-backend/.cursor/rules/authentication.mdc +69 -0
- package/templates/engineering/web-backend/.cursor/rules/database-patterns.mdc +73 -0
- package/templates/engineering/web-backend/.cursor/rules/error-handling.mdc +66 -0
- package/templates/engineering/web-backend/.cursor/rules/overview.mdc +74 -0
- package/templates/engineering/web-backend/.cursor/rules/security.mdc +60 -0
- package/templates/engineering/web-backend/.cursor/rules/testing.mdc +74 -0
- package/templates/engineering/web-backend/CLAUDE.md +366 -0
- package/templates/engineering/web-frontend/.cursor/rules/accessibility.mdc +75 -0
- package/templates/engineering/web-frontend/.cursor/rules/component-patterns.mdc +76 -0
- package/templates/engineering/web-frontend/.cursor/rules/overview.mdc +77 -0
- package/templates/engineering/web-frontend/.cursor/rules/performance.mdc +73 -0
- package/templates/engineering/web-frontend/.cursor/rules/state-management.mdc +71 -0
- package/templates/engineering/web-frontend/.cursor/rules/styling.mdc +69 -0
- package/templates/engineering/web-frontend/.cursor/rules/testing.mdc +75 -0
- package/templates/engineering/web-frontend/CLAUDE.md +399 -0
- package/templates/languages/cpp-expert/.cursor/rules/concurrency.mdc +68 -0
- package/templates/languages/cpp-expert/.cursor/rules/error-handling.mdc +65 -0
- package/templates/languages/cpp-expert/.cursor/rules/memory-and-ownership.mdc +68 -0
- package/templates/languages/cpp-expert/.cursor/rules/modern-cpp.mdc +75 -0
- package/templates/languages/cpp-expert/.cursor/rules/overview.mdc +37 -0
- package/templates/languages/cpp-expert/.cursor/rules/performance.mdc +74 -0
- package/templates/languages/cpp-expert/.cursor/rules/testing.mdc +70 -0
- package/templates/languages/cpp-expert/.cursor/rules/tooling.mdc +77 -0
- package/templates/languages/cpp-expert/CLAUDE.md +242 -0
- package/templates/languages/csharp-expert/.cursor/rules/aspnet-core.mdc +78 -0
- package/templates/languages/csharp-expert/.cursor/rules/async-patterns.mdc +71 -0
- package/templates/languages/csharp-expert/.cursor/rules/dependency-injection.mdc +76 -0
- package/templates/languages/csharp-expert/.cursor/rules/error-handling.mdc +65 -0
- package/templates/languages/csharp-expert/.cursor/rules/language-features.mdc +74 -0
- package/templates/languages/csharp-expert/.cursor/rules/overview.mdc +47 -0
- package/templates/languages/csharp-expert/.cursor/rules/performance.mdc +66 -0
- package/templates/languages/csharp-expert/.cursor/rules/testing.mdc +78 -0
- package/templates/languages/csharp-expert/.cursor/rules/tooling.mdc +78 -0
- package/templates/languages/csharp-expert/CLAUDE.md +360 -0
- package/templates/languages/golang-expert/.cursor/rules/concurrency.mdc +79 -0
- package/templates/languages/golang-expert/.cursor/rules/error-handling.mdc +77 -0
- package/templates/languages/golang-expert/.cursor/rules/interfaces-and-types.mdc +77 -0
- package/templates/languages/golang-expert/.cursor/rules/overview.mdc +74 -0
- package/templates/languages/golang-expert/.cursor/rules/performance.mdc +76 -0
- package/templates/languages/golang-expert/.cursor/rules/production-patterns.mdc +76 -0
- package/templates/languages/golang-expert/.cursor/rules/stdlib-and-tooling.mdc +68 -0
- package/templates/languages/golang-expert/.cursor/rules/testing.mdc +77 -0
- package/templates/languages/golang-expert/CLAUDE.md +361 -0
- package/templates/languages/java-expert/.cursor/rules/concurrency.mdc +69 -0
- package/templates/languages/java-expert/.cursor/rules/error-handling.mdc +70 -0
- package/templates/languages/java-expert/.cursor/rules/modern-java.mdc +74 -0
- package/templates/languages/java-expert/.cursor/rules/overview.mdc +42 -0
- package/templates/languages/java-expert/.cursor/rules/performance.mdc +69 -0
- package/templates/languages/java-expert/.cursor/rules/persistence.mdc +74 -0
- package/templates/languages/java-expert/.cursor/rules/spring-boot.mdc +73 -0
- package/templates/languages/java-expert/.cursor/rules/testing.mdc +79 -0
- package/templates/languages/java-expert/.cursor/rules/tooling.mdc +76 -0
- package/templates/languages/java-expert/CLAUDE.md +325 -0
- package/templates/languages/javascript-expert/.cursor/rules/language-deep-dive.mdc +74 -0
- package/templates/languages/javascript-expert/.cursor/rules/node-patterns.mdc +77 -0
- package/templates/languages/javascript-expert/.cursor/rules/overview.mdc +66 -0
- package/templates/languages/javascript-expert/.cursor/rules/performance.mdc +64 -0
- package/templates/languages/javascript-expert/.cursor/rules/react-patterns.mdc +70 -0
- package/templates/languages/javascript-expert/.cursor/rules/testing.mdc +76 -0
- package/templates/languages/javascript-expert/.cursor/rules/tooling.mdc +72 -0
- package/templates/languages/javascript-expert/.cursor/rules/typescript-deep-dive.mdc +77 -0
- package/templates/languages/javascript-expert/CLAUDE.md +479 -0
- package/templates/languages/kotlin-expert/.cursor/rules/coroutines.mdc +75 -0
- package/templates/languages/kotlin-expert/.cursor/rules/error-handling.mdc +69 -0
- package/templates/languages/kotlin-expert/.cursor/rules/frameworks.mdc +76 -0
- package/templates/languages/kotlin-expert/.cursor/rules/language-features.mdc +78 -0
- package/templates/languages/kotlin-expert/.cursor/rules/overview.mdc +38 -0
- package/templates/languages/kotlin-expert/.cursor/rules/performance.mdc +73 -0
- package/templates/languages/kotlin-expert/.cursor/rules/testing.mdc +70 -0
- package/templates/languages/kotlin-expert/.cursor/rules/tooling.mdc +67 -0
- package/templates/languages/kotlin-expert/CLAUDE.md +276 -0
- package/templates/languages/python-expert/.cursor/rules/async-python.mdc +71 -0
- package/templates/languages/python-expert/.cursor/rules/overview.mdc +76 -0
- package/templates/languages/python-expert/.cursor/rules/patterns-and-idioms.mdc +77 -0
- package/templates/languages/python-expert/.cursor/rules/performance.mdc +74 -0
- package/templates/languages/python-expert/.cursor/rules/testing.mdc +77 -0
- package/templates/languages/python-expert/.cursor/rules/tooling.mdc +77 -0
- package/templates/languages/python-expert/.cursor/rules/type-system.mdc +77 -0
- package/templates/languages/python-expert/.cursor/rules/web-and-apis.mdc +76 -0
- package/templates/languages/python-expert/CLAUDE.md +264 -0
- package/templates/languages/ruby-expert/.cursor/rules/concurrency-and-threading.mdc +65 -0
- package/templates/languages/ruby-expert/.cursor/rules/error-handling.mdc +69 -0
- package/templates/languages/ruby-expert/.cursor/rules/idioms-and-style.mdc +76 -0
- package/templates/languages/ruby-expert/.cursor/rules/overview.mdc +60 -0
- package/templates/languages/ruby-expert/.cursor/rules/performance.mdc +68 -0
- package/templates/languages/ruby-expert/.cursor/rules/rails-and-frameworks.mdc +60 -0
- package/templates/languages/ruby-expert/.cursor/rules/testing.mdc +56 -0
- package/templates/languages/ruby-expert/.cursor/rules/tooling.mdc +52 -0
- package/templates/languages/ruby-expert/CLAUDE.md +102 -0
- package/templates/languages/rust-expert/.cursor/rules/concurrency.mdc +69 -0
- package/templates/languages/rust-expert/.cursor/rules/ecosystem-and-tooling.mdc +76 -0
- package/templates/languages/rust-expert/.cursor/rules/error-handling.mdc +76 -0
- package/templates/languages/rust-expert/.cursor/rules/overview.mdc +62 -0
- package/templates/languages/rust-expert/.cursor/rules/ownership-and-borrowing.mdc +70 -0
- package/templates/languages/rust-expert/.cursor/rules/performance-and-unsafe.mdc +70 -0
- package/templates/languages/rust-expert/.cursor/rules/testing.mdc +73 -0
- package/templates/languages/rust-expert/.cursor/rules/traits-and-generics.mdc +76 -0
- package/templates/languages/rust-expert/CLAUDE.md +283 -0
- package/templates/languages/swift-expert/.cursor/rules/concurrency.mdc +77 -0
- package/templates/languages/swift-expert/.cursor/rules/error-handling.mdc +76 -0
- package/templates/languages/swift-expert/.cursor/rules/language-features.mdc +78 -0
- package/templates/languages/swift-expert/.cursor/rules/overview.mdc +46 -0
- package/templates/languages/swift-expert/.cursor/rules/performance.mdc +69 -0
- package/templates/languages/swift-expert/.cursor/rules/swiftui.mdc +77 -0
- package/templates/languages/swift-expert/.cursor/rules/testing.mdc +75 -0
- package/templates/languages/swift-expert/.cursor/rules/tooling.mdc +77 -0
- package/templates/languages/swift-expert/CLAUDE.md +275 -0
- package/templates/professional/documentation/.cursor/rules/adr.mdc +65 -0
- package/templates/professional/documentation/.cursor/rules/api-documentation.mdc +64 -0
- package/templates/professional/documentation/.cursor/rules/code-comments.mdc +75 -0
- package/templates/professional/documentation/.cursor/rules/maintenance.mdc +58 -0
- package/templates/professional/documentation/.cursor/rules/overview.mdc +48 -0
- package/templates/professional/documentation/.cursor/rules/readme-standards.mdc +70 -0
- package/templates/professional/documentation/CLAUDE.md +120 -0
- package/templates/professional/executive-assistant/.cursor/rules/calendar.mdc +51 -0
- package/templates/professional/executive-assistant/.cursor/rules/confidentiality.mdc +53 -0
- package/templates/professional/executive-assistant/.cursor/rules/email.mdc +49 -0
- package/templates/professional/executive-assistant/.cursor/rules/meetings.mdc +39 -0
- package/templates/professional/executive-assistant/.cursor/rules/overview.mdc +42 -0
- package/templates/professional/executive-assistant/.cursor/rules/prioritization.mdc +48 -0
- package/templates/professional/executive-assistant/.cursor/rules/stakeholder-management.mdc +50 -0
- package/templates/professional/executive-assistant/.cursor/rules/travel.mdc +43 -0
- package/templates/professional/executive-assistant/CLAUDE.md +620 -0
- package/templates/professional/grant-writer/.cursor/rules/budgets.mdc +55 -0
- package/templates/professional/grant-writer/.cursor/rules/compliance.mdc +47 -0
- package/templates/professional/grant-writer/.cursor/rules/funding-research.mdc +47 -0
- package/templates/professional/grant-writer/.cursor/rules/narrative.mdc +58 -0
- package/templates/professional/grant-writer/.cursor/rules/overview.mdc +68 -0
- package/templates/professional/grant-writer/.cursor/rules/post-award.mdc +59 -0
- package/templates/professional/grant-writer/.cursor/rules/review-criteria.mdc +51 -0
- package/templates/professional/grant-writer/.cursor/rules/sustainability.mdc +48 -0
- package/templates/professional/grant-writer/CLAUDE.md +577 -0
- package/templates/professional/knowledge-synthesis/.cursor/rules/document-management.mdc +51 -0
- package/templates/professional/knowledge-synthesis/.cursor/rules/knowledge-graphs.mdc +63 -0
- package/templates/professional/knowledge-synthesis/.cursor/rules/overview.mdc +74 -0
- package/templates/professional/knowledge-synthesis/.cursor/rules/research-workflow.mdc +50 -0
- package/templates/professional/knowledge-synthesis/.cursor/rules/search-retrieval.mdc +62 -0
- package/templates/professional/knowledge-synthesis/.cursor/rules/summarization.mdc +61 -0
- package/templates/professional/knowledge-synthesis/CLAUDE.md +593 -0
- package/templates/professional/life-logistics/.cursor/rules/financial-optimization.mdc +78 -0
- package/templates/professional/life-logistics/.cursor/rules/negotiation.mdc +68 -0
- package/templates/professional/life-logistics/.cursor/rules/overview.mdc +75 -0
- package/templates/professional/life-logistics/.cursor/rules/research-methodology.mdc +76 -0
- package/templates/professional/life-logistics/.cursor/rules/scheduling.mdc +68 -0
- package/templates/professional/life-logistics/.cursor/rules/task-management.mdc +47 -0
- package/templates/professional/life-logistics/CLAUDE.md +601 -0
- package/templates/professional/research-assistant/.cursor/rules/citation-attribution.mdc +61 -0
- package/templates/professional/research-assistant/.cursor/rules/information-synthesis.mdc +65 -0
- package/templates/professional/research-assistant/.cursor/rules/overview.mdc +56 -0
- package/templates/professional/research-assistant/.cursor/rules/research-methodologies.mdc +54 -0
- package/templates/professional/research-assistant/.cursor/rules/search-strategies.mdc +57 -0
- package/templates/professional/research-assistant/.cursor/rules/source-evaluation.mdc +59 -0
- package/templates/professional/research-assistant/CLAUDE.md +318 -0
- package/templates/professional/wellness-orchestrator/.cursor/rules/adaptive-planning.mdc +69 -0
- package/templates/professional/wellness-orchestrator/.cursor/rules/data-integration.mdc +60 -0
- package/templates/professional/wellness-orchestrator/.cursor/rules/fitness-programming.mdc +66 -0
- package/templates/professional/wellness-orchestrator/.cursor/rules/nutrition-planning.mdc +57 -0
- package/templates/professional/wellness-orchestrator/.cursor/rules/overview.mdc +76 -0
- package/templates/professional/wellness-orchestrator/.cursor/rules/sleep-optimization.mdc +68 -0
- package/templates/professional/wellness-orchestrator/CLAUDE.md +573 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Database Patterns
|
|
3
|
+
alwaysApply: false
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Database Patterns
|
|
7
|
+
|
|
8
|
+
Best practices for working with databases in backend applications.
|
|
9
|
+
|
|
10
|
+
## Core Principles
|
|
11
|
+
|
|
12
|
+
- Separate database operations from business logic (repository pattern)
|
|
13
|
+
- Use transactions for related operations to maintain consistency
|
|
14
|
+
- Handle connection errors with retry and exponential backoff
|
|
15
|
+
|
|
16
|
+
## Query Optimization
|
|
17
|
+
|
|
18
|
+
- **Select only needed fields**: Avoid `SELECT *` in production queries
|
|
19
|
+
- **Use pagination**: Offset-based for simple cases, cursor-based for large datasets
|
|
20
|
+
- **Avoid N+1**: Use joins/includes or batch queries with `WHERE id IN (...)`
|
|
21
|
+
- **Index frequently queried columns**: Composite indexes for common query patterns
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
// Bad: N+1
|
|
25
|
+
for (const post of posts) {
|
|
26
|
+
post.author = await db.user.findUnique({ where: { id: post.authorId } });
|
|
27
|
+
}
|
|
28
|
+
// Good: Single query
|
|
29
|
+
const posts = await db.post.findMany({ include: { author: true } });
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Migrations
|
|
33
|
+
|
|
34
|
+
- Version-control all migrations sequentially
|
|
35
|
+
- Write reversible migrations (up + down)
|
|
36
|
+
- Test in staging before production
|
|
37
|
+
- Consider zero-downtime migrations for large tables
|
|
38
|
+
|
|
39
|
+
## Connection Pooling
|
|
40
|
+
|
|
41
|
+
- Match pool size to expected concurrency
|
|
42
|
+
- Set idle and connection timeouts
|
|
43
|
+
- Handle pool exhaustion with query timeouts
|
|
44
|
+
|
|
45
|
+
## Data Integrity
|
|
46
|
+
|
|
47
|
+
```sql
|
|
48
|
+
-- Use constraints
|
|
49
|
+
PRIMARY KEY (id)
|
|
50
|
+
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
|
51
|
+
UNIQUE (email)
|
|
52
|
+
CHECK (price >= 0)
|
|
53
|
+
|
|
54
|
+
-- Use appropriate types
|
|
55
|
+
id UUID, email VARCHAR(255), price DECIMAL(10,2), created_at TIMESTAMPTZ
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Soft Deletes
|
|
59
|
+
|
|
60
|
+
When needed, add `deletedAt` column and filter with `WHERE deletedAt IS NULL`. Be consistent across queries.
|
|
61
|
+
|
|
62
|
+
## Security
|
|
63
|
+
|
|
64
|
+
- **Always parameterized queries**: Never interpolate user input into SQL
|
|
65
|
+
- **Encrypt sensitive data at rest**: SSN, tokens, PII
|
|
66
|
+
- **Audit logging**: Track changes for sensitive operations with userId, action, timestamp
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
// Good
|
|
70
|
+
await db.query('SELECT * FROM users WHERE id = $1', [userId]);
|
|
71
|
+
// Bad: SQL injection
|
|
72
|
+
await db.query(`SELECT * FROM users WHERE id = '${userId}'`);
|
|
73
|
+
```
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Error Handling
|
|
3
|
+
alwaysApply: false
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Error Handling
|
|
7
|
+
|
|
8
|
+
Best practices for handling errors in backend applications.
|
|
9
|
+
|
|
10
|
+
## Principles
|
|
11
|
+
|
|
12
|
+
- **Fail fast**: Detect errors early with clear diagnostics
|
|
13
|
+
- **Fail gracefully**: Users get helpful messages, not stack traces
|
|
14
|
+
- **Log with context**: Errors need requestId, userId, path for debugging
|
|
15
|
+
- **Recover when possible**: Retry transient failures with exponential backoff
|
|
16
|
+
|
|
17
|
+
## Custom Error Classes
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
class AppError extends Error {
|
|
21
|
+
constructor(public statusCode: number, public code: string,
|
|
22
|
+
message: string, public details?: unknown) { super(message); }
|
|
23
|
+
}
|
|
24
|
+
class NotFoundError extends AppError {
|
|
25
|
+
constructor(resource: string, id: string) {
|
|
26
|
+
super(404, 'NOT_FOUND', `${resource} ${id} not found`); }
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Extend for ValidationError (422), UnauthorizedError (401), ForbiddenError (403), ConflictError (409).
|
|
31
|
+
|
|
32
|
+
## Result Types
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
type Result<T, E = Error> = { ok: true; value: T } | { ok: false; error: E };
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Use for explicit error handling without exceptions in service layers.
|
|
39
|
+
|
|
40
|
+
## Global Error Handler
|
|
41
|
+
|
|
42
|
+
- Log error with context (message, stack, requestId, method, path, userId)
|
|
43
|
+
- Return structured `{error: {code, message, details?}}` for AppError subclasses
|
|
44
|
+
- Return generic 500 for unknown errors — never leak stack traces
|
|
45
|
+
|
|
46
|
+
## Async Error Handling
|
|
47
|
+
|
|
48
|
+
Wrap async handlers to forward rejections to error middleware:
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
const asyncHandler = (fn) => (req, res, next) =>
|
|
52
|
+
Promise.resolve(fn(req, res, next)).catch(next);
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Logging Rules
|
|
56
|
+
|
|
57
|
+
- **Log**: Error message, stack, requestId, userId, resource context
|
|
58
|
+
- **Never log**: Passwords, API keys, tokens, credit cards, PII
|
|
59
|
+
|
|
60
|
+
## Anti-Patterns
|
|
61
|
+
|
|
62
|
+
**Swallowing errors**: Empty `catch` blocks. Always log or rethrow.
|
|
63
|
+
|
|
64
|
+
**Leaking internals**: Returning `error.stack` to client. Use generic messages + requestId.
|
|
65
|
+
|
|
66
|
+
**Catching too broadly**: One catch for validation + DB + unknown errors. Catch specific types; let unknown errors bubble up.
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Web Backend Development
|
|
3
|
+
alwaysApply: false
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Web Backend Development
|
|
7
|
+
|
|
8
|
+
Guidelines for building robust backend APIs and services.
|
|
9
|
+
|
|
10
|
+
## Scope
|
|
11
|
+
|
|
12
|
+
This ruleset applies to:
|
|
13
|
+
- RESTful APIs
|
|
14
|
+
- GraphQL APIs
|
|
15
|
+
- Microservices
|
|
16
|
+
- Backend-for-frontend (BFF) services
|
|
17
|
+
- Server-side web applications
|
|
18
|
+
|
|
19
|
+
## Core Technologies
|
|
20
|
+
|
|
21
|
+
Backend development typically involves:
|
|
22
|
+
- Server frameworks (Express, Fastify, Koa, Hono, etc.)
|
|
23
|
+
- Database systems (PostgreSQL, MySQL, MongoDB, Redis, etc.)
|
|
24
|
+
- Authentication/Authorization (JWT, OAuth, sessions)
|
|
25
|
+
- API documentation (OpenAPI/Swagger)
|
|
26
|
+
- Testing frameworks
|
|
27
|
+
|
|
28
|
+
## Key Principles
|
|
29
|
+
|
|
30
|
+
### 1. Security First
|
|
31
|
+
Every input is hostile until validated. Defense in depth.
|
|
32
|
+
|
|
33
|
+
### 2. Reliability
|
|
34
|
+
Handle errors gracefully. Fail fast with clear diagnostics.
|
|
35
|
+
|
|
36
|
+
### 3. Observability
|
|
37
|
+
Log meaningfully. Track metrics. Enable debugging.
|
|
38
|
+
|
|
39
|
+
### 4. Scalability
|
|
40
|
+
Design for horizontal scaling. Avoid single points of failure.
|
|
41
|
+
|
|
42
|
+
## Project Structure
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
src/
|
|
46
|
+
├── routes/ # Route handlers/controllers
|
|
47
|
+
├── services/ # Business logic
|
|
48
|
+
├── repositories/ # Data access layer
|
|
49
|
+
├── middleware/ # Request/response middleware
|
|
50
|
+
├── lib/ # Shared utilities
|
|
51
|
+
├── types/ # TypeScript definitions
|
|
52
|
+
├── validation/ # Input validation schemas
|
|
53
|
+
└── config/ # Configuration management
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## API Design Principles
|
|
57
|
+
|
|
58
|
+
- Use consistent naming conventions
|
|
59
|
+
- Return appropriate HTTP status codes
|
|
60
|
+
- Provide meaningful error messages
|
|
61
|
+
- Version your APIs
|
|
62
|
+
- Document endpoints thoroughly
|
|
63
|
+
|
|
64
|
+
## Definition of Done
|
|
65
|
+
|
|
66
|
+
A backend feature is complete when:
|
|
67
|
+
- [ ] Endpoint works as specified
|
|
68
|
+
- [ ] Input validation implemented
|
|
69
|
+
- [ ] Error handling covers edge cases
|
|
70
|
+
- [ ] Authentication/authorization enforced
|
|
71
|
+
- [ ] Unit and integration tests passing
|
|
72
|
+
- [ ] API documentation updated
|
|
73
|
+
- [ ] No security vulnerabilities
|
|
74
|
+
- [ ] Logging in place for debugging
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Backend Security
|
|
3
|
+
alwaysApply: false
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Backend Security
|
|
7
|
+
|
|
8
|
+
Security best practices specific to backend API development.
|
|
9
|
+
|
|
10
|
+
## Input Validation
|
|
11
|
+
|
|
12
|
+
- Validate all external input at the boundary with strict schemas (Zod, Joi)
|
|
13
|
+
- Reject invalid input with 422 and structured error details
|
|
14
|
+
- Sanitize HTML content before storage (DOMPurify)
|
|
15
|
+
- Strip sensitive fields (passwordHash, tokens) before returning responses
|
|
16
|
+
|
|
17
|
+
## Injection Prevention
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
// SQL: Always parameterized
|
|
21
|
+
await db.query('SELECT * FROM users WHERE email = $1', [email]);
|
|
22
|
+
// Command: Use execFile with array args
|
|
23
|
+
execFile('convert', [inputPath, '-resize', '800x600', outputPath]);
|
|
24
|
+
// NoSQL: Validate input types to prevent $gt/$ne injection
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Never use string interpolation for queries or shell commands.
|
|
28
|
+
|
|
29
|
+
## Rate Limiting
|
|
30
|
+
|
|
31
|
+
- General API: 100 req/min per IP
|
|
32
|
+
- Auth endpoints: 5 attempts per 15min, skip successful requests
|
|
33
|
+
- Per-user limits for expensive operations via Redis counters
|
|
34
|
+
|
|
35
|
+
## Security Headers
|
|
36
|
+
|
|
37
|
+
- Use helmet for CSP, HSTS, referrer policy
|
|
38
|
+
- Configure CORS with explicit allowed origins, credentials, methods
|
|
39
|
+
- Limit request body size (`express.json({ limit: '1mb' })`)
|
|
40
|
+
- Reject unexpected Content-Types with 415
|
|
41
|
+
|
|
42
|
+
## Secrets Management
|
|
43
|
+
|
|
44
|
+
- Validate env vars at startup with schema (Zod)
|
|
45
|
+
- Never log secrets — log host only, not full connection strings
|
|
46
|
+
- Support secret rotation: accept both old and new secrets during transition
|
|
47
|
+
|
|
48
|
+
## Audit Logging
|
|
49
|
+
|
|
50
|
+
Log security events: login attempts (success/failure), permission changes, resource access. Include userId, IP, userAgent, action, timestamp.
|
|
51
|
+
|
|
52
|
+
## Security Checklist
|
|
53
|
+
|
|
54
|
+
- [ ] All inputs validated with strict schemas
|
|
55
|
+
- [ ] Parameterized queries everywhere
|
|
56
|
+
- [ ] Rate limiting on all endpoints
|
|
57
|
+
- [ ] Auth + authorization on protected routes
|
|
58
|
+
- [ ] Security headers configured (HSTS, CSP, CORS)
|
|
59
|
+
- [ ] Secrets not in code or logs
|
|
60
|
+
- [ ] Error messages don't leak internals
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Backend Testing
|
|
3
|
+
alwaysApply: false
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Backend Testing
|
|
7
|
+
|
|
8
|
+
Guidelines for testing backend applications effectively.
|
|
9
|
+
|
|
10
|
+
## Testing Pyramid
|
|
11
|
+
|
|
12
|
+
1. **Unit Tests** — Fast, isolated, test business logic and utilities
|
|
13
|
+
2. **Integration Tests** — Test with real database, repository layer
|
|
14
|
+
3. **API Tests** — Full HTTP request/response cycle with supertest
|
|
15
|
+
|
|
16
|
+
## Unit Tests
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
describe('calculateDiscount', () => {
|
|
20
|
+
it('applies percentage', () => {
|
|
21
|
+
expect(calculateDiscount(100, { type: 'percentage', value: 10 })).toBe(90);
|
|
22
|
+
});
|
|
23
|
+
it('does not go below zero', () => {
|
|
24
|
+
expect(calculateDiscount(10, { type: 'fixed', value: 20 })).toBe(0);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Integration Tests
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
describe('userRepository', () => {
|
|
33
|
+
beforeEach(() => db.user.deleteMany());
|
|
34
|
+
it('creates user', async () => {
|
|
35
|
+
const user = await userRepository.create({ email: 'a@b.com', name: 'Test' });
|
|
36
|
+
expect(user.id).toBeDefined();
|
|
37
|
+
});
|
|
38
|
+
it('throws on duplicate email', async () => {
|
|
39
|
+
await userRepository.create({ email: 'a@b.com', name: 'U1' });
|
|
40
|
+
await expect(userRepository.create({ email: 'a@b.com', name: 'U2' })).rejects.toThrow();
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## API Tests
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
it('creates user', async () => {
|
|
49
|
+
const res = await request(app).post('/users')
|
|
50
|
+
.set('Authorization', `Bearer ${token}`)
|
|
51
|
+
.send({ email: 'new@test.com', name: 'New' });
|
|
52
|
+
expect(res.status).toBe(201);
|
|
53
|
+
});
|
|
54
|
+
it('validates email', async () => {
|
|
55
|
+
const res = await request(app).post('/users')
|
|
56
|
+
.set('Authorization', `Bearer ${token}`)
|
|
57
|
+
.send({ email: 'invalid', name: 'Test' });
|
|
58
|
+
expect(res.status).toBe(422);
|
|
59
|
+
});
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Mocking
|
|
63
|
+
|
|
64
|
+
- Mock external services (email, payment) with `vi.mock()`
|
|
65
|
+
- Mock database only for unit-testing service logic; use real DB for integration
|
|
66
|
+
- Use factories with `@faker-js/faker` for test data
|
|
67
|
+
|
|
68
|
+
## Best Practices
|
|
69
|
+
|
|
70
|
+
- **Test behavior, not implementation**: Assert on persisted data, not `repo.save` calls
|
|
71
|
+
- **One assertion per concept**: Separate tests for auth, validation, success cases
|
|
72
|
+
- **Descriptive names**: `creates order when cart is valid`, `returns 409 when out of stock`
|
|
73
|
+
- **Co-locate tests**: `userService.test.ts` next to `userService.ts`
|
|
74
|
+
- **Clean state**: Truncate tables in `beforeEach`, use test database
|
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
# Web Backend Development Guide
|
|
2
|
+
|
|
3
|
+
Comprehensive guidelines for building robust backend APIs and services.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Overview
|
|
8
|
+
|
|
9
|
+
This guide applies to:
|
|
10
|
+
- RESTful APIs
|
|
11
|
+
- GraphQL APIs
|
|
12
|
+
- Microservices
|
|
13
|
+
- Backend-for-frontend (BFF) services
|
|
14
|
+
|
|
15
|
+
### Key Principles
|
|
16
|
+
|
|
17
|
+
1. **Security First** - Every input is hostile until validated
|
|
18
|
+
2. **Reliability** - Handle errors gracefully, fail fast
|
|
19
|
+
3. **Observability** - Log meaningfully, track metrics
|
|
20
|
+
4. **Scalability** - Design for horizontal scaling
|
|
21
|
+
|
|
22
|
+
### Project Structure
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
src/
|
|
26
|
+
├── routes/ # Route handlers/controllers
|
|
27
|
+
├── services/ # Business logic
|
|
28
|
+
├── repositories/ # Data access layer
|
|
29
|
+
├── middleware/ # Request/response middleware
|
|
30
|
+
├── lib/ # Shared utilities
|
|
31
|
+
├── types/ # TypeScript definitions
|
|
32
|
+
├── validation/ # Input validation schemas
|
|
33
|
+
└── config/ # Configuration management
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## API Design
|
|
39
|
+
|
|
40
|
+
### RESTful Conventions
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
GET /users # List users
|
|
44
|
+
POST /users # Create user
|
|
45
|
+
GET /users/:id # Get user
|
|
46
|
+
PUT /users/:id # Update user
|
|
47
|
+
DELETE /users/:id # Delete user
|
|
48
|
+
GET /users/:id/posts # Get user's posts
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### HTTP Status Codes
|
|
52
|
+
|
|
53
|
+
**Success**: 200 OK, 201 Created, 204 No Content
|
|
54
|
+
**Client Errors**: 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 422 Validation Error, 429 Rate Limited
|
|
55
|
+
**Server Errors**: 500 Internal Error, 502 Bad Gateway, 503 Service Unavailable
|
|
56
|
+
|
|
57
|
+
### Response Format
|
|
58
|
+
|
|
59
|
+
```json
|
|
60
|
+
// Success
|
|
61
|
+
{ "data": { "id": "123", "name": "John" } }
|
|
62
|
+
|
|
63
|
+
// Error
|
|
64
|
+
{
|
|
65
|
+
"error": {
|
|
66
|
+
"code": "VALIDATION_ERROR",
|
|
67
|
+
"message": "Validation failed",
|
|
68
|
+
"details": [{ "field": "email", "message": "Invalid format" }]
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Collection
|
|
73
|
+
{
|
|
74
|
+
"data": [...],
|
|
75
|
+
"pagination": { "page": 1, "limit": 20, "total": 150 }
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Query Parameters
|
|
80
|
+
|
|
81
|
+
- **Filtering**: `?role=admin&status=active`
|
|
82
|
+
- **Sorting**: `?sort=-createdAt` (prefix `-` for descending)
|
|
83
|
+
- **Pagination**: `?page=2&limit=20` or `?cursor=xyz&limit=20`
|
|
84
|
+
- **Fields**: `?fields=id,name,email`
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## Database Patterns
|
|
89
|
+
|
|
90
|
+
### Data Access Layer
|
|
91
|
+
|
|
92
|
+
```ts
|
|
93
|
+
// repository/userRepository.ts
|
|
94
|
+
export const userRepository = {
|
|
95
|
+
async findById(id: string): Promise<User | null> {
|
|
96
|
+
return db.user.findUnique({ where: { id } });
|
|
97
|
+
},
|
|
98
|
+
async create(data: CreateUserInput): Promise<User> {
|
|
99
|
+
return db.user.create({ data });
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Transactions
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
await db.$transaction(async (tx) => {
|
|
108
|
+
const order = await tx.order.create({ data: orderData });
|
|
109
|
+
await tx.inventory.update({ ... });
|
|
110
|
+
await tx.payment.create({ ... });
|
|
111
|
+
});
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Avoid N+1 Queries
|
|
115
|
+
|
|
116
|
+
```ts
|
|
117
|
+
// Bad: N+1
|
|
118
|
+
const posts = await db.post.findMany();
|
|
119
|
+
for (const post of posts) {
|
|
120
|
+
post.author = await db.user.findUnique({ where: { id: post.authorId } });
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Good: Include
|
|
124
|
+
const posts = await db.post.findMany({ include: { author: true } });
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Use Indexes
|
|
128
|
+
|
|
129
|
+
```sql
|
|
130
|
+
CREATE INDEX idx_users_email ON users(email);
|
|
131
|
+
CREATE INDEX idx_posts_user_created ON posts(user_id, created_at);
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
## Authentication & Authorization
|
|
137
|
+
|
|
138
|
+
### JWT Authentication
|
|
139
|
+
|
|
140
|
+
```ts
|
|
141
|
+
const generateToken = (user: User): string => {
|
|
142
|
+
return jwt.sign(
|
|
143
|
+
{ sub: user.id, email: user.email, role: user.role },
|
|
144
|
+
process.env.JWT_SECRET,
|
|
145
|
+
{ expiresIn: '15m' }
|
|
146
|
+
);
|
|
147
|
+
};
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Authorization Middleware
|
|
151
|
+
|
|
152
|
+
```ts
|
|
153
|
+
const requirePermission = (permission: string) => {
|
|
154
|
+
return (req, res, next) => {
|
|
155
|
+
const userPermissions = permissions[req.user.role] || [];
|
|
156
|
+
if (!userPermissions.includes(permission)) {
|
|
157
|
+
return res.status(403).json({ error: 'Forbidden' });
|
|
158
|
+
}
|
|
159
|
+
next();
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### Password Security
|
|
165
|
+
|
|
166
|
+
- Hash with bcrypt (12+ rounds)
|
|
167
|
+
- Enforce minimum requirements
|
|
168
|
+
- Rate limit login attempts
|
|
169
|
+
|
|
170
|
+
### Security Best Practices
|
|
171
|
+
|
|
172
|
+
- Short-lived access tokens + refresh tokens
|
|
173
|
+
- HTTP-only, Secure, SameSite cookies
|
|
174
|
+
- CSRF tokens for session-based auth
|
|
175
|
+
- Never log credentials
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
## Error Handling
|
|
180
|
+
|
|
181
|
+
### Custom Error Classes
|
|
182
|
+
|
|
183
|
+
```ts
|
|
184
|
+
class AppError extends Error {
|
|
185
|
+
constructor(
|
|
186
|
+
public statusCode: number,
|
|
187
|
+
public code: string,
|
|
188
|
+
message: string,
|
|
189
|
+
public details?: unknown
|
|
190
|
+
) {
|
|
191
|
+
super(message);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
class ValidationError extends AppError {
|
|
196
|
+
constructor(message: string, details?: ValidationDetail[]) {
|
|
197
|
+
super(422, 'VALIDATION_ERROR', message, details);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
class NotFoundError extends AppError {
|
|
202
|
+
constructor(resource: string, id: string) {
|
|
203
|
+
super(404, 'NOT_FOUND', `${resource} with id ${id} not found`);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### Global Error Handler
|
|
209
|
+
|
|
210
|
+
```ts
|
|
211
|
+
const errorHandler = (err: Error, req: Request, res: Response, next: NextFunction) => {
|
|
212
|
+
logger.error({ error: err.message, stack: err.stack, requestId: req.id });
|
|
213
|
+
|
|
214
|
+
if (err instanceof AppError) {
|
|
215
|
+
return res.status(err.statusCode).json({
|
|
216
|
+
error: { code: err.code, message: err.message, details: err.details },
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
res.status(500).json({
|
|
221
|
+
error: { code: 'INTERNAL_ERROR', message: 'An unexpected error occurred' },
|
|
222
|
+
});
|
|
223
|
+
};
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
### Result Types
|
|
227
|
+
|
|
228
|
+
```ts
|
|
229
|
+
type Result<T, E = Error> = { ok: true; value: T } | { ok: false; error: E };
|
|
230
|
+
|
|
231
|
+
const findUser = async (id: string): Promise<Result<User, NotFoundError>> => {
|
|
232
|
+
const user = await db.user.findUnique({ where: { id } });
|
|
233
|
+
return user ? { ok: true, value: user } : { ok: false, error: new NotFoundError('User', id) };
|
|
234
|
+
};
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
---
|
|
238
|
+
|
|
239
|
+
## Security
|
|
240
|
+
|
|
241
|
+
### Input Validation
|
|
242
|
+
|
|
243
|
+
```ts
|
|
244
|
+
import { z } from 'zod';
|
|
245
|
+
|
|
246
|
+
const CreateUserSchema = z.object({
|
|
247
|
+
email: z.string().email().max(255),
|
|
248
|
+
name: z.string().min(1).max(100),
|
|
249
|
+
role: z.enum(['user', 'admin']).default('user'),
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
const result = CreateUserSchema.safeParse(req.body);
|
|
253
|
+
if (!result.success) {
|
|
254
|
+
return res.status(422).json({ error: { details: result.error.errors } });
|
|
255
|
+
}
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
### Injection Prevention
|
|
259
|
+
|
|
260
|
+
```ts
|
|
261
|
+
// SQL: Always use parameterized queries
|
|
262
|
+
const users = await db.query('SELECT * FROM users WHERE id = $1', [userId]);
|
|
263
|
+
|
|
264
|
+
// Command: Use execFile with array arguments
|
|
265
|
+
execFile('convert', [inputPath, '-resize', '800x600', outputPath]);
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
### Rate Limiting
|
|
269
|
+
|
|
270
|
+
```ts
|
|
271
|
+
const authLimiter = rateLimit({
|
|
272
|
+
windowMs: 15 * 60 * 1000,
|
|
273
|
+
max: 5,
|
|
274
|
+
message: { error: 'Too many attempts' },
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
app.post('/login', authLimiter, loginHandler);
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
### Security Headers
|
|
281
|
+
|
|
282
|
+
```ts
|
|
283
|
+
app.use(helmet({
|
|
284
|
+
contentSecurityPolicy: { ... },
|
|
285
|
+
hsts: { maxAge: 31536000, includeSubDomains: true },
|
|
286
|
+
}));
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
### Security Checklist
|
|
290
|
+
|
|
291
|
+
- [ ] All inputs validated
|
|
292
|
+
- [ ] Parameterized queries
|
|
293
|
+
- [ ] Rate limiting in place
|
|
294
|
+
- [ ] Auth required on protected routes
|
|
295
|
+
- [ ] Security headers configured
|
|
296
|
+
- [ ] Secrets not in code or logs
|
|
297
|
+
- [ ] HTTPS enforced
|
|
298
|
+
- [ ] Dependencies audited
|
|
299
|
+
|
|
300
|
+
---
|
|
301
|
+
|
|
302
|
+
## Testing
|
|
303
|
+
|
|
304
|
+
### Unit Tests
|
|
305
|
+
|
|
306
|
+
```ts
|
|
307
|
+
describe('calculateDiscount', () => {
|
|
308
|
+
it('applies percentage discount', () => {
|
|
309
|
+
expect(calculateDiscount(100, { type: 'percentage', value: 10 })).toBe(90);
|
|
310
|
+
});
|
|
311
|
+
});
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
### Integration Tests
|
|
315
|
+
|
|
316
|
+
```ts
|
|
317
|
+
describe('userRepository', () => {
|
|
318
|
+
beforeEach(async () => await db.user.deleteMany());
|
|
319
|
+
|
|
320
|
+
it('creates a user', async () => {
|
|
321
|
+
const user = await userRepository.create({ email: 'test@example.com', name: 'Test' });
|
|
322
|
+
expect(user.id).toBeDefined();
|
|
323
|
+
});
|
|
324
|
+
});
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
### API Tests
|
|
328
|
+
|
|
329
|
+
```ts
|
|
330
|
+
describe('POST /users', () => {
|
|
331
|
+
it('creates a new user', async () => {
|
|
332
|
+
const response = await request(app)
|
|
333
|
+
.post('/users')
|
|
334
|
+
.set('Authorization', `Bearer ${authToken}`)
|
|
335
|
+
.send({ email: 'new@test.com', name: 'New User' });
|
|
336
|
+
|
|
337
|
+
expect(response.status).toBe(201);
|
|
338
|
+
expect(response.body.data.email).toBe('new@test.com');
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
it('validates email format', async () => {
|
|
342
|
+
const response = await request(app)
|
|
343
|
+
.post('/users')
|
|
344
|
+
.set('Authorization', `Bearer ${authToken}`)
|
|
345
|
+
.send({ email: 'invalid', name: 'Test' });
|
|
346
|
+
|
|
347
|
+
expect(response.status).toBe(422);
|
|
348
|
+
});
|
|
349
|
+
});
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
---
|
|
353
|
+
|
|
354
|
+
## Definition of Done
|
|
355
|
+
|
|
356
|
+
A backend feature is complete when:
|
|
357
|
+
|
|
358
|
+
- [ ] Endpoint works as specified
|
|
359
|
+
- [ ] Input validation implemented
|
|
360
|
+
- [ ] Error handling covers edge cases
|
|
361
|
+
- [ ] Authentication/authorization enforced
|
|
362
|
+
- [ ] Unit and integration tests passing
|
|
363
|
+
- [ ] API documentation updated
|
|
364
|
+
- [ ] No security vulnerabilities
|
|
365
|
+
- [ ] Logging in place for debugging
|
|
366
|
+
- [ ] Code reviewed and approved
|