@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.
Files changed (418) hide show
  1. package/00-governance/governance-capabilities.md +557 -0
  2. package/00-governance/knowledge-map.md +39 -0
  3. package/00-governance/maintenance-policy.md +76 -0
  4. package/00-governance/review-checklist.md +81 -0
  5. package/README.md +13 -0
  6. package/ai/01-standards/agent-development-complete.md +691 -0
  7. package/ai/01-standards/llm-application-complete.md +488 -0
  8. package/ai/01-standards/mlops-complete.md +798 -0
  9. package/ai/01-standards/prompt-engineering-complete.md +646 -0
  10. package/ai/01-standards/rag-architecture-complete.md +649 -0
  11. package/ai/02-playbooks/llm-evaluation-playbook.md +847 -0
  12. package/ai/03-checklists/ai-project-checklist.md +215 -0
  13. package/ai/04-antipatterns/ai-antipatterns.md +661 -0
  14. package/ai/05-cases/case-rag-production.md +147 -0
  15. package/ai/06-glossary/ai-glossary.md +162 -0
  16. package/ai/agent-evaluation-benchmark.md +53 -0
  17. package/ai/ai-agent-memory-context-management.md +41 -0
  18. package/ai/ai-cost-capacity-optimization-playbook.md +42 -0
  19. package/ai/ai-data-security-and-compliance-playbook.md +37 -0
  20. package/ai/ai-domain-index-and-checklist.md +40 -0
  21. package/ai/ai-governance-maturity-model.md +50 -0
  22. package/ai/ai-model-selection-and-routing-strategy.md +47 -0
  23. package/ai/ai-observability-and-oncall-runbook.md +52 -0
  24. package/ai/ai-rag-engineering-playbook.md +42 -0
  25. package/ai/ai-red-team-and-safety-evaluation.md +42 -0
  26. package/ai/ai-release-readiness-and-rollback-gate.md +42 -0
  27. package/ai/llm-agent-engineering-deep-dive.md +57 -0
  28. package/ai/prompt-and-tool-guardrails.md +52 -0
  29. package/api/01-standards/enterprise-api-standards.md +198 -0
  30. package/api/01-standards/rest-api-design-guide.md +63 -0
  31. package/api/02-playbooks/api-pagination-playbook.md +93 -0
  32. package/api/02-playbooks/graphql-production-playbook.md +176 -0
  33. package/api/03-checklists/api-review-checklist.md +55 -0
  34. package/api/04-antipatterns/api-antipatterns.md +112 -0
  35. package/architecture/01-standards/api-gateway-patterns.md +496 -0
  36. package/architecture/01-standards/cloud-native-patterns.md +644 -0
  37. package/architecture/01-standards/distributed-systems-patterns.md +591 -0
  38. package/architecture/01-standards/event-driven-architecture.md +595 -0
  39. package/architecture/01-standards/microservices-patterns-complete.md +968 -0
  40. package/architecture/01-standards/microservices-patterns.md +495 -0
  41. package/architecture/01-standards/system-design-interview.md +664 -0
  42. package/architecture/02-playbooks/microservices-patterns-playbook.md +137 -0
  43. package/architecture/02-playbooks/migration-playbook.md +780 -0
  44. package/architecture/02-playbooks/system-design-playbook.md +779 -0
  45. package/architecture/03-checklists/architecture-decision-checklist.md +297 -0
  46. package/architecture/04-antipatterns/architecture-antipatterns.md +417 -0
  47. package/architecture/05-cases/case-netflix-microservices.md +413 -0
  48. package/architecture/06-glossary/architecture-glossary.md +164 -0
  49. package/architecture/adr-template-and-examples.md +38 -0
  50. package/architecture/api-gateway-deep-dive.md +1291 -0
  51. package/architecture/configuration-management.md +1162 -0
  52. package/architecture/distributed-transactions.md +1220 -0
  53. package/architecture/microservices-complete.md +735 -0
  54. package/architecture/resilience-and-disaster-patterns.md +37 -0
  55. package/architecture/service-governance.md +1198 -0
  56. package/architecture/system-architecture-deep-dive.md +37 -0
  57. package/backend/01-standards/analytics-and-growth.md +65 -0
  58. package/backend/01-standards/api-and-error-conventions.md +120 -0
  59. package/backend/01-standards/application-layering-and-packaging.md +160 -0
  60. package/backend/01-standards/auth-implementation.md +104 -0
  61. package/backend/01-standards/backend-framework-idioms.md +74 -0
  62. package/backend/01-standards/background-jobs-and-async.md +66 -0
  63. package/backend/01-standards/caching-strategies-complete.md +390 -0
  64. package/backend/01-standards/config-and-observability.md +77 -0
  65. package/backend/01-standards/data-modeling-and-persistence.md +94 -0
  66. package/backend/01-standards/django-complete.md +1765 -0
  67. package/backend/01-standards/email-and-notifications.md +64 -0
  68. package/backend/01-standards/fastapi-complete.md +925 -0
  69. package/backend/01-standards/file-upload-and-storage.md +66 -0
  70. package/backend/01-standards/graphql-api-complete.md +416 -0
  71. package/backend/01-standards/llm-application-standard.md +78 -0
  72. package/backend/01-standards/message-queue-patterns.md +379 -0
  73. package/backend/01-standards/microservices-and-distributed.md +78 -0
  74. package/backend/01-standards/nestjs-complete.md +2167 -0
  75. package/backend/01-standards/payment-integration.md +80 -0
  76. package/backend/01-standards/rate-limiting-complete.md +451 -0
  77. package/backend/01-standards/realtime-and-websocket.md +65 -0
  78. package/backend/01-standards/search-and-filtering.md +64 -0
  79. package/backend/01-standards/spring-boot-complete.md +445 -0
  80. package/backend/02-playbooks/api-design-playbook.md +718 -0
  81. package/backend/02-playbooks/email-send-playbook.md +130 -0
  82. package/backend/02-playbooks/file-upload-s3-playbook.md +153 -0
  83. package/backend/02-playbooks/typescript-enterprise-playbook.md +133 -0
  84. package/backend/02-playbooks/websocket-realtime-playbook.md +154 -0
  85. package/backend/03-checklists/api-launch-checklist.md +189 -0
  86. package/backend/04-antipatterns/backend-antipatterns.md +1051 -0
  87. package/blockchain/01-standards/blockchain-basics.md +557 -0
  88. package/blockchain/01-standards/smart-contract-development.md +1315 -0
  89. package/cicd/01-standards/deployment-and-delivery-standard.md +96 -0
  90. package/cicd/01-standards/github-actions-complete.md +473 -0
  91. package/cicd/01-standards/release-and-store-submission.md +75 -0
  92. package/cicd/02-playbooks/cicd-pipeline-playbook.md +144 -0
  93. package/cicd/02-playbooks/release-management-playbook.md +605 -0
  94. package/cicd/03-checklists/pipeline-security-checklist.md +168 -0
  95. package/cicd/04-antipatterns/cicd-antipatterns.md +589 -0
  96. package/cicd/05-cases/case-deployment-automation.md +221 -0
  97. package/cicd/05-cases/case-gitops-transformation.md +212 -0
  98. package/cicd/06-glossary/cicd-glossary.md +114 -0
  99. package/cicd/cicd-blueprint-deep-dive.md +38 -0
  100. package/cicd/release-readiness-gate.md +37 -0
  101. package/cloud-native/01-standards/container-security.md +741 -0
  102. package/cloud-native/01-standards/kubernetes-complete.md +812 -0
  103. package/cloud-native/02-playbooks/api-gateway-playbook.md +155 -0
  104. package/cloud-native/02-playbooks/gitops-with-argocd.md +760 -0
  105. package/cloud-native/02-playbooks/k8s-troubleshooting-playbook.md +1942 -0
  106. package/cloud-native/02-playbooks/message-queue-playbook.md +129 -0
  107. package/cloud-native/02-playbooks/multicloud-governance.md +726 -0
  108. package/cloud-native/02-playbooks/serverless-patterns.md +788 -0
  109. package/cloud-native/02-playbooks/service-mesh-playbook.md +612 -0
  110. package/cloud-native/02-playbooks/terraform-iac-playbook.md +143 -0
  111. package/cloud-native/03-checklists/container-security-checklist.md +431 -0
  112. package/cloud-native/03-checklists/k8s-production-readiness-checklist.md +460 -0
  113. package/cloud-native/04-antipatterns/container-antipatterns.md +660 -0
  114. package/cloud-native/04-antipatterns/k8s-antipatterns.md +743 -0
  115. package/cloud-native/05-cases/case-k8s-migration.md +478 -0
  116. package/cloud-native/05-cases/case-k8s-scaling.md +642 -0
  117. package/cloud-native/05-cases/case-k8s-security-incident.md +397 -0
  118. package/cloud-native/06-glossary/cloud-native-glossary.md +337 -0
  119. package/cross-platform/01-standards/cross-platform-frameworks.md +83 -0
  120. package/cross-platform/01-standards/platform-selection-and-architecture.md +77 -0
  121. package/data/01-standards/elasticsearch-complete.md +2098 -0
  122. package/data/01-standards/postgresql-complete.md +1613 -0
  123. package/data/01-standards/redis-complete.md +1527 -0
  124. package/data/02-playbooks/database-optimization-playbook.md +403 -0
  125. package/data/02-playbooks/elasticsearch-production-playbook.md +132 -0
  126. package/data/03-checklists/database-launch-checklist.md +187 -0
  127. package/data/04-antipatterns/database-antipatterns.md +873 -0
  128. package/data/05-cases/case-database-migration.md +310 -0
  129. package/data/06-glossary/database-glossary.md +440 -0
  130. package/data/data-governance-and-modeling-deep-dive.md +39 -0
  131. package/data-engineering/01-standards/airflow-complete.md +523 -0
  132. package/data-engineering/01-standards/kafka-complete.md +1521 -0
  133. package/data-engineering/02-playbooks/spark-etl-playbook.md +496 -0
  134. package/data-engineering/03-checklists/pipeline-launch-checklist.md +194 -0
  135. package/data-engineering/04-antipatterns/data-pipeline-antipatterns.md +684 -0
  136. package/data-engineering/05-cases/case-real-time-pipeline.md +355 -0
  137. package/data-engineering/06-glossary/data-engineering-glossary.md +429 -0
  138. package/database/01-standards/database-schema-standards.md +147 -0
  139. package/database/02-playbooks/postgresql-optimization-quick.md +52 -0
  140. package/database/02-playbooks/postgresql-performance-optimization.md +58 -0
  141. package/database/02-playbooks/postgresql-production-playbook.md +146 -0
  142. package/database/02-playbooks/redis-caching-playbook.md +117 -0
  143. package/database/03-checklists/database-review-checklist.md +50 -0
  144. package/database/04-antipatterns/database-antipatterns.md +112 -0
  145. package/design/01-standards/ui-design-system-complete.md +423 -0
  146. package/design/02-playbooks/design-handoff-playbook.md +254 -0
  147. package/design/02-playbooks/design-review-playbook.md +388 -0
  148. package/design/03-checklists/design-review-checklist.md +246 -0
  149. package/design/04-antipatterns/design-antipatterns.md +378 -0
  150. package/design/05-cases/case-design-system-adoption.md +328 -0
  151. package/design/06-glossary/design-glossary.md +329 -0
  152. package/design/ui-full-lifecycle-cross-platform-playbook.md +571 -0
  153. package/design/ux-system-deep-dive.md +38 -0
  154. package/design-systems/00-craft-rules.md +71 -0
  155. package/design-systems/aesthetic-families.md +43 -0
  156. package/design-systems/anti-ai-slop.md +162 -0
  157. package/design-systems/bold-geometric.md +120 -0
  158. package/design-systems/brutalist-bold.md +103 -0
  159. package/design-systems/editorial-clean.md +109 -0
  160. package/design-systems/glass-aurora.md +108 -0
  161. package/design-systems/modern-minimal.md +145 -0
  162. package/design-systems/premium-luxury.md +106 -0
  163. package/design-systems/product-type-design-map.md +48 -0
  164. package/design-systems/soft-warm.md +123 -0
  165. package/design-systems/tech-utility.md +113 -0
  166. package/desktop/01-standards/desktop-app-standard.md +72 -0
  167. package/desktop/01-standards/desktop-design.md +71 -0
  168. package/development/00-governance/document-template.md +41 -0
  169. package/development/01-standards/api-versioning-strategies.md +432 -0
  170. package/development/01-standards/authentication-patterns-complete.md +479 -0
  171. package/development/01-standards/css-architecture-complete.md +550 -0
  172. package/development/01-standards/database-migration-strategies.md +484 -0
  173. package/development/01-standards/elasticsearch-complete.md +347 -0
  174. package/development/01-standards/git-complete.md +371 -0
  175. package/development/01-standards/golang-complete.md +1565 -0
  176. package/development/01-standards/graphql-complete.md +298 -0
  177. package/development/01-standards/javascript-bundlers-complete.md +469 -0
  178. package/development/01-standards/javascript-typescript-complete.md +528 -0
  179. package/development/01-standards/jest-complete.md +275 -0
  180. package/development/01-standards/linux-complete.md +234 -0
  181. package/development/01-standards/logging-observability-complete.md +526 -0
  182. package/development/01-standards/microservices-communication.md +502 -0
  183. package/development/01-standards/mongodb-complete.md +406 -0
  184. package/development/01-standards/oauth2-complete.md +285 -0
  185. package/development/01-standards/performance-optimization-complete.md +289 -0
  186. package/development/01-standards/playwright-complete.md +247 -0
  187. package/development/01-standards/postgresql-complete.md +456 -0
  188. package/development/01-standards/pytest-complete.md +340 -0
  189. package/development/01-standards/python-async-programming.md +902 -0
  190. package/development/01-standards/python-complete.md +956 -0
  191. package/development/01-standards/python-decorators-complete.md +799 -0
  192. package/development/01-standards/python-design-patterns.md +2854 -0
  193. package/development/01-standards/python-packaging-distribution.md +420 -0
  194. package/development/01-standards/python-testing-strategies.md +607 -0
  195. package/development/01-standards/python-web-frameworks-comparison.md +471 -0
  196. package/development/01-standards/redis-complete.md +317 -0
  197. package/development/01-standards/rest-api-complete.md +316 -0
  198. package/development/01-standards/rust-complete.md +578 -0
  199. package/development/01-standards/typescript-advanced-types.md +1513 -0
  200. package/development/01-standards/web-security-complete.md +292 -0
  201. package/development/02-playbooks/api-design-playbook.md +810 -0
  202. package/development/02-playbooks/database-migration-playbook.md +580 -0
  203. package/development/02-playbooks/debugging-playbook.md +692 -0
  204. package/development/02-playbooks/feature-delivery-playbook.md +430 -0
  205. package/development/02-playbooks/incident-hotfix-playbook.md +387 -0
  206. package/development/02-playbooks/performance-optimization-playbook.md +531 -0
  207. package/development/02-playbooks/performance-tuning-playbook.md +652 -0
  208. package/development/02-playbooks/refactor-playbook.md +403 -0
  209. package/development/02-playbooks/release-playbook.md +469 -0
  210. package/development/03-checklists/architecture-review-checklist.md +168 -0
  211. package/development/03-checklists/data-migration-checklist.md +157 -0
  212. package/development/03-checklists/oncall-handover-checklist.md +173 -0
  213. package/development/03-checklists/pr-checklist.md +158 -0
  214. package/development/03-checklists/production-readiness-checklist.md +190 -0
  215. package/development/03-checklists/release-readiness-checklist.md +154 -0
  216. package/development/03-checklists/security-review-checklist.md +182 -0
  217. package/development/04-antipatterns/api-antipatterns.md +657 -0
  218. package/development/04-antipatterns/architecture-antipatterns.md +686 -0
  219. package/development/04-antipatterns/backend-antipatterns.md +648 -0
  220. package/development/04-antipatterns/cicd-antipatterns.md +540 -0
  221. package/development/04-antipatterns/code-smell-antipatterns.md +571 -0
  222. package/development/04-antipatterns/data-antipatterns.md +658 -0
  223. package/development/04-antipatterns/database-antipatterns.md +578 -0
  224. package/development/04-antipatterns/frontend-antipatterns.md +635 -0
  225. package/development/04-antipatterns/reliability-antipatterns.md +700 -0
  226. package/development/04-antipatterns/security-antipatterns.md +747 -0
  227. package/development/05-cases/case-api-version-migration.md +428 -0
  228. package/development/05-cases/case-authorization-hardening.md +383 -0
  229. package/development/05-cases/case-bluegreen-rollback.md +466 -0
  230. package/development/05-cases/case-cache-snowball-protection.md +485 -0
  231. package/development/05-cases/case-ci-cd-pipeline.md +544 -0
  232. package/development/05-cases/case-database-scaling.md +500 -0
  233. package/development/05-cases/case-db-hotspot-optimization.md +487 -0
  234. package/development/05-cases/case-incident-mttr-reduction.md +563 -0
  235. package/development/05-cases/case-microservice-migration.md +375 -0
  236. package/development/05-cases/case-performance-optimization.md +406 -0
  237. package/development/05-cases/case-security-incident-response.md +345 -0
  238. package/development/06-glossary/full-stack-glossary.md +166 -0
  239. package/development/09-maturity/quarterly-audit-template.md +35 -0
  240. package/development/11-ui-excellence/ui-aesthetic-system.md +41 -0
  241. package/development/11-ui-excellence/ui-engineering-excellence.md +435 -0
  242. package/development/12-scenarios/development-scenarios-guide.md +565 -0
  243. package/development/13-implementation-assets/implementation-toolkit.md +282 -0
  244. package/development/13-implementation-assets/knowledge-gates-execution.md +43 -0
  245. package/development/14-full-lifecycle/software-lifecycle-gates.md +511 -0
  246. package/development/15-lifecycle-templates/project-templates-collection.md +791 -0
  247. package/development/api-contract-and-versioning-guide.md +36 -0
  248. package/development/api-governance-complete.md +43 -0
  249. package/development/backend-engineering-complete.md +43 -0
  250. package/development/code-review-quality-complete.md +43 -0
  251. package/development/concurrency-reliability-complete.md +43 -0
  252. package/development/database-engineering-complete.md +43 -0
  253. package/development/engineering-effectiveness-complete.md +43 -0
  254. package/development/engineering-standards-deep-dive.md +38 -0
  255. package/development/frontend-engineering-complete.md +43 -0
  256. package/development/performance-capacity-complete.md +43 -0
  257. package/development/refactor-migration-complete.md +42 -0
  258. package/development/refactoring-and-techdebt-playbook.md +37 -0
  259. package/development/security-in-development-complete.md +43 -0
  260. package/devops/01-standards/cicd-pipeline-complete.md +262 -0
  261. package/devops/01-standards/docker-complete.md +1490 -0
  262. package/devops/01-standards/github-actions-complete.md +337 -0
  263. package/devops/01-standards/kubernetes-complete.md +638 -0
  264. package/devops/01-standards/terraform-complete.md +2117 -0
  265. package/devops/02-playbooks/docker-compose-playbook.md +233 -0
  266. package/devops/02-playbooks/docker-k8s-production-playbook.md +186 -0
  267. package/devops/02-playbooks/docker-production-playbook.md +952 -0
  268. package/edge-iot/01-standards/edge-iot-complete.md +473 -0
  269. package/experts/architect/api-design.md +178 -0
  270. package/experts/architect/methodology.md +124 -0
  271. package/experts/architect/security.md +75 -0
  272. package/experts/backend-lead/methodology.md +216 -0
  273. package/experts/devops/methodology.md +160 -0
  274. package/experts/frontend-lead/methodology.md +178 -0
  275. package/experts/product-manager/industry/ecommerce.md +43 -0
  276. package/experts/product-manager/industry/saas.md +40 -0
  277. package/experts/product-manager/methodology.md +97 -0
  278. package/experts/qa-lead/methodology.md +123 -0
  279. package/experts/qa-lead/test-strategy.md +128 -0
  280. package/experts/uiux-designer/methodology.md +125 -0
  281. package/frontend/01-standards/accessibility-complete.md +532 -0
  282. package/frontend/01-standards/accessibility-standard.md +74 -0
  283. package/frontend/01-standards/admin-dashboard-and-crud.md +72 -0
  284. package/frontend/01-standards/design-tokens-complete.md +444 -0
  285. package/frontend/01-standards/forms-and-validation.md +77 -0
  286. package/frontend/01-standards/frontend-architecture-and-layering.md +119 -0
  287. package/frontend/01-standards/i18n-and-localization.md +65 -0
  288. package/frontend/01-standards/nextjs-complete.md +451 -0
  289. package/frontend/01-standards/react-complete.md +713 -0
  290. package/frontend/01-standards/react-hooks-complete-guide.md +1100 -0
  291. package/frontend/01-standards/react-hooks-complete.md +1171 -0
  292. package/frontend/01-standards/seo-and-web-vitals.md +77 -0
  293. package/frontend/01-standards/state-management-complete.md +444 -0
  294. package/frontend/01-standards/vue-complete.md +499 -0
  295. package/frontend/01-standards/vue3-complete.md +2002 -0
  296. package/frontend/01-standards/web-framework-best-practices.md +64 -0
  297. package/frontend/01-standards/web-performance-complete.md +495 -0
  298. package/frontend/02-playbooks/accessibility-a11y-playbook.md +161 -0
  299. package/frontend/02-playbooks/frontend-performance-playbook.md +707 -0
  300. package/frontend/02-playbooks/i18n-internationalization-playbook.md +120 -0
  301. package/frontend/02-playbooks/performance-optimization-playbook.md +163 -0
  302. package/frontend/02-playbooks/react-nextjs-production-playbook.md +167 -0
  303. package/frontend/02-playbooks/react-state-management-playbook.md +173 -0
  304. package/frontend/03-checklists/component-quality-checklist.md +166 -0
  305. package/frontend/03-checklists/frontend-launch-checklist.md +299 -0
  306. package/frontend/04-antipatterns/frontend-antipatterns.md +886 -0
  307. package/frontend/05-cases/case-performance-optimization.md +274 -0
  308. package/harmony/01-standards/harmonyos-arkts-standard.md +75 -0
  309. package/harmony/01-standards/harmonyos-design.md +65 -0
  310. package/high-quality-engineering-playbook.md +54 -0
  311. package/incident/01-standards/incident-response-complete.md +303 -0
  312. package/incident/02-playbooks/chaos-engineering-playbook.md +883 -0
  313. package/incident/02-playbooks/postmortem-playbook.md +398 -0
  314. package/incident/03-checklists/incident-readiness-checklist.md +181 -0
  315. package/incident/04-antipatterns/incident-antipatterns.md +490 -0
  316. package/incident/05-cases/case-cascade-failure.md +176 -0
  317. package/incident/06-glossary/incident-glossary.md +114 -0
  318. package/incident/postmortem-and-response-deep-dive.md +39 -0
  319. package/industries/ecommerce/ecommerce-complete.md +631 -0
  320. package/industries/education/education-complete.md +555 -0
  321. package/industries/fintech/fintech-complete.md +501 -0
  322. package/industries/gaming/gaming-complete.md +587 -0
  323. package/industries/healthcare/healthcare-complete.md +452 -0
  324. package/low-code/01-standards/low-code-complete.md +944 -0
  325. package/miniprogram/01-standards/ai-common-mistakes.md +61 -0
  326. package/miniprogram/01-standards/miniprogram-custom-navbar-capsule.md +77 -0
  327. package/miniprogram/01-standards/miniprogram-design.md +61 -0
  328. package/miniprogram/01-standards/miniprogram-standard.md +81 -0
  329. package/mobile/01-standards/android-material-design.md +70 -0
  330. package/mobile/01-standards/flutter-complete.md +384 -0
  331. package/mobile/01-standards/ios-design-hig.md +78 -0
  332. package/mobile/01-standards/mobile-app-standard.md +85 -0
  333. package/mobile/01-standards/react-native-complete.md +352 -0
  334. package/mobile/02-playbooks/mobile-cross-platform-playbook.md +175 -0
  335. package/mobile/02-playbooks/mobile-performance.md +473 -0
  336. package/mobile/03-checklists/mobile-release-checklist.md +234 -0
  337. package/mobile/04-antipatterns/mobile-antipatterns.md +798 -0
  338. package/mobile/05-cases/case-app-performance.md +500 -0
  339. package/mobile/05-cases/case-app-startup-optimization.md +218 -0
  340. package/mobile/06-glossary/mobile-glossary.md +484 -0
  341. package/observability/01-standards/observability-standards.md +103 -0
  342. package/observability/02-playbooks/prometheus-grafana-playbook.md +135 -0
  343. package/observability/02-playbooks/structured-logging-playbook.md +73 -0
  344. package/observability/03-checklists/observability-checklist.md +54 -0
  345. package/observability/04-antipatterns/observability-antipatterns.md +106 -0
  346. package/operations/01-standards/prometheus-monitoring-complete.md +1578 -0
  347. package/operations/02-playbooks/capacity-planning-playbook.md +620 -0
  348. package/operations/03-checklists/production-launch-checklist.md +365 -0
  349. package/operations/04-antipatterns/operations-antipatterns.md +664 -0
  350. package/operations/05-cases/case-sre-practices.md +581 -0
  351. package/operations/06-glossary/operations-glossary.md +120 -0
  352. package/operations/aiops-anomaly-detection.md +758 -0
  353. package/operations/capacity-planning.md +1061 -0
  354. package/operations/chaos-engineering.md +659 -0
  355. package/operations/incident-command-system.md +38 -0
  356. package/operations/observability-complete.md +442 -0
  357. package/operations/slo-sli-playbook.md +517 -0
  358. package/operations/sre-operations-deep-dive.md +39 -0
  359. package/package.json +8 -0
  360. package/performance/01-standards/performance-and-scalability.md +80 -0
  361. package/performance/01-standards/performance-standards.md +156 -0
  362. package/performance/02-playbooks/query-optimization-playbook.md +103 -0
  363. package/performance/03-checklists/performance-checklist.md +56 -0
  364. package/performance/04-antipatterns/performance-antipatterns.md +146 -0
  365. package/product/01-standards/product-management-complete.md +285 -0
  366. package/product/02-playbooks/feature-launch-playbook.md +207 -0
  367. package/product/02-playbooks/user-research-playbook.md +532 -0
  368. package/product/03-checklists/feature-launch-checklist.md +275 -0
  369. package/product/04-antipatterns/product-antipatterns.md +355 -0
  370. package/product/05-cases/case-mvp-to-scale.md +384 -0
  371. package/product/06-glossary/product-glossary.md +462 -0
  372. package/product/feature-prioritization-framework.md +40 -0
  373. package/product/kpi-and-metric-tree.md +37 -0
  374. package/product/product-discovery-and-prd-deep-dive.md +41 -0
  375. package/quantum/01-standards/quantum-complete.md +1186 -0
  376. package/security/01-standards/api-security-complete.md +511 -0
  377. package/security/01-standards/container-runtime-security.md +574 -0
  378. package/security/01-standards/data-protection-gdpr.md +543 -0
  379. package/security/01-standards/owasp-top10-complete.md +1890 -0
  380. package/security/01-standards/secure-coding-baseline.md +90 -0
  381. package/security/01-standards/supply-chain-security.md +441 -0
  382. package/security/01-standards/web-security-checklist.md +108 -0
  383. package/security/01-standards/zero-trust-architecture.md +521 -0
  384. package/security/02-playbooks/auth-sso-playbook.md +166 -0
  385. package/security/02-playbooks/incident-response-security-playbook.md +588 -0
  386. package/security/02-playbooks/owasp-api-security-playbook.md +129 -0
  387. package/security/02-playbooks/payment-integration-playbook.md +119 -0
  388. package/security/02-playbooks/penetration-testing-playbook.md +517 -0
  389. package/security/03-checklists/security-audit-checklist.md +356 -0
  390. package/security/04-antipatterns/security-coding-antipatterns.md +580 -0
  391. package/security/05-cases/case-log4shell-incident.md +537 -0
  392. package/security/05-cases/case-major-breaches.md +468 -0
  393. package/security/06-glossary/security-glossary.md +212 -0
  394. package/security/compliance-automation.md +993 -0
  395. package/security/container-security.md +680 -0
  396. package/security/devsecops-complete.md +426 -0
  397. package/security/sast-dast-sca.md +775 -0
  398. package/security/secrets-management.md +594 -0
  399. package/security/security-architecture-deep-dive.md +37 -0
  400. package/security/threat-modeling-stride-playbook.md +40 -0
  401. package/seed-templates/auth-system.md +59 -0
  402. package/seed-templates/blog-content.md +94 -0
  403. package/seed-templates/dashboard.md +89 -0
  404. package/seed-templates/docs-site.md +73 -0
  405. package/seed-templates/e-commerce.md +50 -0
  406. package/seed-templates/saas-landing.md +92 -0
  407. package/seed-templates/settings-page.md +51 -0
  408. package/testing/01-standards/test-strategy-and-layering.md +83 -0
  409. package/testing/01-standards/testing-strategy-complete.md +422 -0
  410. package/testing/01-standards/unit-testing-best-practices.md +118 -0
  411. package/testing/02-playbooks/e2e-testing-playbook.md +988 -0
  412. package/testing/02-playbooks/testing-strategy-playbook.md +126 -0
  413. package/testing/03-checklists/test-strategy-checklist.md +208 -0
  414. package/testing/04-antipatterns/testing-antipatterns.md +718 -0
  415. package/testing/05-cases/case-testing-transformation.md +300 -0
  416. package/testing/06-glossary/testing-glossary.md +110 -0
  417. package/testing/risk-based-test-matrix.md +36 -0
  418. package/testing/testing-strategy-deep-dive.md +37 -0
@@ -0,0 +1,798 @@
1
+ ---
2
+ title: 移动开发反模式库
3
+ category: mobile/antipatterns
4
+ version: 1.0.0
5
+ last_updated: 2026-03-20
6
+ maintainer: Excellent(11964948@qq.com)
7
+ knowledge_score: 9.0/10
8
+ domain: mobile
9
+ difficulty: intermediate
10
+ quality_score: 70
11
+ ---
12
+
13
+ # 开发:Excellent(11964948@qq.com)
14
+
15
+ ## 移动开发反模式库
16
+
17
+ ### 1. 性能反模式
18
+
19
+ #### 1.1 长列表使用 ScrollView
20
+ **反模式描述**
21
+ 使用 ScrollView 渲染长列表(100+ 项),导致内存占用过高和滚动卡顿。
22
+
23
+ **识别信号**
24
+ - 列表项超过 50 个仍使用 ScrollView
25
+ - 滚动时 FPS 低于 50
26
+ - 内存占用持续增长
27
+
28
+ **替代实践**
29
+ 使用虚拟列表(FlatList/ListView.builder)只渲染可见区域。
30
+
31
+ ```typescript
32
+ // 反模式
33
+ <ScrollView>
34
+ {items.map(item => <Item key={item.id} data={item} />)}
35
+ </ScrollView>
36
+
37
+ // 正确做法
38
+ <FlatList
39
+ data={items}
40
+ renderItem={({ item }) => <Item data={item} />}
41
+ keyExtractor={item => item.id}
42
+ initialNumToRender={10}
43
+ maxToRenderPerBatch={10}
44
+ windowSize={5}
45
+ />
46
+ ```
47
+
48
+ #### 1.2 主线程执行耗时操作
49
+ **反模式描述**
50
+ 在主线程执行网络请求、大量计算、文件读写,导致 ANR 或卡顿。
51
+
52
+ **识别信号**
53
+ - UI 线程阻塞超过 16ms
54
+ - 用户操作响应延迟
55
+ - ANR 率 > 0.05%
56
+
57
+ **替代实践**
58
+ 使用异步任务或后台线程。
59
+
60
+ ```dart
61
+ // 反模式
62
+ void loadData() {
63
+ final data = heavyComputation(); // 阻塞主线程
64
+ setState(() {
65
+ items = data;
66
+ });
67
+ }
68
+
69
+ // 正确做法
70
+ Future<void> loadData() async {
71
+ final data = await compute(heavyComputation, null); // 后台线程
72
+ setState(() {
73
+ items = data;
74
+ });
75
+ }
76
+ ```
77
+
78
+ #### 1.3 大图片未压缩直接加载
79
+ **反模式描述**
80
+ 加载原图(5MB+)到内存,导致 OOM 和加载缓慢。
81
+
82
+ **识别信号**
83
+ - 内存峰值超过 300MB
84
+ - 图片加载超过 2 秒
85
+ - OOM 崩溃率高
86
+
87
+ **替代实践**
88
+ 压缩图片并使用缓存策略。
89
+
90
+ ```typescript
91
+ // 反模式
92
+ <Image source={{ uri: originalUrl }} style={{ width: 100, height: 100 }} />
93
+
94
+ // 正确做法
95
+ <FastImage
96
+ source={{
97
+ uri: thumbnailUrl,
98
+ priority: FastImage.priority.normal,
99
+ }}
100
+ style={{ width: 100, height: 100 }}
101
+ resizeMode={FastImage.resizeMode.cover}
102
+ />
103
+ ```
104
+
105
+ ### 2. 架构反模式
106
+
107
+ #### 2.1 业务逻辑写在视图层
108
+ **反模式描述**
109
+ 将复杂业务规则直接写在组件中,导致组件臃肿、难以测试和维护。
110
+
111
+ **识别信号**
112
+ - 组件代码超过 300 行
113
+ - 组件包含多个 API 调用和复杂计算
114
+ - 单元测试困难
115
+
116
+ **替代实践**
117
+ 将业务逻辑抽离到 Service 层或 ViewModel。
118
+
119
+ ```typescript
120
+ // 反模式
121
+ const UserList = () => {
122
+ const [users, setUsers] = useState([]);
123
+ const [loading, setLoading] = useState(false);
124
+
125
+ useEffect(() => {
126
+ setLoading(true);
127
+ fetch('/api/users')
128
+ .then(res => res.json())
129
+ .then(data => {
130
+ const filtered = data.filter(u => u.active);
131
+ const sorted = filtered.sort((a, b) => b.score - a.score);
132
+ setUsers(sorted);
133
+ setLoading(false);
134
+ });
135
+ }, []);
136
+
137
+ return <FlatList data={users} ... />;
138
+ };
139
+
140
+ // 正确做法
141
+ // userService.ts
142
+ export class UserService {
143
+ async getActiveUsersSortedByScore(): Promise<User[]> {
144
+ const response = await fetch('/api/users');
145
+ const users = await response.json();
146
+ return users
147
+ .filter(u => u.active)
148
+ .sort((a, b) => b.score - a.score);
149
+ }
150
+ }
151
+
152
+ // UserList.tsx
153
+ const UserList = () => {
154
+ const [users, setUsers] = useState([]);
155
+ const userService = new UserService();
156
+
157
+ useEffect(() => {
158
+ userService.getActiveUsersSortedByScore()
159
+ .then(setUsers);
160
+ }, []);
161
+
162
+ return <FlatList data={users} ... />;
163
+ };
164
+ ```
165
+
166
+ #### 2.2 全局状态滥用
167
+ **反模式描述**
168
+ 将所有状态都放入全局状态管理,导致性能下降和调试困难。
169
+
170
+ **识别信号**
171
+ - 全局 store 包含大量临时状态
172
+ - 组件重渲染频繁
173
+ - 状态更新链路复杂
174
+
175
+ **替代实践**
176
+ 本地状态优先,仅在需要跨组件共享时使用全局状态。
177
+
178
+ ```typescript
179
+ // 反模式
180
+ const store = {
181
+ modalVisible: false, // 仅在一个组件使用
182
+ inputValue: '', // 仅在一个组件使用
183
+ theme: 'dark', // 全局共享,合理
184
+ };
185
+
186
+ // 正确做法
187
+ const Component = () => {
188
+ const [modalVisible, setModalVisible] = useState(false);
189
+ const [inputValue, setInputValue] = useState('');
190
+ const theme = useThemeStore(state => state.theme); // 仅全局状态
191
+ };
192
+ ```
193
+
194
+ ### 3. UI 反模式
195
+
196
+ #### 3.1 硬编码样式和颜色
197
+ **反模式描述**
198
+ 在代码中直接写死颜色值和样式,导致主题切换困难和维护成本高。
199
+
200
+ **识别信号**
201
+ - 代码中出现大量 #FFFFFF、#000000
202
+ - 同一颜色在不同文件重复定义
203
+ - 主题切换需求无法实现
204
+
205
+ **替代实践**
206
+ 使用设计令牌(Design Tokens)和主题系统。
207
+
208
+ ```typescript
209
+ // 反模式
210
+ <View style={{ backgroundColor: '#1E88E5', padding: 16 }}>
211
+ <Text style={{ color: '#FFFFFF', fontSize: 16 }}>Title</Text>
212
+ </View>
213
+
214
+ // 正确做法
215
+ // theme.ts
216
+ export const theme = {
217
+ colors: {
218
+ primary: '#1E88E5',
219
+ text: {
220
+ primary: '#FFFFFF',
221
+ secondary: '#757575',
222
+ },
223
+ },
224
+ spacing: {
225
+ md: 16,
226
+ },
227
+ typography: {
228
+ body: {
229
+ fontSize: 16,
230
+ },
231
+ },
232
+ };
233
+
234
+ // Component.tsx
235
+ <View style={{ backgroundColor: theme.colors.primary, padding: theme.spacing.md }}>
236
+ <Text style={{ color: theme.colors.text.primary, fontSize: theme.typography.body.fontSize }}>
237
+ Title
238
+ </Text>
239
+ </View>
240
+ ```
241
+
242
+ #### 3.2 缺少加载和错误状态
243
+ **反模式描述**
244
+ 只处理正常状态,缺少加载中、空态、错误态处理。
245
+
246
+ **识别信号**
247
+ - 网络慢时界面空白
248
+ - 请求失败无提示
249
+ - 空数据显示异常布局
250
+
251
+ **替代实践**
252
+ 完整的状态矩阵处理。
253
+
254
+ ```dart
255
+ // 反模式
256
+ Widget build(BuildContext context) {
257
+ return ListView(children: items);
258
+ }
259
+
260
+ // 正确做法
261
+ Widget build(BuildContext context) {
262
+ if (isLoading) {
263
+ return const Center(child: CircularProgressIndicator());
264
+ }
265
+
266
+ if (error != null) {
267
+ return Center(
268
+ child: Column(
269
+ mainAxisAlignment: MainAxisAlignment.center,
270
+ children: [
271
+ const Icon(Icons.error_outline, size: 48),
272
+ const SizedBox(height: 16),
273
+ Text(error!),
274
+ ElevatedButton(
275
+ onPressed: retry,
276
+ child: const Text('重试'),
277
+ ),
278
+ ],
279
+ ),
280
+ );
281
+ }
282
+
283
+ if (items.isEmpty) {
284
+ return const Center(
285
+ child: Column(
286
+ mainAxisAlignment: MainAxisAlignment.center,
287
+ children: [
288
+ Icon(Icons.inbox, size: 48),
289
+ SizedBox(height: 16),
290
+ Text('暂无数据'),
291
+ ],
292
+ ),
293
+ );
294
+ }
295
+
296
+ return ListView(children: items);
297
+ }
298
+ ```
299
+
300
+ ### 4. 网络反模式
301
+
302
+ #### 4.1 网络请求无超时和重试
303
+ **反模式描述**
304
+ 网络请求不设置超时时间,失败后不重试,用户体验差。
305
+
306
+ **识别信号**
307
+ - 弱网环境请求卡死
308
+ - 一次失败即展示错误
309
+ - 用户频繁手动重试
310
+
311
+ **替代实践**
312
+ 设置合理超时和重试策略。
313
+
314
+ ```typescript
315
+ // 反模式
316
+ const response = await fetch('/api/data');
317
+ const data = await response.json();
318
+
319
+ // 正确做法
320
+ async function fetchWithRetry(
321
+ url: string,
322
+ options: RequestInit = {},
323
+ maxRetries = 3
324
+ ): Promise<Response> {
325
+ const timeout = 10000; // 10 秒超时
326
+
327
+ for (let i = 0; i < maxRetries; i++) {
328
+ try {
329
+ const controller = new AbortController();
330
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
331
+
332
+ const response = await fetch(url, {
333
+ ...options,
334
+ signal: controller.signal,
335
+ });
336
+
337
+ clearTimeout(timeoutId);
338
+
339
+ if (response.ok) {
340
+ return response;
341
+ }
342
+ } catch (error) {
343
+ if (i === maxRetries - 1) throw error;
344
+ await new Promise(resolve => setTimeout(resolve, 1000 * (i + 1)));
345
+ }
346
+ }
347
+
348
+ throw new Error('Network request failed after retries');
349
+ }
350
+ ```
351
+
352
+ #### 4.2 缺少离线缓存
353
+ **反模式描述**
354
+ 每次打开应用都从网络加载数据,离线时无法使用。
355
+
356
+ **识别信号**
357
+ - 无网络时应用不可用
358
+ - 重复加载相同数据浪费流量
359
+ - 加载速度慢
360
+
361
+ **替代实践**
362
+ 实施离线优先策略(Cache-First)。
363
+
364
+ ```dart
365
+ // 反模式
366
+ Future<List<Item>> fetchItems() async {
367
+ final response = await dio.get('/api/items');
368
+ return (response.data as List).map((json) => Item.fromJson(json)).toList();
369
+ }
370
+
371
+ // 正确做法
372
+ Future<List<Item>> fetchItems() async {
373
+ // 1. 先读取本地缓存
374
+ final cached = await localDb.getItems();
375
+ if (cached.isNotEmpty) {
376
+ // 立即返回缓存数据
377
+ _notifyListeners(cached);
378
+ }
379
+
380
+ // 2. 后台请求网络数据
381
+ try {
382
+ final response = await dio.get('/api/items');
383
+ final items = (response.data as List)
384
+ .map((json) => Item.fromJson(json))
385
+ .toList();
386
+
387
+ // 3. 更新本地缓存
388
+ await localDb.saveItems(items);
389
+
390
+ // 4. 通知更新
391
+ _notifyListeners(items);
392
+ return items;
393
+ } catch (e) {
394
+ // 网络失败,使用缓存(如果有)
395
+ if (cached.isNotEmpty) {
396
+ return cached;
397
+ }
398
+ rethrow;
399
+ }
400
+ }
401
+ ```
402
+
403
+ ### 5. 安全反模式
404
+
405
+ #### 5.1 敏感数据明文存储
406
+ **反模式描述**
407
+ 将 token、密码等敏感信息直接存储在 AsyncStorage 或 SharedPreferences。
408
+
409
+ **识别信号**
410
+ - 代码中使用 AsyncStorage 存储 token
411
+ - root 权限设备可直接读取敏感数据
412
+ - 数据泄露风险高
413
+
414
+ **替代实践**
415
+ 使用系统安全存储(Keychain/Keystore)。
416
+
417
+ ```typescript
418
+ // 反模式
419
+ await AsyncStorage.setItem('auth_token', token);
420
+
421
+ // 正确做法
422
+ import Keychain from 'react-native-keychain';
423
+
424
+ // 存储
425
+ await Keychain.setGenericPassword('auth', token);
426
+
427
+ // 读取
428
+ const credentials = await Keychain.getGenericPassword();
429
+ if (credentials) {
430
+ const token = credentials.password;
431
+ }
432
+ ```
433
+
434
+ #### 5.2 WebView 不安全配置
435
+ **反模式描述**
436
+ WebView 允许任意来源加载、开启 JavaScript 无限制、文件访问权限过度。
437
+
438
+ **识别信号**
439
+ - WebView 加载 file:// 协议
440
+ - 允许所有来源内容
441
+ - 无白名单限制
442
+
443
+ **替代实践**
444
+ 严格限制 WebView 安全配置。
445
+
446
+ ```typescript
447
+ // 反模式
448
+ <WebView
449
+ source={{ uri: url }}
450
+ javaScriptEnabled={true}
451
+ originWhitelist={['*']}
452
+ />
453
+
454
+ // 正确做法
455
+ <WebView
456
+ source={{ uri: allowedDomains.includes(domain) ? url : 'about:blank' }}
457
+ javaScriptEnabled={true}
458
+ originWhitelist={['https://*.example.com']}
459
+ mixedContentMode="never"
460
+ allowFileAccess={false}
461
+ allowUniversalAccessFromFileURLs={false}
462
+ onShouldStartLoadWithRequest={(request) => {
463
+ return allowedDomains.some(domain => request.url.includes(domain));
464
+ }}
465
+ />
466
+ ```
467
+
468
+ ### 6. 数据库反模式
469
+
470
+ #### 6.1 主线程数据库操作
471
+ **反模式描述**
472
+ 在主线程执行数据库查询和写入,导致 UI 卡顿。
473
+
474
+ **识别信号**
475
+ - 数据库操作时界面冻结
476
+ - 数据量大时响应慢
477
+ - ANR 告警
478
+
479
+ **替代实践**
480
+ 数据库操作移到后台线程。
481
+
482
+ ```dart
483
+ // 反模式
484
+ Future<void> saveItems(List<Item> items) async {
485
+ final db = await database;
486
+ for (final item in items) {
487
+ await db.insert('items', item.toMap()); // 同步插入,阻塞主线程
488
+ }
489
+ }
490
+
491
+ // 正确做法
492
+ Future<void> saveItems(List<Item> items) async {
493
+ final db = await database;
494
+ await db.transaction((txn) async {
495
+ final batch = txn.batch();
496
+ for (final item in items) {
497
+ batch.insert('items', item.toMap());
498
+ }
499
+ await batch.commit(); // 批量提交,后台执行
500
+ });
501
+ }
502
+ ```
503
+
504
+ #### 6.2 缺少数据库索引
505
+ **反模式描述**
506
+ 高频查询字段未建立索引,导致查询性能差。
507
+
508
+ **识别信号**
509
+ - 查询耗时 > 100ms
510
+ - 数据库 CPU 占用高
511
+ - 查询全表扫描
512
+
513
+ **替代实践**
514
+ 为查询字段创建索引。
515
+
516
+ ```sql
517
+ -- 反模式
518
+ CREATE TABLE orders (
519
+ id INTEGER PRIMARY KEY,
520
+ user_id INTEGER,
521
+ status TEXT,
522
+ created_at INTEGER
523
+ );
524
+
525
+ -- 查询慢
526
+ SELECT * FROM orders WHERE user_id = ? AND status = ?;
527
+
528
+ -- 正确做法
529
+ CREATE TABLE orders (
530
+ id INTEGER PRIMARY KEY,
531
+ user_id INTEGER,
532
+ status TEXT,
533
+ created_at INTEGER
534
+ );
535
+
536
+ -- 创建索引
537
+ CREATE INDEX idx_orders_user_status ON orders(user_id, status);
538
+ CREATE INDEX idx_orders_created ON orders(created_at);
539
+ ```
540
+
541
+ ### 7. 测试反模式
542
+
543
+ #### 7.1 测试依赖真实后端
544
+ **反模式描述**
545
+ 单元测试依赖真实 API,导致测试不稳定、速度慢。
546
+
547
+ **识别信号**
548
+ - 测试失败因网络问题
549
+ - 测试运行时间 > 1 分钟
550
+ - CI 环境测试频繁失败
551
+
552
+ **替代实践**
553
+ 使用 Mock 数据和 Mock Server。
554
+
555
+ ```typescript
556
+ // 反模式
557
+ test('fetch users', async () => {
558
+ const users = await apiClient.getUsers(); // 依赖真实 API
559
+ expect(users.length).toBeGreaterThan(0);
560
+ });
561
+
562
+ // 正确做法
563
+ import { rest } from 'msw';
564
+ import { setupServer } from 'msw/node';
565
+
566
+ const server = setupServer(
567
+ rest.get('/api/users', (req, res, ctx) => {
568
+ return res(ctx.json([
569
+ { id: 1, name: 'User 1' },
570
+ { id: 2, name: 'User 2' },
571
+ ]));
572
+ })
573
+ );
574
+
575
+ beforeAll(() => server.listen());
576
+ afterEach(() => server.resetHandlers());
577
+ afterAll(() => server.close());
578
+
579
+ test('fetch users', async () => {
580
+ const users = await apiClient.getUsers();
581
+ expect(users).toHaveLength(2);
582
+ expect(users[0].name).toBe('User 1');
583
+ });
584
+ ```
585
+
586
+ #### 7.2 缺少边界条件测试
587
+ **反模式描述**
588
+ 只测试正常场景,缺少边界条件和异常场景测试。
589
+
590
+ **识别信号**
591
+ - 测试用例全是 happy path
592
+ - 线上频繁出现未测试场景的 bug
593
+ - 测试覆盖率虚高但质量低
594
+
595
+ **替代实践**
596
+ 完整的测试场景覆盖。
597
+
598
+ ```dart
599
+ // 反模式
600
+ test('calculate discount', () {
601
+ expect(calculateDiscount(100, 0.1), equals(90));
602
+ });
603
+
604
+ // 正确做法
605
+ group('calculateDiscount', () {
606
+ test('normal discount', () {
607
+ expect(calculateDiscount(100, 0.1), equals(90));
608
+ });
609
+
610
+ test('zero discount', () {
611
+ expect(calculateDiscount(100, 0), equals(100));
612
+ });
613
+
614
+ test('full discount', () {
615
+ expect(calculateDiscount(100, 1), equals(0));
616
+ });
617
+
618
+ test('negative price throws', () {
619
+ expect(() => calculateDiscount(-100, 0.1), throwsArgumentError);
620
+ });
621
+
622
+ test('invalid discount throws', () {
623
+ expect(() => calculateDiscount(100, 1.5), throwsArgumentError);
624
+ });
625
+ });
626
+ ```
627
+
628
+ ### 8. 内存管理反模式
629
+
630
+ #### 8.1 监听器未取消订阅
631
+ **反模式描述**
632
+ 订阅事件流或监听器后未取消,导致内存泄漏和意外行为。
633
+
634
+ **识别信号**
635
+ - 页面关闭后仍收到事件
636
+ - 内存占用持续增长
637
+ - 多次进入同一页面监听器重复
638
+
639
+ **替代实践**
640
+ 在组件卸载时取消订阅。
641
+
642
+ ```typescript
643
+ // 反模式
644
+ useEffect(() => {
645
+ eventEmitter.addListener('userUpdate', handleUserUpdate);
646
+ }, []);
647
+
648
+ // 正确做法
649
+ useEffect(() => {
650
+ const subscription = eventEmitter.addListener('userUpdate', handleUserUpdate);
651
+
652
+ return () => {
653
+ subscription.remove(); // 组件卸载时取消订阅
654
+ };
655
+ }, []);
656
+ ```
657
+
658
+ #### 8.2 闭包引用导致对象无法释放
659
+ **反模式描述**
660
+ 闭包持有大对象引用,导致无法被垃圾回收。
661
+
662
+ **识别信号**
663
+ - 内存分析显示大量 Detached DOM
664
+ - 重复操作后内存增长
665
+ - WeakRef 对象未被回收
666
+
667
+ **替代实践**
668
+ 及时释放引用或使用 WeakMap。
669
+
670
+ ```dart
671
+ // 反模式
672
+ class DataService {
673
+ List<Data> _cache = [];
674
+
675
+ void fetchData(Function(List<Data>) callback) {
676
+ loadFromNetwork().then((data) {
677
+ _cache.addAll(data); // 持续累积
678
+ callback(data);
679
+ });
680
+ }
681
+ }
682
+
683
+ // 正确做法
684
+ class DataService {
685
+ final int _maxCacheSize = 100;
686
+ List<Data> _cache = [];
687
+
688
+ void fetchData(Function(List<Data>) callback) {
689
+ loadFromNetwork().then((data) {
690
+ _cache.addAll(data);
691
+
692
+ // 限制缓存大小
693
+ if (_cache.length > _maxCacheSize) {
694
+ _cache = _cache.sublist(_cache.length - _maxCacheSize);
695
+ }
696
+
697
+ callback(data);
698
+ });
699
+ }
700
+ }
701
+ ```
702
+
703
+ ### 9. 生命周期反模式
704
+
705
+ #### 9.1 组件卸载后更新状态
706
+ **反模式描述**
707
+ 异步操作完成后更新已卸载组件的状态,导致内存泄漏警告。
708
+
709
+ **识别信号**
710
+ - 控制台警告:Can't perform a React state update on an unmounted component
711
+ - 内存泄漏警告
712
+ - 应用行为异常
713
+
714
+ **替代实践**
715
+ 使用取消标志或 AbortController。
716
+
717
+ ```typescript
718
+ // 反模式
719
+ useEffect(() => {
720
+ fetchUserData().then(setUser);
721
+ }, []);
722
+
723
+ // 正确做法
724
+ useEffect(() => {
725
+ let isCancelled = false;
726
+
727
+ fetchUserData().then(user => {
728
+ if (!isCancelled) {
729
+ setUser(user);
730
+ }
731
+ });
732
+
733
+ return () => {
734
+ isCancelled = true;
735
+ };
736
+ }, []);
737
+ ```
738
+
739
+ #### 9.2 未处理 Android Activity 重建
740
+ **反模式描述**
741
+ 未处理 Android 配置变更(旋转、分屏)导致的 Activity 重建,状态丢失。
742
+
743
+ **识别信号**
744
+ - 旋转屏幕后数据丢失
745
+ - 分屏切换后崩溃
746
+ - 后台恢复后状态异常
747
+
748
+ **替代实践**
749
+ 使用状态保存和恢复机制。
750
+
751
+ ```dart
752
+ // 反模式
753
+ class _MyWidgetState extends State<MyWidget> {
754
+ late Data data;
755
+
756
+ @override
757
+ void initState() {
758
+ super.initState();
759
+ data = loadData(); // 重建时丢失
760
+ }
761
+ }
762
+
763
+ // 正确做法
764
+ class _MyWidgetState extends State<MyWidget> {
765
+ late Data data;
766
+
767
+ @override
768
+ void initState() {
769
+ super.initState();
770
+ data = loadData();
771
+ }
772
+
773
+ // 保存状态
774
+ @override
775
+ void didChangeAppLifecycleState(AppLifecycleState state) {
776
+ if (state == AppLifecycleState.paused) {
777
+ saveState(data);
778
+ }
779
+ }
780
+
781
+ // 恢复状态
782
+ @override
783
+ void didChangeDependencies() {
784
+ super.didChangeDependencies();
785
+ final savedData = getSavedState();
786
+ if (savedData != null) {
787
+ data = savedData;
788
+ }
789
+ }
790
+ }
791
+ ```
792
+
793
+ ### 参考资料
794
+ - React Native 性能优化:https://reactnative.dev/docs/performance
795
+ - Flutter 性能最佳实践:https://flutter.dev/docs/performance/best-practices
796
+ - Android 性能模式:https://developer.android.com/topic/performance
797
+ - iOS 性能优化:https://developer.apple.com/documentation/performance
798
+ - OWASP 移动安全:https://owasp.org/www-project-mobile-security/