trinity-method-sdk 2.0.0

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 (191) hide show
  1. package/CHANGELOG.md +116 -0
  2. package/LICENSE +21 -0
  3. package/README.md +555 -0
  4. package/dist/cli/commands/deploy/agents.d.ts +14 -0
  5. package/dist/cli/commands/deploy/agents.js +59 -0
  6. package/dist/cli/commands/deploy/ci-cd.d.ts +13 -0
  7. package/dist/cli/commands/deploy/ci-cd.js +50 -0
  8. package/dist/cli/commands/deploy/claude-setup.d.ts +17 -0
  9. package/dist/cli/commands/deploy/claude-setup.js +91 -0
  10. package/dist/cli/commands/deploy/configuration.d.ts +13 -0
  11. package/dist/cli/commands/deploy/configuration.js +215 -0
  12. package/dist/cli/commands/deploy/directories.d.ts +12 -0
  13. package/dist/cli/commands/deploy/directories.js +38 -0
  14. package/dist/cli/commands/deploy/gitignore.d.ts +12 -0
  15. package/dist/cli/commands/deploy/gitignore.js +53 -0
  16. package/dist/cli/commands/deploy/index.d.ts +38 -0
  17. package/dist/cli/commands/deploy/index.js +156 -0
  18. package/dist/cli/commands/deploy/knowledge-base.d.ts +16 -0
  19. package/dist/cli/commands/deploy/knowledge-base.js +75 -0
  20. package/dist/cli/commands/deploy/linting.d.ts +18 -0
  21. package/dist/cli/commands/deploy/linting.js +51 -0
  22. package/dist/cli/commands/deploy/metrics.d.ts +13 -0
  23. package/dist/cli/commands/deploy/metrics.js +34 -0
  24. package/dist/cli/commands/deploy/pre-flight.d.ts +13 -0
  25. package/dist/cli/commands/deploy/pre-flight.js +29 -0
  26. package/dist/cli/commands/deploy/root-files.d.ts +16 -0
  27. package/dist/cli/commands/deploy/root-files.js +178 -0
  28. package/dist/cli/commands/deploy/sdk-install.d.ts +12 -0
  29. package/dist/cli/commands/deploy/sdk-install.js +57 -0
  30. package/dist/cli/commands/deploy/summary.d.ts +14 -0
  31. package/dist/cli/commands/deploy/summary.js +130 -0
  32. package/dist/cli/commands/deploy/templates.d.ts +14 -0
  33. package/dist/cli/commands/deploy/templates.js +84 -0
  34. package/dist/cli/commands/deploy/types.d.ts +39 -0
  35. package/dist/cli/commands/deploy/types.js +5 -0
  36. package/dist/cli/commands/update/agents.d.ts +14 -0
  37. package/dist/cli/commands/update/agents.js +31 -0
  38. package/dist/cli/commands/update/backup.d.ts +31 -0
  39. package/dist/cli/commands/update/backup.js +97 -0
  40. package/dist/cli/commands/update/commands.d.ts +14 -0
  41. package/dist/cli/commands/update/commands.js +75 -0
  42. package/dist/cli/commands/update/index.d.ts +15 -0
  43. package/dist/cli/commands/update/index.js +118 -0
  44. package/dist/cli/commands/update/knowledge-base.d.ts +14 -0
  45. package/dist/cli/commands/update/knowledge-base.js +38 -0
  46. package/dist/cli/commands/update/pre-flight.d.ts +13 -0
  47. package/dist/cli/commands/update/pre-flight.js +37 -0
  48. package/dist/cli/commands/update/summary.d.ts +20 -0
  49. package/dist/cli/commands/update/summary.js +47 -0
  50. package/dist/cli/commands/update/templates.d.ts +14 -0
  51. package/dist/cli/commands/update/templates.js +25 -0
  52. package/dist/cli/commands/update/types.d.ts +13 -0
  53. package/dist/cli/commands/update/types.js +7 -0
  54. package/dist/cli/commands/update/utils.d.ts +11 -0
  55. package/dist/cli/commands/update/utils.js +19 -0
  56. package/dist/cli/commands/update/verification.d.ts +20 -0
  57. package/dist/cli/commands/update/verification.js +54 -0
  58. package/dist/cli/commands/update/version.d.ts +18 -0
  59. package/dist/cli/commands/update/version.js +36 -0
  60. package/dist/cli/commands/update.d.ts +7 -0
  61. package/dist/cli/commands/update.js +7 -0
  62. package/dist/cli/index.d.ts +3 -0
  63. package/dist/cli/index.js +36 -0
  64. package/dist/cli/types.d.ts +77 -0
  65. package/dist/cli/types.js +5 -0
  66. package/dist/cli/utils/deploy-ci.d.ts +22 -0
  67. package/dist/cli/utils/deploy-ci.js +138 -0
  68. package/dist/cli/utils/deploy-linting.d.ts +3 -0
  69. package/dist/cli/utils/deploy-linting.js +136 -0
  70. package/dist/cli/utils/detect-stack.d.ts +3 -0
  71. package/dist/cli/utils/detect-stack.js +270 -0
  72. package/dist/cli/utils/error-classes.d.ts +63 -0
  73. package/dist/cli/utils/error-classes.js +84 -0
  74. package/dist/cli/utils/error-handler.d.ts +59 -0
  75. package/dist/cli/utils/error-handler.js +127 -0
  76. package/dist/cli/utils/errors.d.ts +52 -0
  77. package/dist/cli/utils/errors.js +102 -0
  78. package/dist/cli/utils/get-sdk-path.d.ts +18 -0
  79. package/dist/cli/utils/get-sdk-path.js +31 -0
  80. package/dist/cli/utils/inject-dependencies.d.ts +2 -0
  81. package/dist/cli/utils/inject-dependencies.js +55 -0
  82. package/dist/cli/utils/linting-tools.d.ts +8 -0
  83. package/dist/cli/utils/linting-tools.js +206 -0
  84. package/dist/cli/utils/metrics/code-quality.d.ts +32 -0
  85. package/dist/cli/utils/metrics/code-quality.js +122 -0
  86. package/dist/cli/utils/metrics/dependency-parser.d.ts +21 -0
  87. package/dist/cli/utils/metrics/dependency-parser.js +153 -0
  88. package/dist/cli/utils/metrics/file-complexity.d.ts +26 -0
  89. package/dist/cli/utils/metrics/file-complexity.js +77 -0
  90. package/dist/cli/utils/metrics/framework-detector.d.ts +17 -0
  91. package/dist/cli/utils/metrics/framework-detector.js +120 -0
  92. package/dist/cli/utils/metrics/git-metrics.d.ts +30 -0
  93. package/dist/cli/utils/metrics/git-metrics.js +83 -0
  94. package/dist/cli/utils/metrics/index.d.ts +28 -0
  95. package/dist/cli/utils/metrics/index.js +100 -0
  96. package/dist/cli/utils/template-processor.d.ts +10 -0
  97. package/dist/cli/utils/template-processor.js +188 -0
  98. package/dist/cli/utils/validate-path.d.ts +80 -0
  99. package/dist/cli/utils/validate-path.js +180 -0
  100. package/dist/index.d.ts +6 -0
  101. package/dist/index.js +8 -0
  102. package/dist/templates/agents/aj-team/apo-documentation-specialist.md.template +572 -0
  103. package/dist/templates/agents/aj-team/bas-quality-gate.md.template +906 -0
  104. package/dist/templates/agents/aj-team/bon-dependency-manager.md.template +636 -0
  105. package/dist/templates/agents/aj-team/cap-configuration-specialist.md.template +670 -0
  106. package/dist/templates/agents/aj-team/dra-code-reviewer.md.template +768 -0
  107. package/dist/templates/agents/aj-team/kil-task-executor.md.template +764 -0
  108. package/dist/templates/agents/aj-team/uro-refactoring-specialist.md.template +759 -0
  109. package/dist/templates/agents/audit/juno-auditor.md.template +447 -0
  110. package/dist/templates/agents/deployment/ein-cicd.md.template +694 -0
  111. package/dist/templates/agents/deployment/ino-context.md.template +733 -0
  112. package/dist/templates/agents/deployment/tan-structure.md.template +661 -0
  113. package/dist/templates/agents/deployment/zen-knowledge.md.template +451 -0
  114. package/dist/templates/agents/leadership/aj-cc.md.template +462 -0
  115. package/dist/templates/agents/leadership/aj-maestro.md.template +943 -0
  116. package/dist/templates/agents/leadership/aly-cto.md.template +407 -0
  117. package/dist/templates/agents/planning/eus-decomposer.md.template +496 -0
  118. package/dist/templates/agents/planning/mon-requirements.md.template +323 -0
  119. package/dist/templates/agents/planning/ror-design.md.template +465 -0
  120. package/dist/templates/agents/planning/tra-planner.md.template +432 -0
  121. package/dist/templates/ci/cd.yml.template +175 -0
  122. package/dist/templates/ci/ci.yml.template +196 -0
  123. package/dist/templates/ci/generic-ci.yml +115 -0
  124. package/dist/templates/ci/github-actions.yml +86 -0
  125. package/dist/templates/ci/gitlab-ci.yml +103 -0
  126. package/dist/templates/claude/EMPLOYEE-DIRECTORY.md.template +545 -0
  127. package/dist/templates/documentation/ROOT-README.md.template +307 -0
  128. package/dist/templates/documentation/SUBDIRECTORY-README.md.template +261 -0
  129. package/dist/templates/investigations/bug.md.template +484 -0
  130. package/dist/templates/investigations/feature.md.template +564 -0
  131. package/dist/templates/investigations/performance.md.template +625 -0
  132. package/dist/templates/investigations/security.md.template +714 -0
  133. package/dist/templates/investigations/technical.md.template +433 -0
  134. package/dist/templates/knowledge-base/AI-DEVELOPMENT-GUIDE.md.template +957 -0
  135. package/dist/templates/knowledge-base/ARCHITECTURE.md.template +452 -0
  136. package/dist/templates/knowledge-base/CODING-PRINCIPLES.md.template +750 -0
  137. package/dist/templates/knowledge-base/DOCUMENTATION-CRITERIA.md.template +1118 -0
  138. package/dist/templates/knowledge-base/ISSUES.md.template +539 -0
  139. package/dist/templates/knowledge-base/TESTING-PRINCIPLES.md.template +894 -0
  140. package/dist/templates/knowledge-base/Technical-Debt.md.template +640 -0
  141. package/dist/templates/knowledge-base/To-do.md.template +407 -0
  142. package/dist/templates/knowledge-base/Trinity.md.template +464 -0
  143. package/dist/templates/linting/flutter/.pre-commit-config.yaml.template +27 -0
  144. package/dist/templates/linting/flutter/analysis_options.yaml.template +26 -0
  145. package/dist/templates/linting/nodejs/.eslintrc-commonjs.json.template +19 -0
  146. package/dist/templates/linting/nodejs/.eslintrc-esm.json.template +19 -0
  147. package/dist/templates/linting/nodejs/.eslintrc-typescript.json.template +22 -0
  148. package/dist/templates/linting/nodejs/.pre-commit-config.yaml.template +51 -0
  149. package/dist/templates/linting/nodejs/.prettierrc.json.template +10 -0
  150. package/dist/templates/linting/python/.flake8.template +16 -0
  151. package/dist/templates/linting/python/.pre-commit-config.yaml.template +30 -0
  152. package/dist/templates/linting/python/pyproject.toml.template +38 -0
  153. package/dist/templates/linting/rust/.pre-commit-config.yaml.template +28 -0
  154. package/dist/templates/linting/rust/clippy.toml.template +14 -0
  155. package/dist/templates/linting/rust/rustfmt.toml.template +12 -0
  156. package/dist/templates/root/CLAUDE.md.template +65 -0
  157. package/dist/templates/root/TRINITY.md.template +52 -0
  158. package/dist/templates/shared/claude-commands/trinity-agents.md.template +168 -0
  159. package/dist/templates/shared/claude-commands/trinity-audit.md.template +646 -0
  160. package/dist/templates/shared/claude-commands/trinity-changelog.md.template +624 -0
  161. package/dist/templates/shared/claude-commands/trinity-continue.md.template +549 -0
  162. package/dist/templates/shared/claude-commands/trinity-create-investigation.md.template +232 -0
  163. package/dist/templates/shared/claude-commands/trinity-decompose.md.template +181 -0
  164. package/dist/templates/shared/claude-commands/trinity-design.md.template +347 -0
  165. package/dist/templates/shared/claude-commands/trinity-docs.md.template +2093 -0
  166. package/dist/templates/shared/claude-commands/trinity-end.md.template +397 -0
  167. package/dist/templates/shared/claude-commands/trinity-init.md.template +606 -0
  168. package/dist/templates/shared/claude-commands/trinity-investigate-templates.md.template +725 -0
  169. package/dist/templates/shared/claude-commands/trinity-orchestrate.md.template +1061 -0
  170. package/dist/templates/shared/claude-commands/trinity-plan-investigation.md.template +135 -0
  171. package/dist/templates/shared/claude-commands/trinity-plan.md.template +201 -0
  172. package/dist/templates/shared/claude-commands/trinity-readme.md.template +1971 -0
  173. package/dist/templates/shared/claude-commands/trinity-requirements.md.template +148 -0
  174. package/dist/templates/shared/claude-commands/trinity-start.md.template +268 -0
  175. package/dist/templates/shared/claude-commands/trinity-verify.md.template +453 -0
  176. package/dist/templates/shared/claude-commands/trinity-workorder.md.template +249 -0
  177. package/dist/templates/source/base-CLAUDE.md.template +310 -0
  178. package/dist/templates/source/flutter-CLAUDE.md.template +593 -0
  179. package/dist/templates/source/nodejs-CLAUDE.md.template +531 -0
  180. package/dist/templates/source/python-CLAUDE.md.template +510 -0
  181. package/dist/templates/source/react-CLAUDE.md.template +513 -0
  182. package/dist/templates/source/rust-CLAUDE.md.template +653 -0
  183. package/dist/templates/source/tests-CLAUDE.md.template +432 -0
  184. package/dist/templates/trinity/CLAUDE.md.template +372 -0
  185. package/dist/templates/work-orders/ANALYSIS-TEMPLATE.md.template +276 -0
  186. package/dist/templates/work-orders/AUDIT-TEMPLATE.md.template +262 -0
  187. package/dist/templates/work-orders/IMPLEMENTATION-TEMPLATE.md.template +260 -0
  188. package/dist/templates/work-orders/INVESTIGATION-TEMPLATE.md.template +206 -0
  189. package/dist/templates/work-orders/PATTERN-TEMPLATE.md.template +320 -0
  190. package/dist/templates/work-orders/VERIFICATION-TEMPLATE.md.template +273 -0
  191. package/package.json +94 -0
@@ -0,0 +1,2093 @@
1
+ # Trinity docs/ Directory Management
2
+
3
+ **Purpose:** Launch APO (Documentation Specialist) to create, organize, and maintain the project's `docs/` directory with proper structure, seeded content, and navigation.
4
+
5
+ **Use Case:** Create organized docs/ directory structure, seed initial documentation content, migrate scattered docs, generate navigation, validate links.
6
+
7
+ **Deliverable:** docs/ organization report in `trinity/reports/DOCS-ORGANIZATION-{date}.md`
8
+
9
+ ---
10
+
11
+ ## Overview
12
+
13
+ The `/trinity-docs` command invokes APO (Documentation Specialist) to **create and organize** the `docs/` directory. This command creates a well-structured documentation directory with relevant starter content based on your project's actual codebase.
14
+
15
+ **APO's Responsibilities:**
16
+ - Analyze codebase to gather project context
17
+ - Scan existing docs/ files and scattered documentation
18
+ - Create hierarchical directory structure (guides/, api/, architecture/, reference/, images/)
19
+ - Seed initial documentation content based on project type
20
+ - Migrate scattered documentation files into organized structure
21
+ - Auto-generate architecture documentation from codebase
22
+ - Generate docs/README.md navigation file
23
+ - Validate and fix documentation links
24
+ - Integrate auto-generated API docs (TypeDoc, Rustdoc, etc.)
25
+ - Provide actionable recommendations for empty categories
26
+
27
+ **What This Command Does NOT Handle:**
28
+ - ❌ Root README.md (use `/trinity-readme`)
29
+ - ❌ CHANGELOG.md updates (use `/trinity-changelog`)
30
+ - ❌ Trinity infrastructure files (trinity/, CLAUDE.md)
31
+ - ❌ Technical source READMEs (src/README.md, tests/README.md)
32
+
33
+ ---
34
+
35
+ ## CRITICAL: APO Must Perform Work DIRECTLY
36
+
37
+ **APO is NOT a planning agent. APO is an EXECUTION agent for documentation.**
38
+
39
+ **✅ APO MUST:**
40
+ - ANALYZE codebase for project context **in this command execution**
41
+ - CREATE docs/ directory structure **in this command execution**
42
+ - SEED initial documentation content **in this command execution**
43
+ - MIGRATE scattered documentation **in this command execution**
44
+ - GENERATE architecture docs **in this command execution**
45
+ - ORGANIZE existing documentation files **in this command execution**
46
+ - VALIDATE and FIX documentation links **in this command execution**
47
+ - Report COMPLETED work in Phase 5 (past tense: "Created docs/guides/getting-started.md")
48
+
49
+ **❌ APO MUST NOT:**
50
+ - Create work orders for docs organization
51
+ - Create "recommendations" instead of performing organization
52
+ - Skip work because "it's too much effort"
53
+ - Defer work to future execution
54
+ - Move Trinity infrastructure files (trinity/, CLAUDE.md)
55
+ - Move technical source READMEs (src/README.md, etc.)
56
+
57
+ ---
58
+
59
+ ## When to Use `/trinity-docs`
60
+
61
+ ### Perfect Use Cases:
62
+ ✅ **New Project** - Setting up docs/ for the first time with seeded content
63
+ ✅ **Empty docs/** - docs/ exists but contains no useful documentation
64
+ ✅ **Disorganized docs/** - Files scattered without structure
65
+ ✅ **Missing Navigation** - No docs/README.md to guide users
66
+ ✅ **Documentation Growth** - docs/ has grown and needs reorganization
67
+ ✅ **Scattered Documentation** - .md files scattered across project
68
+ ✅ **Pre-Release** - Ensure documentation is well-organized with starter content
69
+
70
+ ### When NOT to Use:
71
+ ❌ **Root README Updates** - Use `/trinity-readme` instead
72
+ ❌ **CHANGELOG Updates** - Use `/trinity-changelog` instead
73
+ ❌ **API Documentation Generation** - Use TypeDoc, Rustdoc, etc. first (this command integrates them)
74
+
75
+ ---
76
+
77
+ ## Usage
78
+
79
+ ### Basic Usage
80
+ ```bash
81
+ /trinity-docs
82
+ ```
83
+
84
+ APO performs complete docs/ creation and organization:
85
+ 1. Analyzes codebase for project context (framework, tech stack, architecture)
86
+ 2. Scans existing docs/ files and scattered documentation
87
+ 3. Creates directory structure (guides/, api/, architecture/, reference/, images/)
88
+ 4. Seeds initial documentation content based on project type
89
+ 5. Migrates scattered .md files into organized structure
90
+ 6. Auto-generates architecture documentation
91
+ 7. Integrates auto-generated API docs (TypeDoc, etc.)
92
+ 8. Validates and fixes documentation links
93
+ 9. Generates docs/README.md navigation with coverage metrics
94
+ 10. Generates comprehensive organization report
95
+
96
+ ---
97
+
98
+ ## APO Execution Principles
99
+
100
+ ### Unlimited Token Budget
101
+
102
+ **CRITICAL: APO has NO token budget limits for this command.**
103
+
104
+ **✅ APO MUST:**
105
+ 1. Complete ALL 5 phases regardless of token usage
106
+ 2. Create ALL seeded content and organize ALL files (no "budget exceeded" stops)
107
+ 3. NEVER claim "token budget constraints" as reason for incomplete work
108
+
109
+ **❌ APO MUST NOT:**
110
+ 1. Stop execution due to token concerns
111
+ 2. Skip phases due to "budget constraints"
112
+ 3. Defer work to future sessions
113
+
114
+ ---
115
+
116
+ ## Phase Execution Rules
117
+
118
+ **ALL 5 phases are MANDATORY. APO MUST execute phases in sequence.**
119
+
120
+ **FORBIDDEN:**
121
+ - ❌ Skipping phases
122
+ - ❌ "Deferring" phases to future sessions
123
+ - ❌ Claiming phases are "optional"
124
+
125
+ ---
126
+
127
+ ## APO's 5-Phase docs/ Organization Process
128
+
129
+ ### Phase 1: Discovery & Codebase Analysis
130
+
131
+ **Goal:** Scan existing documentation, detect scattered files, and analyze codebase for context
132
+
133
+ **Step 1: Check if docs/ Exists**
134
+
135
+ ```bash
136
+ # Check if docs/ directory exists
137
+ if exists("docs/"):
138
+ docs_exists = true
139
+ # Scan docs/ directory
140
+ Use Glob pattern: "docs/**/*"
141
+ else:
142
+ docs_exists = false
143
+ # Will create structure in Phase 2
144
+ ```
145
+
146
+ **Step 2: Inventory Existing docs/ Files**
147
+
148
+ If docs/ exists:
149
+
150
+ ```javascript
151
+ docs_files = []
152
+ docs_dirs = []
153
+
154
+ for each path in glob_results:
155
+ if is_file(path):
156
+ docs_files.push(path)
157
+ else if is_directory(path):
158
+ docs_dirs.push(path)
159
+
160
+ // Categorize files by type
161
+ markdown_files = docs_files.filter(f => f.endsWith('.md'))
162
+ image_files = docs_files.filter(f => f.endsWith('.png', '.jpg', '.svg', '.gif'))
163
+ html_files = docs_files.filter(f => f.endsWith('.html')) // TypeDoc, etc.
164
+ other_files = docs_files.filter(f => not markdown nor image nor html)
165
+ ```
166
+
167
+ **Step 3: Analyze Current docs/ Structure**
168
+
169
+ ```javascript
170
+ has_guides_dir = docs_dirs.includes("docs/guides")
171
+ has_api_dir = docs_dirs.includes("docs/api")
172
+ has_architecture_dir = docs_dirs.includes("docs/architecture")
173
+ has_reference_dir = docs_dirs.includes("docs/reference")
174
+ has_images_dir = docs_dirs.includes("docs/images")
175
+ has_navigation = docs_files.includes("docs/README.md")
176
+
177
+ structure_score = (
178
+ (has_guides_dir ? 20 : 0) +
179
+ (has_api_dir ? 20 : 0) +
180
+ (has_architecture_dir ? 20 : 0) +
181
+ (has_reference_dir ? 20 : 0) +
182
+ (has_navigation ? 20 : 0)
183
+ )
184
+ ```
185
+
186
+ **Step 4: Scan for Scattered Documentation (ENHANCEMENT 3)**
187
+
188
+ **CRITICAL: Identify documentation scattered outside docs/ for migration**
189
+
190
+ ```bash
191
+ # Search entire project for .md files outside docs/
192
+ Use Glob: "**/*.md"
193
+
194
+ # EXCLUDE these patterns (DO NOT migrate):
195
+ excluded_patterns = [
196
+ "node_modules/**",
197
+ ".git/**",
198
+ "docs/**", # Already in docs/
199
+ "trinity/**", # Trinity infrastructure - NEVER move
200
+ "**/CLAUDE.md", # All CLAUDE.md files - NEVER move
201
+ "README.md", # Root README - keep in root
202
+ "CHANGELOG.md", # Root CHANGELOG - keep in root
203
+ "CONTRIBUTING.md", # Root CONTRIBUTING - keep in root
204
+ "LICENSE", # Root LICENSE - keep in root
205
+ "CODE_OF_CONDUCT.md", # Root standards - keep in root
206
+ "SECURITY.md" # Root standards - keep in root
207
+ ]
208
+
209
+ scattered_docs = []
210
+
211
+ for each file in glob_results:
212
+ # Skip if matches excluded patterns
213
+ if matches_any(file, excluded_patterns):
214
+ continue
215
+
216
+ # Categorize by filename/content patterns
217
+ category = detect_category(file)
218
+
219
+ # Check if it's a technical source README (src/README.md, tests/README.md)
220
+ if file.endsWith("/README.md"):
221
+ parent_dir = get_parent_directory(file)
222
+ if is_source_directory(parent_dir): // src/, tests/, lib/, pkg/, etc.
223
+ continue # Keep technical READMEs with source code
224
+
225
+ # This is orphaned documentation - mark for migration
226
+ scattered_docs.push({
227
+ file: file,
228
+ suggested_category: category
229
+ })
230
+
231
+ // Category detection logic
232
+ function detect_category(filename):
233
+ if matches("architecture*", "design*", "*-architecture", "*-design"):
234
+ return "docs/architecture/"
235
+
236
+ if matches("api*", "endpoints*", "*-api", "*-endpoints"):
237
+ return "docs/api/"
238
+
239
+ if matches("guide*", "tutorial*", "how-to*", "*-guide", "*-tutorial"):
240
+ return "docs/guides/"
241
+
242
+ if matches("*-reference", "spec*", "*-spec", "glossary*"):
243
+ return "docs/reference/"
244
+
245
+ // Default category
246
+ return "docs/guides/"
247
+ ```
248
+
249
+ **Step 5: Codebase Context Analysis (ENHANCEMENT 1)**
250
+
251
+ **CRITICAL: Gather project information to seed relevant documentation**
252
+
253
+ ```bash
254
+ # Detect project type and extract metadata
255
+ project_metadata = {}
256
+
257
+ # Check package manifests
258
+ if exists("package.json"):
259
+ package_json = read("package.json")
260
+ project_metadata.type = "Node.js"
261
+ project_metadata.name = package_json.name
262
+ project_metadata.version = package_json.version
263
+ project_metadata.description = package_json.description
264
+ project_metadata.dependencies = Object.keys(package_json.dependencies || {})
265
+ project_metadata.framework = detect_framework(package_json.dependencies)
266
+
267
+ else if exists("Cargo.toml"):
268
+ cargo_toml = read("Cargo.toml")
269
+ project_metadata.type = "Rust"
270
+ project_metadata.name = cargo_toml.package.name
271
+ project_metadata.version = cargo_toml.package.version
272
+ project_metadata.description = cargo_toml.package.description
273
+
274
+ else if exists("pyproject.toml") or exists("setup.py"):
275
+ project_metadata.type = "Python"
276
+ pyproject = read("pyproject.toml" or "setup.py")
277
+ # Extract Python project metadata
278
+
279
+ else if exists("pubspec.yaml"):
280
+ pubspec = read("pubspec.yaml")
281
+ project_metadata.type = "Flutter"
282
+ project_metadata.name = pubspec.name
283
+ project_metadata.version = pubspec.version
284
+
285
+ else if exists("go.mod"):
286
+ go_mod = read("go.mod")
287
+ project_metadata.type = "Go"
288
+ # Extract Go module info
289
+
290
+ # Detect framework
291
+ function detect_framework(dependencies):
292
+ if has("react"): return "React"
293
+ if has("next"): return "Next.js"
294
+ if has("express"): return "Express"
295
+ if has("vue"): return "Vue"
296
+ if has("@nestjs"): return "NestJS"
297
+ if has("django"): return "Django"
298
+ if has("flask"): return "Flask"
299
+ if has("fastapi"): return "FastAPI"
300
+ return "Unknown"
301
+
302
+ # Scan source directory structure
303
+ if exists("src/"):
304
+ src_structure = analyze_directory_structure("src/")
305
+ project_metadata.architecture = detect_architecture_pattern(src_structure)
306
+ project_metadata.entry_point = find_entry_point()
307
+
308
+ # Detect architecture pattern
309
+ function detect_architecture_pattern(structure):
310
+ if has_dirs(["controllers", "models", "views"]): return "MVC"
311
+ if has_dirs(["components", "pages", "hooks"]): return "React Component Architecture"
312
+ if has_dirs(["services", "repositories"]): return "Service Layer Architecture"
313
+ if has_dirs(["handlers", "middleware"]): return "Middleware-based Architecture"
314
+ return "Modular Architecture"
315
+
316
+ # Check for existing documentation candidates
317
+ if exists("CONTRIBUTING.md"):
318
+ project_metadata.has_contributing = true
319
+
320
+ if exists(".env.example"):
321
+ project_metadata.has_env_example = true
322
+ ```
323
+
324
+ **Step 6: Detect Auto-Generated API Documentation (ENHANCEMENT 8)**
325
+
326
+ ```bash
327
+ # Detect TypeDoc (Node.js/TypeScript)
328
+ if exists("docs/index.html") and exists("docs/modules.html"):
329
+ project_metadata.api_docs = {
330
+ type: "TypeDoc",
331
+ location: "docs/",
332
+ entry: "index.html"
333
+ }
334
+
335
+ # Detect JSDoc
336
+ if exists("docs/jsdoc/index.html"):
337
+ project_metadata.api_docs = {
338
+ type: "JSDoc",
339
+ location: "docs/jsdoc/",
340
+ entry: "index.html"
341
+ }
342
+
343
+ # Detect Rustdoc
344
+ if exists("target/doc/index.html"):
345
+ project_metadata.api_docs = {
346
+ type: "Rustdoc",
347
+ location: "target/doc/",
348
+ entry: "index.html"
349
+ }
350
+
351
+ # Detect Sphinx (Python)
352
+ if exists("docs/_build/html/index.html"):
353
+ project_metadata.api_docs = {
354
+ type: "Sphinx",
355
+ location: "docs/_build/html/",
356
+ entry: "index.html"
357
+ }
358
+ ```
359
+
360
+ **Step 7: Detect Duplicate Documentation (ENHANCEMENT 6)**
361
+
362
+ ```bash
363
+ # Find potential duplicates
364
+ all_md_files = glob("**/*.md", exclude=excluded_patterns)
365
+ duplicates = []
366
+
367
+ for each file1 in all_md_files:
368
+ title1 = extract_title(file1)
369
+
370
+ for each file2 in all_md_files (after file1):
371
+ title2 = extract_title(file2)
372
+
373
+ # Check for similar titles
374
+ if similarity(title1, title2) > 0.8:
375
+ duplicates.push({file1, file2, similarity_score})
376
+
377
+ # Check for similar content
378
+ content_similarity = compare_content(file1, file2)
379
+ if content_similarity > 0.7:
380
+ duplicates.push({file1, file2, type: "content", similarity_score})
381
+ ```
382
+
383
+ **APO Output:**
384
+
385
+ ```markdown
386
+ === PHASE 1: DISCOVERY & CODEBASE ANALYSIS ===
387
+
388
+ **docs/ Exists:** {✅ YES | ❌ NO}
389
+
390
+ **Current docs/ Files:** {count}
391
+ - Markdown files: {count}
392
+ - Image files: {count}
393
+ - HTML files (TypeDoc/etc): {count}
394
+ - Other files: {count}
395
+
396
+ **Current docs/ Directories:** {count}
397
+ - guides/: {✅ EXISTS | ❌ MISSING}
398
+ - api/: {✅ EXISTS | ❌ MISSING}
399
+ - architecture/: {✅ EXISTS | ❌ MISSING}
400
+ - reference/: {✅ EXISTS | ❌ MISSING}
401
+ - images/: {✅ EXISTS | ❌ MISSING}
402
+ - Navigation (README.md): {✅ EXISTS | ❌ MISSING}
403
+
404
+ **Structure Score:** {structure_score}/100
405
+ - 0-25: Needs complete organization
406
+ - 26-50: Needs significant organization
407
+ - 51-75: Needs minor organization
408
+ - 76-100: Well-organized
409
+
410
+ **Scattered Documentation Found:** {scattered_docs.length} files
411
+ {For each scattered doc:}
412
+ - {file} → {suggested_category}
413
+
414
+ **Duplicate Documentation:** {duplicates.length} potential duplicates
415
+ {For each duplicate:}
416
+ - {file1} ↔ {file2} (similarity: {score}%)
417
+
418
+ **Project Context:**
419
+ - **Type:** {project_metadata.type}
420
+ - **Name:** {project_metadata.name}
421
+ - **Version:** {project_metadata.version}
422
+ - **Framework:** {project_metadata.framework}
423
+ - **Architecture:** {project_metadata.architecture}
424
+ - **Entry Point:** {project_metadata.entry_point}
425
+
426
+ **Auto-Generated API Docs:**
427
+ {if api_docs detected:}
428
+ - ✅ {api_docs.type} detected at {api_docs.location}
429
+ {else:}
430
+ - ❌ No auto-generated API docs detected
431
+
432
+ **Existing Documentation Assets:**
433
+ - CONTRIBUTING.md: {✅ YES | ❌ NO}
434
+ - .env.example: {✅ YES | ❌ NO}
435
+ ```
436
+
437
+ ---
438
+
439
+ ### Phase 2: Directory Structure & Content Seeding
440
+
441
+ **Goal:** Create hierarchical docs/ structure with seeded initial content
442
+
443
+ **Standard Directory Structure:**
444
+
445
+ ```
446
+ docs/
447
+ ├── README.md (navigation - created in Phase 4)
448
+ ├── guides/ (How-to guides, tutorials)
449
+ │ └── getting-started.md (seeded)
450
+ ├── api/ (API documentation)
451
+ │ └── README.md (seeded with project context)
452
+ ├── architecture/ (Architecture diagrams, design docs)
453
+ │ └── overview.md (auto-generated from codebase)
454
+ ├── reference/ (Reference documentation)
455
+ │ └── README.md (seeded with CLI commands, env vars)
456
+ └── images/ (Images, diagrams, screenshots)
457
+ ```
458
+
459
+ **Step 1: Create Missing Directories**
460
+
461
+ ```javascript
462
+ required_dirs = [
463
+ "docs/guides",
464
+ "docs/api",
465
+ "docs/architecture",
466
+ "docs/reference",
467
+ "docs/images"
468
+ ]
469
+
470
+ created_dirs = []
471
+
472
+ for each dir in required_dirs:
473
+ if not exists(dir):
474
+ create_directory(dir)
475
+ created_dirs.push(dir)
476
+ ```
477
+
478
+ **Step 2: Seed docs/guides/ Content (ENHANCEMENT 2)**
479
+
480
+ **CRITICAL: Create useful starter guides based on project type, not empty placeholders**
481
+
482
+ ```markdown
483
+ ### docs/guides/getting-started.md
484
+
485
+ # Getting Started with {{PROJECT_NAME}}
486
+
487
+ **Version:** {{VERSION}}
488
+ **Last Updated:** {{CURRENT_DATE}}
489
+
490
+ ## Overview
491
+
492
+ {project_metadata.description or "This guide will help you get started with {{PROJECT_NAME}}."}
493
+
494
+ ## Prerequisites
495
+
496
+ {if project_metadata.type === "Node.js":}
497
+ - Node.js ≥ {extract from package.json engines or "16.0.0"}
498
+ - npm or yarn package manager
499
+
500
+ {if project_metadata.type === "Python":}
501
+ - Python ≥ {extract from pyproject.toml or "3.8"}
502
+ - pip package manager
503
+
504
+ {if project_metadata.type === "Rust":}
505
+ - Rust {extract from Cargo.toml or "latest stable"}
506
+ - Cargo build tool
507
+
508
+ {if project_metadata.type === "Flutter":}
509
+ - Flutter SDK {extract from pubspec.yaml or "latest"}
510
+ - Dart SDK
511
+
512
+ ## Installation
513
+
514
+ {if project_metadata.type === "Node.js":}
515
+ ```bash
516
+ # Clone the repository
517
+ git clone {repository URL from package.json or placeholder}
518
+ cd {{PROJECT_NAME}}
519
+
520
+ # Install dependencies
521
+ npm install
522
+
523
+ # Run development server
524
+ npm run dev
525
+ ```
526
+
527
+ {if project_metadata.type === "Python":}
528
+ ```bash
529
+ # Clone the repository
530
+ git clone {repository URL}
531
+ cd {{PROJECT_NAME}}
532
+
533
+ # Create virtual environment
534
+ python -m venv venv
535
+ source venv/bin/activate # On Windows: venv\Scripts\activate
536
+
537
+ # Install dependencies
538
+ pip install -r requirements.txt
539
+
540
+ # Run application
541
+ python main.py
542
+ ```
543
+
544
+ {if project_metadata.type === "Rust":}
545
+ ```bash
546
+ # Clone the repository
547
+ git clone {repository URL}
548
+ cd {{PROJECT_NAME}}
549
+
550
+ # Build project
551
+ cargo build
552
+
553
+ # Run project
554
+ cargo run
555
+ ```
556
+
557
+ ## Project Structure
558
+
559
+ ```
560
+ {actual src/ directory structure from Phase 1 scan}
561
+ ```
562
+
563
+ ## Next Steps
564
+
565
+ - [API Documentation](../api/) - Learn about available APIs
566
+ - [Architecture Overview](../architecture/overview.md) - Understand system design
567
+ {if has CONTRIBUTING.md:}
568
+ - [Contributing Guide](../../CONTRIBUTING.md) - Contribute to the project
569
+
570
+ ## Common Issues
571
+
572
+ {if project_metadata.type === "Node.js":}
573
+ ### "Module not found" errors
574
+ - Ensure you've run `npm install`
575
+ - Clear node_modules and reinstall: `rm -rf node_modules && npm install`
576
+
577
+ {if project_metadata.type === "Python":}
578
+ ### Import errors
579
+ - Ensure virtual environment is activated
580
+ - Reinstall dependencies: `pip install -r requirements.txt`
581
+
582
+ ## Support
583
+
584
+ {Placeholder for support information}
585
+ - GitHub Issues: [repository]/issues
586
+ - Documentation: [docs/](../)
587
+ ```
588
+
589
+ **Create Framework-Specific Guides (ENHANCEMENT 10)**
590
+
591
+ ```markdown
592
+ {if framework === "Express":}
593
+ ### docs/guides/api-development.md
594
+
595
+ # API Development Guide
596
+
597
+ ## Creating Routes
598
+
599
+ ```javascript
600
+ // src/routes/example.js
601
+ const express = require('express');
602
+ const router = express.Router();
603
+
604
+ router.get('/example', (req, res) => {
605
+ res.json({ message: 'Example endpoint' });
606
+ });
607
+
608
+ module.exports = router;
609
+ ```
610
+
611
+ ## Middleware
612
+
613
+ {Examples based on detected middleware patterns in codebase}
614
+
615
+ ## Error Handling
616
+
617
+ {if error handling patterns detected, show them}
618
+
619
+ {if framework === "React":}
620
+ ### docs/guides/component-development.md
621
+
622
+ # Component Development Guide
623
+
624
+ ## Component Structure
625
+
626
+ ```jsx
627
+ // Functional Component Example
628
+ import React from 'react';
629
+
630
+ export const ExampleComponent = ({ prop1, prop2 }) => {
631
+ return (
632
+ <div>
633
+ {/* Component content */}
634
+ </div>
635
+ );
636
+ };
637
+ ```
638
+
639
+ ## State Management
640
+
641
+ {if Redux detected: show Redux patterns}
642
+ {if Context API detected: show Context patterns}
643
+
644
+ {if framework === "Django":}
645
+ ### docs/guides/django-development.md
646
+
647
+ # Django Development Guide
648
+
649
+ ## Creating Apps
650
+
651
+ ```bash
652
+ python manage.py startapp myapp
653
+ ```
654
+
655
+ ## Models and Migrations
656
+
657
+ {Examples of model creation and migration workflow}
658
+
659
+ ## Admin Panel
660
+
661
+ {Django admin setup instructions}
662
+ ```
663
+
664
+ **Step 3: Seed docs/api/ Content (ENHANCEMENT 2 + 8)**
665
+
666
+ ```markdown
667
+ ### docs/api/README.md
668
+
669
+ # API Documentation
670
+
671
+ {if project_metadata.api_docs (TypeDoc/Rustdoc/etc):}
672
+
673
+ **Auto-Generated API Reference:** [{api_docs.type}]({api_docs.entry})
674
+
675
+ Full API documentation is available in the auto-generated {api_docs.type} documentation.
676
+
677
+ {else if framework matches API framework (Express, FastAPI, etc):}
678
+
679
+ **{project_metadata.name}** API documentation.
680
+
681
+ ## Endpoints
682
+
683
+ {if Express and routes detected:}
684
+ ### Available Routes
685
+
686
+ {scan src/ for route files and list endpoints}
687
+
688
+ - `GET /api/example` - Example endpoint
689
+ {list actual detected routes from codebase}
690
+
691
+ ## Authentication
692
+
693
+ {if authentication patterns detected, document them}
694
+
695
+ ## Request/Response Format
696
+
697
+ All API responses follow this format:
698
+
699
+ ```json
700
+ {
701
+ "success": true,
702
+ "data": {},
703
+ "error": null
704
+ }
705
+ ```
706
+
707
+ {else:}
708
+
709
+ API documentation for {{PROJECT_NAME}}.
710
+
711
+ ## Overview
712
+
713
+ {Framework-specific API documentation guidance}
714
+
715
+ {if project_metadata.type === "Node.js":}
716
+ Consider using tools like:
717
+ - Swagger/OpenAPI for REST APIs
718
+ - GraphQL documentation for GraphQL APIs
719
+ - TypeDoc for TypeScript API reference
720
+
721
+ {if project_metadata.type === "Python":}
722
+ Consider using tools like:
723
+ - Sphinx for Python API reference
724
+ - FastAPI automatic documentation (available at /docs)
725
+ - Django REST Framework browsable API
726
+ ```
727
+
728
+ **Step 4: Auto-Generate docs/architecture/overview.md (ENHANCEMENT 4)**
729
+
730
+ **CRITICAL: Create real architecture documentation from codebase analysis**
731
+
732
+ ```markdown
733
+ ### docs/architecture/overview.md
734
+
735
+ # Architecture Overview
736
+
737
+ **Project:** {{PROJECT_NAME}}
738
+ **Type:** {project_metadata.type}
739
+ **Framework:** {project_metadata.framework}
740
+ **Version:** {project_metadata.version}
741
+ **Last Updated:** {{CURRENT_DATE}}
742
+
743
+ ## System Overview
744
+
745
+ {project_metadata.description}
746
+
747
+ ## Technology Stack
748
+
749
+ **Runtime/Language:** {project_metadata.type} {version}
750
+ **Framework:** {project_metadata.framework}
751
+
752
+ {if project_metadata.type === "Node.js":}
753
+ **Package Manager:** npm/yarn
754
+ **Build Tool:** {detect from package.json scripts}
755
+
756
+ {if project_metadata.dependencies.length > 0:}
757
+ **Key Dependencies:**
758
+ {list major dependencies from package.json}
759
+ - {dependency}: {purpose detected or version}
760
+
761
+ {if database detected:}
762
+ **Database:** {detected database from dependencies}
763
+
764
+ ## Architecture Pattern
765
+
766
+ **Pattern:** {project_metadata.architecture}
767
+
768
+ {if architecture === "MVC":}
769
+ This project follows the Model-View-Controller (MVC) architectural pattern:
770
+ - **Models:** Data structures and business logic
771
+ - **Views:** Presentation layer
772
+ - **Controllers:** Request handling and coordination
773
+
774
+ {if architecture === "React Component Architecture":}
775
+ This project follows React's component-based architecture:
776
+ - **Components:** Reusable UI building blocks
777
+ - **Pages:** Top-level route components
778
+ - **Hooks:** Custom React hooks for shared logic
779
+ - **Context:** Global state management
780
+
781
+ {if architecture === "Service Layer Architecture":}
782
+ This project uses a service-oriented architecture:
783
+ - **Services:** Business logic layer
784
+ - **Repositories:** Data access layer
785
+ - **Controllers:** API endpoint handlers
786
+
787
+ ## Directory Structure
788
+
789
+ ```
790
+ {actual src/ directory structure from Phase 1 analysis}
791
+ ```
792
+
793
+ **Key Directories:**
794
+ {for each major directory in src/:}
795
+ - **{directory}:** {purpose based on name/content}
796
+
797
+ ## Entry Points
798
+
799
+ {if project_metadata.entry_point:}
800
+ **Main Entry:** {entry_point}
801
+
802
+ {if CLI commands detected from package.json:}
803
+ **CLI Commands:**
804
+ {list npm scripts or CLI commands}
805
+ - `{command}`: {purpose}
806
+
807
+ ## Data Flow
808
+
809
+ {if architecture pattern is recognized, describe typical data flow}
810
+
811
+ {if API framework:}
812
+ 1. Request received at endpoint
813
+ 2. Middleware processing
814
+ 3. Controller handles request
815
+ 4. Service layer executes business logic
816
+ 5. Repository accesses data
817
+ 6. Response sent to client
818
+
819
+ ## Configuration
820
+
821
+ {if .env.example exists:}
822
+ **Environment Variables:** See [.env.example](../../.env.example)
823
+
824
+ {list detected config files:}
825
+ **Configuration Files:**
826
+ - {config file}: {purpose}
827
+
828
+ ## Build & Deployment
829
+
830
+ {from package.json scripts or build system:}
831
+ **Build Command:** `{build command}`
832
+ **Development:** `{dev command}`
833
+ **Production:** `{start command}`
834
+
835
+ ## Architecture Diagrams
836
+
837
+ *Architecture diagrams can be added to the [images/](../images/) directory and linked here.*
838
+
839
+ Recommended diagrams:
840
+ - System architecture diagram
841
+ - Component interaction diagram
842
+ - Data flow diagram
843
+ - Deployment architecture
844
+
845
+ ## Design Decisions
846
+
847
+ {if ADR files detected, link to them}
848
+
849
+ Key architectural decisions are documented in:
850
+ - [Architecture Decision Records](adr/) - ADRs documenting major technical decisions
851
+
852
+ ## Performance Considerations
853
+
854
+ {Framework-specific performance guidance}
855
+
856
+ ## Security Considerations
857
+
858
+ {Framework-specific security guidance}
859
+
860
+ ---
861
+
862
+ For detailed API documentation, see [../api/](../api/).
863
+ ```
864
+
865
+ **Step 5: Seed docs/reference/ Content (ENHANCEMENT 2)**
866
+
867
+ ```markdown
868
+ ### docs/reference/README.md
869
+
870
+ # Reference Documentation
871
+
872
+ Quick reference materials for {{PROJECT_NAME}}.
873
+
874
+ ## CLI Commands
875
+
876
+ {if package.json scripts detected:}
877
+ ### npm Scripts
878
+
879
+ {for each script in package.json.scripts:}
880
+ - **`npm run {script}`** - {infer purpose from script name or command}
881
+
882
+ {if Makefile detected:}
883
+ ### Make Commands
884
+
885
+ {for each target in Makefile:}
886
+ - **`make {target}`** - {purpose}
887
+
888
+ ## Environment Variables
889
+
890
+ {if .env.example exists:}
891
+ See [.env.example](../../.env.example) for all available environment variables.
892
+
893
+ **Required Variables:**
894
+ {parse .env.example and list required vars}
895
+ - `{VAR_NAME}` - {purpose}
896
+
897
+ ## Configuration
898
+
899
+ {list detected config files and their purpose}
900
+
901
+ ## API Reference
902
+
903
+ {if auto-generated API docs:}
904
+ See [API Documentation](../api/) for complete API reference.
905
+
906
+ ## Dependencies
907
+
908
+ **Production Dependencies:** {count}
909
+ {list major production dependencies}
910
+
911
+ **Development Dependencies:** {count}
912
+ {list major dev dependencies}
913
+
914
+ ## Glossary
915
+
916
+ {Project-specific terminology}
917
+ ```
918
+
919
+ **Step 6: Migrate CONTRIBUTING.md to Reference (if exists)**
920
+
921
+ ```bash
922
+ if exists("CONTRIBUTING.md"):
923
+ # Don't move the file, but reference it from docs/reference/
924
+ # Add link in docs/reference/README.md
925
+ ```
926
+
927
+ **Step 7: Create Category README Files**
928
+
929
+ For each category, create README.md that lists actual content:
930
+
931
+ ```markdown
932
+ ### docs/guides/README.md
933
+
934
+ # Guides
935
+
936
+ User guides and tutorials for {{PROJECT_NAME}}.
937
+
938
+ ## Available Guides
939
+
940
+ {if getting-started.md created:}
941
+ - [Getting Started](getting-started.md) - Quick start guide for new users
942
+
943
+ {if framework-specific guide created:}
944
+ - [{Framework} Development](....md) - {Framework}-specific development guide
945
+
946
+ {if scattered docs migrated to guides/:}
947
+ {list migrated files}
948
+
949
+ ## Planned Guides
950
+
951
+ *Additional guides can be added to this directory. Common guide topics include:*
952
+ - Deployment guide
953
+ - Testing guide
954
+ - Troubleshooting guide
955
+ - Advanced features guide
956
+
957
+ ## Contributing
958
+
959
+ To add a new guide:
960
+ 1. Create a new .md file in this directory
961
+ 2. Follow the guide template format:
962
+ - Clear title and objective
963
+ - Prerequisites section
964
+ - Step-by-step instructions
965
+ - Expected outcomes
966
+ - Troubleshooting tips
967
+ 3. Update this README with a link to your guide
968
+
969
+ ---
970
+
971
+ See [../README.md](../README.md) for complete documentation index.
972
+ ```
973
+
974
+ ```markdown
975
+ ### docs/api/README.md
976
+
977
+ {Content from Step 3 - already seeded with project-specific info}
978
+ ```
979
+
980
+ ```markdown
981
+ ### docs/architecture/README.md
982
+
983
+ # Architecture Documentation
984
+
985
+ System architecture and design documentation for {{PROJECT_NAME}}.
986
+
987
+ ## Architecture Overview
988
+
989
+ **Main Document:** [Architecture Overview](overview.md) - Complete system architecture
990
+
991
+ {if ADR directory exists or should be created:}
992
+ ## Architecture Decision Records (ADRs)
993
+
994
+ *Architecture Decision Records document significant architectural decisions made during development.*
995
+
996
+ {if ADR files exist:}
997
+ {list ADR files}
998
+
999
+ {else:}
1000
+ ADRs can be added to the `adr/` subdirectory following the [ADR template format](https://github.com/joelparkerhenderson/architecture-decision-record).
1001
+
1002
+ ## Architecture Diagrams
1003
+
1004
+ {if images/ has architecture diagrams:}
1005
+ {list diagram files}
1006
+
1007
+ {else:}
1008
+ *Architecture diagrams can be added to [../images/](../images/) directory.*
1009
+
1010
+ Recommended diagrams:
1011
+ - System architecture diagram
1012
+ - Component interaction diagram
1013
+ - Data flow diagram
1014
+ - Deployment architecture
1015
+
1016
+ ## Technology Stack
1017
+
1018
+ See [Architecture Overview](overview.md#technology-stack) for complete technology stack details.
1019
+
1020
+ ---
1021
+
1022
+ See [../README.md](../README.md) for complete documentation index.
1023
+ ```
1024
+
1025
+ ```markdown
1026
+ ### docs/reference/README.md
1027
+
1028
+ {Content from Step 5 - already seeded with CLI commands, env vars}
1029
+ ```
1030
+
1031
+ **APO Output:**
1032
+
1033
+ ```markdown
1034
+ === PHASE 2: DIRECTORY STRUCTURE & CONTENT SEEDING ===
1035
+
1036
+ **Directories Created:** {created_dirs.length}
1037
+ - ✅ docs/guides/
1038
+ - ✅ docs/api/
1039
+ - ✅ docs/architecture/
1040
+ - ✅ docs/reference/
1041
+ - ✅ docs/images/
1042
+
1043
+ **Content Seeded:** {count} files created
1044
+
1045
+ **Guides:**
1046
+ - ✅ docs/guides/getting-started.md ({line_count} lines)
1047
+ {if framework-specific guide created:}
1048
+ - ✅ docs/guides/{framework}-development.md ({line_count} lines)
1049
+
1050
+ **API Documentation:**
1051
+ - ✅ docs/api/README.md ({line_count} lines)
1052
+ {if TypeDoc integrated:}
1053
+ - ✅ Integrated {api_docs.type} documentation
1054
+
1055
+ **Architecture:**
1056
+ - ✅ docs/architecture/overview.md ({line_count} lines) - AUTO-GENERATED from codebase
1057
+ {if ADR directory created:}
1058
+ - ✅ docs/architecture/adr/ directory created
1059
+
1060
+ **Reference:**
1061
+ - ✅ docs/reference/README.md ({line_count} lines)
1062
+
1063
+ **Category READMEs:** 4 files
1064
+ - ✅ docs/guides/README.md
1065
+ - ✅ docs/api/README.md
1066
+ - ✅ docs/architecture/README.md
1067
+ - ✅ docs/reference/README.md
1068
+
1069
+ **Project Context Used:**
1070
+ - Type: {project_metadata.type}
1071
+ - Framework: {project_metadata.framework}
1072
+ - Architecture: {project_metadata.architecture}
1073
+ - Dependencies: {major_deps_count} major dependencies documented
1074
+ ```
1075
+
1076
+ ---
1077
+
1078
+ ### Phase 3: Scattered Documentation Migration
1079
+
1080
+ **Goal:** Migrate scattered .md files into organized docs/ structure
1081
+
1082
+ **CRITICAL: Only migrate orphaned documentation, preserve Trinity infrastructure**
1083
+
1084
+ **Step 1: Review Migration Candidates**
1085
+
1086
+ ```javascript
1087
+ // From Phase 1 Step 4 - scattered_docs array
1088
+
1089
+ migration_plan = []
1090
+
1091
+ for each doc in scattered_docs:
1092
+ // Verify file still exists and should be migrated
1093
+ if exists(doc.file) and not is_excluded(doc.file):
1094
+ migration_plan.push({
1095
+ source: doc.file,
1096
+ destination: doc.suggested_category + extract_filename(doc.file),
1097
+ action: "MOVE"
1098
+ })
1099
+ ```
1100
+
1101
+ **Step 2: Execute Migration**
1102
+
1103
+ ```bash
1104
+ migrated_files = []
1105
+ migration_errors = []
1106
+
1107
+ for each item in migration_plan:
1108
+ try:
1109
+ # Create destination directory if needed
1110
+ ensure_directory_exists(item.destination)
1111
+
1112
+ # Move file to new location
1113
+ move_file(item.source, item.destination)
1114
+
1115
+ migrated_files.push(item)
1116
+ catch error:
1117
+ migration_errors.push({item, error})
1118
+ ```
1119
+
1120
+ **Step 3: Update Internal Links (ENHANCEMENT 5 - partial)**
1121
+
1122
+ ```bash
1123
+ # After migration, update links in migrated files
1124
+ for each migrated_file in migrated_files:
1125
+ content = read(migrated_file.destination)
1126
+
1127
+ # Update relative links that may have broken
1128
+ updated_content = update_relative_links(content, migrated_file.source, migrated_file.destination)
1129
+
1130
+ if updated_content != content:
1131
+ write(migrated_file.destination, updated_content)
1132
+ ```
1133
+
1134
+ **Step 4: Update Category READMEs**
1135
+
1136
+ ```bash
1137
+ # Add migrated files to appropriate category READMEs
1138
+ for each migrated_file in migrated_files:
1139
+ category_readme = get_category_readme(migrated_file.destination)
1140
+
1141
+ # Add link to migrated file in category README
1142
+ append_to_section(category_readme, "Available {Category}", link_to_file)
1143
+ ```
1144
+
1145
+ **APO Output:**
1146
+
1147
+ ```markdown
1148
+ === PHASE 3: SCATTERED DOCUMENTATION MIGRATION ===
1149
+
1150
+ **Migration Summary:**
1151
+ - Files migrated: {migrated_files.length}
1152
+ - Migration errors: {migration_errors.length}
1153
+
1154
+ **Migrated Files:**
1155
+ {for each migrated:}
1156
+ - ✅ {source} → {destination}
1157
+
1158
+ {if migration_errors.length > 0:}
1159
+ **Migration Errors:**
1160
+ {for each error:}
1161
+ - ❌ {item.source}: {error.message}
1162
+
1163
+ **Files NOT Migrated (Preserved):**
1164
+ - Trinity infrastructure (trinity/**): {count} files
1165
+ - CLAUDE.md files: {count} files
1166
+ - Root standards (README, CHANGELOG, etc.): {count} files
1167
+ - Technical source READMEs (src/README.md, etc.): {count} files
1168
+
1169
+ **Link Updates:** {count} files with updated links
1170
+
1171
+ **Category Updates:**
1172
+ {for each category:}
1173
+ - docs/{category}/README.md: Added {count} migrated files
1174
+ ```
1175
+
1176
+ ---
1177
+
1178
+ ### Phase 4: Link Validation & Navigation Creation
1179
+
1180
+ **Goal:** Validate all documentation links, fix broken links, and create comprehensive navigation
1181
+
1182
+ **Step 1: Extract All Links from Documentation (ENHANCEMENT 5)**
1183
+
1184
+ ```bash
1185
+ all_docs_files = glob("docs/**/*.md")
1186
+ all_links = []
1187
+
1188
+ for each doc_file in all_docs_files:
1189
+ content = read(doc_file)
1190
+
1191
+ # Extract markdown links [text](path)
1192
+ links = extract_markdown_links(content)
1193
+
1194
+ for each link in links:
1195
+ all_links.push({
1196
+ source_file: doc_file,
1197
+ link_text: link.text,
1198
+ link_path: link.path,
1199
+ line_number: link.line
1200
+ })
1201
+ ```
1202
+
1203
+ **Step 2: Validate Links**
1204
+
1205
+ ```bash
1206
+ broken_links = []
1207
+ valid_links = []
1208
+
1209
+ for each link in all_links:
1210
+ # Skip external URLs (http://, https://)
1211
+ if is_external_url(link.link_path):
1212
+ continue
1213
+
1214
+ # Resolve relative path
1215
+ resolved_path = resolve_path(link.source_file, link.link_path)
1216
+
1217
+ # Check if linked file exists
1218
+ if exists(resolved_path):
1219
+ valid_links.push(link)
1220
+ else:
1221
+ broken_links.push({
1222
+ link: link,
1223
+ resolved_path: resolved_path,
1224
+ error: "File not found"
1225
+ })
1226
+ ```
1227
+
1228
+ **Step 3: Fix Broken Links**
1229
+
1230
+ ```bash
1231
+ fixed_links = []
1232
+ unfixable_links = []
1233
+
1234
+ for each broken_link in broken_links:
1235
+ # Try to find the correct path
1236
+ filename = extract_filename(broken_link.resolved_path)
1237
+
1238
+ # Search for file in docs/
1239
+ possible_matches = glob(f"docs/**/{filename}")
1240
+
1241
+ if possible_matches.length === 1:
1242
+ # Found unique match - fix the link
1243
+ correct_path = calculate_relative_path(
1244
+ broken_link.link.source_file,
1245
+ possible_matches[0]
1246
+ )
1247
+
1248
+ # Update link in source file
1249
+ update_link_in_file(
1250
+ broken_link.link.source_file,
1251
+ broken_link.link.link_path,
1252
+ correct_path
1253
+ )
1254
+
1255
+ fixed_links.push({broken_link, correct_path})
1256
+
1257
+ else if possible_matches.length > 1:
1258
+ # Multiple matches - can't auto-fix
1259
+ unfixable_links.push({
1260
+ broken_link,
1261
+ reason: "Multiple possible matches",
1262
+ matches: possible_matches
1263
+ })
1264
+
1265
+ else:
1266
+ # No matches - file doesn't exist
1267
+ unfixable_links.push({
1268
+ broken_link,
1269
+ reason: "File not found in docs/"
1270
+ })
1271
+ ```
1272
+
1273
+ **Step 4: Generate docs/README.md Navigation**
1274
+
1275
+ ```markdown
1276
+ ### docs/README.md
1277
+
1278
+ # Documentation
1279
+
1280
+ Comprehensive documentation for {{PROJECT_NAME}}.
1281
+
1282
+ ## Documentation Structure
1283
+
1284
+ This directory contains organized project documentation:
1285
+
1286
+ - **[Guides](guides/)** - How-to guides and tutorials
1287
+ - **[API](api/)** - API reference documentation
1288
+ {if api_docs detected:}
1289
+ - [{api_docs.type} Reference]({api_docs.entry}) - Auto-generated API documentation
1290
+ - **[Architecture](architecture/)** - System architecture and design decisions
1291
+ - **[Reference](reference/)** - Quick references and command guides
1292
+
1293
+ ## Quick Start
1294
+
1295
+ New to {{PROJECT_NAME}}? Start here:
1296
+
1297
+ 1. **[Getting Started Guide](guides/getting-started.md)** - Installation and setup
1298
+ {if framework-specific guide exists:}
1299
+ 2. **[{Framework} Development](guides/{framework}-development.md)** - Framework-specific development guide
1300
+ 3. **[Architecture Overview](architecture/overview.md)** - Understand the system design
1301
+ {if API documentation exists:}
1302
+ 4. **[API Documentation](api/)** - Explore available APIs
1303
+
1304
+ ## Documentation Categories
1305
+
1306
+ ### Guides
1307
+
1308
+ {list actual guide files from docs/guides/, exclude README.md}
1309
+ - [Getting Started](guides/getting-started.md) - Quick start for new users
1310
+ {for each guide file:}
1311
+ - [{title}]({path}) - {extract description from file}
1312
+
1313
+ {if guides/ is empty or only has README:}
1314
+ *No additional guides available yet. See [guides/README.md](guides/README.md) for planned guides.*
1315
+
1316
+ ### API Documentation
1317
+
1318
+ {if TypeDoc/Rustdoc/etc detected:}
1319
+ **[{api_docs.type} Reference]({api_docs.entry})** - Auto-generated API documentation
1320
+
1321
+ {list actual API doc files from docs/api/, exclude README.md}
1322
+ {for each API doc:}
1323
+ - [{title}]({path}) - {description}
1324
+
1325
+ {if api/ has only README or TypeDoc:}
1326
+ See [api/README.md](api/) for API overview and documentation links.
1327
+
1328
+ ### Architecture
1329
+
1330
+ {list actual architecture files from docs/architecture/, exclude README.md}
1331
+ - [Architecture Overview](architecture/overview.md) - System design and technology stack
1332
+
1333
+ {if ADR files exist:}
1334
+ **Architecture Decision Records:**
1335
+ {for each ADR:}
1336
+ - [{ADR title}]({path}) - {decision summary}
1337
+
1338
+ {if architecture diagrams exist in images/:}
1339
+ **Architecture Diagrams:**
1340
+ {for each diagram:}
1341
+ - [{diagram name}]({path})
1342
+
1343
+ ### Reference
1344
+
1345
+ {list actual reference files from docs/reference/, exclude README.md}
1346
+ - [Reference Documentation](reference/README.md) - CLI commands, environment variables, glossary
1347
+
1348
+ ## Documentation Standards
1349
+
1350
+ - All documentation is in Markdown format
1351
+ - Images are stored in `images/` directory
1352
+ - Each category has its own README for navigation
1353
+ {if ADR directory exists:}
1354
+ - Architecture decisions are documented using ADR format
1355
+
1356
+ ## Contributing to Documentation
1357
+
1358
+ {if CONTRIBUTING.md exists:}
1359
+ See [CONTRIBUTING.md](../CONTRIBUTING.md) for documentation contribution guidelines.
1360
+
1361
+ {else:}
1362
+ To contribute to documentation:
1363
+ 1. Follow the existing structure (guides/, api/, architecture/, reference/)
1364
+ 2. Use clear, concise Markdown
1365
+ 3. Include code examples where applicable
1366
+ 4. Update category README files when adding new documentation
1367
+ 5. Validate all links before submitting
1368
+
1369
+ ## Documentation Index
1370
+
1371
+ ### All Documentation Files
1372
+
1373
+ {alphabetical index of all .md files in docs/, organized by category}
1374
+
1375
+ **Guides ({count}):**
1376
+ {for each guide, alphabetically:}
1377
+ - [{title}]({path})
1378
+
1379
+ **API Documentation ({count}):**
1380
+ {for each API doc, alphabetically:}
1381
+ - [{title}]({path})
1382
+
1383
+ **Architecture ({count}):**
1384
+ {for each architecture doc, alphabetically:}
1385
+ - [{title}]({path})
1386
+
1387
+ **Reference ({count}):**
1388
+ {for each reference doc, alphabetically:}
1389
+ - [{title}]({path})
1390
+
1391
+ ---
1392
+
1393
+ **Documentation Coverage:** {coverage_score}/100 (see [Organization Report](../trinity/reports/DOCS-ORGANIZATION-{date}.md))
1394
+
1395
+ *Last updated: {{CURRENT_DATE}}*
1396
+ ```
1397
+
1398
+ **Step 5: Build Complete Documentation Index**
1399
+
1400
+ ```javascript
1401
+ all_docs = []
1402
+
1403
+ // Scan all subdirectories
1404
+ for each category in ["guides", "api", "architecture", "reference"]:
1405
+ files = glob(f"docs/{category}/**/*.md")
1406
+ for each file in files:
1407
+ if file != "README.md":
1408
+ all_docs.push({
1409
+ title: extract_title_from_file(file),
1410
+ path: file,
1411
+ category: category,
1412
+ description: extract_description(file)
1413
+ })
1414
+
1415
+ // Sort alphabetically
1416
+ all_docs.sort_by_title()
1417
+ ```
1418
+
1419
+ **APO Output:**
1420
+
1421
+ ```markdown
1422
+ === PHASE 4: LINK VALIDATION & NAVIGATION CREATION ===
1423
+
1424
+ **Link Validation:**
1425
+ - Total links found: {all_links.length}
1426
+ - Valid links: {valid_links.length}
1427
+ - Broken links: {broken_links.length}
1428
+ - Fixed links: {fixed_links.length}
1429
+ - Unfixable links: {unfixable_links.length}
1430
+
1431
+ **Broken Links Fixed:**
1432
+ {for each fixed_link:}
1433
+ - ✅ {source_file}: {old_path} → {new_path}
1434
+
1435
+ {if unfixable_links.length > 0:}
1436
+ **Unfixable Links (Manual Review Required):**
1437
+ {for each unfixable:}
1438
+ - ⚠️ {source_file}:{line_number}: [{link_text}]({link_path})
1439
+ - Reason: {reason}
1440
+ {if multiple matches:}
1441
+ - Possible matches: {list matches}
1442
+
1443
+ **Navigation Creation:**
1444
+ - ✅ docs/README.md created ({line_count} lines)
1445
+
1446
+ **Documentation Index:**
1447
+ - Total files indexed: {all_docs.length}
1448
+ - Guides: {guides_count}
1449
+ - API docs: {api_count}
1450
+ - Architecture docs: {architecture_count}
1451
+ - Reference docs: {reference_count}
1452
+
1453
+ **Quick Links:** {count} essential documentation files highlighted
1454
+ ```
1455
+
1456
+ ---
1457
+
1458
+ ### Phase 5: Organization Report & Coverage Metrics
1459
+
1460
+ **APO Generates:** `trinity/reports/DOCS-ORGANIZATION-{date}.md`
1461
+
1462
+ **Step 1: Calculate Documentation Coverage Metrics (ENHANCEMENT 9)**
1463
+
1464
+ ```javascript
1465
+ coverage_metrics = {
1466
+ structure: 0,
1467
+ content: 0,
1468
+ navigation: 0,
1469
+ total: 0
1470
+ }
1471
+
1472
+ // Structure score (30 points)
1473
+ structure_score = 0
1474
+ if exists("docs/guides/"): structure_score += 6
1475
+ if exists("docs/api/"): structure_score += 6
1476
+ if exists("docs/architecture/"): structure_score += 6
1477
+ if exists("docs/reference/"): structure_score += 6
1478
+ if exists("docs/images/"): structure_score += 6
1479
+
1480
+ coverage_metrics.structure = structure_score
1481
+
1482
+ // Content score (50 points)
1483
+ content_score = 0
1484
+
1485
+ // Guides content (15 points)
1486
+ guides_files = glob("docs/guides/*.md", exclude="README.md")
1487
+ if guides_files.length >= 1: content_score += 5 // Getting started exists
1488
+ if guides_files.length >= 2: content_score += 5 // Framework guide exists
1489
+ if guides_files.length >= 3: content_score += 5 // Additional guides
1490
+
1491
+ // API documentation (15 points)
1492
+ if api_docs detected or exists("docs/api/*.md"): content_score += 15
1493
+
1494
+ // Architecture documentation (15 points)
1495
+ if exists("docs/architecture/overview.md"): content_score += 10
1496
+ if exists("docs/architecture/adr/*"): content_score += 5
1497
+
1498
+ // Reference documentation (5 points)
1499
+ if exists("docs/reference/README.md") and has_content: content_score += 5
1500
+
1501
+ coverage_metrics.content = content_score
1502
+
1503
+ // Navigation score (20 points)
1504
+ navigation_score = 0
1505
+ if exists("docs/README.md"): navigation_score += 10
1506
+ if all category READMEs exist: navigation_score += 10
1507
+
1508
+ coverage_metrics.navigation = navigation_score
1509
+
1510
+ // Total coverage
1511
+ coverage_metrics.total = structure_score + content_score + navigation_score
1512
+
1513
+ // Grade
1514
+ if coverage_metrics.total >= 90: grade = "A (Excellent)"
1515
+ else if coverage_metrics.total >= 80: grade = "B (Good)"
1516
+ else if coverage_metrics.total >= 70: grade = "C (Fair)"
1517
+ else if coverage_metrics.total >= 60: grade = "D (Needs Improvement)"
1518
+ else: grade = "F (Poor)"
1519
+ ```
1520
+
1521
+ **Step 2: Generate Actionable Recommendations for Empty Categories (ENHANCEMENT 7)**
1522
+
1523
+ ```javascript
1524
+ recommendations = []
1525
+
1526
+ // Check guides/
1527
+ guides_count = count_md_files("docs/guides/", exclude="README.md")
1528
+ if guides_count === 0:
1529
+ recommendations.push({
1530
+ category: "guides",
1531
+ priority: "HIGH",
1532
+ items: [
1533
+ "Create Getting Started guide with installation steps",
1534
+ "Document common workflows and use cases",
1535
+ "Add troubleshooting guide for common issues"
1536
+ ]
1537
+ })
1538
+ else if guides_count < 3:
1539
+ recommendations.push({
1540
+ category: "guides",
1541
+ priority: "MEDIUM",
1542
+ items: [
1543
+ "Add deployment guide",
1544
+ "Create testing guide",
1545
+ "Document advanced features"
1546
+ ]
1547
+ })
1548
+
1549
+ // Check architecture/
1550
+ arch_count = count_md_files("docs/architecture/", exclude="README.md")
1551
+ if arch_count === 0 or not exists("docs/architecture/overview.md"):
1552
+ recommendations.push({
1553
+ category: "architecture",
1554
+ priority: "HIGH",
1555
+ items: [
1556
+ "✅ AUTO-GENERATED: Architecture overview created",
1557
+ "Add system architecture diagram to images/",
1558
+ "Create component interaction diagram",
1559
+ "Document architecture decision records (ADRs)"
1560
+ ]
1561
+ })
1562
+
1563
+ // Check API documentation
1564
+ if not api_docs and api_count === 0:
1565
+ recommendations.push({
1566
+ category: "api",
1567
+ priority: "MEDIUM",
1568
+ items: [
1569
+ "Generate API documentation using TypeDoc/Rustdoc/Sphinx",
1570
+ "Document API endpoints and request/response formats",
1571
+ "Add API authentication and authorization guide"
1572
+ ]
1573
+ })
1574
+
1575
+ // Check for duplicates
1576
+ if duplicates.length > 0:
1577
+ recommendations.push({
1578
+ category: "quality",
1579
+ priority: "MEDIUM",
1580
+ items: [
1581
+ f"Review {duplicates.length} potential duplicate documentation files",
1582
+ "Consolidate overlapping content",
1583
+ "Remove or rename duplicate files"
1584
+ ]
1585
+ })
1586
+
1587
+ // Check for broken links
1588
+ if unfixable_links.length > 0:
1589
+ recommendations.push({
1590
+ category: "quality",
1591
+ priority: "HIGH",
1592
+ items: [
1593
+ f"Fix {unfixable_links.length} broken documentation links (see Phase 4 report)"
1594
+ ]
1595
+ })
1596
+ ```
1597
+
1598
+ **Required Report Structure:**
1599
+
1600
+ ```markdown
1601
+ # docs/ Organization Report
1602
+
1603
+ **Project:** {{PROJECT_NAME}}
1604
+ **Organization Date:** {date}
1605
+ **Organizer:** APO (Documentation Specialist)
1606
+ **Command:** /trinity-docs
1607
+
1608
+ ---
1609
+
1610
+ ## Executive Summary
1611
+
1612
+ **docs/ Structure:** {✅ ORGANIZED | ⚠️ PARTIALLY ORGANIZED}
1613
+ **Navigation:** {✅ COMPLETE | ⚠️ PARTIAL}
1614
+ **Categories:** 5 categories (guides, api, architecture, reference, images)
1615
+ **Content Created:** {count} files with seeded content
1616
+ **Files Migrated:** {migrated_files.length} scattered docs organized
1617
+ **Links Fixed:** {fixed_links.length} broken links repaired
1618
+
1619
+ **Documentation Coverage:** {coverage_metrics.total}/100 - Grade: {grade}
1620
+
1621
+ **COMMAND EXECUTION STATUS:** {✅ SUCCESS | ⚠️ PARTIAL SUCCESS}
1622
+
1623
+ ---
1624
+
1625
+ ## Documentation Coverage Breakdown
1626
+
1627
+ **Overall Score:** {coverage_metrics.total}/100 ({grade})
1628
+
1629
+ **Structure (30 points):** {structure_score}/30
1630
+ - Directory hierarchy: {✅ COMPLETE | ⚠️ PARTIAL}
1631
+ - guides/: {✅ | ❌}
1632
+ - api/: {✅ | ❌}
1633
+ - architecture/: {✅ | ❌}
1634
+ - reference/: {✅ | ❌}
1635
+ - images/: {✅ | ❌}
1636
+
1637
+ **Content (50 points):** {content_score}/50
1638
+ - Guides: {guides_score}/15 {✅ | ⚠️ | ❌}
1639
+ - Getting started: {✅ CREATED | ❌ MISSING}
1640
+ - Framework guide: {✅ CREATED | ❌ MISSING}
1641
+ - Additional guides: {count}
1642
+ - API Documentation: {api_score}/15 {✅ | ⚠️ | ❌}
1643
+ - Auto-generated docs: {✅ INTEGRATED | ❌ NONE}
1644
+ - Manual API docs: {count} files
1645
+ - Architecture: {arch_score}/15 {✅ | ⚠️ | ❌}
1646
+ - Overview: {✅ AUTO-GENERATED | ❌ MISSING}
1647
+ - ADRs: {count} records
1648
+ - Diagrams: {count} diagrams
1649
+ - Reference: {ref_score}/5 {✅ | ❌}
1650
+ - CLI/env reference: {✅ CREATED | ❌ MISSING}
1651
+
1652
+ **Navigation (20 points):** {navigation_score}/20
1653
+ - docs/README.md: {✅ CREATED | ❌ MISSING}
1654
+ - Category READMEs: {count}/4
1655
+ - Documentation index: {✅ COMPLETE | ⚠️ PARTIAL}
1656
+
1657
+ ---
1658
+
1659
+ ## Phase Execution Summary
1660
+
1661
+ ### Phase 1: Discovery & Codebase Analysis
1662
+ - **docs/ existed:** {✅ YES | ❌ NO (created)}
1663
+ - **Files found in docs/:** {count}
1664
+ - **Scattered docs found:** {scattered_docs.length} files
1665
+ - **Structure score:** {structure_score}/100
1666
+ - **Project type:** {project_metadata.type}
1667
+ - **Framework:** {project_metadata.framework}
1668
+ - **Architecture pattern:** {project_metadata.architecture}
1669
+ - **Auto-generated API docs:** {✅ {api_docs.type} | ❌ None}
1670
+ - **Duplicate docs:** {duplicates.length} potential duplicates
1671
+
1672
+ ### Phase 2: Directory Structure & Content Seeding
1673
+ - **Directories created:** {created_dirs.length}
1674
+ - **Content files created:** {count}
1675
+ - Guides: {guides_created_count} ({getting-started, framework guide, etc.})
1676
+ - API: {api_created_count}
1677
+ - Architecture: {arch_created_count} (✅ AUTO-GENERATED overview)
1678
+ - Reference: {ref_created_count}
1679
+ - **Category READMEs:** 4 created with project-specific content
1680
+
1681
+ ### Phase 3: Scattered Documentation Migration
1682
+ - **Files migrated:** {migrated_files.length}
1683
+ - **Migration errors:** {migration_errors.length}
1684
+ - **Links updated:** {count} files
1685
+ - **Files preserved:** {preserved_count} (Trinity infrastructure, CLAUDE.md, source READMEs)
1686
+
1687
+ ### Phase 4: Link Validation & Navigation
1688
+ - **docs/README.md:** ✅ CREATED ({line_count} lines)
1689
+ - **Total links validated:** {all_links.length}
1690
+ - **Broken links found:** {broken_links.length}
1691
+ - **Links fixed:** {fixed_links.length}
1692
+ - **Unfixable links:** {unfixable_links.length}
1693
+ - **Files indexed:** {all_docs.length}
1694
+
1695
+ ---
1696
+
1697
+ ## Directory Structure
1698
+
1699
+ **Before:**
1700
+ ```
1701
+ {show actual before state from Phase 1}
1702
+ ```
1703
+
1704
+ **After:**
1705
+ ```
1706
+ docs/
1707
+ ├── README.md (navigation - {line_count} lines)
1708
+ ├── guides/
1709
+ │ ├── README.md
1710
+ │ ├── getting-started.md (✅ CREATED - {line_count} lines)
1711
+ {if framework guide created:}
1712
+ │ ├── {framework}-development.md (✅ CREATED - {line_count} lines)
1713
+ {for each migrated guide:}
1714
+ │ └── {file} (migrated from {original_location})
1715
+ ├── api/
1716
+ │ ├── README.md (seeded with {api_docs.type or "project context"})
1717
+ {if TypeDoc/etc:}
1718
+ │ ├── index.html ({api_docs.type})
1719
+ │ └── modules.html ({api_docs.type})
1720
+ {for each API doc file:}
1721
+ │ └── {file}
1722
+ ├── architecture/
1723
+ │ ├── README.md
1724
+ │ ├── overview.md (✅ AUTO-GENERATED - {line_count} lines)
1725
+ {if ADR directory:}
1726
+ │ └── adr/
1727
+ {for each architecture file:}
1728
+ │ └── {file}
1729
+ ├── reference/
1730
+ │ ├── README.md (seeded with CLI commands, env vars)
1731
+ {for each reference file:}
1732
+ │ └── {file}
1733
+ └── images/
1734
+ {for each image:}
1735
+ └── {file}
1736
+ ```
1737
+
1738
+ ---
1739
+
1740
+ ## Files Created
1741
+
1742
+ **Seeded Content ({count} files):**
1743
+
1744
+ **Guides:**
1745
+ - ✅ **getting-started.md** ({line_count} lines) - Installation, setup, project structure
1746
+ {if framework guide:}
1747
+ - ✅ **{framework}-development.md** ({line_count} lines) - Framework-specific development guide
1748
+
1749
+ **API Documentation:**
1750
+ - ✅ **api/README.md** ({line_count} lines) - Seeded with {api_docs.type or "project endpoints"}
1751
+
1752
+ **Architecture:**
1753
+ - ✅ **architecture/overview.md** ({line_count} lines) - AUTO-GENERATED from codebase analysis
1754
+ - Technology stack: {tech_stack}
1755
+ - Architecture pattern: {architecture}
1756
+ - Directory structure: Actual src/ layout
1757
+ - Entry points: {entry_points}
1758
+ - Configuration: {config_files}
1759
+
1760
+ **Reference:**
1761
+ - ✅ **reference/README.md** ({line_count} lines) - CLI commands, environment variables
1762
+
1763
+ **Category READMEs (4 files):**
1764
+ - ✅ guides/README.md - Lists all available guides
1765
+ - ✅ api/README.md - API overview and documentation links
1766
+ - ✅ architecture/README.md - Architecture docs and ADRs
1767
+ - ✅ reference/README.md - Quick reference materials
1768
+
1769
+ ---
1770
+
1771
+ ## Files Migrated
1772
+
1773
+ {if migrated_files.length > 0:}
1774
+ **Scattered Documentation Organized ({migrated_files.length} files):**
1775
+
1776
+ {for each migrated file:}
1777
+ - ✅ `{source}` → `{destination}`
1778
+
1779
+ **Files Preserved (NOT migrated):**
1780
+ - Trinity infrastructure: `trinity/**` ({count} files)
1781
+ - AI context files: `**/CLAUDE.md` ({count} files)
1782
+ - Root standards: `README.md`, `CHANGELOG.md`, `CONTRIBUTING.md`, etc.
1783
+ - Technical source READMEs: `src/README.md`, `tests/README.md`, etc.
1784
+
1785
+ {else:}
1786
+ **No scattered documentation found** - All documentation was already in docs/ or properly located.
1787
+
1788
+ ---
1789
+
1790
+ ## Navigation Structure
1791
+
1792
+ **docs/README.md includes:**
1793
+ - ✅ Documentation structure overview
1794
+ - ✅ Quick start guide (links to getting-started.md)
1795
+ - ✅ Complete documentation index by category
1796
+ - ✅ Quick links to essential documentation
1797
+ {if api_docs:}
1798
+ - ✅ Link to {api_docs.type} auto-generated API reference
1799
+ - ✅ Documentation standards
1800
+ - ✅ Contributing guidelines
1801
+
1802
+ **Category Navigation:**
1803
+ - ✅ guides/README.md: {guides_count} guides listed
1804
+ - ✅ api/README.md: API documentation overview
1805
+ - ✅ architecture/README.md: Architecture docs and ADRs
1806
+ - ✅ reference/README.md: CLI commands, env vars, glossary
1807
+
1808
+ ---
1809
+
1810
+ ## Link Validation Results
1811
+
1812
+ **Total Links Validated:** {all_links.length}
1813
+ - Valid links: {valid_links.length} ✅
1814
+ - Broken links found: {broken_links.length} ❌
1815
+ - Links auto-fixed: {fixed_links.length} ✅
1816
+ - Links requiring manual review: {unfixable_links.length} ⚠️
1817
+
1818
+ {if fixed_links.length > 0:}
1819
+ **Auto-Fixed Links:**
1820
+ {for each fixed_link:}
1821
+ - ✅ {source_file}:{line_number}
1822
+ - Old: `{old_path}` (broken)
1823
+ - New: `{new_path}` (fixed)
1824
+
1825
+ {if unfixable_links.length > 0:}
1826
+ **Links Requiring Manual Review:**
1827
+ {for each unfixable:}
1828
+ - ⚠️ {source_file}:{line_number}: [{link_text}]({link_path})
1829
+ - Issue: {reason}
1830
+ {if multiple matches:}
1831
+ - Possible matches: {list matches}
1832
+ - **Action Required:** Determine correct file and update link manually
1833
+
1834
+ ---
1835
+
1836
+ ## Project Context Used
1837
+
1838
+ **Codebase Analysis:**
1839
+ - **Project Type:** {project_metadata.type}
1840
+ - **Framework:** {project_metadata.framework}
1841
+ - **Version:** {project_metadata.version}
1842
+ - **Architecture Pattern:** {project_metadata.architecture}
1843
+ - **Entry Point:** {project_metadata.entry_point}
1844
+ - **Major Dependencies:** {major_deps_count} documented
1845
+
1846
+ **Content Seeding:**
1847
+ - Getting Started guide: Framework-specific installation instructions
1848
+ - Architecture overview: Actual directory structure from `src/`
1849
+ - API documentation: {api_docs.type or "Endpoints detected"} from codebase
1850
+ - Reference: CLI commands from package.json scripts
1851
+ - Reference: Environment variables from .env.example
1852
+
1853
+ ---
1854
+
1855
+ ## Duplicate Documentation Detected
1856
+
1857
+ {if duplicates.length > 0:}
1858
+ **Potential Duplicates Found:** {duplicates.length} cases
1859
+
1860
+ {for each duplicate:}
1861
+ - ⚠️ **{file1}** ↔ **{file2}**
1862
+ - Similarity: {similarity_score}%
1863
+ - Type: {title_similarity or content_similarity}
1864
+ - **Recommendation:** Review and consolidate or clarify differences
1865
+
1866
+ {else:}
1867
+ **No duplicate documentation detected** ✅
1868
+
1869
+ ---
1870
+
1871
+ ## Completion Status
1872
+
1873
+ **Required Elements:**
1874
+ - ✅ docs/ directory exists
1875
+ - ✅ Hierarchical structure (guides/, api/, architecture/, reference/, images/)
1876
+ - ✅ Seeded content in all categories
1877
+ - ✅ Auto-generated architecture overview
1878
+ - ✅ docs/README.md navigation
1879
+ - ✅ Category READMEs with actual content listings
1880
+ - ✅ Scattered documentation migrated ({migrated_files.length} files)
1881
+ - ✅ Documentation links validated ({fixed_links.length} fixed)
1882
+ {if api_docs:}
1883
+ - ✅ Auto-generated API docs integrated ({api_docs.type})
1884
+
1885
+ **Documentation Coverage:** {coverage_metrics.total}/100 ({grade})
1886
+
1887
+ {if coverage_metrics.total >= 70:}
1888
+ **SUCCESS Criteria:** All required elements present ✅
1889
+
1890
+ {else:}
1891
+ **PARTIAL SUCCESS:** Core structure complete, content needs expansion ⚠️
1892
+
1893
+ ---
1894
+
1895
+ ## Recommendations
1896
+
1897
+ {if recommendations.length > 0:}
1898
+
1899
+ {for each category_recommendation in recommendations:}
1900
+ ### {category_recommendation.category} - Priority: {priority}
1901
+
1902
+ {for each item in category_recommendation.items:}
1903
+ - {item}
1904
+
1905
+ {else:}
1906
+ **No recommendations** - Documentation is comprehensive ✅
1907
+
1908
+ ---
1909
+
1910
+ ## Next Steps
1911
+
1912
+ ### Immediate Actions
1913
+
1914
+ {if unfixable_links.length > 0:}
1915
+ 1. **Fix Broken Links** ({unfixable_links.length} links)
1916
+ - Review links requiring manual attention (see Link Validation Results)
1917
+
1918
+ {if duplicates.length > 0:}
1919
+ 2. **Review Duplicate Documentation** ({duplicates.length} cases)
1920
+ - Consolidate or clarify differences between similar files
1921
+
1922
+ {if guides_count < 3:}
1923
+ 3. **Expand Guides**
1924
+ - Add deployment guide
1925
+ - Create testing guide
1926
+ - Document troubleshooting steps
1927
+
1928
+ {if not api_docs and framework matches API framework:}
1929
+ 4. **Generate API Documentation**
1930
+ - Run TypeDoc/Rustdoc/Sphinx to generate API reference
1931
+ - Document API endpoints and authentication
1932
+
1933
+ ### Future Enhancements
1934
+
1935
+ {if not exists("docs/architecture/adr/"):}
1936
+ - **Architecture Decision Records**
1937
+ - Start documenting architectural decisions using ADR format
1938
+ - Create `docs/architecture/adr/` directory
1939
+
1940
+ {if not has_architecture_diagrams:}
1941
+ - **Architecture Diagrams**
1942
+ - Create system architecture diagram
1943
+ - Add component interaction diagram
1944
+ - Document deployment architecture
1945
+
1946
+ - **Advanced Guides**
1947
+ - Performance optimization guide
1948
+ - Security best practices
1949
+ - Debugging guide
1950
+
1951
+ ---
1952
+
1953
+ **Report Generated:** {timestamp}
1954
+ **Report Location:** trinity/reports/DOCS-ORGANIZATION-{date}.md
1955
+
1956
+ **Documentation Status:** {✅ Production-Ready | ⚠️ Needs Content Expansion | ❌ Incomplete}
1957
+ ```
1958
+
1959
+ **APO Output:**
1960
+
1961
+ ```markdown
1962
+ === PHASE 5: ORGANIZATION REPORT ===
1963
+
1964
+ **Report Generated:** trinity/reports/DOCS-ORGANIZATION-{date}.md
1965
+
1966
+ **Documentation Coverage Score:** {coverage_metrics.total}/100
1967
+ - Grade: {grade}
1968
+ - Structure: {structure_score}/30
1969
+ - Content: {content_score}/50
1970
+ - Navigation: {navigation_score}/20
1971
+
1972
+ **Status:** {✅ SUCCESS | ⚠️ PARTIAL SUCCESS}
1973
+
1974
+ **Key Achievements:**
1975
+ - ✅ {created_dirs.length} directories created
1976
+ - ✅ {content_files_created} files created with seeded content
1977
+ - ✅ Architecture overview auto-generated ({line_count} lines)
1978
+ - ✅ {migrated_files.length} scattered docs migrated
1979
+ - ✅ {fixed_links.length} broken links fixed
1980
+ - ✅ Complete navigation structure
1981
+
1982
+ {if recommendations.length > 0:}
1983
+ **Recommendations:** {recommendations.length} categories
1984
+ - {list priority recommendations}
1985
+
1986
+ **Report Location:** trinity/reports/DOCS-ORGANIZATION-{date}.md
1987
+ ```
1988
+
1989
+ ---
1990
+
1991
+ ## Success Criteria
1992
+
1993
+ **Command succeeds when:**
1994
+
1995
+ 1. **docs/ Structure:** Hierarchical directories exist (guides/, api/, architecture/, reference/, images/)
1996
+ 2. **Seeded Content:** Initial documentation created based on project type
1997
+ 3. **Architecture Overview:** Auto-generated from codebase analysis
1998
+ 4. **Navigation:** docs/README.md exists with complete index
1999
+ 5. **Category READMEs:** Each category directory has README.md listing actual files
2000
+ 6. **Migration:** Scattered documentation organized (if any found)
2001
+ 7. **Link Validation:** Documentation links validated and fixed where possible
2002
+ 8. **All Phases Complete:** 5/5 phases executed
2003
+
2004
+ **Status Determination:**
2005
+
2006
+ **✅ SUCCESS (Coverage ≥ 70/100):**
2007
+ - All required structure created
2008
+ - Content seeded in all categories
2009
+ - Architecture overview auto-generated
2010
+ - Navigation complete
2011
+ - Documentation coverage ≥ 70%
2012
+
2013
+ **⚠️ PARTIAL SUCCESS (Coverage 40-69/100):**
2014
+ - Structure created
2015
+ - Some content seeded
2016
+ - Navigation exists
2017
+ - Manual content expansion needed
2018
+
2019
+ **❌ NEEDS ATTENTION (Coverage < 40/100):**
2020
+ - Structural issues remain
2021
+ - Minimal content created
2022
+ - Re-run command or manual intervention needed
2023
+
2024
+ ---
2025
+
2026
+ ## Post-Execution Checklist
2027
+
2028
+ **After `/trinity-docs` completes, verify:**
2029
+
2030
+ 1. ✅ Check `trinity/reports/DOCS-ORGANIZATION-{date}.md` for full report
2031
+ 2. ✅ Verify docs/README.md exists and navigation works
2032
+ 3. ✅ Check docs/guides/getting-started.md was created
2033
+ 4. ✅ Verify docs/architecture/overview.md was auto-generated
2034
+ 5. ✅ Check all category directories exist with READMEs
2035
+ 6. ✅ Review documentation coverage score (target: ≥70/100)
2036
+ 7. ✅ Review recommendations section for next steps
2037
+ 8. ✅ Fix any unfixable broken links (if reported)
2038
+ 9. ✅ Review duplicate documentation (if reported)
2039
+ 10. ✅ Check "COMMAND EXECUTION STATUS" = "✅ SUCCESS"
2040
+
2041
+ ---
2042
+
2043
+ ## Framework-Specific Content Examples
2044
+
2045
+ ### Node.js/Express Projects
2046
+
2047
+ **Guides Created:**
2048
+ - `getting-started.md`: npm install, project structure, npm run dev
2049
+ - `api-development.md`: Route creation, middleware, error handling
2050
+
2051
+ **Architecture:**
2052
+ - Auto-detects Express routes, middleware patterns
2053
+ - Documents dependencies from package.json
2054
+
2055
+ **Reference:**
2056
+ - CLI commands from package.json scripts
2057
+ - Environment variables from .env.example
2058
+
2059
+ ### Python/Django Projects
2060
+
2061
+ **Guides Created:**
2062
+ - `getting-started.md`: pip install, virtual env, python manage.py runserver
2063
+ - `django-development.md`: App creation, models, migrations, admin
2064
+
2065
+ **Architecture:**
2066
+ - Auto-detects Django apps, settings structure
2067
+ - Documents dependencies from requirements.txt or pyproject.toml
2068
+
2069
+ ### Rust Projects
2070
+
2071
+ **Guides Created:**
2072
+ - `getting-started.md`: cargo build, cargo run
2073
+ - Crate-specific development guide
2074
+
2075
+ **Architecture:**
2076
+ - Auto-detects from Cargo.toml
2077
+ - Documents crate dependencies
2078
+
2079
+ ### React Projects
2080
+
2081
+ **Guides Created:**
2082
+ - `getting-started.md`: npm install, npm start
2083
+ - `component-development.md`: Component patterns, state management
2084
+
2085
+ **Architecture:**
2086
+ - Auto-detects React components, hooks, context
2087
+ - Documents frontend architecture
2088
+
2089
+ ---
2090
+
2091
+ **Command Specification Version:** 3.0.0
2092
+ **Last Updated:** {{CURRENT_DATE}}
2093
+ **Enhancements:** Codebase analysis, content seeding, migration, auto-generation, link validation, coverage metrics, framework-specific content, duplicate detection, TypeDoc integration, actionable recommendations