aodw-skill 0.7.3

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 (188) hide show
  1. package/.aodw/01-core/ai-interaction-rules.md +218 -0
  2. package/.aodw/01-core/ai-knowledge-rules.md +302 -0
  3. package/.aodw/01-core/ai-project-overview-rules.md +284 -0
  4. package/.aodw/01-core/aodw-constitution-summary.md +20 -0
  5. package/.aodw/01-core/aodw-constitution.md +419 -0
  6. package/.aodw/01-core/csf-thinking-framework.md +373 -0
  7. package/.aodw/01-core/git-discipline.md +226 -0
  8. package/.aodw/01-core/module-doc-rules.md +90 -0
  9. package/.aodw/02-workflow/aodw-development-stages.md +235 -0
  10. package/.aodw/02-workflow/rt-id-generation-rules.md +267 -0
  11. package/.aodw/02-workflow/rt-manager-summary.md +15 -0
  12. package/.aodw/02-workflow/rt-manager.md +399 -0
  13. package/.aodw/02-workflow/spec-full-profile-summary.md +13 -0
  14. package/.aodw/02-workflow/spec-full-profile.md +391 -0
  15. package/.aodw/02-workflow/spec-lite-profile.md +313 -0
  16. package/.aodw/02-workflow/ui-workflow-rules.md +334 -0
  17. package/.aodw/03-standards/ai-coding-rules-common.md +89 -0
  18. package/.aodw/03-standards/ai-coding-rules.md +370 -0
  19. package/.aodw/03-standards/stacks/java-springboot/ai-coding-rules-backend.md +100 -0
  20. package/.aodw/03-standards/stacks/python-fastapi/ai-coding-rules-backend.md +612 -0
  21. package/.aodw/03-standards/stacks/react-typescript/ai-coding-rules-frontend.md +291 -0
  22. package/.aodw/03-standards/stacks/vue2/ai-coding-rules-frontend.md +97 -0
  23. package/.aodw/03-standards/ui-kit/ui-kit.md +163 -0
  24. package/.aodw/04-auditors/aodw-development-auditor-rules.md +470 -0
  25. package/.aodw/04-auditors/aodw-full-auditor-rules.md +365 -0
  26. package/.aodw/04-auditors/aodw-requirement-auditor-rules.md +408 -0
  27. package/.aodw/05-tooling/ai-tools-init-rules.md +465 -0
  28. package/.aodw/06-project/ai-overview.md +116 -0
  29. package/.aodw/06-project/modules-index.yaml +11 -0
  30. package/.aodw/07-optimization/token-usage-analysis.md +253 -0
  31. package/.aodw/README.md +26 -0
  32. package/.aodw/RELEASE-CHECKLIST.md +144 -0
  33. package/.aodw/config.yaml +2 -0
  34. package/.aodw/manifest.yaml +98 -0
  35. package/.aodw/templates/SOURCE-TO-DISTRIBUTION-GUIDE.md +276 -0
  36. package/.aodw/templates/TEMPLATE-APPLICATION-GUIDE.md +246 -0
  37. package/.aodw/templates/aodw-kernel-loader-template.md +70 -0
  38. package/.aodw/templates/audit-report-template.md +232 -0
  39. package/.aodw/templates/changelog-template.md +16 -0
  40. package/.aodw/templates/checklists/coding-standards-template.md +110 -0
  41. package/.aodw/templates/csf-review-template.md +201 -0
  42. package/.aodw/templates/impact-template.md +17 -0
  43. package/.aodw/templates/invariants-template.md +12 -0
  44. package/.aodw/templates/module-readme-template.md +39 -0
  45. package/.aodw/templates/plan-lite-template.md +11 -0
  46. package/.aodw/templates/rt-decision-template.md +13 -0
  47. package/.aodw/templates/rt-intake-template.md +33 -0
  48. package/.aodw/templates/rt-meta-template.yaml +43 -0
  49. package/.aodw/templates/spec-lite-template.md +17 -0
  50. package/.aodw/templates/tests-template.md +13 -0
  51. package/.aodw/templates/tools-config/README.md +80 -0
  52. package/.aodw/templates/tools-config/backend/black.config.template.toml +6 -0
  53. package/.aodw/templates/tools-config/backend/pre-commit.config.template.yaml +16 -0
  54. package/.aodw/templates/tools-config/backend/ruff.config.template.toml +23 -0
  55. package/.aodw/templates/tools-config/frontend/eslint.config.template.json +113 -0
  56. package/.aodw/templates/tools-config/frontend/prettier.config.template.json +10 -0
  57. package/.aodw/templates/tools-config/frontend/tsconfig.paths.template.json +11 -0
  58. package/.aodw/workflow-guide.md +51 -0
  59. package/AODW_Adapters/README.md +143 -0
  60. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/antigravity/.agent/rules/aodw-check.md +7 -0
  61. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/antigravity/.agent/rules/aodw-done.md +7 -0
  62. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/antigravity/.agent/rules/aodw-full.md +7 -0
  63. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/antigravity/.agent/rules/aodw-governance.md +7 -0
  64. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/antigravity/.agent/rules/aodw-impact.md +7 -0
  65. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/antigravity/.agent/rules/aodw-init.md +7 -0
  66. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/antigravity/.agent/rules/aodw-invariants.md +7 -0
  67. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/antigravity/.agent/rules/aodw-lite.md +7 -0
  68. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/antigravity/.agent/rules/aodw-module.md +7 -0
  69. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/antigravity/.agent/rules/aodw-new.md +7 -0
  70. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/antigravity/.agent/rules/aodw-open.md +7 -0
  71. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/antigravity/.agent/rules/aodw-pause.md +7 -0
  72. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/antigravity/.agent/rules/aodw-resume.md +7 -0
  73. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/antigravity/.agent/rules/aodw-tests.md +7 -0
  74. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/antigravity/.agent/rules/aodw-upgrade.md +7 -0
  75. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/antigravity/.agent/rules/aodw.md +35 -0
  76. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/antigravity/global_workflows/aodw-check.md +16 -0
  77. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/antigravity/global_workflows/aodw-done.md +16 -0
  78. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/antigravity/global_workflows/aodw-full.md +14 -0
  79. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/antigravity/global_workflows/aodw-governance.md +13 -0
  80. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/antigravity/global_workflows/aodw-impact.md +13 -0
  81. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/antigravity/global_workflows/aodw-init.md +13 -0
  82. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/antigravity/global_workflows/aodw-invariants.md +13 -0
  83. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/antigravity/global_workflows/aodw-lite.md +14 -0
  84. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/antigravity/global_workflows/aodw-module.md +13 -0
  85. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/antigravity/global_workflows/aodw-new.md +30 -0
  86. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/antigravity/global_workflows/aodw-open.md +10 -0
  87. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/antigravity/global_workflows/aodw-pause.md +12 -0
  88. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/antigravity/global_workflows/aodw-resume.md +12 -0
  89. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/antigravity/global_workflows/aodw-tests.md +13 -0
  90. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/antigravity/global_workflows/aodw-upgrade.md +12 -0
  91. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/antigravity/global_workflows/aodw.md +18 -0
  92. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/claude/CLAUDE.md +17 -0
  93. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/cursor/.cursor/commands/aodw-check.md +30 -0
  94. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/cursor/.cursor/commands/aodw-done.md +52 -0
  95. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/cursor/.cursor/commands/aodw-full.md +31 -0
  96. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/cursor/.cursor/commands/aodw-governance.md +34 -0
  97. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/cursor/.cursor/commands/aodw-impact.md +25 -0
  98. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/cursor/.cursor/commands/aodw-init.md +75 -0
  99. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/cursor/.cursor/commands/aodw-invariants.md +29 -0
  100. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/cursor/.cursor/commands/aodw-lite.md +23 -0
  101. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/cursor/.cursor/commands/aodw-module.md +24 -0
  102. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/cursor/.cursor/commands/aodw-new.md +70 -0
  103. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/cursor/.cursor/commands/aodw-open.md +19 -0
  104. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/cursor/.cursor/commands/aodw-pause.md +19 -0
  105. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/cursor/.cursor/commands/aodw-resume.md +20 -0
  106. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/cursor/.cursor/commands/aodw-tests.md +26 -0
  107. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/cursor/.cursor/commands/aodw-upgrade.md +27 -0
  108. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/cursor/.cursor/commands/aodw.md +69 -0
  109. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/cursor/.cursor/commands/deploypromote.md +20 -0
  110. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/cursor/.cursor/commands/featuretotester.md +32 -0
  111. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/cursor/.cursor/deploy/feature_to_master_push_test_local.sh +390 -0
  112. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/cursor/.cursor/deploy/promote_only.sh +210 -0
  113. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/cursor/.cursor/deploy/rollback_prod.sh +99 -0
  114. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/cursor/.cursor/rules/aodw.mdc +26 -0
  115. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/gemini/.agent/rules/aodw-check.md +29 -0
  116. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/gemini/.agent/rules/aodw-done.md +52 -0
  117. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/gemini/.agent/rules/aodw-full.md +30 -0
  118. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/gemini/.agent/rules/aodw-governance.md +33 -0
  119. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/gemini/.agent/rules/aodw-impact.md +24 -0
  120. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/gemini/.agent/rules/aodw-init.md +75 -0
  121. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/gemini/.agent/rules/aodw-invariants.md +28 -0
  122. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/gemini/.agent/rules/aodw-lite.md +22 -0
  123. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/gemini/.agent/rules/aodw-module.md +23 -0
  124. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/gemini/.agent/rules/aodw-new.md +92 -0
  125. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/gemini/.agent/rules/aodw-open.md +18 -0
  126. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/gemini/.agent/rules/aodw-pause.md +18 -0
  127. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/gemini/.agent/rules/aodw-resume.md +19 -0
  128. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/gemini/.agent/rules/aodw-tests.md +25 -0
  129. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/gemini/.agent/rules/aodw-upgrade.md +26 -0
  130. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/gemini/.agent/rules/aodw.md +68 -0
  131. package/AODW_Adapters/_backup/v3.1.0-pre-refactor/gemini/GEMINI.md +17 -0
  132. package/AODW_Adapters/_backup/v4.0.0-simplified/antigravity/.agent/rules/aodw-analyze.md +15 -0
  133. package/AODW_Adapters/_backup/v4.0.0-simplified/antigravity/.agent/rules/aodw-complete.md +15 -0
  134. package/AODW_Adapters/_backup/v4.0.0-simplified/antigravity/.agent/rules/aodw-control.md +14 -0
  135. package/AODW_Adapters/_backup/v4.0.0-simplified/antigravity/.agent/rules/aodw-decide.md +16 -0
  136. package/AODW_Adapters/_backup/v4.0.0-simplified/antigravity/.agent/rules/aodw-governance.md +7 -0
  137. package/AODW_Adapters/_backup/v4.0.0-simplified/antigravity/.agent/rules/aodw-implement.md +16 -0
  138. package/AODW_Adapters/_backup/v4.0.0-simplified/antigravity/.agent/rules/aodw-init.md +7 -0
  139. package/AODW_Adapters/_backup/v4.0.0-simplified/antigravity/.agent/rules/aodw-intake.md +15 -0
  140. package/AODW_Adapters/_backup/v4.0.0-simplified/antigravity/.agent/rules/aodw-open.md +7 -0
  141. package/AODW_Adapters/_backup/v4.0.0-simplified/antigravity/.agent/rules/aodw-simplified.md +107 -0
  142. package/AODW_Adapters/_backup/v4.0.0-simplified/antigravity/.agent/rules/aodw-verify.md +14 -0
  143. package/AODW_Adapters/_backup/v4.0.0-simplified/antigravity/global_workflows/aodw-analyze.md +24 -0
  144. package/AODW_Adapters/_backup/v4.0.0-simplified/antigravity/global_workflows/aodw-complete.md +23 -0
  145. package/AODW_Adapters/_backup/v4.0.0-simplified/antigravity/global_workflows/aodw-control.md +21 -0
  146. package/AODW_Adapters/_backup/v4.0.0-simplified/antigravity/global_workflows/aodw-decide.md +26 -0
  147. package/AODW_Adapters/_backup/v4.0.0-simplified/antigravity/global_workflows/aodw-governance.md +13 -0
  148. package/AODW_Adapters/_backup/v4.0.0-simplified/antigravity/global_workflows/aodw-implement.md +21 -0
  149. package/AODW_Adapters/_backup/v4.0.0-simplified/antigravity/global_workflows/aodw-init.md +13 -0
  150. package/AODW_Adapters/_backup/v4.0.0-simplified/antigravity/global_workflows/aodw-intake.md +28 -0
  151. package/AODW_Adapters/_backup/v4.0.0-simplified/antigravity/global_workflows/aodw-open.md +10 -0
  152. package/AODW_Adapters/_backup/v4.0.0-simplified/antigravity/global_workflows/aodw-verify.md +20 -0
  153. package/AODW_Adapters/_backup/v4.0.0-simplified/antigravity/global_workflows/aodw.md +18 -0
  154. package/AODW_Adapters/antigravity/.agent/rules/aodw.md +74 -0
  155. package/AODW_Adapters/claude/CLAUDE.md +70 -0
  156. package/AODW_Adapters/cursor/.cursor/commands/README.md +37 -0
  157. package/AODW_Adapters/cursor/.cursor/rules/aodw.mdc +77 -0
  158. package/AODW_Adapters/gemini/.agent/rules/aodw-analyze.md +15 -0
  159. package/AODW_Adapters/gemini/.agent/rules/aodw-complete.md +15 -0
  160. package/AODW_Adapters/gemini/.agent/rules/aodw-control.md +14 -0
  161. package/AODW_Adapters/gemini/.agent/rules/aodw-decide.md +16 -0
  162. package/AODW_Adapters/gemini/.agent/rules/aodw-governance.md +33 -0
  163. package/AODW_Adapters/gemini/.agent/rules/aodw-implement.md +16 -0
  164. package/AODW_Adapters/gemini/.agent/rules/aodw-init.md +75 -0
  165. package/AODW_Adapters/gemini/.agent/rules/aodw-intake.md +15 -0
  166. package/AODW_Adapters/gemini/.agent/rules/aodw-open.md +18 -0
  167. package/AODW_Adapters/gemini/.agent/rules/aodw-verify.md +14 -0
  168. package/AODW_Adapters/gemini/.agent/rules/aodw.md +70 -0
  169. package/AODW_Adapters/gemini/GEMINI.md +17 -0
  170. package/AODW_Adapters/general/.github/copilot-instructions.md +34 -0
  171. package/AODW_Adapters/general/AGENTS.md +70 -0
  172. package/README.md +118 -0
  173. package/bin/aodw.js +627 -0
  174. package/bin/commands/init-overview.js +801 -0
  175. package/bin/commands/init-tools.js +811 -0
  176. package/bin/commands/new.js +235 -0
  177. package/bin/commands/serve.js +79 -0
  178. package/bin/processors/index.js +109 -0
  179. package/bin/update-adapters-from-template.js +89 -0
  180. package/bin/utils/config.js +56 -0
  181. package/docs/README.md +26 -0
  182. package/docs/adapter-evaluation.md +55 -0
  183. package/docs/backend-guidelines.md +335 -0
  184. package/docs/frontend-guidelines.md +266 -0
  185. package/docs/installation-variants.md +88 -0
  186. package/docs/migration-guide-0.2.0.md +250 -0
  187. package/docs/platform-matrix.md +83 -0
  188. package/package.json +40 -0
@@ -0,0 +1,612 @@
1
+ # AI Coding Rules - Backend Development
2
+
3
+ > **注意**:本文件是 `.aodw/03-standards/ai-coding-rules.md` 的子规范文件。
4
+ > 请先阅读主文件了解通用编码原则,再阅读本文件了解后端特定规范。
5
+
6
+ **适用场景**:
7
+ - 后端开发(FastAPI / Python、Node.js、Go 等)
8
+ - API 开发
9
+ - 数据库操作
10
+ - 后端工具配置
11
+
12
+ **必须与以下规范配合使用**:
13
+ - `.aodw/03-standards/ai-coding-rules.md`(主文件,包含通用原则)
14
+ - `.aodw/03-standards/ai-coding-rules-common.md`(通用编码规范)
15
+ - `.aodw/05-tooling/ai-tools-init-rules.md`(工具初始化规则,如果通过 AI 方式初始化工具)
16
+
17
+ **⚠️ 强制要求**:所有后端开发必须严格遵守 `docs/backend-guidelines.md` 中的规范(如果存在)。
18
+
19
+ ---
20
+
21
+ ## 1. 技术栈确认
22
+
23
+ ### 1.1 Python / FastAPI 技术栈
24
+
25
+ 适用项目技术栈:
26
+ - 语言:Python 3.11+
27
+ - Web 框架:FastAPI
28
+ - 运行:Uvicorn / Gunicorn+Uvicorn worker
29
+ - 数据库:MySQL / PostgreSQL / SQLite 等
30
+ - ORM:可选 SQLAlchemy / Tortoise ORM / 其他
31
+ - **依赖管理**:uv + pip-tools(必须)
32
+ - 工具:Ruff + Black/Blue + pre-commit
33
+
34
+ ### 1.2 其他技术栈
35
+
36
+ 根据项目实际情况确认技术栈(Node.js、Go、Java 等)。
37
+
38
+ ---
39
+
40
+ ## 2. 工具初始化检查(必须)
41
+
42
+ > **⚠️ 重要**:后端规范必须通过工具强制执行,不能只靠自觉。
43
+ > 本项目的后端规范通过 **"后端四件套"自动化质量体系** 实现:
44
+ > - ✅ 编辑器即时提示 → Git 提交前阻断 → CI 自动失败 → AI 自动服从
45
+
46
+ 在开始任何后端开发前,AI 必须检查工具初始化状态:
47
+
48
+ ### 2.1 工具初始化状态检查
49
+
50
+ **AI 必须检查**:
51
+ - [ ] 是否已运行工具初始化?
52
+ - [ ] `.aodw/tools-status.yaml` 中 `initialized: true` 且后端工具状态为 `configured: true`?
53
+
54
+ **检查方法**:
55
+ 1. 读取 `.aodw/tools-status.yaml` 文件
56
+ 2. 检查 `tools_init.initialized` 是否为 `true`
57
+ 3. 检查 `tools_init.backend.dependency_manager.configured` 是否为 `true`(uv + pip-tools)
58
+ 4. 检查 `tools_init.backend.ruff.configured` 是否为 `true`
59
+ 5. 检查 `tools_init.backend.black.configured` 是否为 `true`
60
+ 6. 检查 `tools_init.backend.pre_commit.configured` 和 `hooks_installed` 是否为 `true`
61
+
62
+ ### 2.2 工具要求
63
+
64
+ **后端开发必须使用以下工具**:
65
+ - **uv + pip-tools**:依赖管理(必须)
66
+ - **Ruff**:代码质量 & 复杂度检查(核心工具)
67
+ - **Black**:代码格式化(统一风格)
68
+ - **pre-commit**:Git 提交前强制检查(关键)
69
+ - **import-linter**:目录结构/模块边界检查(可选,推荐)
70
+
71
+ **工具作用**:
72
+ - **uv + pip-tools**:依赖管理,确保依赖版本一致性和可重现性
73
+ - **Ruff**:自动拦截"怪物函数"、复杂 Service、未使用变量、import 乱序等
74
+ - **Black**:自动统一代码格式,避免风格争议
75
+ - **pre-commit**:不合格的代码连 commit 都提不上去,实现"提交前阻断"
76
+ - **import-linter**:强制分层架构,防止违反目录结构规范
77
+
78
+ **工具工作流程**:
79
+ - 每次执行 `git commit` 时,将自动触发:
80
+ 1. Ruff 检查:发现怪物函数 → ❌ 直接中断提交
81
+ 2. Black 格式化:格式不统一 → ❌ 强制格式化后重新提交
82
+ 3. 全部通过 → ✅ 才允许提交
83
+
84
+ ### 2.3 工具未初始化时的处理
85
+
86
+ **如果工具未初始化或未配置**:
87
+ 1. **AI 必须立即停止编码**
88
+ 2. **AI 必须提示用户运行工具初始化**:
89
+ - **CLI 方式**:运行 `aodw` 选择"工具初始化",或运行 `aodw init-tools`
90
+ - **AI 方式**:说"初始化工具"或"设置开发工具"
91
+ 3. **AI 必须说明**:工具初始化会引导用户完成工具的安装和配置
92
+ 4. **在工具初始化完成前,不能开始编码**
93
+
94
+ ### 2.4 工具配置参考
95
+
96
+ **配置模板位置**:`.aodw/templates/tools-config/backend/`
97
+ - Ruff 配置模板:`ruff.config.template.toml`(需要合并到 `pyproject.toml`)
98
+ - Black 配置模板:`black.config.template.toml`(需要合并到 `pyproject.toml`)
99
+ - pre-commit 配置模板:`pre-commit.config.template.yaml`
100
+
101
+ **如果工具已初始化**:
102
+ - 配置应已符合 AODW 规范
103
+ - 配置文件应已生成或合并
104
+ - 工具应已正确安装和配置
105
+ - pre-commit hooks 应已安装
106
+
107
+ **如果需要对配置进行调整**:
108
+ - 可以再次运行工具初始化
109
+ - 或参考配置模板手动调整
110
+
111
+ ### 2.5 其他语言工具配置
112
+
113
+ 根据项目使用的语言,检查相应的工具配置:
114
+ - **Node.js**:ESLint + Prettier + husky
115
+ - **Go**:gofmt + golangci-lint + pre-commit
116
+ - **Java**:Checkstyle + Spotless + pre-commit
117
+
118
+ **注意**:其他语言的工具配置模板和初始化流程,将在后续版本中添加。
119
+
120
+ ---
121
+
122
+ ## 3. 依赖管理规范(uv + pip-tools)⚡
123
+
124
+ > **⚠️ 重要**:本项目使用 **uv + pip-tools** 管理依赖,严格遵循以下规则。
125
+
126
+ ### 3.1 核心原则
127
+
128
+ **必须遵守**:
129
+ - ✅ **只编辑 `.in` 文件**(`requirements.in` / `requirements-dev.in`)
130
+ - ❌ **禁止直接编辑 `.txt` 文件**(`requirements.txt` / `requirements-dev.txt` 由工具自动生成)
131
+ - ❌ **禁止使用 `pip install package`** 直接安装
132
+ - ❌ **禁止使用 `pip freeze > requirements.txt`**
133
+
134
+ ### 3.2 添加依赖的正确流程
135
+
136
+ #### 3.2.1 添加生产依赖
137
+
138
+ ```bash
139
+ # 1. 编辑 requirements.in(使用版本约束)
140
+ echo "httpx>=0.25.0,<1.0.0" >> requirements.in
141
+
142
+ # 2. 重新编译依赖锁定文件
143
+ make compile-deps
144
+ # 或: uv pip compile requirements.in -o requirements.txt
145
+
146
+ # 3. 同步到当前环境
147
+ make sync
148
+ # 或: uv pip sync requirements-dev.txt
149
+
150
+ # 4. 提交所有文件到 Git
151
+ git add requirements.in requirements.txt requirements-dev.txt
152
+ ```
153
+
154
+ #### 3.2.2 添加开发依赖
155
+
156
+ ```bash
157
+ # 1. 编辑 requirements-dev.in
158
+ echo "pytest-mock>=3.12.0" >> requirements-dev.in
159
+
160
+ # 2. 编译依赖
161
+ make compile-deps
162
+
163
+ # 3. 同步环境
164
+ make sync
165
+ ```
166
+
167
+ ### 3.3 AI 必须遵守的规则
168
+
169
+ **当 AI 建议安装新包时**:
170
+ - ❌ **禁止说**:"运行 `pip install package`"
171
+ - ✅ **正确做法**:"将 `package>=1.0.0` 添加到 `requirements.in`,然后运行 `make compile-deps && make sync`"
172
+
173
+ **当 AI 询问如何添加依赖时**:
174
+ - 总是提供完整流程(编辑 .in → compile → sync)
175
+ - 说明依赖应该加到 `requirements.in` 还是 `requirements-dev.in`
176
+
177
+ **当需要数据库/缓存等依赖时**:
178
+ - 明确告知在 `requirements.in` 中添加哪些包
179
+ - 提供合适的版本约束(如 `>=2.0.0,<3.0.0`)
180
+
181
+ **禁止的操作**:
182
+ - ❌ `pip install package`
183
+ - ❌ 直接编辑 `requirements.txt`
184
+ - ❌ `pip freeze > requirements.txt`
185
+ - ❌ 不使用版本约束(如只写 `package` 而不是 `package>=1.0.0`)
186
+
187
+ ### 3.4 常用命令参考
188
+
189
+ ```bash
190
+ make install-dev # 安装开发依赖
191
+ make compile-deps # 编译 .in -> .txt
192
+ make sync # 同步环境
193
+ make update # 更新所有依赖
194
+ ```
195
+
196
+ ### 3.5 版本约束建议
197
+
198
+ ```bash
199
+ # ✅ 推荐:指定最小版本 + 主版本上限
200
+ fastapi>=0.104.0,<1.0.0
201
+
202
+ # ⚠️ 可接受:只指定最小版本(谨慎使用)
203
+ fastapi>=0.104.0
204
+
205
+ # ❌ 不推荐:完全锁定(除非有特殊原因)
206
+ fastapi==0.104.0
207
+
208
+ # ❌ 禁止:无版本约束
209
+ fastapi
210
+ ```
211
+
212
+ ### 3.6 依赖管理检查清单
213
+
214
+ 在开始后端开发前,AI 必须检查:
215
+
216
+ - [ ] 项目是否使用 `uv + pip-tools` 管理依赖?
217
+ - [ ] 是否存在 `requirements.in` 和 `requirements-dev.in` 文件?
218
+ - [ ] 是否存在 `Makefile` 或相关编译脚本?
219
+ - [ ] 是否已安装 `uv` 和 `pip-tools`?
220
+
221
+ **如果项目未使用 uv + pip-tools**:
222
+ - AI 必须提醒用户:本项目要求使用 uv + pip-tools 管理依赖
223
+ - AI 可以提供迁移建议(如果需要)
224
+
225
+ ---
226
+
227
+ ## 4. 目录结构规范
228
+
229
+ ### 3.1 FastAPI 项目结构(强制要求)
230
+
231
+ ```
232
+ backend/
233
+ app/
234
+ api/
235
+ v1/
236
+ endpoints/ # API 端点(路由层)
237
+ schemas/ # Pydantic 模型(请求/响应)
238
+ core/
239
+ config.py # 配置
240
+ security.py # 安全相关
241
+ db/
242
+ base.py # 数据库基类
243
+ session.py # 数据库会话
244
+ models/ # SQLAlchemy 模型(ORM 层)
245
+ services/ # 业务逻辑层
246
+ repositories/ # 数据访问层(可选,如果使用 Repository 模式)
247
+ utils/ # 工具函数
248
+ tests/ # 测试文件
249
+ ```
250
+
251
+ ### 3.2 分层架构规则(强制要求)
252
+
253
+ **依赖关系规则**(必须严格遵守):
254
+ - **api/**(路由层):
255
+ - ✅ 可以导入:`schemas/`、`services/`
256
+ - ❌ **禁止**直接导入:`models/`、`repositories/`
257
+ - **services/**(业务逻辑层):
258
+ - ✅ 可以导入:`repositories/`、`models/`、`schemas/`
259
+ - ❌ **禁止**直接导入:`api/`
260
+ - **repositories/**(数据访问层):
261
+ - ✅ 可以导入:`models/`
262
+ - ❌ **禁止**直接导入:`api/`、`services/`
263
+ - **models/**(ORM 层):
264
+ - ✅ 只能包含 ORM 模型定义
265
+ - ❌ **禁止**导入其他业务层
266
+
267
+ **工具强制检查**:
268
+ - 如果配置了 `import-linter`,违反上述规则将直接报错
269
+ - 即使未配置 `import-linter`,AI 也必须严格遵守这些规则
270
+
271
+ ### 3.3 其他框架结构
272
+
273
+ 根据项目使用的框架,遵循相应的目录结构规范,但必须保持分层架构原则。
274
+
275
+ ---
276
+
277
+ ## 4. 命名规范
278
+
279
+ ### 4.1 Python 命名规范
280
+
281
+ - 模块名:小写字母,单词间用下划线(`user_service.py`)
282
+ - 类名:PascalCase(`UserService`)
283
+ - 函数/方法名:小写字母,单词间用下划线(`get_user_by_id`)
284
+ - 常量:SCREAMING_SNAKE_CASE(`MAX_RETRY_COUNT`)
285
+ - 私有方法/属性:以下划线开头(`_internal_method`)
286
+
287
+ ### 4.2 API 端点命名
288
+
289
+ - RESTful API:使用名词复数形式(`/api/v1/users`)
290
+ - 操作使用 HTTP 方法(GET、POST、PUT、DELETE)
291
+ - 嵌套资源:`/api/v1/users/{user_id}/orders`
292
+
293
+ ---
294
+
295
+ ## 5. API 设计规范
296
+
297
+ ### 5.1 请求/响应格式
298
+
299
+ - 使用 Pydantic 模型定义请求和响应结构
300
+ - 统一响应格式:
301
+ ```python
302
+ {
303
+ "code": 200,
304
+ "message": "success",
305
+ "data": {...}
306
+ }
307
+ ```
308
+
309
+ ### 5.2 错误处理
310
+
311
+ - 使用 HTTP 状态码表示错误类型
312
+ - 统一错误响应格式
313
+ - 提供详细的错误信息(开发环境)
314
+
315
+ ### 5.3 分页
316
+
317
+ - 统一分页参数:`page`、`page_size`
318
+ - 统一分页响应格式
319
+
320
+ ---
321
+
322
+ ## 6. 数据库操作规范
323
+
324
+ ### 6.1 ORM 使用
325
+
326
+ - 优先使用 ORM,避免直接写 SQL
327
+ - 使用事务管理数据库操作
328
+ - 注意 N+1 查询问题
329
+
330
+ ### 6.2 数据迁移
331
+
332
+ - 使用数据库迁移工具(Alembic、Django Migrations 等)
333
+ - 迁移文件必须可回滚
334
+ - 生产环境迁移前必须备份
335
+
336
+ ---
337
+
338
+ ## 7. 安全规范
339
+
340
+ ### 7.1 认证与授权
341
+
342
+ - 使用 JWT 或其他标准认证方式
343
+ - 实现基于角色的访问控制(RBAC)
344
+ - 验证用户权限
345
+
346
+ ### 7.2 数据验证
347
+
348
+ - 所有输入数据必须验证
349
+ - 使用 Pydantic 或其他验证库
350
+ - 防止 SQL 注入、XSS 等安全漏洞
351
+
352
+ ---
353
+
354
+ ## 8. 性能优化
355
+
356
+ ### 8.1 数据库查询优化
357
+
358
+ - 使用索引优化查询
359
+ - 避免 N+1 查询问题
360
+ - 使用连接池管理数据库连接
361
+
362
+ ### 8.2 缓存策略
363
+
364
+ - 合理使用缓存(Redis、Memcached 等)
365
+ - 设置合适的缓存过期时间
366
+ - 处理缓存穿透、缓存击穿、缓存雪崩
367
+
368
+ ---
369
+
370
+ ## 9. 测试规范
371
+
372
+ ### 9.1 单元测试
373
+
374
+ - 为所有业务逻辑编写单元测试
375
+ - 测试覆盖率 ≥ 80%
376
+ - 使用 pytest、unittest 等测试框架
377
+
378
+ ### 9.2 集成测试
379
+
380
+ - 为 API 端点编写集成测试
381
+ - 测试数据库操作
382
+ - 测试认证和授权
383
+
384
+ ---
385
+
386
+ ## 10. AI 实现流程约束(强制要求)
387
+
388
+ AI 在编写后端代码时必须遵守以下流程和规则:
389
+
390
+ ### 10.1 目录与分层(强制要求)
391
+
392
+ - **路由层**:`app/api/v1/endpoints/`
393
+ - **业务逻辑层**:`app/services/`
394
+ - **数据访问层**:`app/repositories/`(如果使用 Repository 模式)
395
+ - **Pydantic 模型**:`app/api/v1/schemas/`
396
+ - **ORM 模型**:`app/models/`
397
+ - **工具函数**:`app/utils/`
398
+
399
+ **禁止行为**:
400
+ - ❌ 不允许把路由、业务逻辑、数据库操作写在同一个文件
401
+ - ❌ 不允许在路由中直接写数据库查询
402
+ - ❌ 不允许违反分层架构的依赖关系
403
+
404
+ ### 10.2 代码复杂度(强制要求)
405
+
406
+ - **单个路由文件**:≤ 300 行
407
+ - **单个 service / repository 文件**:≤ 300 行
408
+ - **单个函数**:≤ 60 行
409
+ - **分支过多**:必须拆函数
410
+
411
+ **工具自动检查**:
412
+ - Ruff 的 PLR 规则会自动拦截违反上述限制的代码
413
+ - 如果函数超过 60 行,Ruff 会直接报错
414
+
415
+ ### 10.3 生成流程(强制要求)
416
+
417
+ **第一步:输出文件列表和职责(必须)**
418
+ - 新功能必须先输出【涉及的文件列表 + 每个函数职责】
419
+ - 说明每个文件属于哪一层(api/services/repositories/models)
420
+ - 说明文件之间的依赖关系
421
+
422
+ **第二步:按文件逐步实现**
423
+ - 按"一个文件一次"的方式逐个生成
424
+ - 不允许一次性输出多个层的所有代码混在一起
425
+
426
+ **第三步:验证工具检查**
427
+ - 每个文件生成后,运行 `ruff check .` 验证
428
+ - 运行 `black .` 格式化代码
429
+ - 确保通过检查后再继续下一个文件
430
+
431
+ ### 10.4 类型与异步(强制要求)
432
+
433
+ - **所有函数必须有完整类型注解**
434
+ - **FastAPI handler 使用 `async def`**
435
+ - **不允许在路由中直接写数据库查询**
436
+
437
+ ### 10.5 依赖管理约束提醒
438
+
439
+ **AI 必须明确告知用户**:
440
+ - "本项目使用 uv + pip-tools 管理依赖"
441
+ - "添加依赖时,必须编辑 requirements.in 或 requirements-dev.in,然后运行 make compile-deps && make sync"
442
+ - "禁止使用 pip install 直接安装依赖"
443
+ - "禁止直接编辑 requirements.txt 文件"
444
+
445
+ ### 10.6 工具约束提醒
446
+
447
+ **AI 必须明确告知用户**:
448
+ - "本项目启用了 Ruff + Black + pre-commit"
449
+ - "任何不符合规范的代码最终都会被拒绝提交"
450
+ - "生成的代码必须通过 Ruff 检查才能提交"
451
+
452
+ ---
453
+
454
+ ## 11. 后端代码提交前检查清单
455
+
456
+ 在提交后端代码前,必须完成以下检查:
457
+
458
+ ### 11.1 工具初始化检查(参考 `.aodw/03-standards/stacks/python-fastapi/ai-coding-rules-backend.md` 第 2 节)
459
+
460
+ - [ ] **工具是否已初始化**:
461
+ - [ ] 检查 `.aodw/tools-status.yaml` 中 `initialized: true`
462
+ - [ ] **依赖管理工具**(uv + pip-tools)是否已安装并配置?
463
+ - [ ] Ruff 是否已安装并配置?
464
+ - [ ] Black 是否已安装并配置?
465
+ - [ ] pre-commit 是否已安装并配置?
466
+ - [ ] pre-commit hooks 是否已安装?
467
+
468
+ ### 11.2 依赖管理检查(参考 `.aodw/03-standards/stacks/python-fastapi/ai-coding-rules-backend.md` 第 3 节)
469
+
470
+ - [ ] **依赖管理规范**:
471
+ - [ ] 是否使用 `uv + pip-tools` 管理依赖?
472
+ - [ ] 是否存在 `requirements.in` 和 `requirements-dev.in` 文件?
473
+ - [ ] 是否只编辑 `.in` 文件,不直接编辑 `.txt` 文件?
474
+ - [ ] 添加依赖时是否使用版本约束(如 `package>=1.0.0,<2.0.0`)?
475
+ - [ ] 是否通过 `make compile-deps && make sync` 更新依赖?
476
+
477
+ ### 11.3 代码质量检查(工具自动)
478
+
479
+ - [ ] **Ruff 静态检查**:
480
+ - [ ] `ruff check .` 是否通过?
481
+ - [ ] 是否拦截了怪物函数、复杂代码?
482
+ - [ ] 是否有未使用的导入?
483
+ - [ ] 是否有语法错误?
484
+ - [ ] **Black 格式化**:
485
+ - [ ] `black .` 是否已运行?
486
+ - [ ] 代码格式是否统一?
487
+
488
+ ### 11.4 文件大小检查(工具自动)
489
+
490
+ - [ ] **Ruff PLR 规则检查**:
491
+ - [ ] Python 模块是否 ≤ 300 行?(Ruff 自动检查)
492
+ - [ ] 单个函数是否 ≤ 60 行?(Ruff PLR0915 自动拦截)
493
+ - [ ] 复杂度是否 ≤ 10?(Ruff PLR 规则自动检查)
494
+
495
+ ### 11.5 目录结构检查
496
+
497
+ - [ ] **分层架构检查**:
498
+ - [ ] api 层是否未直接导入 models?
499
+ - [ ] services 层是否未直接导入 api?
500
+ - [ ] 依赖关系是否符合规范?
501
+ - [ ] 如果配置了 import-linter,是否通过检查?
502
+
503
+ ### 11.6 API 设计检查
504
+
505
+ - [ ] API 端点是否符合 RESTful 规范?
506
+ - [ ] 请求/响应格式是否统一?
507
+ - [ ] 错误处理是否完善?
508
+
509
+ ### 11.7 安全检查
510
+
511
+ - [ ] 输入数据是否已验证?
512
+ - [ ] 是否防止 SQL 注入、XSS 等安全漏洞?
513
+ - [ ] 认证和授权是否正确实现?
514
+
515
+ ### 11.8 测试检查
516
+
517
+ - [ ] 是否编写了单元测试?
518
+ - [ ] 是否编写了集成测试?
519
+ - [ ] 测试是否通过?
520
+
521
+ ### 11.9 最终验证
522
+
523
+ - [ ] **运行完整检查**:
524
+ ```bash
525
+ ruff check .
526
+ black .
527
+ pre-commit run --all-files
528
+ ```
529
+ - [ ] **所有检查通过后,才能提交代码**
530
+
531
+ ---
532
+
533
+ ## 12. 依赖管理快速参考
534
+
535
+ ### 12.1 添加依赖的标准流程
536
+
537
+ ```bash
538
+ # 1. 编辑 requirements.in(生产依赖)或 requirements-dev.in(开发依赖)
539
+ echo "package>=1.0.0,<2.0.0" >> requirements.in
540
+
541
+ # 2. 编译依赖锁定文件
542
+ make compile-deps
543
+ # 或: uv pip compile requirements.in -o requirements.txt
544
+
545
+ # 3. 同步到当前环境
546
+ make sync
547
+ # 或: uv pip sync requirements-dev.txt
548
+
549
+ # 4. 提交所有文件
550
+ git add requirements.in requirements.txt requirements-dev.txt
551
+ ```
552
+
553
+ ### 12.2 常用命令
554
+
555
+ ```bash
556
+ make install-dev # 安装开发依赖
557
+ make compile-deps # 编译 .in -> .txt
558
+ make sync # 同步环境
559
+ make update # 更新所有依赖
560
+ ```
561
+
562
+ ### 12.3 版本约束格式
563
+
564
+ ```bash
565
+ # ✅ 推荐
566
+ package>=1.0.0,<2.0.0
567
+
568
+ # ⚠️ 可接受
569
+ package>=1.0.0
570
+
571
+ # ❌ 禁止
572
+ package
573
+ package==1.0.0 # 除非有特殊原因
574
+ ```
575
+
576
+ ---
577
+
578
+ ## 13. 工具配置参考
579
+
580
+ ### 13.1 配置模板位置
581
+
582
+ **配置模板**:`.aodw/templates/tools-config/backend/`
583
+ - Ruff 配置模板:`ruff.config.template.toml`(需要合并到 `pyproject.toml`)
584
+ - Black 配置模板:`black.config.template.toml`(需要合并到 `pyproject.toml`)
585
+ - pre-commit 配置模板:`pre-commit.config.template.yaml`
586
+
587
+ ### 13.2 工具工作流程
588
+
589
+ ```
590
+ 编辑器编写代码
591
+
592
+ Ruff 实时检查(编辑器插件)
593
+
594
+ git commit
595
+
596
+ pre-commit 触发
597
+
598
+ Ruff 检查 → ❌ 失败则中断提交
599
+
600
+ Black 格式化 → ❌ 失败则中断提交
601
+
602
+ ✅ 全部通过 → 允许提交
603
+
604
+ CI/CD 再次验证(可选)
605
+ ```
606
+
607
+ ### 13.3 工具初始化
608
+
609
+ **如果工具未初始化**:
610
+ - 运行 `aodw init-tools` 或通过 AI 命令"初始化工具"
611
+ - 工具初始化会引导您完成工具的安装和配置
612
+ - 配置模板会自动应用到项目中