@umacloud/knowledge 1.0.1
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/00-governance/governance-capabilities.md +557 -0
- package/00-governance/knowledge-map.md +39 -0
- package/00-governance/maintenance-policy.md +76 -0
- package/00-governance/review-checklist.md +81 -0
- package/README.md +13 -0
- package/ai/01-standards/agent-development-complete.md +691 -0
- package/ai/01-standards/llm-application-complete.md +488 -0
- package/ai/01-standards/mlops-complete.md +798 -0
- package/ai/01-standards/prompt-engineering-complete.md +646 -0
- package/ai/01-standards/rag-architecture-complete.md +649 -0
- package/ai/02-playbooks/llm-evaluation-playbook.md +847 -0
- package/ai/03-checklists/ai-project-checklist.md +215 -0
- package/ai/04-antipatterns/ai-antipatterns.md +661 -0
- package/ai/05-cases/case-rag-production.md +147 -0
- package/ai/06-glossary/ai-glossary.md +162 -0
- package/ai/agent-evaluation-benchmark.md +53 -0
- package/ai/ai-agent-memory-context-management.md +41 -0
- package/ai/ai-cost-capacity-optimization-playbook.md +42 -0
- package/ai/ai-data-security-and-compliance-playbook.md +37 -0
- package/ai/ai-domain-index-and-checklist.md +40 -0
- package/ai/ai-governance-maturity-model.md +50 -0
- package/ai/ai-model-selection-and-routing-strategy.md +47 -0
- package/ai/ai-observability-and-oncall-runbook.md +52 -0
- package/ai/ai-rag-engineering-playbook.md +42 -0
- package/ai/ai-red-team-and-safety-evaluation.md +42 -0
- package/ai/ai-release-readiness-and-rollback-gate.md +42 -0
- package/ai/llm-agent-engineering-deep-dive.md +57 -0
- package/ai/prompt-and-tool-guardrails.md +52 -0
- package/api/01-standards/enterprise-api-standards.md +198 -0
- package/api/01-standards/rest-api-design-guide.md +63 -0
- package/api/02-playbooks/api-pagination-playbook.md +93 -0
- package/api/02-playbooks/graphql-production-playbook.md +176 -0
- package/api/03-checklists/api-review-checklist.md +55 -0
- package/api/04-antipatterns/api-antipatterns.md +112 -0
- package/architecture/01-standards/api-gateway-patterns.md +496 -0
- package/architecture/01-standards/cloud-native-patterns.md +644 -0
- package/architecture/01-standards/distributed-systems-patterns.md +591 -0
- package/architecture/01-standards/event-driven-architecture.md +595 -0
- package/architecture/01-standards/microservices-patterns-complete.md +968 -0
- package/architecture/01-standards/microservices-patterns.md +495 -0
- package/architecture/01-standards/system-design-interview.md +664 -0
- package/architecture/02-playbooks/microservices-patterns-playbook.md +137 -0
- package/architecture/02-playbooks/migration-playbook.md +780 -0
- package/architecture/02-playbooks/system-design-playbook.md +779 -0
- package/architecture/03-checklists/architecture-decision-checklist.md +297 -0
- package/architecture/04-antipatterns/architecture-antipatterns.md +417 -0
- package/architecture/05-cases/case-netflix-microservices.md +413 -0
- package/architecture/06-glossary/architecture-glossary.md +164 -0
- package/architecture/adr-template-and-examples.md +38 -0
- package/architecture/api-gateway-deep-dive.md +1291 -0
- package/architecture/configuration-management.md +1162 -0
- package/architecture/distributed-transactions.md +1220 -0
- package/architecture/microservices-complete.md +735 -0
- package/architecture/resilience-and-disaster-patterns.md +37 -0
- package/architecture/service-governance.md +1198 -0
- package/architecture/system-architecture-deep-dive.md +37 -0
- package/backend/01-standards/analytics-and-growth.md +65 -0
- package/backend/01-standards/api-and-error-conventions.md +120 -0
- package/backend/01-standards/application-layering-and-packaging.md +160 -0
- package/backend/01-standards/auth-implementation.md +104 -0
- package/backend/01-standards/backend-framework-idioms.md +74 -0
- package/backend/01-standards/background-jobs-and-async.md +66 -0
- package/backend/01-standards/caching-strategies-complete.md +390 -0
- package/backend/01-standards/config-and-observability.md +77 -0
- package/backend/01-standards/data-modeling-and-persistence.md +94 -0
- package/backend/01-standards/django-complete.md +1765 -0
- package/backend/01-standards/email-and-notifications.md +64 -0
- package/backend/01-standards/fastapi-complete.md +925 -0
- package/backend/01-standards/file-upload-and-storage.md +66 -0
- package/backend/01-standards/graphql-api-complete.md +416 -0
- package/backend/01-standards/llm-application-standard.md +78 -0
- package/backend/01-standards/message-queue-patterns.md +379 -0
- package/backend/01-standards/microservices-and-distributed.md +78 -0
- package/backend/01-standards/nestjs-complete.md +2167 -0
- package/backend/01-standards/payment-integration.md +80 -0
- package/backend/01-standards/rate-limiting-complete.md +451 -0
- package/backend/01-standards/realtime-and-websocket.md +65 -0
- package/backend/01-standards/search-and-filtering.md +64 -0
- package/backend/01-standards/spring-boot-complete.md +445 -0
- package/backend/02-playbooks/api-design-playbook.md +718 -0
- package/backend/02-playbooks/email-send-playbook.md +130 -0
- package/backend/02-playbooks/file-upload-s3-playbook.md +153 -0
- package/backend/02-playbooks/typescript-enterprise-playbook.md +133 -0
- package/backend/02-playbooks/websocket-realtime-playbook.md +154 -0
- package/backend/03-checklists/api-launch-checklist.md +189 -0
- package/backend/04-antipatterns/backend-antipatterns.md +1051 -0
- package/blockchain/01-standards/blockchain-basics.md +557 -0
- package/blockchain/01-standards/smart-contract-development.md +1315 -0
- package/cicd/01-standards/deployment-and-delivery-standard.md +96 -0
- package/cicd/01-standards/github-actions-complete.md +473 -0
- package/cicd/01-standards/release-and-store-submission.md +75 -0
- package/cicd/02-playbooks/cicd-pipeline-playbook.md +144 -0
- package/cicd/02-playbooks/release-management-playbook.md +605 -0
- package/cicd/03-checklists/pipeline-security-checklist.md +168 -0
- package/cicd/04-antipatterns/cicd-antipatterns.md +589 -0
- package/cicd/05-cases/case-deployment-automation.md +221 -0
- package/cicd/05-cases/case-gitops-transformation.md +212 -0
- package/cicd/06-glossary/cicd-glossary.md +114 -0
- package/cicd/cicd-blueprint-deep-dive.md +38 -0
- package/cicd/release-readiness-gate.md +37 -0
- package/cloud-native/01-standards/container-security.md +741 -0
- package/cloud-native/01-standards/kubernetes-complete.md +812 -0
- package/cloud-native/02-playbooks/api-gateway-playbook.md +155 -0
- package/cloud-native/02-playbooks/gitops-with-argocd.md +760 -0
- package/cloud-native/02-playbooks/k8s-troubleshooting-playbook.md +1942 -0
- package/cloud-native/02-playbooks/message-queue-playbook.md +129 -0
- package/cloud-native/02-playbooks/multicloud-governance.md +726 -0
- package/cloud-native/02-playbooks/serverless-patterns.md +788 -0
- package/cloud-native/02-playbooks/service-mesh-playbook.md +612 -0
- package/cloud-native/02-playbooks/terraform-iac-playbook.md +143 -0
- package/cloud-native/03-checklists/container-security-checklist.md +431 -0
- package/cloud-native/03-checklists/k8s-production-readiness-checklist.md +460 -0
- package/cloud-native/04-antipatterns/container-antipatterns.md +660 -0
- package/cloud-native/04-antipatterns/k8s-antipatterns.md +743 -0
- package/cloud-native/05-cases/case-k8s-migration.md +478 -0
- package/cloud-native/05-cases/case-k8s-scaling.md +642 -0
- package/cloud-native/05-cases/case-k8s-security-incident.md +397 -0
- package/cloud-native/06-glossary/cloud-native-glossary.md +337 -0
- package/cross-platform/01-standards/cross-platform-frameworks.md +83 -0
- package/cross-platform/01-standards/platform-selection-and-architecture.md +77 -0
- package/data/01-standards/elasticsearch-complete.md +2098 -0
- package/data/01-standards/postgresql-complete.md +1613 -0
- package/data/01-standards/redis-complete.md +1527 -0
- package/data/02-playbooks/database-optimization-playbook.md +403 -0
- package/data/02-playbooks/elasticsearch-production-playbook.md +132 -0
- package/data/03-checklists/database-launch-checklist.md +187 -0
- package/data/04-antipatterns/database-antipatterns.md +873 -0
- package/data/05-cases/case-database-migration.md +310 -0
- package/data/06-glossary/database-glossary.md +440 -0
- package/data/data-governance-and-modeling-deep-dive.md +39 -0
- package/data-engineering/01-standards/airflow-complete.md +523 -0
- package/data-engineering/01-standards/kafka-complete.md +1521 -0
- package/data-engineering/02-playbooks/spark-etl-playbook.md +496 -0
- package/data-engineering/03-checklists/pipeline-launch-checklist.md +194 -0
- package/data-engineering/04-antipatterns/data-pipeline-antipatterns.md +684 -0
- package/data-engineering/05-cases/case-real-time-pipeline.md +355 -0
- package/data-engineering/06-glossary/data-engineering-glossary.md +429 -0
- package/database/01-standards/database-schema-standards.md +147 -0
- package/database/02-playbooks/postgresql-optimization-quick.md +52 -0
- package/database/02-playbooks/postgresql-performance-optimization.md +58 -0
- package/database/02-playbooks/postgresql-production-playbook.md +146 -0
- package/database/02-playbooks/redis-caching-playbook.md +117 -0
- package/database/03-checklists/database-review-checklist.md +50 -0
- package/database/04-antipatterns/database-antipatterns.md +112 -0
- package/design/01-standards/ui-design-system-complete.md +423 -0
- package/design/02-playbooks/design-handoff-playbook.md +254 -0
- package/design/02-playbooks/design-review-playbook.md +388 -0
- package/design/03-checklists/design-review-checklist.md +246 -0
- package/design/04-antipatterns/design-antipatterns.md +378 -0
- package/design/05-cases/case-design-system-adoption.md +328 -0
- package/design/06-glossary/design-glossary.md +329 -0
- package/design/ui-full-lifecycle-cross-platform-playbook.md +571 -0
- package/design/ux-system-deep-dive.md +38 -0
- package/design-systems/00-craft-rules.md +71 -0
- package/design-systems/aesthetic-families.md +43 -0
- package/design-systems/anti-ai-slop.md +162 -0
- package/design-systems/bold-geometric.md +120 -0
- package/design-systems/brutalist-bold.md +103 -0
- package/design-systems/editorial-clean.md +109 -0
- package/design-systems/glass-aurora.md +108 -0
- package/design-systems/modern-minimal.md +145 -0
- package/design-systems/premium-luxury.md +106 -0
- package/design-systems/product-type-design-map.md +48 -0
- package/design-systems/soft-warm.md +123 -0
- package/design-systems/tech-utility.md +113 -0
- package/desktop/01-standards/desktop-app-standard.md +72 -0
- package/desktop/01-standards/desktop-design.md +71 -0
- package/development/00-governance/document-template.md +41 -0
- package/development/01-standards/api-versioning-strategies.md +432 -0
- package/development/01-standards/authentication-patterns-complete.md +479 -0
- package/development/01-standards/css-architecture-complete.md +550 -0
- package/development/01-standards/database-migration-strategies.md +484 -0
- package/development/01-standards/elasticsearch-complete.md +347 -0
- package/development/01-standards/git-complete.md +371 -0
- package/development/01-standards/golang-complete.md +1565 -0
- package/development/01-standards/graphql-complete.md +298 -0
- package/development/01-standards/javascript-bundlers-complete.md +469 -0
- package/development/01-standards/javascript-typescript-complete.md +528 -0
- package/development/01-standards/jest-complete.md +275 -0
- package/development/01-standards/linux-complete.md +234 -0
- package/development/01-standards/logging-observability-complete.md +526 -0
- package/development/01-standards/microservices-communication.md +502 -0
- package/development/01-standards/mongodb-complete.md +406 -0
- package/development/01-standards/oauth2-complete.md +285 -0
- package/development/01-standards/performance-optimization-complete.md +289 -0
- package/development/01-standards/playwright-complete.md +247 -0
- package/development/01-standards/postgresql-complete.md +456 -0
- package/development/01-standards/pytest-complete.md +340 -0
- package/development/01-standards/python-async-programming.md +902 -0
- package/development/01-standards/python-complete.md +956 -0
- package/development/01-standards/python-decorators-complete.md +799 -0
- package/development/01-standards/python-design-patterns.md +2854 -0
- package/development/01-standards/python-packaging-distribution.md +420 -0
- package/development/01-standards/python-testing-strategies.md +607 -0
- package/development/01-standards/python-web-frameworks-comparison.md +471 -0
- package/development/01-standards/redis-complete.md +317 -0
- package/development/01-standards/rest-api-complete.md +316 -0
- package/development/01-standards/rust-complete.md +578 -0
- package/development/01-standards/typescript-advanced-types.md +1513 -0
- package/development/01-standards/web-security-complete.md +292 -0
- package/development/02-playbooks/api-design-playbook.md +810 -0
- package/development/02-playbooks/database-migration-playbook.md +580 -0
- package/development/02-playbooks/debugging-playbook.md +692 -0
- package/development/02-playbooks/feature-delivery-playbook.md +430 -0
- package/development/02-playbooks/incident-hotfix-playbook.md +387 -0
- package/development/02-playbooks/performance-optimization-playbook.md +531 -0
- package/development/02-playbooks/performance-tuning-playbook.md +652 -0
- package/development/02-playbooks/refactor-playbook.md +403 -0
- package/development/02-playbooks/release-playbook.md +469 -0
- package/development/03-checklists/architecture-review-checklist.md +168 -0
- package/development/03-checklists/data-migration-checklist.md +157 -0
- package/development/03-checklists/oncall-handover-checklist.md +173 -0
- package/development/03-checklists/pr-checklist.md +158 -0
- package/development/03-checklists/production-readiness-checklist.md +190 -0
- package/development/03-checklists/release-readiness-checklist.md +154 -0
- package/development/03-checklists/security-review-checklist.md +182 -0
- package/development/04-antipatterns/api-antipatterns.md +657 -0
- package/development/04-antipatterns/architecture-antipatterns.md +686 -0
- package/development/04-antipatterns/backend-antipatterns.md +648 -0
- package/development/04-antipatterns/cicd-antipatterns.md +540 -0
- package/development/04-antipatterns/code-smell-antipatterns.md +571 -0
- package/development/04-antipatterns/data-antipatterns.md +658 -0
- package/development/04-antipatterns/database-antipatterns.md +578 -0
- package/development/04-antipatterns/frontend-antipatterns.md +635 -0
- package/development/04-antipatterns/reliability-antipatterns.md +700 -0
- package/development/04-antipatterns/security-antipatterns.md +747 -0
- package/development/05-cases/case-api-version-migration.md +428 -0
- package/development/05-cases/case-authorization-hardening.md +383 -0
- package/development/05-cases/case-bluegreen-rollback.md +466 -0
- package/development/05-cases/case-cache-snowball-protection.md +485 -0
- package/development/05-cases/case-ci-cd-pipeline.md +544 -0
- package/development/05-cases/case-database-scaling.md +500 -0
- package/development/05-cases/case-db-hotspot-optimization.md +487 -0
- package/development/05-cases/case-incident-mttr-reduction.md +563 -0
- package/development/05-cases/case-microservice-migration.md +375 -0
- package/development/05-cases/case-performance-optimization.md +406 -0
- package/development/05-cases/case-security-incident-response.md +345 -0
- package/development/06-glossary/full-stack-glossary.md +166 -0
- package/development/09-maturity/quarterly-audit-template.md +35 -0
- package/development/11-ui-excellence/ui-aesthetic-system.md +41 -0
- package/development/11-ui-excellence/ui-engineering-excellence.md +435 -0
- package/development/12-scenarios/development-scenarios-guide.md +565 -0
- package/development/13-implementation-assets/implementation-toolkit.md +282 -0
- package/development/13-implementation-assets/knowledge-gates-execution.md +43 -0
- package/development/14-full-lifecycle/software-lifecycle-gates.md +511 -0
- package/development/15-lifecycle-templates/project-templates-collection.md +791 -0
- package/development/api-contract-and-versioning-guide.md +36 -0
- package/development/api-governance-complete.md +43 -0
- package/development/backend-engineering-complete.md +43 -0
- package/development/code-review-quality-complete.md +43 -0
- package/development/concurrency-reliability-complete.md +43 -0
- package/development/database-engineering-complete.md +43 -0
- package/development/engineering-effectiveness-complete.md +43 -0
- package/development/engineering-standards-deep-dive.md +38 -0
- package/development/frontend-engineering-complete.md +43 -0
- package/development/performance-capacity-complete.md +43 -0
- package/development/refactor-migration-complete.md +42 -0
- package/development/refactoring-and-techdebt-playbook.md +37 -0
- package/development/security-in-development-complete.md +43 -0
- package/devops/01-standards/cicd-pipeline-complete.md +262 -0
- package/devops/01-standards/docker-complete.md +1490 -0
- package/devops/01-standards/github-actions-complete.md +337 -0
- package/devops/01-standards/kubernetes-complete.md +638 -0
- package/devops/01-standards/terraform-complete.md +2117 -0
- package/devops/02-playbooks/docker-compose-playbook.md +233 -0
- package/devops/02-playbooks/docker-k8s-production-playbook.md +186 -0
- package/devops/02-playbooks/docker-production-playbook.md +952 -0
- package/edge-iot/01-standards/edge-iot-complete.md +473 -0
- package/experts/architect/api-design.md +178 -0
- package/experts/architect/methodology.md +124 -0
- package/experts/architect/security.md +75 -0
- package/experts/backend-lead/methodology.md +216 -0
- package/experts/devops/methodology.md +160 -0
- package/experts/frontend-lead/methodology.md +178 -0
- package/experts/product-manager/industry/ecommerce.md +43 -0
- package/experts/product-manager/industry/saas.md +40 -0
- package/experts/product-manager/methodology.md +97 -0
- package/experts/qa-lead/methodology.md +123 -0
- package/experts/qa-lead/test-strategy.md +128 -0
- package/experts/uiux-designer/methodology.md +125 -0
- package/frontend/01-standards/accessibility-complete.md +532 -0
- package/frontend/01-standards/accessibility-standard.md +74 -0
- package/frontend/01-standards/admin-dashboard-and-crud.md +72 -0
- package/frontend/01-standards/design-tokens-complete.md +444 -0
- package/frontend/01-standards/forms-and-validation.md +77 -0
- package/frontend/01-standards/frontend-architecture-and-layering.md +119 -0
- package/frontend/01-standards/i18n-and-localization.md +65 -0
- package/frontend/01-standards/nextjs-complete.md +451 -0
- package/frontend/01-standards/react-complete.md +713 -0
- package/frontend/01-standards/react-hooks-complete-guide.md +1100 -0
- package/frontend/01-standards/react-hooks-complete.md +1171 -0
- package/frontend/01-standards/seo-and-web-vitals.md +77 -0
- package/frontend/01-standards/state-management-complete.md +444 -0
- package/frontend/01-standards/vue-complete.md +499 -0
- package/frontend/01-standards/vue3-complete.md +2002 -0
- package/frontend/01-standards/web-framework-best-practices.md +64 -0
- package/frontend/01-standards/web-performance-complete.md +495 -0
- package/frontend/02-playbooks/accessibility-a11y-playbook.md +161 -0
- package/frontend/02-playbooks/frontend-performance-playbook.md +707 -0
- package/frontend/02-playbooks/i18n-internationalization-playbook.md +120 -0
- package/frontend/02-playbooks/performance-optimization-playbook.md +163 -0
- package/frontend/02-playbooks/react-nextjs-production-playbook.md +167 -0
- package/frontend/02-playbooks/react-state-management-playbook.md +173 -0
- package/frontend/03-checklists/component-quality-checklist.md +166 -0
- package/frontend/03-checklists/frontend-launch-checklist.md +299 -0
- package/frontend/04-antipatterns/frontend-antipatterns.md +886 -0
- package/frontend/05-cases/case-performance-optimization.md +274 -0
- package/harmony/01-standards/harmonyos-arkts-standard.md +75 -0
- package/harmony/01-standards/harmonyos-design.md +65 -0
- package/high-quality-engineering-playbook.md +54 -0
- package/incident/01-standards/incident-response-complete.md +303 -0
- package/incident/02-playbooks/chaos-engineering-playbook.md +883 -0
- package/incident/02-playbooks/postmortem-playbook.md +398 -0
- package/incident/03-checklists/incident-readiness-checklist.md +181 -0
- package/incident/04-antipatterns/incident-antipatterns.md +490 -0
- package/incident/05-cases/case-cascade-failure.md +176 -0
- package/incident/06-glossary/incident-glossary.md +114 -0
- package/incident/postmortem-and-response-deep-dive.md +39 -0
- package/industries/ecommerce/ecommerce-complete.md +631 -0
- package/industries/education/education-complete.md +555 -0
- package/industries/fintech/fintech-complete.md +501 -0
- package/industries/gaming/gaming-complete.md +587 -0
- package/industries/healthcare/healthcare-complete.md +452 -0
- package/low-code/01-standards/low-code-complete.md +944 -0
- package/miniprogram/01-standards/ai-common-mistakes.md +61 -0
- package/miniprogram/01-standards/miniprogram-custom-navbar-capsule.md +77 -0
- package/miniprogram/01-standards/miniprogram-design.md +61 -0
- package/miniprogram/01-standards/miniprogram-standard.md +81 -0
- package/mobile/01-standards/android-material-design.md +70 -0
- package/mobile/01-standards/flutter-complete.md +384 -0
- package/mobile/01-standards/ios-design-hig.md +78 -0
- package/mobile/01-standards/mobile-app-standard.md +85 -0
- package/mobile/01-standards/react-native-complete.md +352 -0
- package/mobile/02-playbooks/mobile-cross-platform-playbook.md +175 -0
- package/mobile/02-playbooks/mobile-performance.md +473 -0
- package/mobile/03-checklists/mobile-release-checklist.md +234 -0
- package/mobile/04-antipatterns/mobile-antipatterns.md +798 -0
- package/mobile/05-cases/case-app-performance.md +500 -0
- package/mobile/05-cases/case-app-startup-optimization.md +218 -0
- package/mobile/06-glossary/mobile-glossary.md +484 -0
- package/observability/01-standards/observability-standards.md +103 -0
- package/observability/02-playbooks/prometheus-grafana-playbook.md +135 -0
- package/observability/02-playbooks/structured-logging-playbook.md +73 -0
- package/observability/03-checklists/observability-checklist.md +54 -0
- package/observability/04-antipatterns/observability-antipatterns.md +106 -0
- package/operations/01-standards/prometheus-monitoring-complete.md +1578 -0
- package/operations/02-playbooks/capacity-planning-playbook.md +620 -0
- package/operations/03-checklists/production-launch-checklist.md +365 -0
- package/operations/04-antipatterns/operations-antipatterns.md +664 -0
- package/operations/05-cases/case-sre-practices.md +581 -0
- package/operations/06-glossary/operations-glossary.md +120 -0
- package/operations/aiops-anomaly-detection.md +758 -0
- package/operations/capacity-planning.md +1061 -0
- package/operations/chaos-engineering.md +659 -0
- package/operations/incident-command-system.md +38 -0
- package/operations/observability-complete.md +442 -0
- package/operations/slo-sli-playbook.md +517 -0
- package/operations/sre-operations-deep-dive.md +39 -0
- package/package.json +8 -0
- package/performance/01-standards/performance-and-scalability.md +80 -0
- package/performance/01-standards/performance-standards.md +156 -0
- package/performance/02-playbooks/query-optimization-playbook.md +103 -0
- package/performance/03-checklists/performance-checklist.md +56 -0
- package/performance/04-antipatterns/performance-antipatterns.md +146 -0
- package/product/01-standards/product-management-complete.md +285 -0
- package/product/02-playbooks/feature-launch-playbook.md +207 -0
- package/product/02-playbooks/user-research-playbook.md +532 -0
- package/product/03-checklists/feature-launch-checklist.md +275 -0
- package/product/04-antipatterns/product-antipatterns.md +355 -0
- package/product/05-cases/case-mvp-to-scale.md +384 -0
- package/product/06-glossary/product-glossary.md +462 -0
- package/product/feature-prioritization-framework.md +40 -0
- package/product/kpi-and-metric-tree.md +37 -0
- package/product/product-discovery-and-prd-deep-dive.md +41 -0
- package/quantum/01-standards/quantum-complete.md +1186 -0
- package/security/01-standards/api-security-complete.md +511 -0
- package/security/01-standards/container-runtime-security.md +574 -0
- package/security/01-standards/data-protection-gdpr.md +543 -0
- package/security/01-standards/owasp-top10-complete.md +1890 -0
- package/security/01-standards/secure-coding-baseline.md +90 -0
- package/security/01-standards/supply-chain-security.md +441 -0
- package/security/01-standards/web-security-checklist.md +108 -0
- package/security/01-standards/zero-trust-architecture.md +521 -0
- package/security/02-playbooks/auth-sso-playbook.md +166 -0
- package/security/02-playbooks/incident-response-security-playbook.md +588 -0
- package/security/02-playbooks/owasp-api-security-playbook.md +129 -0
- package/security/02-playbooks/payment-integration-playbook.md +119 -0
- package/security/02-playbooks/penetration-testing-playbook.md +517 -0
- package/security/03-checklists/security-audit-checklist.md +356 -0
- package/security/04-antipatterns/security-coding-antipatterns.md +580 -0
- package/security/05-cases/case-log4shell-incident.md +537 -0
- package/security/05-cases/case-major-breaches.md +468 -0
- package/security/06-glossary/security-glossary.md +212 -0
- package/security/compliance-automation.md +993 -0
- package/security/container-security.md +680 -0
- package/security/devsecops-complete.md +426 -0
- package/security/sast-dast-sca.md +775 -0
- package/security/secrets-management.md +594 -0
- package/security/security-architecture-deep-dive.md +37 -0
- package/security/threat-modeling-stride-playbook.md +40 -0
- package/seed-templates/auth-system.md +59 -0
- package/seed-templates/blog-content.md +94 -0
- package/seed-templates/dashboard.md +89 -0
- package/seed-templates/docs-site.md +73 -0
- package/seed-templates/e-commerce.md +50 -0
- package/seed-templates/saas-landing.md +92 -0
- package/seed-templates/settings-page.md +51 -0
- package/testing/01-standards/test-strategy-and-layering.md +83 -0
- package/testing/01-standards/testing-strategy-complete.md +422 -0
- package/testing/01-standards/unit-testing-best-practices.md +118 -0
- package/testing/02-playbooks/e2e-testing-playbook.md +988 -0
- package/testing/02-playbooks/testing-strategy-playbook.md +126 -0
- package/testing/03-checklists/test-strategy-checklist.md +208 -0
- package/testing/04-antipatterns/testing-antipatterns.md +718 -0
- package/testing/05-cases/case-testing-transformation.md +300 -0
- package/testing/06-glossary/testing-glossary.md +110 -0
- package/testing/risk-based-test-matrix.md +36 -0
- package/testing/testing-strategy-deep-dive.md +37 -0
|
@@ -0,0 +1,635 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: frontend-antipatterns
|
|
3
|
+
title: 前端反模式指南
|
|
4
|
+
domain: development
|
|
5
|
+
category: 04-antipatterns
|
|
6
|
+
difficulty: intermediate
|
|
7
|
+
tags: [antipatterns, bloat, budget, chaos, component, development, error, frontend]
|
|
8
|
+
quality_score: 70
|
|
9
|
+
last_updated: 2026-06-15
|
|
10
|
+
---
|
|
11
|
+
# 前端反模式指南
|
|
12
|
+
|
|
13
|
+
> 适用范围:React / Vue / Angular / Next.js / Nuxt
|
|
14
|
+
> 约束级别:SHALL(必须在 Code Review 阶段拦截)
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## 1. 组件臃肿(Fat Component)
|
|
19
|
+
|
|
20
|
+
### 描述
|
|
21
|
+
单个组件承载了数据获取、业务逻辑、状态管理、UI 渲染、事件处理等全部职责,导致组件行数膨胀到数百行,难以测试、难以复用。
|
|
22
|
+
|
|
23
|
+
### 错误示例
|
|
24
|
+
```tsx
|
|
25
|
+
// OrderPage.tsx -- 500 行的巨型组件
|
|
26
|
+
function OrderPage() {
|
|
27
|
+
const [orders, setOrders] = useState([]);
|
|
28
|
+
const [loading, setLoading] = useState(false);
|
|
29
|
+
const [error, setError] = useState(null);
|
|
30
|
+
const [page, setPage] = useState(1);
|
|
31
|
+
const [filters, setFilters] = useState({});
|
|
32
|
+
const [selectedOrder, setSelectedOrder] = useState(null);
|
|
33
|
+
const [showModal, setShowModal] = useState(false);
|
|
34
|
+
const [sortField, setSortField] = useState("created_at");
|
|
35
|
+
const [sortOrder, setSortOrder] = useState("desc");
|
|
36
|
+
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
setLoading(true);
|
|
39
|
+
fetch(`/api/orders?page=${page}&sort=${sortField}&order=${sortOrder}`)
|
|
40
|
+
.then((res) => res.json())
|
|
41
|
+
.then((data) => { setOrders(data.items); setLoading(false); })
|
|
42
|
+
.catch((err) => { setError(err.message); setLoading(false); });
|
|
43
|
+
}, [page, sortField, sortOrder, filters]);
|
|
44
|
+
|
|
45
|
+
const handleCancelOrder = async (orderId) => {
|
|
46
|
+
// 30 行的取消逻辑
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const handleExport = async () => {
|
|
50
|
+
// 40 行的导出逻辑
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const calculateTotal = (items) => {
|
|
54
|
+
// 20 行的计算逻辑
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<div>
|
|
59
|
+
{/* 200 行的 JSX 渲染 */}
|
|
60
|
+
</div>
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### 正确示例
|
|
66
|
+
```tsx
|
|
67
|
+
// OrderPage.tsx -- 只负责页面组装
|
|
68
|
+
function OrderPage() {
|
|
69
|
+
return (
|
|
70
|
+
<PageLayout title="Orders">
|
|
71
|
+
<OrderFilters />
|
|
72
|
+
<OrderList />
|
|
73
|
+
<OrderDetailModal />
|
|
74
|
+
</PageLayout>
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// hooks/useOrders.ts -- 数据获取逻辑
|
|
79
|
+
function useOrders(filters: OrderFilters) {
|
|
80
|
+
return useQuery({
|
|
81
|
+
queryKey: ["orders", filters],
|
|
82
|
+
queryFn: () => orderApi.list(filters),
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// components/OrderList.tsx -- 只负责列表渲染
|
|
87
|
+
function OrderList() {
|
|
88
|
+
const { filters } = useOrderFilters();
|
|
89
|
+
const { data, isLoading, error } = useOrders(filters);
|
|
90
|
+
|
|
91
|
+
if (isLoading) return <OrderListSkeleton />;
|
|
92
|
+
if (error) return <ErrorState message={error.message} onRetry={refetch} />;
|
|
93
|
+
if (!data?.items.length) return <EmptyState message="No orders found" />;
|
|
94
|
+
|
|
95
|
+
return (
|
|
96
|
+
<div>
|
|
97
|
+
{data.items.map((order) => (
|
|
98
|
+
<OrderCard key={order.id} order={order} />
|
|
99
|
+
))}
|
|
100
|
+
<Pagination total={data.total} page={data.page} />
|
|
101
|
+
</div>
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### 检测方法
|
|
107
|
+
- 组件文件行数 > 200 行。
|
|
108
|
+
- 单个组件的 `useState` 调用 > 5 个。
|
|
109
|
+
- 组件内包含 `fetch` / `axios` 直接调用。
|
|
110
|
+
- 组件内包含复杂的计算逻辑(应提取为 hook 或 util)。
|
|
111
|
+
|
|
112
|
+
### 修复步骤
|
|
113
|
+
1. 将数据获取逻辑提取为自定义 Hook(`useOrders`、`useUser`)。
|
|
114
|
+
2. 将业务逻辑提取为独立函数或 Hook。
|
|
115
|
+
3. 将 UI 拆分为展示组件(Presentational)和容器组件(Container)。
|
|
116
|
+
4. 每个组件只做一件事,文件 <= 150 行。
|
|
117
|
+
|
|
118
|
+
### Agent Checklist
|
|
119
|
+
- [ ] 组件文件行数 <= 200
|
|
120
|
+
- [ ] `useState` 调用 <= 5 个(否则用 `useReducer` 或提取 Hook)
|
|
121
|
+
- [ ] 组件内无 `fetch` / `axios` 直接调用
|
|
122
|
+
- [ ] 有独立的自定义 Hook 管理数据获取
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## 2. 依赖堆叠(Dependency Bloat)
|
|
127
|
+
|
|
128
|
+
### 描述
|
|
129
|
+
不加节制地引入第三方依赖,每个小功能都用一个库(日期格式化用 moment.js、数组操作用 lodash 全量导入、图标用完整 icon 库),导致 bundle 体积膨胀,首屏加载慢。
|
|
130
|
+
|
|
131
|
+
### 错误示例
|
|
132
|
+
```json
|
|
133
|
+
{
|
|
134
|
+
"dependencies": {
|
|
135
|
+
"moment": "^2.29.4", // 300KB,只用了 format
|
|
136
|
+
"lodash": "^4.17.21", // 70KB,只用了 debounce
|
|
137
|
+
"antd": "^5.0.0", // 全量导入
|
|
138
|
+
"@fortawesome/fontawesome-free": "^6.0.0", // 全量图标
|
|
139
|
+
"jquery": "^3.7.0", // React 项目不需要
|
|
140
|
+
"axios": "^1.6.0", // fetch 就够了
|
|
141
|
+
"classnames": "^2.3.0", // 一行代码能替代
|
|
142
|
+
"uuid": "^9.0.0" // crypto.randomUUID() 已原生支持
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
```javascript
|
|
148
|
+
// 全量导入 -- 打包全部模块
|
|
149
|
+
import _ from "lodash";
|
|
150
|
+
import moment from "moment";
|
|
151
|
+
import { Button, Table, Form, Input, Modal, Select, DatePicker } from "antd";
|
|
152
|
+
|
|
153
|
+
const formatted = moment().format("YYYY-MM-DD");
|
|
154
|
+
const debounced = _.debounce(handler, 300);
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### 正确示例
|
|
158
|
+
```json
|
|
159
|
+
{
|
|
160
|
+
"dependencies": {
|
|
161
|
+
"date-fns": "^3.0.0" // 按需导入,tree-shakeable
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
```javascript
|
|
167
|
+
// 按需导入
|
|
168
|
+
import { format } from "date-fns";
|
|
169
|
+
import debounce from "lodash/debounce"; // 只导入需要的函数
|
|
170
|
+
|
|
171
|
+
const formatted = format(new Date(), "yyyy-MM-dd");
|
|
172
|
+
const debounced = debounce(handler, 300);
|
|
173
|
+
|
|
174
|
+
// 原生替代
|
|
175
|
+
const id = crypto.randomUUID(); // 替代 uuid
|
|
176
|
+
const classes = [base, active && "active"].filter(Boolean).join(" "); // 替代 classnames
|
|
177
|
+
|
|
178
|
+
// 动态导入大型组件
|
|
179
|
+
const HeavyChart = lazy(() => import("./HeavyChart"));
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### 检测方法
|
|
183
|
+
- `npm run build` 后 bundle 体积 > 500KB(gzipped)。
|
|
184
|
+
- `npx bundlephobia` 或 `source-map-explorer` 分析依赖体积。
|
|
185
|
+
- `package.json` 中 dependencies 数量 > 30。
|
|
186
|
+
- 存在已有原生替代的库(moment -> date-fns/dayjs、lodash -> 原生 ES6)。
|
|
187
|
+
|
|
188
|
+
### 修复步骤
|
|
189
|
+
1. 使用 `source-map-explorer` 或 `webpack-bundle-analyzer` 分析 bundle 组成。
|
|
190
|
+
2. 删除未使用的依赖(`npx depcheck`)。
|
|
191
|
+
3. 将全量导入改为按需导入(`lodash/debounce` 而非 `lodash`)。
|
|
192
|
+
4. 用原生 API 替代小型工具库。
|
|
193
|
+
5. 大型组件使用 `React.lazy` 动态加载。
|
|
194
|
+
6. 设置 bundle 体积预算,CI 中检查。
|
|
195
|
+
|
|
196
|
+
### Agent Checklist
|
|
197
|
+
- [ ] Bundle 体积 < 500KB gzipped
|
|
198
|
+
- [ ] 无全量导入的大型库(lodash / moment / antd)
|
|
199
|
+
- [ ] 无原生可替代的小工具库
|
|
200
|
+
- [ ] 大型组件使用动态加载
|
|
201
|
+
- [ ] CI 包含 bundle 体积检查
|
|
202
|
+
|
|
203
|
+
---
|
|
204
|
+
|
|
205
|
+
## 3. 状态管理混乱(State Management Chaos)
|
|
206
|
+
|
|
207
|
+
### 描述
|
|
208
|
+
全局状态和局部状态边界不清,所有数据都放在全局 Store 中(Redux / Vuex),或者 prop drilling 层层传递,或者状态同时存在于多个源(URL、Store、组件本地)导致不一致。
|
|
209
|
+
|
|
210
|
+
### 错误示例
|
|
211
|
+
```tsx
|
|
212
|
+
// 所有东西都放全局 Store
|
|
213
|
+
const store = createStore({
|
|
214
|
+
user: null,
|
|
215
|
+
orders: [],
|
|
216
|
+
products: [],
|
|
217
|
+
cart: [],
|
|
218
|
+
theme: "light",
|
|
219
|
+
language: "zh",
|
|
220
|
+
modalVisible: false, // UI 状态不应全局化
|
|
221
|
+
formData: {}, // 表单状态不应全局化
|
|
222
|
+
tooltipPosition: { x: 0 }, // 临时 UI 状态不应全局化
|
|
223
|
+
searchQuery: "", // 应在 URL 中
|
|
224
|
+
currentPage: 1, // 应在 URL 中
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
// Prop drilling -- 5 层传递
|
|
228
|
+
function App() {
|
|
229
|
+
const [user, setUser] = useState(null);
|
|
230
|
+
return <Layout user={user} setUser={setUser}>
|
|
231
|
+
<Sidebar user={user}>
|
|
232
|
+
<Navigation user={user}>
|
|
233
|
+
<UserMenu user={user} onLogout={() => setUser(null)} />
|
|
234
|
+
</Navigation>
|
|
235
|
+
</Sidebar>
|
|
236
|
+
</Layout>;
|
|
237
|
+
}
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
### 正确示例
|
|
241
|
+
```tsx
|
|
242
|
+
// 状态分层管理
|
|
243
|
+
|
|
244
|
+
// 1. 服务端状态 -> React Query / SWR
|
|
245
|
+
function useUser() {
|
|
246
|
+
return useQuery({ queryKey: ["user"], queryFn: userApi.getCurrent });
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function useOrders(filters: OrderFilters) {
|
|
250
|
+
return useQuery({ queryKey: ["orders", filters], queryFn: () => orderApi.list(filters) });
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// 2. URL 状态 -> useSearchParams
|
|
254
|
+
function useOrderFilters() {
|
|
255
|
+
const [searchParams, setSearchParams] = useSearchParams();
|
|
256
|
+
return {
|
|
257
|
+
page: Number(searchParams.get("page")) || 1,
|
|
258
|
+
status: searchParams.get("status"),
|
|
259
|
+
setPage: (p: number) => setSearchParams({ ...Object.fromEntries(searchParams), page: String(p) }),
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// 3. 全局客户端状态 -> Zustand(精简)
|
|
264
|
+
const useAuthStore = create<AuthState>((set) => ({
|
|
265
|
+
token: null,
|
|
266
|
+
setToken: (token) => set({ token }),
|
|
267
|
+
logout: () => set({ token: null }),
|
|
268
|
+
}));
|
|
269
|
+
|
|
270
|
+
// 4. 局部 UI 状态 -> useState / useReducer
|
|
271
|
+
function OrderDetailModal({ orderId }: { orderId: string }) {
|
|
272
|
+
const [isOpen, setIsOpen] = useState(false); // 局部 UI 状态
|
|
273
|
+
const { data: order } = useOrder(orderId);
|
|
274
|
+
// ...
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// 5. 跨组件共享(无需全局)-> Context
|
|
278
|
+
const ThemeContext = createContext<Theme>("light");
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
### 检测方法
|
|
282
|
+
- 全局 Store 包含 UI 临时状态(modal / tooltip / form)。
|
|
283
|
+
- 同一数据存在于多个源(Store + URL + 组件内)。
|
|
284
|
+
- Props 传递层级 > 3。
|
|
285
|
+
- 修改一个状态触发大范围不相关的组件重渲染。
|
|
286
|
+
|
|
287
|
+
### 修复步骤
|
|
288
|
+
1. 分类所有状态:服务端缓存 / URL / 全局客户端 / 局部 UI。
|
|
289
|
+
2. 服务端数据迁移到 React Query / SWR。
|
|
290
|
+
3. 筛选、分页、搜索参数迁移到 URL。
|
|
291
|
+
4. 全局 Store 只保留认证、主题等真正全局的状态。
|
|
292
|
+
5. UI 临时状态下沉到使用它的组件内。
|
|
293
|
+
|
|
294
|
+
### Agent Checklist
|
|
295
|
+
- [ ] 全局 Store 只包含认证 / 主题等全局状态
|
|
296
|
+
- [ ] 服务端数据使用 React Query / SWR
|
|
297
|
+
- [ ] 筛选 / 分页参数在 URL 中
|
|
298
|
+
- [ ] Props 传递层级 <= 3
|
|
299
|
+
- [ ] 表单 / Modal 状态在组件内局部管理
|
|
300
|
+
|
|
301
|
+
---
|
|
302
|
+
|
|
303
|
+
## 4. 只做正常态(Missing Error & Loading States)
|
|
304
|
+
|
|
305
|
+
### 描述
|
|
306
|
+
组件只处理数据正常加载成功的场景,不处理加载中、加载失败、空数据、部分失败等状态,导致用户体验差(白屏、卡死、数据消失无提示)。
|
|
307
|
+
|
|
308
|
+
### 错误示例
|
|
309
|
+
```tsx
|
|
310
|
+
function UserProfile({ userId }) {
|
|
311
|
+
const [user, setUser] = useState(null);
|
|
312
|
+
|
|
313
|
+
useEffect(() => {
|
|
314
|
+
fetch(`/api/users/${userId}`)
|
|
315
|
+
.then((res) => res.json())
|
|
316
|
+
.then(setUser);
|
|
317
|
+
// 无 loading 状态
|
|
318
|
+
// 无 error 处理
|
|
319
|
+
// 无 404 处理
|
|
320
|
+
}, [userId]);
|
|
321
|
+
|
|
322
|
+
// user 为 null 时直接报错:Cannot read property 'name' of null
|
|
323
|
+
return (
|
|
324
|
+
<div>
|
|
325
|
+
<h1>{user.name}</h1>
|
|
326
|
+
<p>{user.email}</p>
|
|
327
|
+
</div>
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
### 正确示例
|
|
333
|
+
```tsx
|
|
334
|
+
function UserProfile({ userId }: { userId: string }) {
|
|
335
|
+
const { data: user, isLoading, error, refetch } = useUser(userId);
|
|
336
|
+
|
|
337
|
+
if (isLoading) {
|
|
338
|
+
return <ProfileSkeleton />; // 骨架屏,不是 spinner
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
if (error) {
|
|
342
|
+
if (error.status === 404) {
|
|
343
|
+
return <NotFoundState message="User not found" />;
|
|
344
|
+
}
|
|
345
|
+
return (
|
|
346
|
+
<ErrorState
|
|
347
|
+
title="Failed to load profile"
|
|
348
|
+
message={error.message}
|
|
349
|
+
onRetry={refetch}
|
|
350
|
+
/>
|
|
351
|
+
);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
if (!user) {
|
|
355
|
+
return <EmptyState message="No user data available" />;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
return (
|
|
359
|
+
<div>
|
|
360
|
+
<h1>{user.name}</h1>
|
|
361
|
+
<p>{user.email}</p>
|
|
362
|
+
{user.orders?.length ? (
|
|
363
|
+
<OrderList orders={user.orders} />
|
|
364
|
+
) : (
|
|
365
|
+
<EmptyState message="No orders yet" />
|
|
366
|
+
)}
|
|
367
|
+
</div>
|
|
368
|
+
);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
// 全局错误边界
|
|
372
|
+
class ErrorBoundary extends React.Component {
|
|
373
|
+
state = { hasError: false, error: null };
|
|
374
|
+
|
|
375
|
+
static getDerivedStateFromError(error) {
|
|
376
|
+
return { hasError: true, error };
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
componentDidCatch(error, errorInfo) {
|
|
380
|
+
errorReporter.capture(error, errorInfo);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
render() {
|
|
384
|
+
if (this.state.hasError) {
|
|
385
|
+
return <FatalErrorPage error={this.state.error} onReset={() => this.setState({ hasError: false })} />;
|
|
386
|
+
}
|
|
387
|
+
return this.props.children;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
### 检测方法
|
|
393
|
+
- 组件直接访问 `data.property` 无空值检查。
|
|
394
|
+
- `useEffect` 中的 `fetch` 无 `.catch()` 处理。
|
|
395
|
+
- 无 `<ErrorBoundary>` 包裹。
|
|
396
|
+
- 页面加载时出现白屏或 console 报错但 UI 无提示。
|
|
397
|
+
|
|
398
|
+
### 修复步骤
|
|
399
|
+
1. 为每个数据获取组件添加 Loading / Error / Empty 三个状态。
|
|
400
|
+
2. 使用 React Query / SWR 统一管理数据获取状态。
|
|
401
|
+
3. 使用骨架屏(Skeleton)替代 Spinner,提升感知性能。
|
|
402
|
+
4. 添加全局 ErrorBoundary 捕获未处理的渲染错误。
|
|
403
|
+
5. 创建可复用的 `<ErrorState>` / `<EmptyState>` / `<Skeleton>` 组件。
|
|
404
|
+
|
|
405
|
+
### Agent Checklist
|
|
406
|
+
- [ ] 每个数据组件有 Loading / Error / Empty 状态
|
|
407
|
+
- [ ] 无未处理的 fetch 错误
|
|
408
|
+
- [ ] 有全局 ErrorBoundary
|
|
409
|
+
- [ ] 使用骨架屏而非 Spinner
|
|
410
|
+
- [ ] 空数据有友好提示
|
|
411
|
+
|
|
412
|
+
---
|
|
413
|
+
|
|
414
|
+
## 5. 性能无预算(Missing Performance Budget)
|
|
415
|
+
|
|
416
|
+
### 描述
|
|
417
|
+
无首屏加载时间目标、无 bundle 体积限制、无渲染性能基线。每次迭代都可能引入性能退化,直到用户投诉才发现。
|
|
418
|
+
|
|
419
|
+
### 错误示例
|
|
420
|
+
```tsx
|
|
421
|
+
// 不必要的重渲染
|
|
422
|
+
function ProductList({ products, onSelect }) {
|
|
423
|
+
// 每次父组件渲染都创建新的 handler,导致所有子组件重渲染
|
|
424
|
+
return products.map((p) => (
|
|
425
|
+
<ProductCard
|
|
426
|
+
key={p.id}
|
|
427
|
+
product={p}
|
|
428
|
+
onClick={() => onSelect(p.id)} // 每次创建新函数
|
|
429
|
+
style={{ margin: "10px" }} // 每次创建新对象
|
|
430
|
+
/>
|
|
431
|
+
));
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
// 未优化的大列表
|
|
435
|
+
function ChatMessages({ messages }) {
|
|
436
|
+
// 10000 条消息全部渲染
|
|
437
|
+
return messages.map((msg) => <Message key={msg.id} data={msg} />);
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
// 阻塞主线程的计算
|
|
441
|
+
function Dashboard({ data }) {
|
|
442
|
+
// 每次渲染都执行昂贵的计算
|
|
443
|
+
const stats = data.reduce((acc, item) => {
|
|
444
|
+
// 复杂统计计算...
|
|
445
|
+
}, {});
|
|
446
|
+
return <StatsPanel stats={stats} />;
|
|
447
|
+
}
|
|
448
|
+
```
|
|
449
|
+
|
|
450
|
+
### 正确示例
|
|
451
|
+
```tsx
|
|
452
|
+
// 优化重渲染
|
|
453
|
+
const ProductCard = memo(function ProductCard({ product, onSelect }) {
|
|
454
|
+
return <div onClick={() => onSelect(product.id)}>{product.name}</div>;
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
function ProductList({ products, onSelect }) {
|
|
458
|
+
const handleSelect = useCallback((id: string) => onSelect(id), [onSelect]);
|
|
459
|
+
|
|
460
|
+
return products.map((p) => (
|
|
461
|
+
<ProductCard key={p.id} product={p} onSelect={handleSelect} />
|
|
462
|
+
));
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
// 虚拟滚动大列表
|
|
466
|
+
import { useVirtualizer } from "@tanstack/react-virtual";
|
|
467
|
+
|
|
468
|
+
function ChatMessages({ messages }) {
|
|
469
|
+
const parentRef = useRef(null);
|
|
470
|
+
const virtualizer = useVirtualizer({
|
|
471
|
+
count: messages.length,
|
|
472
|
+
getScrollElement: () => parentRef.current,
|
|
473
|
+
estimateSize: () => 60,
|
|
474
|
+
});
|
|
475
|
+
|
|
476
|
+
return (
|
|
477
|
+
<div ref={parentRef} style={{ height: "600px", overflow: "auto" }}>
|
|
478
|
+
<div style={{ height: virtualizer.getTotalSize() }}>
|
|
479
|
+
{virtualizer.getVirtualItems().map((virtualItem) => (
|
|
480
|
+
<Message key={virtualItem.key} data={messages[virtualItem.index]} />
|
|
481
|
+
))}
|
|
482
|
+
</div>
|
|
483
|
+
</div>
|
|
484
|
+
);
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
// 缓存昂贵计算
|
|
488
|
+
function Dashboard({ data }) {
|
|
489
|
+
const stats = useMemo(() => computeStats(data), [data]);
|
|
490
|
+
return <StatsPanel stats={stats} />;
|
|
491
|
+
}
|
|
492
|
+
```
|
|
493
|
+
|
|
494
|
+
```javascript
|
|
495
|
+
// vite.config.ts -- 性能预算
|
|
496
|
+
export default defineConfig({
|
|
497
|
+
build: {
|
|
498
|
+
rollupOptions: {
|
|
499
|
+
output: {
|
|
500
|
+
manualChunks: {
|
|
501
|
+
vendor: ["react", "react-dom"],
|
|
502
|
+
ui: ["@radix-ui/react-dialog", "@radix-ui/react-dropdown"],
|
|
503
|
+
},
|
|
504
|
+
},
|
|
505
|
+
},
|
|
506
|
+
chunkSizeWarningLimit: 250, // KB
|
|
507
|
+
},
|
|
508
|
+
});
|
|
509
|
+
```
|
|
510
|
+
|
|
511
|
+
### 检测方法
|
|
512
|
+
- Lighthouse Performance 评分 < 90。
|
|
513
|
+
- LCP (Largest Contentful Paint) > 2.5 秒。
|
|
514
|
+
- React DevTools Profiler 显示不必要的重渲染。
|
|
515
|
+
- 列表超过 100 条数据时出现明显卡顿。
|
|
516
|
+
- `vite build` 后单个 chunk > 250KB。
|
|
517
|
+
|
|
518
|
+
### 修复步骤
|
|
519
|
+
1. 设定性能预算:LCP < 2.5s、FID < 100ms、CLS < 0.1、bundle < 500KB gzipped。
|
|
520
|
+
2. 使用 `React.memo` / `useMemo` / `useCallback` 减少不必要的重渲染。
|
|
521
|
+
3. 列表超过 50 条使用虚拟滚动。
|
|
522
|
+
4. 重型计算使用 Web Worker。
|
|
523
|
+
5. 在 CI 中集成 Lighthouse CI,设置性能阈值。
|
|
524
|
+
|
|
525
|
+
### Agent Checklist
|
|
526
|
+
- [ ] Lighthouse Performance >= 90
|
|
527
|
+
- [ ] LCP < 2.5s
|
|
528
|
+
- [ ] Bundle 主包 < 250KB gzipped
|
|
529
|
+
- [ ] 大列表使用虚拟滚动
|
|
530
|
+
- [ ] CI 包含 Lighthouse 性能检查
|
|
531
|
+
|
|
532
|
+
---
|
|
533
|
+
|
|
534
|
+
## 6. 无可访问性(Missing Accessibility)
|
|
535
|
+
|
|
536
|
+
### 描述
|
|
537
|
+
完全忽略 Web 可访问性(a11y),自定义控件无键盘操作、无 ARIA 标签、无语义化 HTML、颜色对比度不足。导致残障用户无法使用,且在部分地区可能面临法规合规风险。
|
|
538
|
+
|
|
539
|
+
### 错误示例
|
|
540
|
+
```tsx
|
|
541
|
+
// 无语义化:全部用 div
|
|
542
|
+
<div onClick={handleClick}>Submit</div> // 不是 button
|
|
543
|
+
<div className="nav"> // 不是 nav
|
|
544
|
+
<div onClick={() => navigate("/")}>Home</div> // 不是 a/Link
|
|
545
|
+
</div>
|
|
546
|
+
|
|
547
|
+
// 自定义下拉菜单:无键盘支持、无 ARIA
|
|
548
|
+
<div className="dropdown" onClick={toggle}>
|
|
549
|
+
<div className="selected">{value}</div>
|
|
550
|
+
{isOpen && (
|
|
551
|
+
<div className="options">
|
|
552
|
+
{options.map((opt) => (
|
|
553
|
+
<div key={opt} onClick={() => select(opt)}>{opt}</div>
|
|
554
|
+
))}
|
|
555
|
+
</div>
|
|
556
|
+
)}
|
|
557
|
+
</div>
|
|
558
|
+
|
|
559
|
+
// 图片无 alt
|
|
560
|
+
<img src={user.avatar} />
|
|
561
|
+
|
|
562
|
+
// 表单无 label
|
|
563
|
+
<input type="email" placeholder="Enter email" />
|
|
564
|
+
```
|
|
565
|
+
|
|
566
|
+
### 正确示例
|
|
567
|
+
```tsx
|
|
568
|
+
// 语义化 HTML
|
|
569
|
+
<button type="button" onClick={handleClick}>Submit</button>
|
|
570
|
+
|
|
571
|
+
<nav aria-label="Main navigation">
|
|
572
|
+
<Link to="/">Home</Link>
|
|
573
|
+
<Link to="/orders">Orders</Link>
|
|
574
|
+
</nav>
|
|
575
|
+
|
|
576
|
+
// 可访问的下拉菜单(使用 Radix UI 或 Headless UI)
|
|
577
|
+
import * as Select from "@radix-ui/react-select";
|
|
578
|
+
|
|
579
|
+
<Select.Root value={value} onValueChange={onChange}>
|
|
580
|
+
<Select.Trigger aria-label="Select status">
|
|
581
|
+
<Select.Value placeholder="Select..." />
|
|
582
|
+
</Select.Trigger>
|
|
583
|
+
<Select.Content>
|
|
584
|
+
{options.map((opt) => (
|
|
585
|
+
<Select.Item key={opt.value} value={opt.value}>
|
|
586
|
+
<Select.ItemText>{opt.label}</Select.ItemText>
|
|
587
|
+
</Select.Item>
|
|
588
|
+
))}
|
|
589
|
+
</Select.Content>
|
|
590
|
+
</Select.Root>
|
|
591
|
+
|
|
592
|
+
// 图片有 alt
|
|
593
|
+
<img src={user.avatar} alt={`${user.name}'s avatar`} />
|
|
594
|
+
|
|
595
|
+
// 表单有 label
|
|
596
|
+
<label htmlFor="email">Email address</label>
|
|
597
|
+
<input id="email" type="email" aria-describedby="email-hint" />
|
|
598
|
+
<span id="email-hint">We will never share your email.</span>
|
|
599
|
+
```
|
|
600
|
+
|
|
601
|
+
### 检测方法
|
|
602
|
+
- `eslint-plugin-jsx-a11y` 报告 a11y 违规。
|
|
603
|
+
- Lighthouse Accessibility 评分 < 90。
|
|
604
|
+
- 键盘 Tab 无法导航到所有交互元素。
|
|
605
|
+
- `axe-core` 浏览器扩展报告问题。
|
|
606
|
+
- `<img>` 标签无 `alt` 属性。
|
|
607
|
+
|
|
608
|
+
### 修复步骤
|
|
609
|
+
1. 启用 `eslint-plugin-jsx-a11y` 规则。
|
|
610
|
+
2. 使用语义化 HTML(`button`、`nav`、`main`、`article`、`section`)。
|
|
611
|
+
3. 自定义控件使用 Radix UI / Headless UI 等无障碍组件库。
|
|
612
|
+
4. 所有图片添加有意义的 `alt` 文本。
|
|
613
|
+
5. 所有表单控件关联 `label`。
|
|
614
|
+
6. 验证键盘导航和屏幕阅读器体验。
|
|
615
|
+
|
|
616
|
+
### Agent Checklist
|
|
617
|
+
- [ ] Lighthouse Accessibility >= 90
|
|
618
|
+
- [ ] 无 `<div onClick>` 替代 `<button>`
|
|
619
|
+
- [ ] 所有 `<img>` 有 `alt` 属性
|
|
620
|
+
- [ ] 所有表单控件有 `<label>`
|
|
621
|
+
- [ ] eslint-plugin-jsx-a11y 无错误
|
|
622
|
+
|
|
623
|
+
---
|
|
624
|
+
|
|
625
|
+
## 全局 Agent Checklist
|
|
626
|
+
|
|
627
|
+
| 检查项 | 阈值 | 工具 |
|
|
628
|
+
|--------|------|------|
|
|
629
|
+
| 组件文件行数 | <= 200 | ESLint / Code Review |
|
|
630
|
+
| Bundle 体积 | < 500KB gzipped | `source-map-explorer` |
|
|
631
|
+
| 全局 Store 状态数 | <= 10 | Code Review |
|
|
632
|
+
| Loading/Error/Empty 覆盖 | 100% 数据组件 | Code Review |
|
|
633
|
+
| Lighthouse Performance | >= 90 | Lighthouse CI |
|
|
634
|
+
| Lighthouse Accessibility | >= 90 | Lighthouse CI |
|
|
635
|
+
| a11y 违规 | 0 个 | `eslint-plugin-jsx-a11y` / `axe-core` |
|