@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,66 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: file-upload-and-storage
|
|
3
|
+
title: 文件上传与存储标准(商业级必读)
|
|
4
|
+
domain: backend
|
|
5
|
+
category: 01-standards
|
|
6
|
+
difficulty: intermediate
|
|
7
|
+
tags: [文件上传, upload, 存储, storage, s3, 对象存储, cdn, 校验, 预签名, presigned, 安全, 图片, 商业级]
|
|
8
|
+
quality_score: 95
|
|
9
|
+
last_updated: 2026-06-19
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
# 文件上传与存储标准(商业级必读)
|
|
13
|
+
|
|
14
|
+
> 文件上传是常见功能,也是常见漏洞与体验坑(无大小/类型校验、存数据库、走应用服务器中转、可执行文件、无 CDN)。本标准给出商业级做法。
|
|
15
|
+
|
|
16
|
+
## 1. 存哪里
|
|
17
|
+
|
|
18
|
+
- 用**对象存储**(S3/OSS/COS/MinIO),**不要存数据库**(撑大库、难扩展、难走 CDN),也不要长期放应用服务器本地磁盘。
|
|
19
|
+
- DB 只存**元数据 + 存储 key/URL**(文件名、大小、类型、上传者、时间)。
|
|
20
|
+
- 静态/图片通过 **CDN** 分发 + 长缓存(内容哈希作 key 便于缓存失效)。
|
|
21
|
+
|
|
22
|
+
## 2. 上传方式:优先预签名直传
|
|
23
|
+
|
|
24
|
+
- 大文件/高并发优先**前端直传对象存储**(后端签发**预签名 URL**,前端直传,不经应用服务器中转)——省带宽、可扩展。
|
|
25
|
+
- 流程:前端请求上传 → 后端校验权限/类型/大小并签发短期预签名 URL → 前端直传 → 回调后端落元数据。
|
|
26
|
+
- 小文件可经后端中转,但要流式处理、限大小,别全读进内存。
|
|
27
|
+
|
|
28
|
+
## 3. 校验(安全关键)
|
|
29
|
+
|
|
30
|
+
- **大小限制**(前后端都限,后端为准);超限拒绝。
|
|
31
|
+
- **类型校验**:白名单允许的 MIME/扩展名;**校验真实内容**(magic bytes/文件头),不只信扩展名或客户端 MIME。
|
|
32
|
+
- 图片做尺寸/像素限制,必要时重新编码(去除恶意载荷/EXIF 隐私)。
|
|
33
|
+
- **重命名**存储(用随机/哈希名),不用用户原始文件名(防路径穿越/覆盖)。
|
|
34
|
+
- 上传目录**不可执行**;绝不把上传文件当代码执行。
|
|
35
|
+
|
|
36
|
+
## 4. 访问控制
|
|
37
|
+
|
|
38
|
+
- 私有文件用**预签名下载 URL(短期)**或经鉴权的代理,不要公开可枚举的 URL。
|
|
39
|
+
- 公开资源也避免可猜测的顺序 id(用随机 key)。
|
|
40
|
+
- 校验下载者对该文件的权限(对象级授权,防越权下别人文件)。
|
|
41
|
+
|
|
42
|
+
## 5. 体验与可靠性
|
|
43
|
+
|
|
44
|
+
- 前端:进度条、loading、错误态、可取消;大文件分片/断点续传。
|
|
45
|
+
- 失败重试;上传完成才落元数据(避免半成品记录)。
|
|
46
|
+
- 限制单用户上传频率/配额;清理孤儿文件(有记录无文件/有文件无记录)。
|
|
47
|
+
- 病毒扫描(用户可下载的内容平台尤其需要)。
|
|
48
|
+
|
|
49
|
+
## 6. 反模式(出现即不合格)
|
|
50
|
+
|
|
51
|
+
- 文件存数据库 BLOB;长期存应用服务器本地盘。
|
|
52
|
+
- 无大小/类型校验;只信扩展名/客户端 MIME;用原始文件名直存。
|
|
53
|
+
- 大文件全读进内存中转;同步阻塞上传。
|
|
54
|
+
- 私有文件用公开可枚举 URL;不校验下载权限。
|
|
55
|
+
- 上传目录可执行;不重命名导致覆盖/穿越。
|
|
56
|
+
|
|
57
|
+
## 7. 最低交付 checklist
|
|
58
|
+
|
|
59
|
+
- [ ] 文件存对象存储,DB 只存元数据;公开资源走 CDN + 内容哈希。
|
|
60
|
+
- [ ] 大文件预签名直传(短期 URL);小文件流式 + 限大小。
|
|
61
|
+
- [ ] 大小限制 + 类型白名单 + 真实内容校验 + 随机重命名 + 目录不可执行。
|
|
62
|
+
- [ ] 私有文件短期预签名/鉴权代理 + 对象级授权下载。
|
|
63
|
+
- [ ] 进度/错误/取消/重试;上传成功才落元数据;配额 + 孤儿清理。
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
**参考**:S3/对象存储最佳实践、预签名 URL、OWASP 文件上传 Cheat Sheet、CDN 缓存策略。
|
|
@@ -0,0 +1,416 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: graphql-api-complete
|
|
3
|
+
title: GraphQL API 完整指南
|
|
4
|
+
domain: backend
|
|
5
|
+
category: 01-standards
|
|
6
|
+
difficulty: intermediate
|
|
7
|
+
tags: [api, backend, complete, dataloader, graphql, resolver, schema, subscription]
|
|
8
|
+
quality_score: 70
|
|
9
|
+
last_updated: 2026-06-15
|
|
10
|
+
---
|
|
11
|
+
# GraphQL API 完整指南
|
|
12
|
+
|
|
13
|
+
## 概述
|
|
14
|
+
|
|
15
|
+
GraphQL 是 Facebook 开发的 API 查询语言和运行时,允许客户端精确指定所需数据。与 REST 相比,GraphQL 解决了 over-fetching 和 under-fetching 问题,提供强类型 Schema、内省能力和实时订阅支持。
|
|
16
|
+
|
|
17
|
+
### 何时选择 GraphQL
|
|
18
|
+
|
|
19
|
+
- 多端(Web/iOS/Android)数据需求差异大
|
|
20
|
+
- 页面需要聚合多个资源的数据
|
|
21
|
+
- 需要实时数据推送(Subscription)
|
|
22
|
+
- API 演进频繁,需要向后兼容
|
|
23
|
+
- 前端团队需要自主决定数据形状
|
|
24
|
+
|
|
25
|
+
### 何时选择 REST
|
|
26
|
+
|
|
27
|
+
- 简单 CRUD 操作
|
|
28
|
+
- 文件上传/下载为主
|
|
29
|
+
- 缓存需求强(HTTP 缓存天然支持)
|
|
30
|
+
- 团队 GraphQL 经验不足
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## Schema 设计
|
|
35
|
+
|
|
36
|
+
### SDL (Schema Definition Language)
|
|
37
|
+
|
|
38
|
+
```graphql
|
|
39
|
+
# 类型定义
|
|
40
|
+
type User {
|
|
41
|
+
id: ID!
|
|
42
|
+
email: String!
|
|
43
|
+
name: String!
|
|
44
|
+
role: Role!
|
|
45
|
+
posts(first: Int = 10, after: String): PostConnection!
|
|
46
|
+
createdAt: DateTime!
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
type Post {
|
|
50
|
+
id: ID!
|
|
51
|
+
title: String!
|
|
52
|
+
content: String!
|
|
53
|
+
author: User!
|
|
54
|
+
tags: [Tag!]!
|
|
55
|
+
status: PostStatus!
|
|
56
|
+
publishedAt: DateTime
|
|
57
|
+
createdAt: DateTime!
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
type Tag {
|
|
61
|
+
id: ID!
|
|
62
|
+
name: String!
|
|
63
|
+
posts(first: Int = 10, after: String): PostConnection!
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
# 枚举
|
|
67
|
+
enum Role {
|
|
68
|
+
USER
|
|
69
|
+
EDITOR
|
|
70
|
+
ADMIN
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
enum PostStatus {
|
|
74
|
+
DRAFT
|
|
75
|
+
PUBLISHED
|
|
76
|
+
ARCHIVED
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
# 自定义标量
|
|
80
|
+
scalar DateTime
|
|
81
|
+
scalar JSON
|
|
82
|
+
|
|
83
|
+
# 连接(Relay 规范分页)
|
|
84
|
+
type PostConnection {
|
|
85
|
+
edges: [PostEdge!]!
|
|
86
|
+
pageInfo: PageInfo!
|
|
87
|
+
totalCount: Int!
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
type PostEdge {
|
|
91
|
+
node: Post!
|
|
92
|
+
cursor: String!
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
type PageInfo {
|
|
96
|
+
hasNextPage: Boolean!
|
|
97
|
+
hasPreviousPage: Boolean!
|
|
98
|
+
startCursor: String
|
|
99
|
+
endCursor: String
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
# 输入类型
|
|
103
|
+
input CreatePostInput {
|
|
104
|
+
title: String!
|
|
105
|
+
content: String!
|
|
106
|
+
tags: [ID!]
|
|
107
|
+
status: PostStatus = DRAFT
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
input UpdatePostInput {
|
|
111
|
+
title: String
|
|
112
|
+
content: String
|
|
113
|
+
tags: [ID!]
|
|
114
|
+
status: PostStatus
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
# Query
|
|
118
|
+
type Query {
|
|
119
|
+
user(id: ID!): User
|
|
120
|
+
me: User!
|
|
121
|
+
posts(
|
|
122
|
+
first: Int = 20
|
|
123
|
+
after: String
|
|
124
|
+
status: PostStatus
|
|
125
|
+
search: String
|
|
126
|
+
): PostConnection!
|
|
127
|
+
post(id: ID!): Post
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
# Mutation
|
|
131
|
+
type Mutation {
|
|
132
|
+
createPost(input: CreatePostInput!): Post!
|
|
133
|
+
updatePost(id: ID!, input: UpdatePostInput!): Post!
|
|
134
|
+
deletePost(id: ID!): Boolean!
|
|
135
|
+
login(email: String!, password: String!): AuthPayload!
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
type AuthPayload {
|
|
139
|
+
token: String!
|
|
140
|
+
user: User!
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
# Subscription
|
|
144
|
+
type Subscription {
|
|
145
|
+
postPublished: Post!
|
|
146
|
+
commentAdded(postId: ID!): Comment!
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
## Resolver 实现
|
|
153
|
+
|
|
154
|
+
### Node.js (Apollo Server)
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
import { GraphQLResolveInfo } from "graphql";
|
|
158
|
+
|
|
159
|
+
const resolvers = {
|
|
160
|
+
Query: {
|
|
161
|
+
me: (_parent: unknown, _args: unknown, context: Context) => {
|
|
162
|
+
if (!context.user) throw new AuthenticationError("未认证");
|
|
163
|
+
return context.user;
|
|
164
|
+
},
|
|
165
|
+
|
|
166
|
+
posts: async (_parent: unknown, args: PostsArgs, context: Context) => {
|
|
167
|
+
const { first = 20, after, status, search } = args;
|
|
168
|
+
return context.dataSources.postAPI.getPosts({ first, after, status, search });
|
|
169
|
+
},
|
|
170
|
+
|
|
171
|
+
post: async (_parent: unknown, { id }: { id: string }, context: Context) => {
|
|
172
|
+
const post = await context.dataSources.postAPI.getPostById(id);
|
|
173
|
+
if (!post) throw new NotFoundError(`Post ${id} not found`);
|
|
174
|
+
return post;
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
|
|
178
|
+
Mutation: {
|
|
179
|
+
createPost: async (_parent: unknown, { input }: { input: CreatePostInput }, context: Context) => {
|
|
180
|
+
if (!context.user) throw new AuthenticationError("未认证");
|
|
181
|
+
return context.dataSources.postAPI.createPost({
|
|
182
|
+
...input,
|
|
183
|
+
authorId: context.user.id,
|
|
184
|
+
});
|
|
185
|
+
},
|
|
186
|
+
|
|
187
|
+
updatePost: async (_parent: unknown, { id, input }: { id: string; input: UpdatePostInput }, context: Context) => {
|
|
188
|
+
if (!context.user) throw new AuthenticationError("未认证");
|
|
189
|
+
const post = await context.dataSources.postAPI.getPostById(id);
|
|
190
|
+
if (!post) throw new NotFoundError(`Post ${id} not found`);
|
|
191
|
+
if (post.authorId !== context.user.id && context.user.role !== "ADMIN") {
|
|
192
|
+
throw new ForbiddenError("无权修改");
|
|
193
|
+
}
|
|
194
|
+
return context.dataSources.postAPI.updatePost(id, input);
|
|
195
|
+
},
|
|
196
|
+
},
|
|
197
|
+
|
|
198
|
+
// 字段级 Resolver
|
|
199
|
+
User: {
|
|
200
|
+
posts: (parent: User, args: ConnectionArgs, context: Context) => {
|
|
201
|
+
return context.dataSources.postAPI.getPostsByAuthor(parent.id, args);
|
|
202
|
+
},
|
|
203
|
+
},
|
|
204
|
+
|
|
205
|
+
Post: {
|
|
206
|
+
author: (parent: Post, _args: unknown, context: Context) => {
|
|
207
|
+
// 使用 DataLoader 避免 N+1
|
|
208
|
+
return context.loaders.userLoader.load(parent.authorId);
|
|
209
|
+
},
|
|
210
|
+
tags: (parent: Post, _args: unknown, context: Context) => {
|
|
211
|
+
return context.loaders.tagLoader.load(parent.id);
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
};
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
219
|
+
## DataLoader (N+1 解决方案)
|
|
220
|
+
|
|
221
|
+
```typescript
|
|
222
|
+
import DataLoader from "dataloader";
|
|
223
|
+
|
|
224
|
+
// 创建 DataLoader
|
|
225
|
+
function createLoaders(db: Database) {
|
|
226
|
+
return {
|
|
227
|
+
userLoader: new DataLoader<string, User>(async (ids) => {
|
|
228
|
+
const users = await db.user.findMany({
|
|
229
|
+
where: { id: { in: [...ids] } },
|
|
230
|
+
});
|
|
231
|
+
const userMap = new Map(users.map(u => [u.id, u]));
|
|
232
|
+
return ids.map(id => userMap.get(id) || new Error(`User ${id} not found`));
|
|
233
|
+
}),
|
|
234
|
+
|
|
235
|
+
tagLoader: new DataLoader<string, Tag[]>(async (postIds) => {
|
|
236
|
+
const postTags = await db.postTag.findMany({
|
|
237
|
+
where: { postId: { in: [...postIds] } },
|
|
238
|
+
include: { tag: true },
|
|
239
|
+
});
|
|
240
|
+
const tagMap = new Map<string, Tag[]>();
|
|
241
|
+
for (const pt of postTags) {
|
|
242
|
+
const tags = tagMap.get(pt.postId) || [];
|
|
243
|
+
tags.push(pt.tag);
|
|
244
|
+
tagMap.set(pt.postId, tags);
|
|
245
|
+
}
|
|
246
|
+
return postIds.map(id => tagMap.get(id) || []);
|
|
247
|
+
}),
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// 在 Context 中每请求创建新实例
|
|
252
|
+
const server = new ApolloServer({
|
|
253
|
+
typeDefs,
|
|
254
|
+
resolvers,
|
|
255
|
+
context: ({ req }) => ({
|
|
256
|
+
user: getUserFromToken(req.headers.authorization),
|
|
257
|
+
loaders: createLoaders(db),
|
|
258
|
+
dataSources: { postAPI: new PostAPI(db) },
|
|
259
|
+
}),
|
|
260
|
+
});
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
---
|
|
264
|
+
|
|
265
|
+
## 订阅 (Subscription)
|
|
266
|
+
|
|
267
|
+
```typescript
|
|
268
|
+
import { PubSub } from "graphql-subscriptions";
|
|
269
|
+
|
|
270
|
+
const pubsub = new PubSub();
|
|
271
|
+
|
|
272
|
+
const resolvers = {
|
|
273
|
+
Mutation: {
|
|
274
|
+
createPost: async (_parent, { input }, context) => {
|
|
275
|
+
const post = await context.dataSources.postAPI.createPost(input);
|
|
276
|
+
if (post.status === "PUBLISHED") {
|
|
277
|
+
pubsub.publish("POST_PUBLISHED", { postPublished: post });
|
|
278
|
+
}
|
|
279
|
+
return post;
|
|
280
|
+
},
|
|
281
|
+
},
|
|
282
|
+
|
|
283
|
+
Subscription: {
|
|
284
|
+
postPublished: {
|
|
285
|
+
subscribe: () => pubsub.asyncIterator(["POST_PUBLISHED"]),
|
|
286
|
+
},
|
|
287
|
+
commentAdded: {
|
|
288
|
+
subscribe: (_parent, { postId }) =>
|
|
289
|
+
pubsub.asyncIterator([`COMMENT_ADDED_${postId}`]),
|
|
290
|
+
},
|
|
291
|
+
},
|
|
292
|
+
};
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
---
|
|
296
|
+
|
|
297
|
+
## 安全
|
|
298
|
+
|
|
299
|
+
### 查询深度与复杂度限制
|
|
300
|
+
|
|
301
|
+
```typescript
|
|
302
|
+
import depthLimit from "graphql-depth-limit";
|
|
303
|
+
import { createComplexityLimitRule } from "graphql-validation-complexity";
|
|
304
|
+
|
|
305
|
+
const server = new ApolloServer({
|
|
306
|
+
typeDefs,
|
|
307
|
+
resolvers,
|
|
308
|
+
validationRules: [
|
|
309
|
+
depthLimit(7), // 查询深度限制
|
|
310
|
+
createComplexityLimitRule(1000, { // 查询复杂度限制
|
|
311
|
+
scalarCost: 1,
|
|
312
|
+
objectCost: 5,
|
|
313
|
+
listFactor: 10,
|
|
314
|
+
}),
|
|
315
|
+
],
|
|
316
|
+
});
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
### 速率限制
|
|
320
|
+
|
|
321
|
+
```typescript
|
|
322
|
+
import { RateLimitDirective } from "graphql-rate-limit-directive";
|
|
323
|
+
|
|
324
|
+
const typeDefs = gql`
|
|
325
|
+
directive @rateLimit(limit: Int!, duration: Int!) on FIELD_DEFINITION
|
|
326
|
+
|
|
327
|
+
type Mutation {
|
|
328
|
+
login(email: String!, password: String!): AuthPayload!
|
|
329
|
+
@rateLimit(limit: 5, duration: 60)
|
|
330
|
+
createPost(input: CreatePostInput!): Post!
|
|
331
|
+
@rateLimit(limit: 10, duration: 60)
|
|
332
|
+
}
|
|
333
|
+
`;
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
### 字段级授权
|
|
337
|
+
|
|
338
|
+
```typescript
|
|
339
|
+
const resolvers = {
|
|
340
|
+
User: {
|
|
341
|
+
email: (parent, _args, context) => {
|
|
342
|
+
// 仅自己或管理员可见邮箱
|
|
343
|
+
if (context.user?.id === parent.id || context.user?.role === "ADMIN") {
|
|
344
|
+
return parent.email;
|
|
345
|
+
}
|
|
346
|
+
return null;
|
|
347
|
+
},
|
|
348
|
+
},
|
|
349
|
+
};
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
---
|
|
353
|
+
|
|
354
|
+
## 性能优化
|
|
355
|
+
|
|
356
|
+
### 持久化查询 (Persisted Queries)
|
|
357
|
+
|
|
358
|
+
```typescript
|
|
359
|
+
// 客户端发送 query hash 而非完整 query
|
|
360
|
+
// POST /graphql
|
|
361
|
+
// { "extensions": { "persistedQuery": { "version": 1, "sha256Hash": "abc123..." } } }
|
|
362
|
+
|
|
363
|
+
import { ApolloServerPluginCacheControl } from "@apollo/server/plugin/cacheControl";
|
|
364
|
+
|
|
365
|
+
const server = new ApolloServer({
|
|
366
|
+
typeDefs,
|
|
367
|
+
resolvers,
|
|
368
|
+
persistedQueries: { ttl: 900 }, // 15 分钟 TTL
|
|
369
|
+
plugins: [ApolloServerPluginCacheControl({ defaultMaxAge: 60 })],
|
|
370
|
+
});
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
### 查询批处理
|
|
374
|
+
|
|
375
|
+
```typescript
|
|
376
|
+
// 客户端批量发送多个查询
|
|
377
|
+
// POST /graphql
|
|
378
|
+
// [{ "query": "..." }, { "query": "..." }]
|
|
379
|
+
|
|
380
|
+
// Apollo Client 配置
|
|
381
|
+
const link = new BatchHttpLink({
|
|
382
|
+
uri: "/graphql",
|
|
383
|
+
batchMax: 5, // 最多 5 个查询合批
|
|
384
|
+
batchInterval: 20, // 20ms 窗口
|
|
385
|
+
});
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
---
|
|
389
|
+
|
|
390
|
+
## 常见反模式
|
|
391
|
+
|
|
392
|
+
| 反模式 | 问题 | 正确做法 |
|
|
393
|
+
|--------|------|----------|
|
|
394
|
+
| 不用 DataLoader | N+1 查询 | 每请求创建 DataLoader 实例 |
|
|
395
|
+
| 无深度/复杂度限制 | DoS 攻击 | 设置 depthLimit + complexityLimit |
|
|
396
|
+
| Schema 暴露内部结构 | 信息泄露 | 以客户端需求设计 Schema |
|
|
397
|
+
| 巨型 Resolver 函数 | 难维护 | 拆分为 Service + DataSource |
|
|
398
|
+
| 忽略错误处理 | 敏感信息泄露 | 统一错误格式,隐藏内部细节 |
|
|
399
|
+
| Subscription 用轮询实现 | 浪费资源 | 用 WebSocket + PubSub |
|
|
400
|
+
|
|
401
|
+
---
|
|
402
|
+
|
|
403
|
+
## Agent Checklist
|
|
404
|
+
|
|
405
|
+
- [ ] Schema 遵循 Relay 规范分页(Connection / Edge / PageInfo)
|
|
406
|
+
- [ ] 所有关联字段使用 DataLoader 避免 N+1
|
|
407
|
+
- [ ] 设置查询深度限制(推荐 <= 7 层)
|
|
408
|
+
- [ ] 设置查询复杂度限制
|
|
409
|
+
- [ ] 敏感字段实现字段级授权
|
|
410
|
+
- [ ] Mutation 使用 Input 类型参数化
|
|
411
|
+
- [ ] 错误返回统一格式,不暴露内部堆栈
|
|
412
|
+
- [ ] 登录等敏感操作设置速率限制
|
|
413
|
+
- [ ] 生产环境禁用 Introspection(或仅限内部)
|
|
414
|
+
- [ ] Subscription 使用 WebSocket,生产环境用 Redis PubSub
|
|
415
|
+
- [ ] Schema 变更有向后兼容策略(@deprecated 标记)
|
|
416
|
+
- [ ] 接入 APM 监控 Resolver 级别性能
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: llm-application-standard
|
|
3
|
+
title: AI/LLM 应用开发标准(商业级 · RAG/Agent/护栏/成本)
|
|
4
|
+
domain: backend
|
|
5
|
+
category: 01-standards
|
|
6
|
+
difficulty: advanced
|
|
7
|
+
tags: [ai, llm, 大模型, rag, 检索增强, prompt, 提示注入, prompt-injection, 护栏, guardrails, agent, 智能体, 成本, 评测, 流式, 向量, 商业级]
|
|
8
|
+
quality_score: 95
|
|
9
|
+
last_updated: 2026-06-19
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
# AI/LLM 应用开发标准(商业级 · RAG/Agent/护栏/成本)
|
|
13
|
+
|
|
14
|
+
> AI 应用是当下最热的商业方向,也是纯底座最容易做不规范的地方(无护栏、易被提示注入、成本失控、不可评测)。本标准给出生产级 LLM 应用要点。
|
|
15
|
+
|
|
16
|
+
## 1. 架构与抽象
|
|
17
|
+
|
|
18
|
+
- **抽象 LLM 供应商**:封装统一接口(chat/embeddings/tools),便于切换模型/供应商、做降级与多模型路由,不要把某家 SDK 散落业务。
|
|
19
|
+
- 模型分层路由:**60-80% 的查询用更小更便宜的模型即可**,复杂的才上大模型——可显著降本(50-70%)。
|
|
20
|
+
- 流式输出(SSE)提升体感;超时/重试/限流/熔断(外部模型会抖动)。
|
|
21
|
+
- Prompt 用**模板 + 版本管理**,与代码一起评审,不要散落硬编码字符串。
|
|
22
|
+
|
|
23
|
+
## 2. RAG(检索增强生成)
|
|
24
|
+
|
|
25
|
+
- 标准管线:**切分(chunk) → 向量化(embedding) → 向量库检索 → 重排(rerank) → 拼上下文 → 生成**。
|
|
26
|
+
- 切分要语义合理(按结构/语义而非定长硬切);保留来源元数据(用于引用与权限)。
|
|
27
|
+
- 检索质量决定一切:合适的相似度 + 数量 + rerank;中文注意分词/向量模型选型。
|
|
28
|
+
- **引用来源**:让模型基于检索内容回答并给出处,减少幻觉;用 thinking/answer 分段标记提升复杂问答准确率。
|
|
29
|
+
- 评估检索召回/命中,别只看生成。
|
|
30
|
+
|
|
31
|
+
## 3. 安全:提示注入与护栏(非可选)
|
|
32
|
+
|
|
33
|
+
- **直接提示注入**:用户输入试图覆盖系统指令——系统提示与用户输入分离、最小信任用户输入、关键约束放系统侧并防覆盖。
|
|
34
|
+
- **间接提示注入(RAG/Agent 关键风险)**:恶意指令藏在**被检索的文档/网页/工具返回**里。必须:对检索内容**文档可信度评分/来源过滤**、把检索内容当**数据而非指令**对待。
|
|
35
|
+
- **输入/输出护栏(guardrails)**:过滤/审核输入与输出(敏感词、PII、越权、有害内容、越狱),检测对抗行为。
|
|
36
|
+
- **工具/Agent 护栏**:工具**白名单** + 参数校验 + 权限校验(Agent 不能调用它不该调的工具/越权操作);危险操作需确认。
|
|
37
|
+
- 不把密钥/内部数据放进会发给模型的上下文;输出落库/执行前校验。
|
|
38
|
+
|
|
39
|
+
## 4. Agent(智能体)
|
|
40
|
+
|
|
41
|
+
- 明确**工具集 + 权限边界**;每个工具有 schema 校验与授权。
|
|
42
|
+
- **防失控成本**:Agent 反复检索/调用不收敛会烧 token/延迟——设**步数/预算/超时上限** + 循环检测 + 兜底退出。
|
|
43
|
+
- 关键动作(写库、发消息、花钱)需幂等 + 审计 + 必要时人工确认(human-in-the-loop)。
|
|
44
|
+
- 可观测:记录每步思考/工具调用/结果,便于调试与审计。
|
|
45
|
+
|
|
46
|
+
## 5. 成本与性能
|
|
47
|
+
|
|
48
|
+
- 控制 token:精简 prompt/上下文、缓存(prompt cache/语义缓存重复问)、截断历史、小模型分流。
|
|
49
|
+
- 监控每请求/每用户 **token 成本**;设配额/限流防滥用与成本爆炸。
|
|
50
|
+
- 流式 + 提前返回提升体感;批处理离线任务。
|
|
51
|
+
|
|
52
|
+
## 6. 评测与可观测(让 AI 可度量)
|
|
53
|
+
|
|
54
|
+
- **LLM-as-judge**:用模型评估输出质量,在 **5-10% 生产流量**上跑,形成持续改进闭环。
|
|
55
|
+
- 建评测集(黄金问答/标注),回归测试 prompt/模型变更,防"改了更差"。
|
|
56
|
+
- 可观测:记录 prompt/响应/延迟/成本/反馈/检索命中(脱敏 PII),接 LLM 观测工具。
|
|
57
|
+
- 收集用户反馈(赞/踩)闭环优化。
|
|
58
|
+
|
|
59
|
+
## 7. 反模式(出现即不合格)
|
|
60
|
+
|
|
61
|
+
- 无任何护栏,用户输入直接拼进系统提示(易被注入/越狱)。
|
|
62
|
+
- RAG 把检索文档当指令信任(间接提示注入);不评估检索质量。
|
|
63
|
+
- Agent 无步数/预算上限(成本炸弹)、工具无白名单/权限校验。
|
|
64
|
+
- prompt 硬编码散落、无版本;不监控 token 成本、不限流。
|
|
65
|
+
- 不评测不可观测,改 prompt/模型凭感觉;幻觉无来源引用。
|
|
66
|
+
- 密钥/敏感数据进模型上下文;输出不校验直接执行/落库。
|
|
67
|
+
|
|
68
|
+
## 8. 最低交付 checklist
|
|
69
|
+
|
|
70
|
+
- [ ] 抽象 LLM 供应商 + 模型分层路由(小模型分流) + 流式 + 超时重试限流。
|
|
71
|
+
- [ ] RAG:合理切分+向量检索+rerank+来源引用+检索评估。
|
|
72
|
+
- [ ] 护栏:输入输出过滤、提示注入(直接+间接/检索内容当数据)防护、工具白名单+参数/权限校验。
|
|
73
|
+
- [ ] Agent:步数/预算/超时上限 + 循环检测 + 关键动作幂等/审计/人工确认。
|
|
74
|
+
- [ ] 成本:token 监控 + 缓存 + 配额限流;prompt 模板+版本。
|
|
75
|
+
- [ ] 评测:LLM-as-judge + 评测集回归 + 可观测(prompt/成本/延迟/反馈) + 用户反馈闭环。
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
**参考**:OWASP LLM Top 10(提示注入/不安全输出/过度代理)、RAG 生产实践、LLM Guardrails、LLM-as-judge 评测、各模型供应商官方最佳实践。
|