agent-skill-kit 3.9.135
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/.agent/global.d.ts +80 -0
- package/.agent/rules/GEMINI.md +210 -0
- package/.agent/rules/autopilot.md +287 -0
- package/.agent/rules/code-rules.md +227 -0
- package/.agent/scripts/audit_workflows.ts +23 -0
- package/.agent/scripts/auto_preview.ts +170 -0
- package/.agent/scripts/checklist.ts +180 -0
- package/.agent/scripts/compile-agents.ts +237 -0
- package/.agent/scripts/fix_skills.ts +49 -0
- package/.agent/scripts/session_manager.ts +222 -0
- package/.agent/scripts/skill-audit.ts +255 -0
- package/.agent/scripts/sync_workflows.ts +54 -0
- package/.agent/scripts/utils/colors.ts +58 -0
- package/.agent/scripts/utils/process-manager.ts +131 -0
- package/.agent/scripts/utils/reporter.ts +192 -0
- package/.agent/scripts/utils/runner.ts +128 -0
- package/.agent/scripts/verify_all.ts +243 -0
- package/.agent/scripts/version-sync.ts +256 -0
- package/.agent/skills/SKILL_INDEX.md +129 -0
- package/.agent/skills/agent-browser/AGENTS.md +728 -0
- package/.agent/skills/agent-browser/SKILL.md +193 -0
- package/.agent/skills/agent-browser/rules/_sections.md +15 -0
- package/.agent/skills/agent-browser/rules/_template.md +32 -0
- package/.agent/skills/agent-browser/rules/engineering-spec.md +528 -0
- package/.agent/skills/agent-browser/scripts/browser_cli.ts +52 -0
- package/.agent/skills/agent-browser/scripts/session_manager.ts +166 -0
- package/.agent/skills/ai-artist/AGENTS.md +1082 -0
- package/.agent/skills/ai-artist/SKILL.md +186 -0
- package/.agent/skills/ai-artist/rules/_sections.md +30 -0
- package/.agent/skills/ai-artist/rules/_template.md +32 -0
- package/.agent/skills/ai-artist/rules/domain-code.md +118 -0
- package/.agent/skills/ai-artist/rules/domain-marketing.md +105 -0
- package/.agent/skills/ai-artist/rules/engineering-spec.md +519 -0
- package/.agent/skills/ai-artist/rules/image-prompts.md +195 -0
- package/.agent/skills/ai-artist/rules/model-syntax.md +115 -0
- package/.agent/skills/ai-artist/scripts/prompt_compiler.ts +72 -0
- package/.agent/skills/ai-artist/templates/image-core.txt +1 -0
- package/.agent/skills/ai-artist/templates/llm-core.txt +6 -0
- package/.agent/skills/api-architect/AGENTS.md +1896 -0
- package/.agent/skills/api-architect/SKILL.md +173 -0
- package/.agent/skills/api-architect/rules/_sections.md +35 -0
- package/.agent/skills/api-architect/rules/_template.md +32 -0
- package/.agent/skills/api-architect/rules/api-style.md +115 -0
- package/.agent/skills/api-architect/rules/auth.md +134 -0
- package/.agent/skills/api-architect/rules/documentation.md +131 -0
- package/.agent/skills/api-architect/rules/engineering-spec.md +505 -0
- package/.agent/skills/api-architect/rules/graphql.md +154 -0
- package/.agent/skills/api-architect/rules/rate-limiting.md +76 -0
- package/.agent/skills/api-architect/rules/response.md +138 -0
- package/.agent/skills/api-architect/rules/rest.md +113 -0
- package/.agent/skills/api-architect/rules/security-testing.md +146 -0
- package/.agent/skills/api-architect/rules/trpc.md +129 -0
- package/.agent/skills/api-architect/rules/versioning.md +100 -0
- package/.agent/skills/api-architect/scripts/api_validator.ts +413 -0
- package/.agent/skills/auth-patterns/AGENTS.md +1830 -0
- package/.agent/skills/auth-patterns/SKILL.md +163 -0
- package/.agent/skills/auth-patterns/rules/_sections.md +30 -0
- package/.agent/skills/auth-patterns/rules/_template.md +32 -0
- package/.agent/skills/auth-patterns/rules/engineering-spec.md +515 -0
- package/.agent/skills/auth-patterns/rules/jwt-deep.md +196 -0
- package/.agent/skills/auth-patterns/rules/mfa.md +174 -0
- package/.agent/skills/auth-patterns/rules/oauth2.md +134 -0
- package/.agent/skills/auth-patterns/rules/passkey.md +243 -0
- package/.agent/skills/auth-patterns/rules/rbac-abac.md +206 -0
- package/.agent/skills/auth-patterns/rules/session.md +183 -0
- package/.agent/skills/auth-patterns/scripts/auth_validator.ts +121 -0
- package/.agent/skills/chrome-devtools/AGENTS.md +952 -0
- package/.agent/skills/chrome-devtools/SKILL.md +160 -0
- package/.agent/skills/chrome-devtools/rules/_sections.md +25 -0
- package/.agent/skills/chrome-devtools/rules/_template.md +32 -0
- package/.agent/skills/chrome-devtools/rules/aria-snapshot.md +95 -0
- package/.agent/skills/chrome-devtools/rules/engineering-spec.md +510 -0
- package/.agent/skills/chrome-devtools/rules/scripts-guide.md +174 -0
- package/.agent/skills/chrome-devtools/scripts/aria-snapshot.ts +3 -0
- package/.agent/skills/chrome-devtools/scripts/click.ts +3 -0
- package/.agent/skills/chrome-devtools/scripts/console.ts +3 -0
- package/.agent/skills/chrome-devtools/scripts/core_cli.ts +79 -0
- package/.agent/skills/chrome-devtools/scripts/evaluate.ts +3 -0
- package/.agent/skills/chrome-devtools/scripts/fill.ts +3 -0
- package/.agent/skills/chrome-devtools/scripts/navigate.ts +3 -0
- package/.agent/skills/chrome-devtools/scripts/network.ts +3 -0
- package/.agent/skills/chrome-devtools/scripts/performance.ts +3 -0
- package/.agent/skills/chrome-devtools/scripts/screenshot.ts +3 -0
- package/.agent/skills/chrome-devtools/scripts/select-ref.ts +3 -0
- package/.agent/skills/cicd-pipeline/AGENTS.md +809 -0
- package/.agent/skills/cicd-pipeline/SKILL.md +164 -0
- package/.agent/skills/cicd-pipeline/rules/_sections.md +15 -0
- package/.agent/skills/cicd-pipeline/rules/_template.md +32 -0
- package/.agent/skills/cicd-pipeline/rules/engineering-spec.md +477 -0
- package/.agent/skills/cicd-pipeline/scripts/flag-manager.ts +253 -0
- package/.agent/skills/cicd-pipeline/scripts/pipeline_validator.ts +133 -0
- package/.agent/skills/code-constitution/AGENTS.md +597 -0
- package/.agent/skills/code-constitution/CHANGELOG.md +216 -0
- package/.agent/skills/code-constitution/SKILL.md +191 -0
- package/.agent/skills/code-constitution/VERSION +3 -0
- package/.agent/skills/code-constitution/examples/violation-backend-mutation/after.tsx +59 -0
- package/.agent/skills/code-constitution/examples/violation-backend-mutation/before.tsx +42 -0
- package/.agent/skills/code-constitution/examples/violation-backend-mutation/explanation.md +91 -0
- package/.agent/skills/code-constitution/examples/violation-chart-injection/after.tsx +99 -0
- package/.agent/skills/code-constitution/examples/violation-chart-injection/before.tsx +57 -0
- package/.agent/skills/code-constitution/examples/violation-chart-injection/explanation.md +120 -0
- package/.agent/skills/code-constitution/knowledge/lessons-learned.yaml +3 -0
- package/.agent/skills/code-constitution/metadata/precedence.yaml +117 -0
- package/.agent/skills/code-constitution/metadata/scope-map.yaml +156 -0
- package/.agent/skills/code-constitution/proposals/v1.1-change-proposal-template.md +201 -0
- package/.agent/skills/code-constitution/resources/AUTHORITY_MODEL.md +115 -0
- package/.agent/skills/code-constitution/resources/ENFORCEMENT_GUIDE.md +246 -0
- package/.agent/skills/code-constitution/resources/LOAD_ORDER.md +86 -0
- package/.agent/skills/code-constitution/rules/_sections.md +15 -0
- package/.agent/skills/code-constitution/rules/_template.md +32 -0
- package/.agent/skills/code-constitution/rules/constitution/master-constitution.md +210 -0
- package/.agent/skills/code-constitution/rules/doctrines/architecture/architecture-doctrine.md +188 -0
- package/.agent/skills/code-constitution/rules/doctrines/backend/backend-data-engine-doctrine.md +218 -0
- package/.agent/skills/code-constitution/rules/doctrines/commercial/commercial-guardrails-doctrine.md +196 -0
- package/.agent/skills/code-constitution/rules/doctrines/data/data-integrity-doctrine.md +202 -0
- package/.agent/skills/code-constitution/rules/doctrines/frontend/frontend-mobile-doctrine.md +169 -0
- package/.agent/skills/code-constitution/rules/doctrines/frontend/interaction-patterns-doctrine.md +176 -0
- package/.agent/skills/code-constitution/rules/doctrines/learning/learning-engine-doctrine.md +192 -0
- package/.agent/skills/code-constitution/rules/doctrines/performance/performance-doctrine.md +180 -0
- package/.agent/skills/code-constitution/rules/doctrines/review/code-review-doctrine.md +174 -0
- package/.agent/skills/code-constitution/rules/enforcement/agents/agent-enforcement-protocol.md +218 -0
- package/.agent/skills/code-constitution/rules/enforcement/agents/agent-system-prompt.md +196 -0
- package/.agent/skills/code-constitution/rules/enforcement/checklists/backend-api-review-checklist.md +131 -0
- package/.agent/skills/code-constitution/rules/enforcement/checklists/chart-component-review-checklist.md +147 -0
- package/.agent/skills/code-constitution/rules/enforcement/checklists/frontend-review-checklist.md +194 -0
- package/.agent/skills/code-constitution/rules/enforcement/playbooks/doctrine-violation-playbook.md +236 -0
- package/.agent/skills/code-constitution/rules/engineering-spec.md +561 -0
- package/.agent/skills/code-constitution/scripts/audit_pr.ts +219 -0
- package/.agent/skills/code-constitution/scripts/check_boundaries.ts +134 -0
- package/.agent/skills/code-constitution/scripts/learn.ts +202 -0
- package/.agent/skills/code-constitution/scripts/validate_doctrine.ts +287 -0
- package/.agent/skills/code-craft/AGENTS.md +803 -0
- package/.agent/skills/code-craft/SKILL.md +170 -0
- package/.agent/skills/code-craft/rules/_sections.md +20 -0
- package/.agent/skills/code-craft/rules/_template.md +32 -0
- package/.agent/skills/code-craft/rules/engineering-spec.md +447 -0
- package/.agent/skills/code-craft/rules/verification-scripts.md +83 -0
- package/.agent/skills/code-craft/scripts/code_quality_checker.ts +193 -0
- package/.agent/skills/code-review/AGENTS.md +1664 -0
- package/.agent/skills/code-review/SKILL.md +152 -0
- package/.agent/skills/code-review/rules/_sections.md +15 -0
- package/.agent/skills/code-review/rules/_template.md +32 -0
- package/.agent/skills/code-review/rules/engineering-spec.md +466 -0
- package/.agent/skills/code-review/scripts/lint_runner.ts +213 -0
- package/.agent/skills/code-review/scripts/type_coverage.ts +118 -0
- package/.agent/skills/context-engineering/AGENTS.md +499 -0
- package/.agent/skills/context-engineering/SKILL.md +147 -0
- package/.agent/skills/context-engineering/rules/_sections.md +15 -0
- package/.agent/skills/context-engineering/rules/_template.md +32 -0
- package/.agent/skills/context-engineering/rules/engineering-spec.md +463 -0
- package/.agent/skills/context-engineering/scripts/context_analyzer.ts +127 -0
- package/.agent/skills/copywriting/AGENTS.md +501 -0
- package/.agent/skills/copywriting/SKILL.md +188 -0
- package/.agent/skills/copywriting/rules/_sections.md +15 -0
- package/.agent/skills/copywriting/rules/_template.md +32 -0
- package/.agent/skills/copywriting/rules/engineering-spec.md +465 -0
- package/.agent/skills/copywriting/scripts/copy_validator.ts +185 -0
- package/.agent/skills/data-modeler/AGENTS.md +814 -0
- package/.agent/skills/data-modeler/SKILL.md +195 -0
- package/.agent/skills/data-modeler/rules/_sections.md +15 -0
- package/.agent/skills/data-modeler/rules/_template.md +32 -0
- package/.agent/skills/data-modeler/rules/database-selection.md +124 -0
- package/.agent/skills/data-modeler/rules/engineering-spec.md +479 -0
- package/.agent/skills/data-modeler/rules/indexing.md +166 -0
- package/.agent/skills/data-modeler/rules/migrations.md +176 -0
- package/.agent/skills/data-modeler/rules/optimization.md +161 -0
- package/.agent/skills/data-modeler/rules/orm-selection.md +155 -0
- package/.agent/skills/data-modeler/rules/schema-design.md +162 -0
- package/.agent/skills/data-modeler/scripts/schema_validator.ts +357 -0
- package/.agent/skills/debug-pro/AGENTS.md +798 -0
- package/.agent/skills/debug-pro/SKILL.md +193 -0
- package/.agent/skills/debug-pro/defense-in-depth/SKILL.md +148 -0
- package/.agent/skills/debug-pro/root-cause-tracing/SKILL.md +196 -0
- package/.agent/skills/debug-pro/root-cause-tracing/find-polluter.sh +63 -0
- package/.agent/skills/debug-pro/rules/_sections.md +15 -0
- package/.agent/skills/debug-pro/rules/_template.md +32 -0
- package/.agent/skills/debug-pro/rules/engineering-spec.md +491 -0
- package/.agent/skills/debug-pro/scripts/debug_verifier.ts +148 -0
- package/.agent/skills/debug-pro/verification-before-completion/SKILL.md +160 -0
- package/.agent/skills/design-system/AGENTS.md +4216 -0
- package/.agent/skills/design-system/SKILL.md +186 -0
- package/.agent/skills/design-system/rules/_sections.md +65 -0
- package/.agent/skills/design-system/rules/_template.md +32 -0
- package/.agent/skills/design-system/rules/animation-guide.md +355 -0
- package/.agent/skills/design-system/rules/color-system.md +335 -0
- package/.agent/skills/design-system/rules/color-systems.md +133 -0
- package/.agent/skills/design-system/rules/decision-trees.md +442 -0
- package/.agent/skills/design-system/rules/design-extraction.md +152 -0
- package/.agent/skills/design-system/rules/engineering-spec.md +484 -0
- package/.agent/skills/design-system/rules/motion-design.md +161 -0
- package/.agent/skills/design-system/rules/motion-graphics.md +330 -0
- package/.agent/skills/design-system/rules/spatial-composition.md +184 -0
- package/.agent/skills/design-system/rules/typography-system.md +369 -0
- package/.agent/skills/design-system/rules/typography.md +124 -0
- package/.agent/skills/design-system/rules/ux-psychology.md +565 -0
- package/.agent/skills/design-system/rules/visual-effects.md +407 -0
- package/.agent/skills/design-system/scripts/accessibility_checker.ts +292 -0
- package/.agent/skills/design-system/scripts/ux_audit.ts +356 -0
- package/.agent/skills/doc-templates/AGENTS.md +820 -0
- package/.agent/skills/doc-templates/SKILL.md +260 -0
- package/.agent/skills/doc-templates/rules/_sections.md +20 -0
- package/.agent/skills/doc-templates/rules/_template.md +32 -0
- package/.agent/skills/doc-templates/rules/doc.md +355 -0
- package/.agent/skills/doc-templates/rules/engineering-spec.md +422 -0
- package/.agent/skills/doc-templates/scripts/editor-server.ts +162 -0
- package/.agent/skills/doc-templates/scripts/inject_otel.ts +22 -0
- package/.agent/skills/doc-templates/scripts/kanban-server.ts +171 -0
- package/.agent/skills/doc-templates/scripts/markdown-server.ts +185 -0
- package/.agent/skills/e2e-automation/AGENTS.md +882 -0
- package/.agent/skills/e2e-automation/SKILL.md +175 -0
- package/.agent/skills/e2e-automation/rules/_sections.md +20 -0
- package/.agent/skills/e2e-automation/rules/_template.md +32 -0
- package/.agent/skills/e2e-automation/rules/aria-snapshot.md +185 -0
- package/.agent/skills/e2e-automation/rules/engineering-spec.md +501 -0
- package/.agent/skills/e2e-automation/scripts/playwright_runner.ts +208 -0
- package/.agent/skills/execution-reporter/AGENTS.md +419 -0
- package/.agent/skills/execution-reporter/SKILL.md +152 -0
- package/.agent/skills/execution-reporter/rules/_sections.md +15 -0
- package/.agent/skills/execution-reporter/rules/_template.md +32 -0
- package/.agent/skills/execution-reporter/rules/engineering-spec.md +389 -0
- package/.agent/skills/game-development/2d-games/SKILL.md +140 -0
- package/.agent/skills/game-development/3d-games/SKILL.md +156 -0
- package/.agent/skills/game-development/AGENTS.md +783 -0
- package/.agent/skills/game-development/SKILL.md +178 -0
- package/.agent/skills/game-development/game-art/SKILL.md +207 -0
- package/.agent/skills/game-development/game-audio/SKILL.md +211 -0
- package/.agent/skills/game-development/game-design/SKILL.md +151 -0
- package/.agent/skills/game-development/mobile-games/SKILL.md +130 -0
- package/.agent/skills/game-development/multiplayer/SKILL.md +154 -0
- package/.agent/skills/game-development/pc-games/SKILL.md +167 -0
- package/.agent/skills/game-development/rules/_sections.md +15 -0
- package/.agent/skills/game-development/rules/_template.md +32 -0
- package/.agent/skills/game-development/rules/engineering-spec.md +480 -0
- package/.agent/skills/game-development/vr-ar/SKILL.md +144 -0
- package/.agent/skills/game-development/web-games/SKILL.md +173 -0
- package/.agent/skills/git-workflow/AGENTS.md +554 -0
- package/.agent/skills/git-workflow/SKILL.md +181 -0
- package/.agent/skills/git-workflow/rules/_sections.md +15 -0
- package/.agent/skills/git-workflow/rules/_template.md +32 -0
- package/.agent/skills/git-workflow/rules/engineering-spec.md +518 -0
- package/.agent/skills/gitops/AGENTS.md +921 -0
- package/.agent/skills/gitops/SKILL.md +163 -0
- package/.agent/skills/gitops/rules/_sections.md +25 -0
- package/.agent/skills/gitops/rules/_template.md +32 -0
- package/.agent/skills/gitops/rules/argocd-setup.md +148 -0
- package/.agent/skills/gitops/rules/engineering-spec.md +450 -0
- package/.agent/skills/gitops/rules/sync-policies.md +145 -0
- package/.agent/skills/google-adk-python/AGENTS.md +1054 -0
- package/.agent/skills/google-adk-python/SKILL.md +168 -0
- package/.agent/skills/google-adk-python/rules/_sections.md +25 -0
- package/.agent/skills/google-adk-python/rules/_template.md +32 -0
- package/.agent/skills/google-adk-python/rules/deployment.md +138 -0
- package/.agent/skills/google-adk-python/rules/engineering-spec.md +451 -0
- package/.agent/skills/google-adk-python/rules/multi-agent.md +146 -0
- package/.agent/skills/google-adk-python/rules/tools.md +131 -0
- package/.agent/skills/idea-storm/AGENTS.md +995 -0
- package/.agent/skills/idea-storm/SKILL.md +160 -0
- package/.agent/skills/idea-storm/rules/_sections.md +25 -0
- package/.agent/skills/idea-storm/rules/_template.md +32 -0
- package/.agent/skills/idea-storm/rules/architecture-debate.md +122 -0
- package/.agent/skills/idea-storm/rules/dynamic-questioning.md +374 -0
- package/.agent/skills/idea-storm/rules/engineering-spec.md +466 -0
- package/.agent/skills/knowledge-compiler/SKILL.md +320 -0
- package/.agent/skills/knowledge-graph/AGENTS.md +762 -0
- package/.agent/skills/knowledge-graph/SKILL.md +157 -0
- package/.agent/skills/knowledge-graph/rules/_sections.md +15 -0
- package/.agent/skills/knowledge-graph/rules/_template.md +32 -0
- package/.agent/skills/knowledge-graph/rules/engineering-spec.md +439 -0
- package/.agent/skills/knowledge-linter/SKILL.md +217 -0
- package/.agent/skills/lifecycle-orchestrator/AGENTS.md +989 -0
- package/.agent/skills/lifecycle-orchestrator/SKILL.md +169 -0
- package/.agent/skills/lifecycle-orchestrator/rules/_sections.md +15 -0
- package/.agent/skills/lifecycle-orchestrator/rules/_template.md +32 -0
- package/.agent/skills/lifecycle-orchestrator/rules/engineering-spec.md +525 -0
- package/.agent/skills/lifecycle-orchestrator/scripts/state_manager.ts +189 -0
- package/.agent/skills/mcp-builder/AGENTS.md +1653 -0
- package/.agent/skills/mcp-builder/SKILL.md +166 -0
- package/.agent/skills/mcp-builder/rules/_sections.md +40 -0
- package/.agent/skills/mcp-builder/rules/_template.md +32 -0
- package/.agent/skills/mcp-builder/rules/best-practices.md +157 -0
- package/.agent/skills/mcp-builder/rules/design-principles.md +105 -0
- package/.agent/skills/mcp-builder/rules/engineering-spec.md +473 -0
- package/.agent/skills/mcp-builder/rules/evaluation.md +103 -0
- package/.agent/skills/mcp-builder/rules/python-implementation.md +249 -0
- package/.agent/skills/mcp-builder/rules/quickstart.md +111 -0
- package/.agent/skills/mcp-builder/rules/typescript-implementation.md +280 -0
- package/.agent/skills/mcp-management/AGENTS.md +837 -0
- package/.agent/skills/mcp-management/SKILL.md +164 -0
- package/.agent/skills/mcp-management/rules/_sections.md +25 -0
- package/.agent/skills/mcp-management/rules/_template.md +32 -0
- package/.agent/skills/mcp-management/rules/cli-usage.md +146 -0
- package/.agent/skills/mcp-management/rules/engineering-spec.md +501 -0
- package/.agent/skills/mcp-management/rules/protocol.md +159 -0
- package/.agent/skills/media-processing/AGENTS.md +479 -0
- package/.agent/skills/media-processing/SKILL.md +176 -0
- package/.agent/skills/media-processing/rules/_sections.md +15 -0
- package/.agent/skills/media-processing/rules/_template.md +32 -0
- package/.agent/skills/media-processing/rules/engineering-spec.md +452 -0
- package/.agent/skills/media-processing/scripts/convert-video.ts +155 -0
- package/.agent/skills/media-processing/scripts/optimize-image.ts +127 -0
- package/.agent/skills/mobile-design/AGENTS.md +6531 -0
- package/.agent/skills/mobile-design/SKILL.md +165 -0
- package/.agent/skills/mobile-design/rules/_sections.md +45 -0
- package/.agent/skills/mobile-design/rules/_template.md +32 -0
- package/.agent/skills/mobile-design/rules/decision-trees.md +540 -0
- package/.agent/skills/mobile-design/rules/engineering-spec.md +467 -0
- package/.agent/skills/mobile-design/rules/mobile-backend.md +516 -0
- package/.agent/skills/mobile-design/rules/mobile-color-system.md +436 -0
- package/.agent/skills/mobile-design/rules/mobile-debugging.md +146 -0
- package/.agent/skills/mobile-design/rules/mobile-design-thinking.md +381 -0
- package/.agent/skills/mobile-design/rules/mobile-navigation.md +474 -0
- package/.agent/skills/mobile-design/rules/mobile-performance.md +783 -0
- package/.agent/skills/mobile-design/rules/mobile-testing.md +380 -0
- package/.agent/skills/mobile-design/rules/mobile-typography.md +449 -0
- package/.agent/skills/mobile-design/rules/platform-android.md +682 -0
- package/.agent/skills/mobile-design/rules/platform-ios.md +577 -0
- package/.agent/skills/mobile-design/rules/touch-psychology.md +553 -0
- package/.agent/skills/mobile-design/scripts/mobile_audit.ts +309 -0
- package/.agent/skills/mobile-developer/AGENTS.md +904 -0
- package/.agent/skills/mobile-developer/SKILL.md +194 -0
- package/.agent/skills/mobile-developer/rules/_sections.md +75 -0
- package/.agent/skills/mobile-developer/rules/_template.md +32 -0
- package/.agent/skills/mobile-developer/rules/anti-patterns.md +70 -0
- package/.agent/skills/mobile-developer/rules/app-store-optimization.md +319 -0
- package/.agent/skills/mobile-developer/rules/decision-trees.md +545 -0
- package/.agent/skills/mobile-developer/rules/deep-linking.md +441 -0
- package/.agent/skills/mobile-developer/rules/engineering-spec.md +477 -0
- package/.agent/skills/mobile-developer/rules/flutter.md +475 -0
- package/.agent/skills/mobile-developer/rules/mobile-backend.md +516 -0
- package/.agent/skills/mobile-developer/rules/mobile-color-system.md +444 -0
- package/.agent/skills/mobile-developer/rules/mobile-debugging.md +428 -0
- package/.agent/skills/mobile-developer/rules/mobile-design-thinking.md +367 -0
- package/.agent/skills/mobile-developer/rules/mobile-navigation.md +483 -0
- package/.agent/skills/mobile-developer/rules/mobile-performance.md +778 -0
- package/.agent/skills/mobile-developer/rules/mobile-testing.md +382 -0
- package/.agent/skills/mobile-developer/rules/mobile-typography.md +457 -0
- package/.agent/skills/mobile-developer/rules/native.md +572 -0
- package/.agent/skills/mobile-developer/rules/platform-android.md +676 -0
- package/.agent/skills/mobile-developer/rules/platform-ios.md +571 -0
- package/.agent/skills/mobile-developer/rules/push-notifications.md +599 -0
- package/.agent/skills/mobile-developer/rules/react-native.md +422 -0
- package/.agent/skills/mobile-developer/rules/touch-psychology.md +547 -0
- package/.agent/skills/mobile-developer/scripts/mobile_audit.ts +701 -0
- package/.agent/skills/nextjs-pro/AGENTS.md +3932 -0
- package/.agent/skills/nextjs-pro/SKILL.md +171 -0
- package/.agent/skills/nextjs-pro/rules/_sections.md +50 -0
- package/.agent/skills/nextjs-pro/rules/_template.md +32 -0
- package/.agent/skills/nextjs-pro/rules/advanced-event-handler-refs.md +59 -0
- package/.agent/skills/nextjs-pro/rules/advanced-init-once.md +46 -0
- package/.agent/skills/nextjs-pro/rules/advanced-use-latest.md +43 -0
- package/.agent/skills/nextjs-pro/rules/async-api-routes.md +42 -0
- package/.agent/skills/nextjs-pro/rules/async-defer-await.md +84 -0
- package/.agent/skills/nextjs-pro/rules/async-dependencies.md +55 -0
- package/.agent/skills/nextjs-pro/rules/async-parallel.md +32 -0
- package/.agent/skills/nextjs-pro/rules/async-suspense-boundaries.md +103 -0
- package/.agent/skills/nextjs-pro/rules/bundle-barrel-imports.md +63 -0
- package/.agent/skills/nextjs-pro/rules/bundle-conditional.md +35 -0
- package/.agent/skills/nextjs-pro/rules/bundle-defer-third-party.md +53 -0
- package/.agent/skills/nextjs-pro/rules/bundle-dynamic-imports.md +39 -0
- package/.agent/skills/nextjs-pro/rules/bundle-preload.md +54 -0
- package/.agent/skills/nextjs-pro/rules/client-event-listeners.md +78 -0
- package/.agent/skills/nextjs-pro/rules/client-localstorage-schema.md +75 -0
- package/.agent/skills/nextjs-pro/rules/client-passive-event-listeners.md +52 -0
- package/.agent/skills/nextjs-pro/rules/client-swr-dedup.md +60 -0
- package/.agent/skills/nextjs-pro/rules/engineering-spec.md +440 -0
- package/.agent/skills/nextjs-pro/rules/js-batch-dom-css.md +111 -0
- package/.agent/skills/nextjs-pro/rules/js-cache-function-results.md +84 -0
- package/.agent/skills/nextjs-pro/rules/js-cache-property-access.md +32 -0
- package/.agent/skills/nextjs-pro/rules/js-cache-storage.md +74 -0
- package/.agent/skills/nextjs-pro/rules/js-combine-iterations.md +36 -0
- package/.agent/skills/nextjs-pro/rules/js-early-exit.md +54 -0
- package/.agent/skills/nextjs-pro/rules/js-hoist-regexp.md +49 -0
- package/.agent/skills/nextjs-pro/rules/js-index-maps.md +41 -0
- package/.agent/skills/nextjs-pro/rules/js-length-check-first.md +53 -0
- package/.agent/skills/nextjs-pro/rules/js-min-max-loop.md +86 -0
- package/.agent/skills/nextjs-pro/rules/js-set-map-lookups.md +28 -0
- package/.agent/skills/nextjs-pro/rules/js-tosorted-immutable.md +61 -0
- package/.agent/skills/nextjs-pro/rules/rendering-activity.md +30 -0
- package/.agent/skills/nextjs-pro/rules/rendering-animate-svg-wrapper.md +51 -0
- package/.agent/skills/nextjs-pro/rules/rendering-conditional-render.md +44 -0
- package/.agent/skills/nextjs-pro/rules/rendering-content-visibility.md +42 -0
- package/.agent/skills/nextjs-pro/rules/rendering-hoist-jsx.md +50 -0
- package/.agent/skills/nextjs-pro/rules/rendering-hydration-no-flicker.md +86 -0
- package/.agent/skills/nextjs-pro/rules/rendering-hydration-suppress-warning.md +34 -0
- package/.agent/skills/nextjs-pro/rules/rendering-svg-precision.md +32 -0
- package/.agent/skills/nextjs-pro/rules/rendering-usetransition-loading.md +79 -0
- package/.agent/skills/nextjs-pro/rules/rerender-defer-reads.md +43 -0
- package/.agent/skills/nextjs-pro/rules/rerender-dependencies.md +49 -0
- package/.agent/skills/nextjs-pro/rules/rerender-derived-state-no-effect.md +44 -0
- package/.agent/skills/nextjs-pro/rules/rerender-derived-state.md +33 -0
- package/.agent/skills/nextjs-pro/rules/rerender-functional-setstate.md +78 -0
- package/.agent/skills/nextjs-pro/rules/rerender-lazy-state-init.md +62 -0
- package/.agent/skills/nextjs-pro/rules/rerender-memo-with-default-value.md +42 -0
- package/.agent/skills/nextjs-pro/rules/rerender-memo.md +48 -0
- package/.agent/skills/nextjs-pro/rules/rerender-move-effect-to-event.md +49 -0
- package/.agent/skills/nextjs-pro/rules/rerender-simple-expression-in-memo.md +39 -0
- package/.agent/skills/nextjs-pro/rules/rerender-transitions.md +44 -0
- package/.agent/skills/nextjs-pro/rules/rerender-use-ref-transient-values.md +77 -0
- package/.agent/skills/nextjs-pro/rules/schema.json +34 -0
- package/.agent/skills/nextjs-pro/rules/server-after-nonblocking.md +77 -0
- package/.agent/skills/nextjs-pro/rules/server-auth-actions.md +100 -0
- package/.agent/skills/nextjs-pro/rules/server-cache-lru.md +45 -0
- package/.agent/skills/nextjs-pro/rules/server-cache-react.md +80 -0
- package/.agent/skills/nextjs-pro/rules/server-dedup-props.md +69 -0
- package/.agent/skills/nextjs-pro/rules/server-parallel-fetching.md +87 -0
- package/.agent/skills/nextjs-pro/rules/server-serialization.md +42 -0
- package/.agent/skills/nodejs-pro/AGENTS.md +866 -0
- package/.agent/skills/nodejs-pro/SKILL.md +172 -0
- package/.agent/skills/nodejs-pro/rules/_sections.md +50 -0
- package/.agent/skills/nodejs-pro/rules/_template.md +32 -0
- package/.agent/skills/nodejs-pro/rules/architecture-patterns.md +229 -0
- package/.agent/skills/nodejs-pro/rules/async-patterns.md +246 -0
- package/.agent/skills/nodejs-pro/rules/engineering-spec.md +438 -0
- package/.agent/skills/nodejs-pro/rules/error-handling.md +257 -0
- package/.agent/skills/nodejs-pro/rules/framework-selection.md +220 -0
- package/.agent/skills/nodejs-pro/rules/runtime-modules.md +176 -0
- package/.agent/skills/nodejs-pro/rules/testing-strategy.md +266 -0
- package/.agent/skills/nodejs-pro/rules/validation-security.md +205 -0
- package/.agent/skills/observability/AGENTS.md +607 -0
- package/.agent/skills/observability/SKILL.md +178 -0
- package/.agent/skills/observability/rules/_sections.md +15 -0
- package/.agent/skills/observability/rules/_template.md +32 -0
- package/.agent/skills/observability/rules/engineering-spec.md +440 -0
- package/.agent/skills/offensive-sec/AGENTS.md +849 -0
- package/.agent/skills/offensive-sec/SKILL.md +191 -0
- package/.agent/skills/offensive-sec/rules/_sections.md +15 -0
- package/.agent/skills/offensive-sec/rules/_template.md +32 -0
- package/.agent/skills/offensive-sec/rules/engineering-spec.md +470 -0
- package/.agent/skills/perf-optimizer/AGENTS.md +870 -0
- package/.agent/skills/perf-optimizer/SKILL.md +189 -0
- package/.agent/skills/perf-optimizer/rules/_sections.md +15 -0
- package/.agent/skills/perf-optimizer/rules/_template.md +32 -0
- package/.agent/skills/perf-optimizer/rules/backend-patterns.md +312 -0
- package/.agent/skills/perf-optimizer/rules/engineering-spec.md +428 -0
- package/.agent/skills/perf-optimizer/scripts/lighthouse_audit.ts +201 -0
- package/.agent/skills/problem-checker/AGENTS.md +519 -0
- package/.agent/skills/problem-checker/SKILL.md +189 -0
- package/.agent/skills/problem-checker/rules/_sections.md +15 -0
- package/.agent/skills/problem-checker/rules/_template.md +32 -0
- package/.agent/skills/problem-checker/rules/engineering-spec.md +483 -0
- package/.agent/skills/problem-checker/scripts/check_problems.ts +396 -0
- package/.agent/skills/project-planner/AGENTS.md +2698 -0
- package/.agent/skills/project-planner/SKILL.md +166 -0
- package/.agent/skills/project-planner/rules/_sections.md +15 -0
- package/.agent/skills/project-planner/rules/_template.md +32 -0
- package/.agent/skills/project-planner/rules/engineering-spec.md +420 -0
- package/.agent/skills/python-pro/AGENTS.md +1871 -0
- package/.agent/skills/python-pro/SKILL.md +182 -0
- package/.agent/skills/python-pro/rules/_sections.md +50 -0
- package/.agent/skills/python-pro/rules/_template.md +32 -0
- package/.agent/skills/python-pro/rules/async-patterns.md +168 -0
- package/.agent/skills/python-pro/rules/django-patterns.md +194 -0
- package/.agent/skills/python-pro/rules/engineering-spec.md +442 -0
- package/.agent/skills/python-pro/rules/fastapi-patterns.md +179 -0
- package/.agent/skills/python-pro/rules/framework-selection.md +167 -0
- package/.agent/skills/python-pro/rules/project-structure.md +181 -0
- package/.agent/skills/python-pro/rules/testing-patterns.md +212 -0
- package/.agent/skills/python-pro/rules/type-hints.md +159 -0
- package/.agent/skills/react-pro/AGENTS.md +963 -0
- package/.agent/skills/react-pro/SKILL.md +232 -0
- package/.agent/skills/react-pro/rules/_sections.md +40 -0
- package/.agent/skills/react-pro/rules/_template.md +32 -0
- package/.agent/skills/react-pro/rules/component-patterns.md +145 -0
- package/.agent/skills/react-pro/rules/composition-compound.md +82 -0
- package/.agent/skills/react-pro/rules/data-fetching.md +133 -0
- package/.agent/skills/react-pro/rules/engineering-spec.md +453 -0
- package/.agent/skills/react-pro/rules/error-boundary.md +61 -0
- package/.agent/skills/react-pro/rules/file-organization.md +158 -0
- package/.agent/skills/react-pro/rules/hooks-custom.md +61 -0
- package/.agent/skills/react-pro/rules/mui-styling.md +138 -0
- package/.agent/skills/react-pro/rules/patterns.md +24 -0
- package/.agent/skills/react-pro/rules/performance-optimization.md +65 -0
- package/.agent/skills/react-pro/rules/performance.md +137 -0
- package/.agent/skills/react-pro/rules/react19-hooks.md +85 -0
- package/.agent/skills/react-pro/rules/state-management.md +90 -0
- package/.agent/skills/react-pro/rules/testing-patterns.md +52 -0
- package/.agent/skills/registry.json +1251 -0
- package/.agent/skills/security-scanner/AGENTS.md +851 -0
- package/.agent/skills/security-scanner/SKILL.md +182 -0
- package/.agent/skills/security-scanner/rules/_sections.md +15 -0
- package/.agent/skills/security-scanner/rules/_template.md +32 -0
- package/.agent/skills/security-scanner/rules/auth-patterns.md +281 -0
- package/.agent/skills/security-scanner/rules/checklists.md +186 -0
- package/.agent/skills/security-scanner/rules/engineering-spec.md +440 -0
- package/.agent/skills/security-scanner/scripts/security_scan.ts +513 -0
- package/.agent/skills/seo-optimizer/AGENTS.md +839 -0
- package/.agent/skills/seo-optimizer/SKILL.md +180 -0
- package/.agent/skills/seo-optimizer/rules/_sections.md +15 -0
- package/.agent/skills/seo-optimizer/rules/_template.md +32 -0
- package/.agent/skills/seo-optimizer/rules/engineering-spec.md +433 -0
- package/.agent/skills/seo-optimizer/scripts/geo_checker.ts +109 -0
- package/.agent/skills/seo-optimizer/scripts/seo_checker.ts +308 -0
- package/.agent/skills/server-ops/AGENTS.md +643 -0
- package/.agent/skills/server-ops/SKILL.md +194 -0
- package/.agent/skills/server-ops/rules/_sections.md +15 -0
- package/.agent/skills/server-ops/rules/_template.md +32 -0
- package/.agent/skills/server-ops/rules/engineering-spec.md +450 -0
- package/.agent/skills/shell-script/AGENTS.md +499 -0
- package/.agent/skills/shell-script/SKILL.md +205 -0
- package/.agent/skills/shell-script/rules/_sections.md +15 -0
- package/.agent/skills/shell-script/rules/_template.md +32 -0
- package/.agent/skills/shell-script/rules/engineering-spec.md +463 -0
- package/.agent/skills/skill-generator/SKILL.md +147 -0
- package/.agent/skills/smart-router/SKILL.md +95 -0
- package/.agent/skills/studio/AGENTS.md +636 -0
- package/.agent/skills/studio/SKILL.md +178 -0
- package/.agent/skills/studio/data/charts.csv +26 -0
- package/.agent/skills/studio/data/colors.csv +97 -0
- package/.agent/skills/studio/data/icons.csv +101 -0
- package/.agent/skills/studio/data/landing.csv +31 -0
- package/.agent/skills/studio/data/products.csv +97 -0
- package/.agent/skills/studio/data/prompts.csv +24 -0
- package/.agent/skills/studio/data/react-performance.csv +45 -0
- package/.agent/skills/studio/data/stacks/flutter.csv +52 -0
- package/.agent/skills/studio/data/stacks/html-tailwind.csv +56 -0
- package/.agent/skills/studio/data/stacks/jetpack-compose.csv +53 -0
- package/.agent/skills/studio/data/stacks/nextjs.csv +53 -0
- package/.agent/skills/studio/data/stacks/nuxt-ui.csv +51 -0
- package/.agent/skills/studio/data/stacks/nuxtjs.csv +59 -0
- package/.agent/skills/studio/data/stacks/react-native.csv +52 -0
- package/.agent/skills/studio/data/stacks/react.csv +54 -0
- package/.agent/skills/studio/data/stacks/shadcn.csv +61 -0
- package/.agent/skills/studio/data/stacks/svelte.csv +54 -0
- package/.agent/skills/studio/data/stacks/swiftui.csv +51 -0
- package/.agent/skills/studio/data/stacks/vue.csv +50 -0
- package/.agent/skills/studio/data/styles.csv +59 -0
- package/.agent/skills/studio/data/typography.csv +58 -0
- package/.agent/skills/studio/data/ui-reasoning.csv +101 -0
- package/.agent/skills/studio/data/ux-guidelines.csv +100 -0
- package/.agent/skills/studio/data/web-interface.csv +31 -0
- package/.agent/skills/studio/rules/_sections.md +15 -0
- package/.agent/skills/studio/rules/_template.md +32 -0
- package/.agent/skills/studio/rules/engineering-spec.md +455 -0
- package/.agent/skills/studio/scripts/core.ts +345 -0
- package/.agent/skills/studio/scripts/design_system.ts +953 -0
- package/.agent/skills/studio/scripts/search.ts +197 -0
- package/.agent/skills/studio/scripts/types.ts +147 -0
- package/.agent/skills/studio/scripts/utils/component-specs.ts +154 -0
- package/.agent/skills/studio/scripts/utils/config-loader.ts +165 -0
- package/.agent/skills/studio/scripts/utils/css-templates.ts +169 -0
- package/.agent/skills/studio/scripts/utils/css-validator.ts +95 -0
- package/.agent/skills/studio/scripts/utils/csv-loader.ts +52 -0
- package/.agent/skills/studio/scripts/utils/intelligent-overrides.ts +129 -0
- package/.agent/skills/studio/scripts/utils/page-override-formatter.ts +143 -0
- package/.agent/skills/studio/scripts/utils/page-type-detector.ts +124 -0
- package/.agent/skills/studio/scripts/utils/search-cache.ts +165 -0
- package/.agent/skills/studio/scripts/utils/text-utils.ts +44 -0
- package/.agent/skills/system-design/AGENTS.md +597 -0
- package/.agent/skills/system-design/SKILL.md +153 -0
- package/.agent/skills/system-design/rules/_sections.md +15 -0
- package/.agent/skills/system-design/rules/_template.md +32 -0
- package/.agent/skills/system-design/rules/context-discovery.md +117 -0
- package/.agent/skills/system-design/rules/engineering-spec.md +437 -0
- package/.agent/skills/system-design/rules/examples.md +180 -0
- package/.agent/skills/system-design/rules/pattern-selection.md +130 -0
- package/.agent/skills/system-design/rules/patterns-reference.md +110 -0
- package/.agent/skills/system-design/rules/trade-off-analysis.md +169 -0
- package/.agent/skills/tailwind-kit/AGENTS.md +1135 -0
- package/.agent/skills/tailwind-kit/SKILL.md +171 -0
- package/.agent/skills/tailwind-kit/rules/_sections.md +20 -0
- package/.agent/skills/tailwind-kit/rules/_template.md +32 -0
- package/.agent/skills/tailwind-kit/rules/components.md +232 -0
- package/.agent/skills/tailwind-kit/rules/engineering-spec.md +435 -0
- package/.agent/skills/tailwind-kit/rules/responsive.md +221 -0
- package/.agent/skills/tailwind-kit/rules/v4-config.md +72 -0
- package/.agent/skills/test-architect/AGENTS.md +851 -0
- package/.agent/skills/test-architect/SKILL.md +176 -0
- package/.agent/skills/test-architect/rules/_sections.md +15 -0
- package/.agent/skills/test-architect/rules/_template.md +32 -0
- package/.agent/skills/test-architect/rules/engineering-spec.md +434 -0
- package/.agent/skills/test-architect/scripts/test_runner.ts +265 -0
- package/.agent/skills/typescript-expert/AGENTS.md +1045 -0
- package/.agent/skills/typescript-expert/SKILL.md +200 -0
- package/.agent/skills/typescript-expert/rules/_sections.md +20 -0
- package/.agent/skills/typescript-expert/rules/_template.md +32 -0
- package/.agent/skills/typescript-expert/rules/engineering-spec.md +433 -0
- package/.agent/skills/typescript-expert/rules/tsconfig-strict.json +92 -0
- package/.agent/skills/typescript-expert/rules/typescript-cheatsheet.md +407 -0
- package/.agent/skills/typescript-expert/rules/utility-types.ts +264 -0
- package/.agent/skills/typescript-expert/scripts/ts_diagnostic.ts +321 -0
- package/.agent/skills/vercel-deploy/AGENTS.md +490 -0
- package/.agent/skills/vercel-deploy/SKILL.md +175 -0
- package/.agent/skills/vercel-deploy/rules/_sections.md +15 -0
- package/.agent/skills/vercel-deploy/rules/_template.md +32 -0
- package/.agent/skills/vercel-deploy/rules/engineering-spec.md +463 -0
- package/.agent/skills/vercel-deploy/scripts/deploy.sh +310 -0
- package/.agent/workflows/api.md +377 -0
- package/.agent/workflows/autopilot.md +344 -0
- package/.agent/workflows/build.md +338 -0
- package/.agent/workflows/chronicle.md +279 -0
- package/.agent/workflows/cook.md +217 -0
- package/.agent/workflows/diagnose.md +302 -0
- package/.agent/workflows/fix.md +253 -0
- package/.agent/workflows/game.md +329 -0
- package/.agent/workflows/inspect.md +276 -0
- package/.agent/workflows/knowledge.md +212 -0
- package/.agent/workflows/launch.md +345 -0
- package/.agent/workflows/mobile.md +354 -0
- package/.agent/workflows/monitor.md +239 -0
- package/.agent/workflows/optimize.md +269 -0
- package/.agent/workflows/plan.md +278 -0
- package/.agent/workflows/stage.md +286 -0
- package/.agent/workflows/studio.md +276 -0
- package/.agent/workflows/think.md +262 -0
- package/.agent/workflows/validate.md +289 -0
- package/.agentignore +161 -0
- package/.gitattributes +16 -0
- package/CHANGELOG.md +198 -0
- package/LICENSE +40 -0
- package/README.md +173 -0
- package/docs/SKILL_DESIGN_GUIDE.md +561 -0
- package/docs/The-Complete-Guide-to-Building-Skills-for-Claude.md +1207 -0
- package/docs/WORKFLOW_DESIGN_GUIDE.md +325 -0
- package/package.json +33 -0
- package/tsconfig.json +28 -0
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: framework-selection
|
|
3
|
+
description: Python framework comparison — FastAPI vs Django vs Flask with decision tree, benchmarks, and minimal app examples
|
|
4
|
+
title: "Framework Selection (2025)"
|
|
5
|
+
impact: MEDIUM
|
|
6
|
+
impactDescription: "Moderate improvement to quality or maintainability"
|
|
7
|
+
tags: framework, selection
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# Framework Selection (2025)
|
|
11
|
+
|
|
12
|
+
> Pick the right tool. Don't default to one framework for everything.
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## Decision Tree
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
What are you building?
|
|
20
|
+
│
|
|
21
|
+
├── API-first / Microservices → FastAPI
|
|
22
|
+
├── Full-stack web / CMS → Django
|
|
23
|
+
├── Simple / Script / Learning → Flask
|
|
24
|
+
├── AI/ML API serving → FastAPI
|
|
25
|
+
└── Background workers → Celery + any framework
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
**If user has explicit preference → respect it.** Ask when unclear.
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## Comparison
|
|
33
|
+
|
|
34
|
+
| Factor | FastAPI | Django | Flask |
|
|
35
|
+
|--------|---------|--------|-------|
|
|
36
|
+
| **Best for** | APIs, microservices, ML | Full-stack, CMS, admin | Simple, learning, prototyping |
|
|
37
|
+
| **Performance** | ⭐⭐⭐ (Starlette/uvicorn) | ⭐⭐ (improved in 5.x) | ⭐⭐ (Werkzeug) |
|
|
38
|
+
| **Async** | Native | Django 5.0+ (partial) | Via extensions (Quart) |
|
|
39
|
+
| **Admin** | Manual | Built-in (excellent) | Flask-Admin |
|
|
40
|
+
| **ORM** | SQLAlchemy / Tortoise | Django ORM (built-in) | SQLAlchemy |
|
|
41
|
+
| **Validation** | Pydantic (built-in) | Django Forms / DRF | Manual / Marshmallow |
|
|
42
|
+
| **Auth** | Manual / FastAPI-Users | Built-in | Flask-Login |
|
|
43
|
+
| **Learning curve** | Low | Medium | Low |
|
|
44
|
+
| **Type safety** | Excellent (Pydantic) | Good (mypy support) | Manual |
|
|
45
|
+
| **OpenAPI docs** | Auto-generated | DRF (drf-spectacular) | Flask-RESTX |
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## Minimal App Examples
|
|
50
|
+
|
|
51
|
+
### FastAPI
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
from fastapi import FastAPI
|
|
55
|
+
from pydantic import BaseModel
|
|
56
|
+
|
|
57
|
+
app = FastAPI()
|
|
58
|
+
|
|
59
|
+
class Item(BaseModel):
|
|
60
|
+
name: str
|
|
61
|
+
price: float
|
|
62
|
+
in_stock: bool = True
|
|
63
|
+
|
|
64
|
+
@app.get("/")
|
|
65
|
+
async def root():
|
|
66
|
+
return {"message": "Hello World"}
|
|
67
|
+
|
|
68
|
+
@app.post("/items")
|
|
69
|
+
async def create_item(item: Item) -> Item:
|
|
70
|
+
return item
|
|
71
|
+
|
|
72
|
+
# Run: uvicorn main:app --reload
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Django (with DRF)
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
# views.py
|
|
79
|
+
from rest_framework import viewsets
|
|
80
|
+
from rest_framework.decorators import api_view
|
|
81
|
+
from rest_framework.response import Response
|
|
82
|
+
|
|
83
|
+
@api_view(["GET"])
|
|
84
|
+
def root(request):
|
|
85
|
+
return Response({"message": "Hello World"})
|
|
86
|
+
|
|
87
|
+
class ItemViewSet(viewsets.ModelViewSet):
|
|
88
|
+
queryset = Item.objects.all()
|
|
89
|
+
serializer_class = ItemSerializer
|
|
90
|
+
|
|
91
|
+
# Run: python manage.py runserver
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Flask
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
from flask import Flask, jsonify, request
|
|
98
|
+
|
|
99
|
+
app = Flask(__name__)
|
|
100
|
+
|
|
101
|
+
@app.get("/")
|
|
102
|
+
def root():
|
|
103
|
+
return jsonify(message="Hello World")
|
|
104
|
+
|
|
105
|
+
@app.post("/items")
|
|
106
|
+
def create_item():
|
|
107
|
+
data = request.get_json()
|
|
108
|
+
return jsonify(data), 201
|
|
109
|
+
|
|
110
|
+
# Run: flask run --debug
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## pyproject.toml (Modern Python)
|
|
116
|
+
|
|
117
|
+
```toml
|
|
118
|
+
[project]
|
|
119
|
+
name = "myapp"
|
|
120
|
+
version = "0.1.0"
|
|
121
|
+
requires-python = ">=3.12"
|
|
122
|
+
|
|
123
|
+
dependencies = [
|
|
124
|
+
# FastAPI stack
|
|
125
|
+
"fastapi>=0.115",
|
|
126
|
+
"uvicorn[standard]>=0.32",
|
|
127
|
+
"pydantic>=2.0",
|
|
128
|
+
# Or Django stack
|
|
129
|
+
# "django>=5.1",
|
|
130
|
+
# "djangorestframework>=3.15",
|
|
131
|
+
]
|
|
132
|
+
|
|
133
|
+
[project.optional-dependencies]
|
|
134
|
+
dev = [
|
|
135
|
+
"pytest>=8.0",
|
|
136
|
+
"pytest-asyncio>=0.24",
|
|
137
|
+
"httpx>=0.27",
|
|
138
|
+
"ruff>=0.8",
|
|
139
|
+
"mypy>=1.13",
|
|
140
|
+
]
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
## Anti-Patterns
|
|
146
|
+
|
|
147
|
+
| ❌ Don't | ✅ Do |
|
|
148
|
+
|---------|-------|
|
|
149
|
+
| Default to Django for simple APIs | Use FastAPI for API-first |
|
|
150
|
+
| Use Flask for complex apps | Use Django (batteries included) |
|
|
151
|
+
| Pick framework by popularity | Pick by project requirements |
|
|
152
|
+
| Skip framework when prototyping | Flask for quick prototypes |
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
## 🔗 Related
|
|
157
|
+
|
|
158
|
+
| File | When to Read |
|
|
159
|
+
|------|-------------|
|
|
160
|
+
| [fastapi-patterns.md](fastapi-patterns.md) | Chosen FastAPI |
|
|
161
|
+
| [django-patterns.md](django-patterns.md) | Chosen Django |
|
|
162
|
+
| [project-structure.md](project-structure.md) | Directory layout |
|
|
163
|
+
| [async-patterns.md](async-patterns.md) | Async decision |
|
|
164
|
+
|
|
165
|
+
---
|
|
166
|
+
|
|
167
|
+
⚡ PikaKit v3.9.134
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: project-structure
|
|
3
|
+
description: Python project structure — directory layouts for small/medium/large apps, FastAPI vs Django, pyproject.toml
|
|
4
|
+
title: "Structure by size. Feature-based for large apps. Layer-based for small."
|
|
5
|
+
impact: MEDIUM
|
|
6
|
+
impactDescription: "Moderate improvement to quality or maintainability"
|
|
7
|
+
tags: project, structure
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# Project Structure
|
|
11
|
+
|
|
12
|
+
> Structure by size. Feature-based for large apps. Layer-based for small.
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## By Project Size
|
|
17
|
+
|
|
18
|
+
### Small (Script / Tool)
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
myapp/
|
|
22
|
+
├── main.py
|
|
23
|
+
├── utils.py
|
|
24
|
+
├── pyproject.toml
|
|
25
|
+
└── README.md
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Medium (API / Service)
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
myapp/
|
|
32
|
+
├── app/
|
|
33
|
+
│ ├── __init__.py
|
|
34
|
+
│ ├── main.py # App entry + lifespan
|
|
35
|
+
│ ├── config.py # Pydantic Settings
|
|
36
|
+
│ ├── dependencies.py # Shared DI (db session, auth)
|
|
37
|
+
│ ├── models/ # SQLAlchemy / DB models
|
|
38
|
+
│ │ ├── __init__.py
|
|
39
|
+
│ │ └── user.py
|
|
40
|
+
│ ├── schemas/ # Pydantic request/response
|
|
41
|
+
│ │ ├── __init__.py
|
|
42
|
+
│ │ └── user.py
|
|
43
|
+
│ ├── routes/ # API routes
|
|
44
|
+
│ │ ├── __init__.py
|
|
45
|
+
│ │ └── users.py
|
|
46
|
+
│ └── services/ # Business logic
|
|
47
|
+
│ ├── __init__.py
|
|
48
|
+
│ └── user_service.py
|
|
49
|
+
├── tests/
|
|
50
|
+
│ ├── conftest.py # Shared fixtures
|
|
51
|
+
│ ├── test_users.py
|
|
52
|
+
│ └── test_services.py
|
|
53
|
+
├── alembic/ # DB migrations
|
|
54
|
+
├── pyproject.toml
|
|
55
|
+
├── .env.example
|
|
56
|
+
└── README.md
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Large (Monolith / Multiple Domains)
|
|
60
|
+
|
|
61
|
+
```
|
|
62
|
+
src/
|
|
63
|
+
└── myapp/
|
|
64
|
+
├── core/ # Shared kernel
|
|
65
|
+
│ ├── config.py
|
|
66
|
+
│ ├── database.py
|
|
67
|
+
│ ├── security.py
|
|
68
|
+
│ └── exceptions.py
|
|
69
|
+
├── users/ # Feature module
|
|
70
|
+
│ ├── models.py
|
|
71
|
+
│ ├── schemas.py
|
|
72
|
+
│ ├── routes.py
|
|
73
|
+
│ ├── service.py
|
|
74
|
+
│ └── repository.py
|
|
75
|
+
├── products/ # Feature module
|
|
76
|
+
│ └── ...
|
|
77
|
+
└── main.py
|
|
78
|
+
tests/
|
|
79
|
+
├── users/
|
|
80
|
+
├── products/
|
|
81
|
+
└── conftest.py
|
|
82
|
+
pyproject.toml
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## FastAPI Entry Point
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
# app/main.py
|
|
91
|
+
from contextlib import asynccontextmanager
|
|
92
|
+
from fastapi import FastAPI
|
|
93
|
+
from app.config import settings
|
|
94
|
+
from app.routes import users, products
|
|
95
|
+
|
|
96
|
+
@asynccontextmanager
|
|
97
|
+
async def lifespan(app: FastAPI):
|
|
98
|
+
# Startup
|
|
99
|
+
await database.connect()
|
|
100
|
+
yield
|
|
101
|
+
# Shutdown
|
|
102
|
+
await database.disconnect()
|
|
103
|
+
|
|
104
|
+
app = FastAPI(
|
|
105
|
+
title=settings.app_name,
|
|
106
|
+
version="1.0.0",
|
|
107
|
+
lifespan=lifespan,
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
app.include_router(users.router, prefix="/api/v1/users", tags=["users"])
|
|
111
|
+
app.include_router(products.router, prefix="/api/v1/products", tags=["products"])
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
## Django Structure
|
|
117
|
+
|
|
118
|
+
```
|
|
119
|
+
myproject/
|
|
120
|
+
├── manage.py
|
|
121
|
+
├── myproject/
|
|
122
|
+
│ ├── __init__.py
|
|
123
|
+
│ ├── settings/
|
|
124
|
+
│ │ ├── __init__.py
|
|
125
|
+
│ │ ├── base.py # Shared settings
|
|
126
|
+
│ │ ├── dev.py # Development
|
|
127
|
+
│ │ └── prod.py # Production
|
|
128
|
+
│ ├── urls.py
|
|
129
|
+
│ └── wsgi.py / asgi.py
|
|
130
|
+
├── users/ # Django app
|
|
131
|
+
│ ├── models.py
|
|
132
|
+
│ ├── views.py / viewsets.py
|
|
133
|
+
│ ├── serializers.py
|
|
134
|
+
│ ├── urls.py
|
|
135
|
+
│ ├── admin.py
|
|
136
|
+
│ ├── tests.py
|
|
137
|
+
│ └── migrations/
|
|
138
|
+
├── products/ # Django app
|
|
139
|
+
│ └── ...
|
|
140
|
+
└── requirements/
|
|
141
|
+
├── base.txt
|
|
142
|
+
├── dev.txt
|
|
143
|
+
└── prod.txt
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
---
|
|
147
|
+
|
|
148
|
+
## Background Tasks Selection
|
|
149
|
+
|
|
150
|
+
| Solution | Best For | Async | Persistence |
|
|
151
|
+
|----------|----------|:-----:|:-----------:|
|
|
152
|
+
| **BackgroundTasks** (FastAPI) | Quick, in-process | ✅ | ❌ |
|
|
153
|
+
| **Celery** | Distributed workflows | ❌ | ✅ |
|
|
154
|
+
| **ARQ** | Async + Redis | ✅ | ✅ |
|
|
155
|
+
| **Dramatiq** | Actor-based | ❌ | ✅ |
|
|
156
|
+
| **RQ** | Simple Redis queue | ❌ | ✅ |
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
## Anti-Patterns
|
|
161
|
+
|
|
162
|
+
| ❌ Don't | ✅ Do |
|
|
163
|
+
|---------|-------|
|
|
164
|
+
| Flat file dump (all in root) | Organize by feature/layer |
|
|
165
|
+
| Business logic in routes | Routes → services → repos |
|
|
166
|
+
| `settings.py` with hardcoded values | Pydantic Settings + `.env` |
|
|
167
|
+
| Skip `__init__.py` | Always include (explicit packages) |
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
## 🔗 Related
|
|
172
|
+
|
|
173
|
+
| File | When to Read |
|
|
174
|
+
|------|-------------|
|
|
175
|
+
| [framework-selection.md](framework-selection.md) | Which framework |
|
|
176
|
+
| [fastapi-patterns.md](fastapi-patterns.md) | FastAPI specifics |
|
|
177
|
+
| [django-patterns.md](django-patterns.md) | Django specifics |
|
|
178
|
+
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
⚡ PikaKit v3.9.134
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: testing-patterns
|
|
3
|
+
description: Python testing patterns — pytest, async tests, fixtures, mocking, FastAPI/Django test clients, coverage
|
|
4
|
+
title: "Python Testing Patterns"
|
|
5
|
+
impact: MEDIUM
|
|
6
|
+
impactDescription: "Moderate improvement to quality or maintainability"
|
|
7
|
+
tags: testing, patterns
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# Python Testing Patterns
|
|
11
|
+
|
|
12
|
+
> pytest for everything. Fixtures for setup. Mock at boundaries. Test behavior, not implementation.
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## Testing Strategy
|
|
17
|
+
|
|
18
|
+
| Type | Purpose | Tools | Speed |
|
|
19
|
+
|------|---------|-------|:-----:|
|
|
20
|
+
| **Unit** | Business logic / services | pytest | ⚡ Fast |
|
|
21
|
+
| **Integration** | API endpoints + DB | pytest + httpx/TestClient | 🔄 Medium |
|
|
22
|
+
| **E2E** | Full workflows | pytest + real DB | 🐢 Slow |
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## FastAPI Testing
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
import pytest
|
|
30
|
+
from httpx import AsyncClient, ASGITransport
|
|
31
|
+
from app.main import app
|
|
32
|
+
from app.dependencies import get_db
|
|
33
|
+
|
|
34
|
+
# Override database dependency for tests
|
|
35
|
+
async def get_test_db():
|
|
36
|
+
async with test_session_maker() as session:
|
|
37
|
+
yield session
|
|
38
|
+
|
|
39
|
+
app.dependency_overrides[get_db] = get_test_db
|
|
40
|
+
|
|
41
|
+
@pytest.mark.asyncio
|
|
42
|
+
async def test_create_user():
|
|
43
|
+
transport = ASGITransport(app=app)
|
|
44
|
+
async with AsyncClient(transport=transport, base_url="http://test") as client:
|
|
45
|
+
response = await client.post("/api/v1/users/", json={
|
|
46
|
+
"email": "test@example.com",
|
|
47
|
+
"name": "Test User",
|
|
48
|
+
})
|
|
49
|
+
assert response.status_code == 201
|
|
50
|
+
data = response.json()
|
|
51
|
+
assert data["email"] == "test@example.com"
|
|
52
|
+
assert "id" in data
|
|
53
|
+
|
|
54
|
+
@pytest.mark.asyncio
|
|
55
|
+
async def test_get_user_not_found():
|
|
56
|
+
transport = ASGITransport(app=app)
|
|
57
|
+
async with AsyncClient(transport=transport, base_url="http://test") as client:
|
|
58
|
+
response = await client.get("/api/v1/users/99999")
|
|
59
|
+
assert response.status_code == 404
|
|
60
|
+
assert response.json()["error"] == "NOT_FOUND"
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## Django Testing
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
from django.test import TestCase
|
|
69
|
+
from rest_framework.test import APIClient
|
|
70
|
+
|
|
71
|
+
class UserAPITest(TestCase):
|
|
72
|
+
def setUp(self):
|
|
73
|
+
self.client = APIClient()
|
|
74
|
+
self.user = User.objects.create_user(
|
|
75
|
+
email="test@test.com", password="testpass123"
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
def test_list_users(self):
|
|
79
|
+
self.client.force_authenticate(user=self.user)
|
|
80
|
+
response = self.client.get("/api/users/")
|
|
81
|
+
self.assertEqual(response.status_code, 200)
|
|
82
|
+
self.assertEqual(len(response.data), 1)
|
|
83
|
+
|
|
84
|
+
def test_create_user_unauthenticated(self):
|
|
85
|
+
response = self.client.post("/api/users/", {"email": "new@test.com"})
|
|
86
|
+
self.assertEqual(response.status_code, 401)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## Fixtures (conftest.py)
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
# tests/conftest.py
|
|
95
|
+
import pytest
|
|
96
|
+
from app.models import User
|
|
97
|
+
|
|
98
|
+
@pytest.fixture
|
|
99
|
+
def sample_user(db) -> User:
|
|
100
|
+
"""Create a test user — available to all tests."""
|
|
101
|
+
return User.objects.create(
|
|
102
|
+
email="fixture@test.com",
|
|
103
|
+
name="Fixture User",
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
@pytest.fixture
|
|
107
|
+
def auth_client(sample_user) -> APIClient:
|
|
108
|
+
"""Authenticated API client."""
|
|
109
|
+
client = APIClient()
|
|
110
|
+
client.force_authenticate(user=sample_user)
|
|
111
|
+
return client
|
|
112
|
+
|
|
113
|
+
@pytest.fixture
|
|
114
|
+
async def async_client() -> AsyncClient:
|
|
115
|
+
"""Async client for FastAPI."""
|
|
116
|
+
transport = ASGITransport(app=app)
|
|
117
|
+
async with AsyncClient(transport=transport, base_url="http://test") as client:
|
|
118
|
+
yield client
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## Mocking
|
|
124
|
+
|
|
125
|
+
```python
|
|
126
|
+
from unittest.mock import AsyncMock, patch
|
|
127
|
+
|
|
128
|
+
@pytest.mark.asyncio
|
|
129
|
+
async def test_send_email_on_signup():
|
|
130
|
+
"""Mock external services at boundaries."""
|
|
131
|
+
with patch("app.services.email.send_welcome_email", new_callable=AsyncMock) as mock_email:
|
|
132
|
+
transport = ASGITransport(app=app)
|
|
133
|
+
async with AsyncClient(transport=transport, base_url="http://test") as client:
|
|
134
|
+
await client.post("/api/v1/users/", json={
|
|
135
|
+
"email": "new@test.com",
|
|
136
|
+
"name": "New User",
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
mock_email.assert_called_once_with("new@test.com", "New User")
|
|
140
|
+
|
|
141
|
+
@pytest.mark.asyncio
|
|
142
|
+
async def test_external_api_failure():
|
|
143
|
+
"""Test error handling when external service fails."""
|
|
144
|
+
with patch("app.services.payment.charge", side_effect=Exception("Payment failed")):
|
|
145
|
+
transport = ASGITransport(app=app)
|
|
146
|
+
async with AsyncClient(transport=transport, base_url="http://test") as client:
|
|
147
|
+
response = await client.post("/api/v1/orders/", json={"amount": 100})
|
|
148
|
+
assert response.status_code == 500
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## Test Configuration
|
|
154
|
+
|
|
155
|
+
```toml
|
|
156
|
+
# pyproject.toml
|
|
157
|
+
[tool.pytest.ini_options]
|
|
158
|
+
asyncio_mode = "auto"
|
|
159
|
+
testpaths = ["tests"]
|
|
160
|
+
python_files = "test_*.py"
|
|
161
|
+
python_functions = "test_*"
|
|
162
|
+
addopts = "-v --tb=short --strict-markers"
|
|
163
|
+
markers = [
|
|
164
|
+
"slow: marks tests as slow",
|
|
165
|
+
"integration: marks integration tests",
|
|
166
|
+
]
|
|
167
|
+
|
|
168
|
+
[tool.coverage.run]
|
|
169
|
+
source = ["app"]
|
|
170
|
+
omit = ["tests/*", "*/migrations/*"]
|
|
171
|
+
|
|
172
|
+
[tool.coverage.report]
|
|
173
|
+
fail_under = 80
|
|
174
|
+
show_missing = true
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
# Run tests
|
|
179
|
+
pytest # All tests
|
|
180
|
+
pytest -x # Stop on first failure
|
|
181
|
+
pytest -k "test_user" # Filter by name
|
|
182
|
+
pytest --cov=app --cov-report=html # With coverage
|
|
183
|
+
pytest -m "not slow" # Skip slow tests
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
---
|
|
187
|
+
|
|
188
|
+
## Anti-Patterns
|
|
189
|
+
|
|
190
|
+
| ❌ Don't | ✅ Do |
|
|
191
|
+
|---------|-------|
|
|
192
|
+
| Test implementation details | Test behavior (inputs → outputs) |
|
|
193
|
+
| Mock everything | Mock only boundaries (DB, APIs, email) |
|
|
194
|
+
| Share state between tests | Each test is independent |
|
|
195
|
+
| Skip error path tests | Test both success AND failure |
|
|
196
|
+
| Ignore coverage | Aim for ≥80% with `fail_under` |
|
|
197
|
+
| Use `print()` for debugging | Use `pytest --pdb` or `breakpoint()` |
|
|
198
|
+
|
|
199
|
+
---
|
|
200
|
+
|
|
201
|
+
## 🔗 Related
|
|
202
|
+
|
|
203
|
+
| File | When to Read |
|
|
204
|
+
|------|-------------|
|
|
205
|
+
| [fastapi-patterns.md](fastapi-patterns.md) | FastAPI patterns |
|
|
206
|
+
| [django-patterns.md](django-patterns.md) | Django patterns |
|
|
207
|
+
| [async-patterns.md](async-patterns.md) | Testing async code |
|
|
208
|
+
| [type-hints.md](type-hints.md) | Typed test fixtures |
|
|
209
|
+
|
|
210
|
+
---
|
|
211
|
+
|
|
212
|
+
⚡ PikaKit v3.9.134
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: type-hints
|
|
3
|
+
description: Python type hints — modern syntax, Pydantic v2, generics, TypeVar, and validation patterns
|
|
4
|
+
title: "Python Type Hints & Validation"
|
|
5
|
+
impact: MEDIUM
|
|
6
|
+
impactDescription: "Moderate improvement to quality or maintainability"
|
|
7
|
+
tags: type, hints
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# Python Type Hints & Validation
|
|
11
|
+
|
|
12
|
+
> Type all public APIs. Use Pydantic at boundaries. No `Any` in public signatures.
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## Modern Type Syntax (Python 3.12+)
|
|
17
|
+
|
|
18
|
+
```python
|
|
19
|
+
# ✅ Modern — use built-in generics (no typing import needed)
|
|
20
|
+
def get_items() -> list[dict[str, int]]:
|
|
21
|
+
...
|
|
22
|
+
|
|
23
|
+
def find_user(user_id: int) -> User | None: # Union syntax
|
|
24
|
+
...
|
|
25
|
+
|
|
26
|
+
def process(data: str | bytes) -> None:
|
|
27
|
+
...
|
|
28
|
+
|
|
29
|
+
# ❌ Legacy — avoid in new code
|
|
30
|
+
from typing import Optional, Union, List, Dict
|
|
31
|
+
def get_items() -> List[Dict[str, int]]: # Old style
|
|
32
|
+
...
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## Common Patterns
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
from typing import TypeVar, Generic, Callable
|
|
41
|
+
from collections.abc import Sequence, Mapping
|
|
42
|
+
|
|
43
|
+
# TypeVar for generics
|
|
44
|
+
T = TypeVar("T")
|
|
45
|
+
|
|
46
|
+
def first(items: Sequence[T]) -> T | None:
|
|
47
|
+
return items[0] if items else None
|
|
48
|
+
|
|
49
|
+
# Callable types
|
|
50
|
+
def apply(fn: Callable[[int], str], value: int) -> str:
|
|
51
|
+
return fn(value)
|
|
52
|
+
|
|
53
|
+
# Generic class
|
|
54
|
+
class Repository(Generic[T]):
|
|
55
|
+
def __init__(self, model: type[T]) -> None:
|
|
56
|
+
self.model = model
|
|
57
|
+
|
|
58
|
+
async def get(self, id: int) -> T | None:
|
|
59
|
+
...
|
|
60
|
+
|
|
61
|
+
async def list(self, limit: int = 20) -> list[T]:
|
|
62
|
+
...
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## Pydantic v2 Models
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
from pydantic import BaseModel, Field, EmailStr, field_validator
|
|
71
|
+
from datetime import datetime
|
|
72
|
+
|
|
73
|
+
class UserCreate(BaseModel):
|
|
74
|
+
"""Input validation at API boundary."""
|
|
75
|
+
name: str = Field(min_length=1, max_length=100)
|
|
76
|
+
email: EmailStr
|
|
77
|
+
age: int = Field(ge=0, le=150)
|
|
78
|
+
role: str = "user"
|
|
79
|
+
|
|
80
|
+
@field_validator("name")
|
|
81
|
+
@classmethod
|
|
82
|
+
def name_must_not_be_empty(cls, v: str) -> str:
|
|
83
|
+
if not v.strip():
|
|
84
|
+
raise ValueError("Name cannot be blank")
|
|
85
|
+
return v.strip()
|
|
86
|
+
|
|
87
|
+
class UserResponse(BaseModel):
|
|
88
|
+
"""Output serialization — never expose internal fields."""
|
|
89
|
+
id: int
|
|
90
|
+
name: str
|
|
91
|
+
email: str
|
|
92
|
+
created_at: datetime
|
|
93
|
+
|
|
94
|
+
model_config = {"from_attributes": True} # Enable ORM mode
|
|
95
|
+
|
|
96
|
+
class UserUpdate(BaseModel):
|
|
97
|
+
"""Partial update — all fields optional."""
|
|
98
|
+
name: str | None = None
|
|
99
|
+
email: EmailStr | None = None
|
|
100
|
+
age: int | None = Field(default=None, ge=0, le=150)
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Pydantic Settings (Configuration)
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
from pydantic_settings import BaseSettings
|
|
107
|
+
|
|
108
|
+
class Settings(BaseSettings):
|
|
109
|
+
"""Load from environment variables automatically."""
|
|
110
|
+
database_url: str
|
|
111
|
+
redis_url: str = "redis://localhost:6379"
|
|
112
|
+
secret_key: str
|
|
113
|
+
debug: bool = False
|
|
114
|
+
allowed_origins: list[str] = ["http://localhost:3000"]
|
|
115
|
+
|
|
116
|
+
model_config = {"env_file": ".env", "env_file_encoding": "utf-8"}
|
|
117
|
+
|
|
118
|
+
settings = Settings() # Auto-reads from .env + environment
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## When to Type
|
|
124
|
+
|
|
125
|
+
| Scope | Rule |
|
|
126
|
+
|-------|------|
|
|
127
|
+
| Function parameters | Always |
|
|
128
|
+
| Return types | Always |
|
|
129
|
+
| Class attributes | Always |
|
|
130
|
+
| Local variables | Let inference work (skip) |
|
|
131
|
+
| Tests | Optional (usually skip) |
|
|
132
|
+
| Scripts | Minimal |
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
## Anti-Patterns
|
|
137
|
+
|
|
138
|
+
| ❌ Don't | ✅ Do |
|
|
139
|
+
|---------|-------|
|
|
140
|
+
| `Any` in public APIs | Use specific types or `TypeVar` |
|
|
141
|
+
| `typing.Optional[X]` | `X \| None` (Python 3.10+) |
|
|
142
|
+
| `typing.List`, `typing.Dict` | `list`, `dict` (Python 3.9+) |
|
|
143
|
+
| Skip return type hints | Always annotate return types |
|
|
144
|
+
| Validate manually | Use Pydantic at boundaries |
|
|
145
|
+
| Hardcode config values | Use Pydantic Settings |
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
## 🔗 Related
|
|
150
|
+
|
|
151
|
+
| File | When to Read |
|
|
152
|
+
|------|-------------|
|
|
153
|
+
| [fastapi-patterns.md](fastapi-patterns.md) | Pydantic with FastAPI |
|
|
154
|
+
| [testing-patterns.md](testing-patterns.md) | Testing typed code |
|
|
155
|
+
| [project-structure.md](project-structure.md) | Where to put models |
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
⚡ PikaKit v3.9.134
|