@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,686 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: architecture-antipatterns
|
|
3
|
+
title: 架构反模式指南
|
|
4
|
+
domain: development
|
|
5
|
+
category: 04-antipatterns
|
|
6
|
+
difficulty: intermediate
|
|
7
|
+
tags: [agent, antipatterns, architecture, ball, bounded, checklist, context, dependency]
|
|
8
|
+
quality_score: 70
|
|
9
|
+
last_updated: 2026-06-15
|
|
10
|
+
---
|
|
11
|
+
# 架构反模式指南
|
|
12
|
+
|
|
13
|
+
> 适用范围:微服务 / 单体 / 模块化单体 / 事件驱动架构
|
|
14
|
+
> 约束级别:SHALL(必须在架构评审阶段拦截)
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## 1. 分布式单体(Distributed Monolith)
|
|
19
|
+
|
|
20
|
+
### 描述
|
|
21
|
+
名义上拆分为多个微服务,但服务间通过同步 RPC 紧密耦合,共享数据库,必须同时部署。具备了分布式系统的所有复杂性(网络延迟、部分失败、数据一致性),却没有获得微服务的任何好处(独立部署、独立扩展、技术多样性)。
|
|
22
|
+
|
|
23
|
+
### 错误示例
|
|
24
|
+
```python
|
|
25
|
+
# order-service 同步调用 user-service、inventory-service、payment-service
|
|
26
|
+
# 任何一个服务宕机,整个下单流程失败
|
|
27
|
+
|
|
28
|
+
class OrderService:
|
|
29
|
+
def create_order(self, user_id: str, items: list) -> Order:
|
|
30
|
+
# 同步 RPC 链:order -> user -> inventory -> payment -> notification
|
|
31
|
+
user = requests.get(f"{USER_SERVICE}/users/{user_id}").json() # 阻塞
|
|
32
|
+
for item in items:
|
|
33
|
+
stock = requests.get( # 阻塞
|
|
34
|
+
f"{INVENTORY_SERVICE}/stock/{item['product_id']}"
|
|
35
|
+
).json()
|
|
36
|
+
if stock['quantity'] < item['qty']:
|
|
37
|
+
raise InsufficientStockError(item['product_id'])
|
|
38
|
+
|
|
39
|
+
order = self._save_order(user_id, items)
|
|
40
|
+
|
|
41
|
+
payment = requests.post(f"{PAYMENT_SERVICE}/charge", json={ # 阻塞
|
|
42
|
+
"order_id": order.id, "amount": order.total
|
|
43
|
+
}).json()
|
|
44
|
+
|
|
45
|
+
requests.post(f"{NOTIFICATION_SERVICE}/email", json={ # 阻塞
|
|
46
|
+
"to": user['email'], "template": "order_created"
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
return order
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
```yaml
|
|
53
|
+
# 所有服务共享同一个数据库 -- 本质还是单体
|
|
54
|
+
# docker-compose.yml
|
|
55
|
+
services:
|
|
56
|
+
user-service:
|
|
57
|
+
environment:
|
|
58
|
+
DATABASE_URL: postgres://shared-db:5432/main_db
|
|
59
|
+
order-service:
|
|
60
|
+
environment:
|
|
61
|
+
DATABASE_URL: postgres://shared-db:5432/main_db # 同一个库!
|
|
62
|
+
payment-service:
|
|
63
|
+
environment:
|
|
64
|
+
DATABASE_URL: postgres://shared-db:5432/main_db # 同一个库!
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### 正确示例
|
|
68
|
+
```python
|
|
69
|
+
# 使用事件驱动解耦关键路径
|
|
70
|
+
class OrderService:
|
|
71
|
+
def __init__(self, event_bus: EventBus, order_repo: OrderRepository):
|
|
72
|
+
self._event_bus = event_bus
|
|
73
|
+
self._repo = order_repo
|
|
74
|
+
|
|
75
|
+
async def create_order(self, user_id: str, items: list) -> Order:
|
|
76
|
+
# 只做最少的同步校验
|
|
77
|
+
order = self._repo.create(user_id=user_id, items=items, status="pending")
|
|
78
|
+
|
|
79
|
+
# 通过事件异步编排后续流程
|
|
80
|
+
await self._event_bus.publish(OrderCreatedEvent(
|
|
81
|
+
order_id=order.id,
|
|
82
|
+
user_id=user_id,
|
|
83
|
+
items=items,
|
|
84
|
+
total=order.total,
|
|
85
|
+
))
|
|
86
|
+
return order
|
|
87
|
+
|
|
88
|
+
# inventory-service 订阅事件,独立处理
|
|
89
|
+
class InventoryEventHandler:
|
|
90
|
+
async def handle_order_created(self, event: OrderCreatedEvent):
|
|
91
|
+
try:
|
|
92
|
+
self._reserve_stock(event.items)
|
|
93
|
+
await self._event_bus.publish(StockReservedEvent(order_id=event.order_id))
|
|
94
|
+
except InsufficientStockError:
|
|
95
|
+
await self._event_bus.publish(StockReservationFailedEvent(
|
|
96
|
+
order_id=event.order_id, reason="insufficient_stock"
|
|
97
|
+
))
|
|
98
|
+
|
|
99
|
+
# 每个服务有自己的数据库
|
|
100
|
+
# docker-compose.yml
|
|
101
|
+
services:
|
|
102
|
+
user-service:
|
|
103
|
+
environment:
|
|
104
|
+
DATABASE_URL: postgres://user-db:5432/users
|
|
105
|
+
order-service:
|
|
106
|
+
environment:
|
|
107
|
+
DATABASE_URL: postgres://order-db:5432/orders
|
|
108
|
+
payment-service:
|
|
109
|
+
environment:
|
|
110
|
+
DATABASE_URL: postgres://payment-db:5432/payments
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### 检测方法
|
|
114
|
+
- 部署时需要多个服务同时发版才能工作。
|
|
115
|
+
- 服务间调用链深度 > 3(A -> B -> C -> D)。
|
|
116
|
+
- 多个服务连接同一个数据库实例。
|
|
117
|
+
- 单个服务宕机导致全链路不可用。
|
|
118
|
+
- 服务间 RPC 调用无超时、无熔断、无降级。
|
|
119
|
+
|
|
120
|
+
### 修复步骤
|
|
121
|
+
1. 绘制服务依赖图,识别同步调用链。
|
|
122
|
+
2. 将非关键路径(通知、日志、统计)改为异步事件。
|
|
123
|
+
3. 为每个服务建立独立数据库(Database per Service)。
|
|
124
|
+
4. 引入消息队列(Kafka / RabbitMQ / NATS)作为服务间通信骨干。
|
|
125
|
+
5. 对仍需同步调用的场景,添加超时、熔断、降级策略。
|
|
126
|
+
6. 实现 Saga 模式处理跨服务的分布式事务。
|
|
127
|
+
|
|
128
|
+
### Agent Checklist
|
|
129
|
+
- [ ] 每个服务有独立数据库
|
|
130
|
+
- [ ] 服务间同步调用链深度 <= 2
|
|
131
|
+
- [ ] 非关键路径使用异步事件
|
|
132
|
+
- [ ] 同步 RPC 有超时 + 熔断 + 降级
|
|
133
|
+
- [ ] 可独立部署和扩展单个服务
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
## 2. 大泥球(Big Ball of Mud)
|
|
138
|
+
|
|
139
|
+
### 描述
|
|
140
|
+
系统没有明确的架构,代码随意组织,模块间无边界,任何代码可以调用任何代码。随着功能增长,系统变得越来越难以理解、修改和测试。通常是长期缺乏架构治理的结果。
|
|
141
|
+
|
|
142
|
+
### 错误示例
|
|
143
|
+
```
|
|
144
|
+
# 项目结构:所有代码扁平堆放在一起
|
|
145
|
+
src/
|
|
146
|
+
├── utils.py # 3000 行的"工具"文件
|
|
147
|
+
├── helpers.py # 2000 行的"帮助"文件
|
|
148
|
+
├── models.py # 所有表模型混在一个文件
|
|
149
|
+
├── views.py # 所有 API 混在一个文件
|
|
150
|
+
├── services.py # 所有业务逻辑混在一个文件
|
|
151
|
+
├── tasks.py # 所有异步任务混在一个文件
|
|
152
|
+
└── constants.py # 所有常量混在一个文件
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
```python
|
|
156
|
+
# utils.py -- 什么都往里塞
|
|
157
|
+
def send_email(to, subject, body): ...
|
|
158
|
+
def calculate_tax(amount): ...
|
|
159
|
+
def parse_csv(file_path): ...
|
|
160
|
+
def resize_image(image, width): ...
|
|
161
|
+
def validate_credit_card(number): ...
|
|
162
|
+
def generate_report(data): ...
|
|
163
|
+
def encrypt_password(password): ...
|
|
164
|
+
def format_currency(amount, locale): ...
|
|
165
|
+
# ... 300 个互不相关的函数
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### 正确示例
|
|
169
|
+
```
|
|
170
|
+
# 按业务域组织的模块化结构
|
|
171
|
+
src/
|
|
172
|
+
├── users/
|
|
173
|
+
│ ├── __init__.py
|
|
174
|
+
│ ├── models.py # User、UserProfile
|
|
175
|
+
│ ├── repository.py # UserRepository
|
|
176
|
+
│ ├── service.py # UserService
|
|
177
|
+
│ ├── api.py # /api/v1/users 路由
|
|
178
|
+
│ └── tests/
|
|
179
|
+
│ ├── test_service.py
|
|
180
|
+
│ └── test_api.py
|
|
181
|
+
├── orders/
|
|
182
|
+
│ ├── __init__.py
|
|
183
|
+
│ ├── models.py # Order、OrderItem
|
|
184
|
+
│ ├── repository.py
|
|
185
|
+
│ ├── service.py
|
|
186
|
+
│ ├── api.py
|
|
187
|
+
│ ├── events.py # OrderCreated、OrderPaid
|
|
188
|
+
│ └── tests/
|
|
189
|
+
├── payments/
|
|
190
|
+
│ ├── __init__.py
|
|
191
|
+
│ ├── models.py
|
|
192
|
+
│ ├── gateway.py # 支付网关抽象
|
|
193
|
+
│ ├── service.py
|
|
194
|
+
│ └── tests/
|
|
195
|
+
├── shared/
|
|
196
|
+
│ ├── auth/ # 认证模块
|
|
197
|
+
│ ├── email/ # 邮件模块
|
|
198
|
+
│ └── storage/ # 文件存储模块
|
|
199
|
+
└── infrastructure/
|
|
200
|
+
├── database.py # 数据库连接
|
|
201
|
+
├── cache.py # 缓存配置
|
|
202
|
+
└── message_bus.py # 消息队列
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
```python
|
|
206
|
+
# 明确的模块边界:模块间通过接口通信
|
|
207
|
+
# orders/service.py
|
|
208
|
+
class OrderService:
|
|
209
|
+
def __init__(
|
|
210
|
+
self,
|
|
211
|
+
order_repo: OrderRepository,
|
|
212
|
+
user_service: UserServiceInterface, # 接口,不是具体实现
|
|
213
|
+
payment_service: PaymentServiceInterface,
|
|
214
|
+
):
|
|
215
|
+
self._repo = order_repo
|
|
216
|
+
self._users = user_service
|
|
217
|
+
self._payments = payment_service
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
### 检测方法
|
|
221
|
+
- 单文件行数 > 1000 行。
|
|
222
|
+
- `utils.py` / `helpers.py` / `common.py` 文件存在且行数 > 500。
|
|
223
|
+
- 模块间存在双向 import。
|
|
224
|
+
- 无法用一句话描述一个模块的职责。
|
|
225
|
+
- `git log` 显示大部分 PR 都修改了同一组文件。
|
|
226
|
+
|
|
227
|
+
### 修复步骤
|
|
228
|
+
1. 梳理业务域,列出 3-7 个核心域(用户、订单、支付等)。
|
|
229
|
+
2. 按业务域创建目录结构,每个域包含 models / repository / service / api。
|
|
230
|
+
3. 将现有代码按业务域逐步迁移到对应目录。
|
|
231
|
+
4. 定义模块间的公开接口(`__init__.py` 只导出接口类)。
|
|
232
|
+
5. 使用 `import-linter` 或 `deptry` 强制模块间的依赖方向。
|
|
233
|
+
6. 每次迁移后运行全量测试确认行为不变。
|
|
234
|
+
|
|
235
|
+
### Agent Checklist
|
|
236
|
+
- [ ] 按业务域组织目录结构
|
|
237
|
+
- [ ] 单文件行数 <= 500
|
|
238
|
+
- [ ] 无 `utils.py` / `helpers.py` 万能文件
|
|
239
|
+
- [ ] 模块间无双向依赖
|
|
240
|
+
- [ ] 有 import lint 工具强制依赖方向
|
|
241
|
+
|
|
242
|
+
---
|
|
243
|
+
|
|
244
|
+
## 3. 金锤子(Golden Hammer)
|
|
245
|
+
|
|
246
|
+
### 描述
|
|
247
|
+
对所有问题都使用同一个技术方案,不考虑场景适配性。例如所有存储都用 MySQL、所有通信都用 REST、所有前端都用 React。导致在不适合的场景中勉强使用,增加了复杂度和维护成本。
|
|
248
|
+
|
|
249
|
+
### 错误示例
|
|
250
|
+
```python
|
|
251
|
+
# 所有数据都塞进 MySQL,包括日志、会话、搜索、缓存
|
|
252
|
+
|
|
253
|
+
# 用 MySQL 做缓存(应该用 Redis)
|
|
254
|
+
def get_cached_result(key):
|
|
255
|
+
row = db.execute("SELECT value FROM cache_table WHERE key = %s AND expires_at > NOW()", (key,))
|
|
256
|
+
return json.loads(row['value']) if row else None
|
|
257
|
+
|
|
258
|
+
# 用 MySQL 做全文搜索(应该用 Elasticsearch)
|
|
259
|
+
def search_products(query):
|
|
260
|
+
return db.execute(
|
|
261
|
+
"SELECT * FROM products WHERE name LIKE %s OR description LIKE %s",
|
|
262
|
+
(f"%{query}%", f"%{query}%")
|
|
263
|
+
) # 性能极差,不支持分词、相关度排序
|
|
264
|
+
|
|
265
|
+
# 用 MySQL 做消息队列(应该用 Kafka / RabbitMQ)
|
|
266
|
+
def publish_message(topic, payload):
|
|
267
|
+
db.execute(
|
|
268
|
+
"INSERT INTO message_queue (topic, payload, status) VALUES (%s, %s, 'pending')",
|
|
269
|
+
(topic, json.dumps(payload))
|
|
270
|
+
)
|
|
271
|
+
|
|
272
|
+
def consume_messages(topic):
|
|
273
|
+
while True:
|
|
274
|
+
rows = db.execute(
|
|
275
|
+
"SELECT * FROM message_queue WHERE topic = %s AND status = 'pending' "
|
|
276
|
+
"ORDER BY id LIMIT 10 FOR UPDATE SKIP LOCKED",
|
|
277
|
+
(topic,)
|
|
278
|
+
)
|
|
279
|
+
for row in rows:
|
|
280
|
+
process(row)
|
|
281
|
+
db.execute("UPDATE message_queue SET status = 'done' WHERE id = %s", (row['id'],))
|
|
282
|
+
time.sleep(1) # 轮询
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
### 正确示例
|
|
286
|
+
```python
|
|
287
|
+
# 根据场景选择合适的技术
|
|
288
|
+
|
|
289
|
+
# 结构化业务数据 -> PostgreSQL
|
|
290
|
+
class OrderRepository:
|
|
291
|
+
def __init__(self, db: AsyncSession):
|
|
292
|
+
self._db = db
|
|
293
|
+
|
|
294
|
+
# 缓存 -> Redis
|
|
295
|
+
class CacheService:
|
|
296
|
+
def __init__(self, redis: Redis):
|
|
297
|
+
self._redis = redis
|
|
298
|
+
|
|
299
|
+
async def get(self, key: str) -> str | None:
|
|
300
|
+
return await self._redis.get(key)
|
|
301
|
+
|
|
302
|
+
async def set(self, key: str, value: str, ttl: int = 300) -> None:
|
|
303
|
+
await self._redis.setex(key, ttl, value)
|
|
304
|
+
|
|
305
|
+
# 全文搜索 -> Elasticsearch
|
|
306
|
+
class ProductSearchService:
|
|
307
|
+
def __init__(self, es: AsyncElasticsearch):
|
|
308
|
+
self._es = es
|
|
309
|
+
|
|
310
|
+
async def search(self, query: str, page: int = 1, size: int = 20):
|
|
311
|
+
return await self._es.search(
|
|
312
|
+
index="products",
|
|
313
|
+
body={
|
|
314
|
+
"query": {"multi_match": {"query": query, "fields": ["name^3", "description"]}},
|
|
315
|
+
"from": (page - 1) * size,
|
|
316
|
+
"size": size,
|
|
317
|
+
},
|
|
318
|
+
)
|
|
319
|
+
|
|
320
|
+
# 异步消息 -> Kafka / RabbitMQ
|
|
321
|
+
class EventPublisher:
|
|
322
|
+
def __init__(self, producer: AIOKafkaProducer):
|
|
323
|
+
self._producer = producer
|
|
324
|
+
|
|
325
|
+
async def publish(self, topic: str, event: BaseEvent) -> None:
|
|
326
|
+
await self._producer.send_and_wait(
|
|
327
|
+
topic, value=event.model_dump_json().encode()
|
|
328
|
+
)
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
### 检测方法
|
|
332
|
+
- 同一个数据库承担了缓存、搜索、消息队列、会话管理等多种职责。
|
|
333
|
+
- 技术选型文档中只有一种方案,无对比分析。
|
|
334
|
+
- `LIKE '%query%'` 出现在搜索场景中。
|
|
335
|
+
- 数据库中存在名为 `cache_table`、`message_queue`、`sessions` 的表。
|
|
336
|
+
|
|
337
|
+
### 修复步骤
|
|
338
|
+
1. 列出系统中所有的数据访问模式(CRUD、缓存、搜索、消息、流处理)。
|
|
339
|
+
2. 为每种访问模式选择最适合的技术方案。
|
|
340
|
+
3. 制定技术选型决策记录(ADR),记录选型理由和替代方案。
|
|
341
|
+
4. 通过抽象层(Repository / Client 接口)隔离具体实现。
|
|
342
|
+
5. 逐步迁移,先迁移性能瓶颈最严重的场景。
|
|
343
|
+
|
|
344
|
+
### Agent Checklist
|
|
345
|
+
- [ ] 技术选型有 ADR 文档记录
|
|
346
|
+
- [ ] 缓存使用 Redis / Memcached
|
|
347
|
+
- [ ] 全文搜索使用 Elasticsearch / Meilisearch
|
|
348
|
+
- [ ] 消息队列使用 Kafka / RabbitMQ / NATS
|
|
349
|
+
- [ ] 不同技术通过抽象接口隔离
|
|
350
|
+
|
|
351
|
+
---
|
|
352
|
+
|
|
353
|
+
## 4. 过度设计(Over-Engineering)
|
|
354
|
+
|
|
355
|
+
### 描述
|
|
356
|
+
在简单的业务场景中引入了不必要的复杂架构(微服务、CQRS、Event Sourcing、DDD 全套战术模式),导致开发效率低、认知负担高、运维成本大。典型表现是项目只有 3 个开发者和 1000 个 DAU,却部署了 20 个微服务。
|
|
357
|
+
|
|
358
|
+
### 错误示例
|
|
359
|
+
```python
|
|
360
|
+
# 一个简单的博客系统,被过度设计为完整的 DDD + CQRS + Event Sourcing
|
|
361
|
+
|
|
362
|
+
# 6 层抽象才能创建一篇文章
|
|
363
|
+
class CreatePostCommandHandler:
|
|
364
|
+
def __init__(self, unit_of_work: UnitOfWork):
|
|
365
|
+
self._uow = unit_of_work
|
|
366
|
+
|
|
367
|
+
def handle(self, command: CreatePostCommand) -> None:
|
|
368
|
+
with self._uow:
|
|
369
|
+
post = PostAggregate.create(
|
|
370
|
+
title=Title(command.title), # 值对象
|
|
371
|
+
content=Content(command.content), # 值对象
|
|
372
|
+
author_id=AuthorId(command.author_id), # 值对象
|
|
373
|
+
)
|
|
374
|
+
self._uow.posts.add(post)
|
|
375
|
+
self._uow.commit()
|
|
376
|
+
|
|
377
|
+
class CreatePostCommand:
|
|
378
|
+
title: str
|
|
379
|
+
content: str
|
|
380
|
+
author_id: str
|
|
381
|
+
|
|
382
|
+
class PostAggregate(AggregateRoot):
|
|
383
|
+
@classmethod
|
|
384
|
+
def create(cls, title: Title, content: Content, author_id: AuthorId):
|
|
385
|
+
post = cls()
|
|
386
|
+
post.apply(PostCreatedEvent(title=title, content=content, author_id=author_id))
|
|
387
|
+
return post
|
|
388
|
+
|
|
389
|
+
def _on_post_created(self, event: PostCreatedEvent):
|
|
390
|
+
self._title = event.title
|
|
391
|
+
self._content = event.content
|
|
392
|
+
|
|
393
|
+
# 读模型还需要单独的投影和查询处理器...
|
|
394
|
+
class PostReadModelProjection:
|
|
395
|
+
def on_post_created(self, event: PostCreatedEvent): ...
|
|
396
|
+
|
|
397
|
+
class GetPostQueryHandler:
|
|
398
|
+
def handle(self, query: GetPostQuery) -> PostReadModel: ...
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
### 正确示例
|
|
402
|
+
```python
|
|
403
|
+
# 同样的博客系统,适度设计
|
|
404
|
+
|
|
405
|
+
# models.py
|
|
406
|
+
class Post(Base):
|
|
407
|
+
__tablename__ = "posts"
|
|
408
|
+
id = Column(Integer, primary_key=True)
|
|
409
|
+
title = Column(String(200), nullable=False)
|
|
410
|
+
content = Column(Text, nullable=False)
|
|
411
|
+
author_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
|
412
|
+
created_at = Column(DateTime, default=func.now())
|
|
413
|
+
updated_at = Column(DateTime, onupdate=func.now())
|
|
414
|
+
|
|
415
|
+
# service.py
|
|
416
|
+
class PostService:
|
|
417
|
+
def __init__(self, db: Session):
|
|
418
|
+
self._db = db
|
|
419
|
+
|
|
420
|
+
def create_post(self, author_id: int, title: str, content: str) -> Post:
|
|
421
|
+
post = Post(author_id=author_id, title=title, content=content)
|
|
422
|
+
self._db.add(post)
|
|
423
|
+
self._db.commit()
|
|
424
|
+
return post
|
|
425
|
+
|
|
426
|
+
def get_post(self, post_id: int) -> Post | None:
|
|
427
|
+
return self._db.query(Post).get(post_id)
|
|
428
|
+
|
|
429
|
+
# api.py
|
|
430
|
+
@app.post("/posts", response_model=PostResponse, status_code=201)
|
|
431
|
+
def create_post(data: CreatePostRequest, user: User = Depends(get_current_user)):
|
|
432
|
+
return post_service.create_post(
|
|
433
|
+
author_id=user.id, title=data.title, content=data.content
|
|
434
|
+
)
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
### 检测方法
|
|
438
|
+
- 实现一个简单 CRUD 功能需要修改 > 5 个文件。
|
|
439
|
+
- 项目中存在大量只有一个实现的接口(`IXxxRepository`、`IXxxService`)。
|
|
440
|
+
- 代码行数和业务复杂度不成比例(1000 DAU 的应用有 10 万行代码)。
|
|
441
|
+
- 新人 onboarding 需要 > 1 周才能提交第一个 PR。
|
|
442
|
+
- 存在 `AbstractFactoryBuilder`、`CommandHandlerDispatcher` 等深层嵌套的设计模式。
|
|
443
|
+
|
|
444
|
+
### 修复步骤
|
|
445
|
+
1. 评估当前系统的实际规模(DAU、数据量、团队大小)。
|
|
446
|
+
2. 对比当前架构复杂度与业务复杂度是否匹配。
|
|
447
|
+
3. 删除只有一个实现的接口,直接使用具体类。
|
|
448
|
+
4. 合并过度拆分的微服务为模块化单体。
|
|
449
|
+
5. 保留架构扩展点(接口),但延迟到真正需要时再引入。
|
|
450
|
+
|
|
451
|
+
### Agent Checklist
|
|
452
|
+
- [ ] CRUD 功能修改文件数 <= 3
|
|
453
|
+
- [ ] 接口和实现的比例合理(非 1:1 对应)
|
|
454
|
+
- [ ] 架构复杂度与业务规模匹配
|
|
455
|
+
- [ ] 新人可在 3 天内提交首个 PR
|
|
456
|
+
- [ ] 无不必要的设计模式嵌套
|
|
457
|
+
|
|
458
|
+
---
|
|
459
|
+
|
|
460
|
+
## 5. 循环依赖(Circular Dependency)
|
|
461
|
+
|
|
462
|
+
### 描述
|
|
463
|
+
模块 A 依赖 B,B 又依赖 A(直接或间接),形成环形依赖。导致无法独立测试、无法独立部署、import 顺序敏感、编译错误。在微服务场景下表现为服务间的循环调用。
|
|
464
|
+
|
|
465
|
+
### 错误示例
|
|
466
|
+
```python
|
|
467
|
+
# user/service.py
|
|
468
|
+
from order.service import OrderService # user 依赖 order
|
|
469
|
+
|
|
470
|
+
class UserService:
|
|
471
|
+
def __init__(self):
|
|
472
|
+
self._order_service = OrderService()
|
|
473
|
+
|
|
474
|
+
def get_user_with_orders(self, user_id: int):
|
|
475
|
+
user = self._repo.get(user_id)
|
|
476
|
+
user.orders = self._order_service.get_by_user(user_id)
|
|
477
|
+
return user
|
|
478
|
+
|
|
479
|
+
def deactivate_user(self, user_id: int):
|
|
480
|
+
self._repo.deactivate(user_id)
|
|
481
|
+
|
|
482
|
+
# order/service.py
|
|
483
|
+
from user.service import UserService # order 反过来依赖 user -- 循环!
|
|
484
|
+
|
|
485
|
+
class OrderService:
|
|
486
|
+
def __init__(self):
|
|
487
|
+
self._user_service = UserService()
|
|
488
|
+
|
|
489
|
+
def get_by_user(self, user_id: int):
|
|
490
|
+
return self._repo.get_by_user(user_id)
|
|
491
|
+
|
|
492
|
+
def cancel_order(self, order_id: int):
|
|
493
|
+
order = self._repo.get(order_id)
|
|
494
|
+
# 取消订单时需要检查用户状态
|
|
495
|
+
user = self._user_service.get_user(order.user_id)
|
|
496
|
+
if user.is_deactivated:
|
|
497
|
+
raise UserDeactivatedError()
|
|
498
|
+
self._repo.cancel(order_id)
|
|
499
|
+
```
|
|
500
|
+
|
|
501
|
+
### 正确示例
|
|
502
|
+
```python
|
|
503
|
+
# 方案 1: 依赖倒置 -- 引入接口
|
|
504
|
+
# shared/interfaces.py
|
|
505
|
+
from abc import ABC, abstractmethod
|
|
506
|
+
|
|
507
|
+
class UserQueryInterface(ABC):
|
|
508
|
+
@abstractmethod
|
|
509
|
+
def get_user(self, user_id: int) -> User: ...
|
|
510
|
+
|
|
511
|
+
@abstractmethod
|
|
512
|
+
def is_active(self, user_id: int) -> bool: ...
|
|
513
|
+
|
|
514
|
+
# user/service.py -- 实现接口
|
|
515
|
+
class UserService(UserQueryInterface):
|
|
516
|
+
def get_user(self, user_id: int) -> User:
|
|
517
|
+
return self._repo.get(user_id)
|
|
518
|
+
|
|
519
|
+
def is_active(self, user_id: int) -> bool:
|
|
520
|
+
user = self._repo.get(user_id)
|
|
521
|
+
return user is not None and not user.is_deactivated
|
|
522
|
+
|
|
523
|
+
# order/service.py -- 依赖接口而非具体实现
|
|
524
|
+
class OrderService:
|
|
525
|
+
def __init__(self, user_query: UserQueryInterface): # 注入接口
|
|
526
|
+
self._user_query = user_query
|
|
527
|
+
|
|
528
|
+
def cancel_order(self, order_id: int):
|
|
529
|
+
order = self._repo.get(order_id)
|
|
530
|
+
if not self._user_query.is_active(order.user_id):
|
|
531
|
+
raise UserDeactivatedError()
|
|
532
|
+
self._repo.cancel(order_id)
|
|
533
|
+
```
|
|
534
|
+
|
|
535
|
+
```python
|
|
536
|
+
# 方案 2: 事件解耦
|
|
537
|
+
# user/service.py
|
|
538
|
+
class UserService:
|
|
539
|
+
def deactivate_user(self, user_id: int):
|
|
540
|
+
self._repo.deactivate(user_id)
|
|
541
|
+
self._event_bus.publish(UserDeactivatedEvent(user_id=user_id))
|
|
542
|
+
|
|
543
|
+
# order/event_handler.py -- 订阅事件,无 import 依赖
|
|
544
|
+
class OrderEventHandler:
|
|
545
|
+
def on_user_deactivated(self, event: UserDeactivatedEvent):
|
|
546
|
+
self._order_repo.cancel_pending_orders(event.user_id)
|
|
547
|
+
```
|
|
548
|
+
|
|
549
|
+
### 检测方法
|
|
550
|
+
- Python: `import-linter` 配置分层规则,CI 中检查。
|
|
551
|
+
- `pydeps` / `madge` (JS) 生成依赖图,检查是否有环。
|
|
552
|
+
- 运行时出现 `ImportError: cannot import name` 循环导入错误。
|
|
553
|
+
- 微服务场景:绘制服务调用图,检查是否有双向调用。
|
|
554
|
+
|
|
555
|
+
### 修复步骤
|
|
556
|
+
1. 使用 `pydeps` / `madge` 生成依赖图,识别所有环。
|
|
557
|
+
2. 对于直接循环:引入接口层(依赖倒置原则)。
|
|
558
|
+
3. 对于间接循环:考虑事件驱动解耦或合并紧耦合的模块。
|
|
559
|
+
4. 在 CI 中配置 `import-linter` 规则,阻止新的循环依赖进入。
|
|
560
|
+
5. 定期检查依赖图,确保架构约束持续有效。
|
|
561
|
+
|
|
562
|
+
### Agent Checklist
|
|
563
|
+
- [ ] 无循环 import(`import-linter` CI 检查通过)
|
|
564
|
+
- [ ] 模块间依赖方向单一(上层 -> 下层)
|
|
565
|
+
- [ ] 紧耦合的模块通过接口解耦
|
|
566
|
+
- [ ] 服务间无双向同步调用
|
|
567
|
+
|
|
568
|
+
---
|
|
569
|
+
|
|
570
|
+
## 6. 无边界上下文(Missing Bounded Context)
|
|
571
|
+
|
|
572
|
+
### 描述
|
|
573
|
+
不同业务域共用相同的模型定义,导致一个模型承担多个业务域的含义。例如 `User` 模型同时用于认证、订单、支付、社交,修改认证逻辑可能意外影响订单模块。
|
|
574
|
+
|
|
575
|
+
### 错误示例
|
|
576
|
+
```python
|
|
577
|
+
# 一个 User 模型被所有业务域共用
|
|
578
|
+
class User(Base):
|
|
579
|
+
__tablename__ = "users"
|
|
580
|
+
id = Column(Integer, primary_key=True)
|
|
581
|
+
# 认证域
|
|
582
|
+
username = Column(String(50))
|
|
583
|
+
password_hash = Column(String(255))
|
|
584
|
+
last_login = Column(DateTime)
|
|
585
|
+
mfa_secret = Column(String(100))
|
|
586
|
+
# 订单域
|
|
587
|
+
shipping_address = Column(String(500))
|
|
588
|
+
default_payment_method = Column(String(50))
|
|
589
|
+
# 社交域
|
|
590
|
+
bio = Column(Text)
|
|
591
|
+
avatar_url = Column(String(500))
|
|
592
|
+
follower_count = Column(Integer)
|
|
593
|
+
# 营销域
|
|
594
|
+
newsletter_opt_in = Column(Boolean)
|
|
595
|
+
referral_code = Column(String(20))
|
|
596
|
+
loyalty_points = Column(Integer)
|
|
597
|
+
|
|
598
|
+
# 所有服务都直接操作这个巨型 User 表
|
|
599
|
+
# auth_service.py
|
|
600
|
+
def login(username, password):
|
|
601
|
+
user = session.query(User).filter_by(username=username).first()
|
|
602
|
+
# 加载了 20+ 列,只需要 2 列
|
|
603
|
+
|
|
604
|
+
# social_service.py
|
|
605
|
+
def get_profile(user_id):
|
|
606
|
+
user = session.query(User).get(user_id)
|
|
607
|
+
# 修改这个查询可能影响认证服务的性能
|
|
608
|
+
```
|
|
609
|
+
|
|
610
|
+
### 正确示例
|
|
611
|
+
```python
|
|
612
|
+
# 按边界上下文拆分模型
|
|
613
|
+
|
|
614
|
+
# auth/models.py -- 认证上下文
|
|
615
|
+
class AuthUser(Base):
|
|
616
|
+
__tablename__ = "auth_users"
|
|
617
|
+
id = Column(Integer, primary_key=True)
|
|
618
|
+
username = Column(String(50), unique=True, nullable=False)
|
|
619
|
+
password_hash = Column(String(255), nullable=False)
|
|
620
|
+
last_login = Column(DateTime)
|
|
621
|
+
mfa_secret = Column(String(100))
|
|
622
|
+
|
|
623
|
+
# orders/models.py -- 订单上下文
|
|
624
|
+
class Customer(Base):
|
|
625
|
+
"""订单域中的用户表示 -- 只包含订单相关的属性"""
|
|
626
|
+
__tablename__ = "order_customers"
|
|
627
|
+
id = Column(Integer, primary_key=True)
|
|
628
|
+
user_id = Column(Integer, index=True) # 关联到 auth_users.id
|
|
629
|
+
shipping_address = Column(String(500))
|
|
630
|
+
default_payment_method = Column(String(50))
|
|
631
|
+
|
|
632
|
+
# social/models.py -- 社交上下文
|
|
633
|
+
class UserProfile(Base):
|
|
634
|
+
"""社交域中的用户表示 -- 只包含社交相关的属性"""
|
|
635
|
+
__tablename__ = "social_profiles"
|
|
636
|
+
id = Column(Integer, primary_key=True)
|
|
637
|
+
user_id = Column(Integer, unique=True, index=True)
|
|
638
|
+
display_name = Column(String(100))
|
|
639
|
+
bio = Column(Text)
|
|
640
|
+
avatar_url = Column(String(500))
|
|
641
|
+
follower_count = Column(Integer, default=0)
|
|
642
|
+
|
|
643
|
+
# 上下文间通过 user_id 关联,不直接 import 对方的模型
|
|
644
|
+
# 跨上下文的数据同步通过事件实现
|
|
645
|
+
class UserRegisteredEventHandler:
|
|
646
|
+
"""当用户注册时,在其他上下文中创建对应的记录"""
|
|
647
|
+
def handle(self, event: UserRegisteredEvent):
|
|
648
|
+
# 在订单域创建 Customer
|
|
649
|
+
customer_repo.create(Customer(user_id=event.user_id))
|
|
650
|
+
# 在社交域创建 Profile
|
|
651
|
+
profile_repo.create(UserProfile(user_id=event.user_id))
|
|
652
|
+
```
|
|
653
|
+
|
|
654
|
+
### 检测方法
|
|
655
|
+
- 单个模型类的字段数 > 20。
|
|
656
|
+
- 模型类包含属于不同业务域的字段(认证 + 支付 + 社交)。
|
|
657
|
+
- 修改一个业务域的逻辑需要修改另一个业务域的代码。
|
|
658
|
+
- 多个团队频繁在同一个模型文件上产生合并冲突。
|
|
659
|
+
|
|
660
|
+
### 修复步骤
|
|
661
|
+
1. 进行事件风暴(Event Storming),识别业务域和边界上下文。
|
|
662
|
+
2. 为每个边界上下文定义独立的模型,即使它们代表同一个实体。
|
|
663
|
+
3. 上下文间通过 ID 关联,不直接 import 对方的模型。
|
|
664
|
+
4. 使用领域事件同步跨上下文的数据变更。
|
|
665
|
+
5. 每个上下文可以有自己的数据库 Schema 或独立数据库。
|
|
666
|
+
|
|
667
|
+
### Agent Checklist
|
|
668
|
+
- [ ] 每个业务域有独立的模型定义
|
|
669
|
+
- [ ] 单个模型字段数 <= 15
|
|
670
|
+
- [ ] 模块间不直接 import 对方的模型类
|
|
671
|
+
- [ ] 跨域数据同步使用事件机制
|
|
672
|
+
- [ ] 不同团队不会在同一个模型文件上冲突
|
|
673
|
+
|
|
674
|
+
---
|
|
675
|
+
|
|
676
|
+
## 全局 Agent Checklist
|
|
677
|
+
|
|
678
|
+
| 检查项 | 阈值 | 工具 |
|
|
679
|
+
|--------|------|------|
|
|
680
|
+
| 服务间同步调用链深度 | <= 2 | 调用链追踪 / APM |
|
|
681
|
+
| 共享数据库 | 0 个 | 架构图审查 |
|
|
682
|
+
| 单文件行数 | <= 500 | `wc -l` |
|
|
683
|
+
| 循环依赖 | 0 个 | `import-linter` / `pydeps` |
|
|
684
|
+
| 单模型字段数 | <= 15 | Code Review |
|
|
685
|
+
| CRUD 修改文件数 | <= 3 | git diff 统计 |
|
|
686
|
+
| 万能工具文件 | 0 个 | `grep -r "utils.py"` |
|