ai-first-cli 1.2.3 → 1.3.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 (470) hide show
  1. package/CHANGELOG.md +292 -6
  2. package/README.md +24 -4
  3. package/dist/analyzers/symbols.d.ts.map +1 -1
  4. package/dist/analyzers/symbols.js +9 -7
  5. package/dist/analyzers/symbols.js.map +1 -1
  6. package/dist/analyzers/techStack.d.ts.map +1 -1
  7. package/dist/analyzers/techStack.js +198 -3
  8. package/dist/analyzers/techStack.js.map +1 -1
  9. package/dist/commands/ai-first.d.ts.map +1 -1
  10. package/dist/commands/ai-first.js +14 -13
  11. package/dist/commands/ai-first.js.map +1 -1
  12. package/dist/core/analysis/architectureDetector.d.ts +37 -0
  13. package/dist/core/analysis/architectureDetector.d.ts.map +1 -0
  14. package/dist/core/analysis/architectureDetector.js +316 -0
  15. package/dist/core/analysis/architectureDetector.js.map +1 -0
  16. package/dist/core/analysis/callGraphBuilder.d.ts +37 -0
  17. package/dist/core/analysis/callGraphBuilder.d.ts.map +1 -0
  18. package/dist/core/analysis/callGraphBuilder.js +101 -0
  19. package/dist/core/analysis/callGraphBuilder.js.map +1 -0
  20. package/dist/core/analysis/dependencyAnalyzer.d.ts +45 -0
  21. package/dist/core/analysis/dependencyAnalyzer.d.ts.map +1 -0
  22. package/dist/core/analysis/dependencyAnalyzer.js +98 -0
  23. package/dist/core/analysis/dependencyAnalyzer.js.map +1 -0
  24. package/dist/core/analysis/index.d.ts +5 -0
  25. package/dist/core/analysis/index.d.ts.map +1 -0
  26. package/dist/core/analysis/index.js +5 -0
  27. package/dist/core/analysis/index.js.map +1 -0
  28. package/dist/core/analysis/inheritanceAnalyzer.d.ts +35 -0
  29. package/dist/core/analysis/inheritanceAnalyzer.d.ts.map +1 -0
  30. package/dist/core/analysis/inheritanceAnalyzer.js +115 -0
  31. package/dist/core/analysis/inheritanceAnalyzer.js.map +1 -0
  32. package/dist/core/ccp.d.ts.map +1 -1
  33. package/dist/core/ccp.js +3 -2
  34. package/dist/core/ccp.js.map +1 -1
  35. package/dist/core/generation/aiContextGenerator.d.ts +71 -0
  36. package/dist/core/generation/aiContextGenerator.d.ts.map +1 -0
  37. package/dist/core/generation/aiContextGenerator.js +217 -0
  38. package/dist/core/generation/aiContextGenerator.js.map +1 -0
  39. package/dist/core/generation/architectureGenerator.d.ts +17 -0
  40. package/dist/core/generation/architectureGenerator.d.ts.map +1 -0
  41. package/dist/core/generation/architectureGenerator.js +160 -0
  42. package/dist/core/generation/architectureGenerator.js.map +1 -0
  43. package/dist/core/generation/flowGenerator.d.ts +52 -0
  44. package/dist/core/generation/flowGenerator.d.ts.map +1 -0
  45. package/dist/core/generation/flowGenerator.js +164 -0
  46. package/dist/core/generation/flowGenerator.js.map +1 -0
  47. package/dist/core/generation/index.d.ts +4 -0
  48. package/dist/core/generation/index.d.ts.map +1 -0
  49. package/dist/core/generation/index.js +4 -0
  50. package/dist/core/generation/index.js.map +1 -0
  51. package/dist/core/hierarchyGenerator.d.ts.map +1 -1
  52. package/dist/core/hierarchyGenerator.js +3 -2
  53. package/dist/core/hierarchyGenerator.js.map +1 -1
  54. package/dist/core/parsers/index.d.ts +20 -0
  55. package/dist/core/parsers/index.d.ts.map +1 -0
  56. package/dist/core/parsers/index.js +76 -0
  57. package/dist/core/parsers/index.js.map +1 -0
  58. package/dist/core/parsers/pythonParser.d.ts +37 -0
  59. package/dist/core/parsers/pythonParser.d.ts.map +1 -0
  60. package/dist/core/parsers/pythonParser.js +229 -0
  61. package/dist/core/parsers/pythonParser.js.map +1 -0
  62. package/dist/core/parsers/typescriptParser.d.ts +54 -0
  63. package/dist/core/parsers/typescriptParser.d.ts.map +1 -0
  64. package/dist/core/parsers/typescriptParser.js +291 -0
  65. package/dist/core/parsers/typescriptParser.js.map +1 -0
  66. package/dist/core/pipeline.d.ts +42 -0
  67. package/dist/core/pipeline.d.ts.map +1 -0
  68. package/dist/core/pipeline.js +172 -0
  69. package/dist/core/pipeline.js.map +1 -0
  70. package/dist/core/semanticContexts.js +1 -1
  71. package/dist/core/semanticContexts.js.map +1 -1
  72. package/dist/utils/constants.d.ts +46 -0
  73. package/dist/utils/constants.d.ts.map +1 -0
  74. package/dist/utils/constants.js +67 -0
  75. package/dist/utils/constants.js.map +1 -0
  76. package/package.json +1 -1
  77. package/run-all-tests.sh +184 -0
  78. package/src/analyzers/symbols.ts +12 -7
  79. package/src/analyzers/techStack.ts +203 -3
  80. package/src/commands/ai-first.ts +14 -13
  81. package/src/core/analysis/architectureDetector.ts +487 -0
  82. package/src/core/analysis/callGraphBuilder.ts +158 -0
  83. package/src/core/analysis/dependencyAnalyzer.ts +167 -0
  84. package/src/core/analysis/index.ts +28 -0
  85. package/src/core/analysis/inheritanceAnalyzer.ts +169 -0
  86. package/src/core/ccp.ts +3 -2
  87. package/src/core/generation/aiContextGenerator.ts +335 -0
  88. package/src/core/generation/architectureGenerator.ts +200 -0
  89. package/src/core/generation/flowGenerator.ts +238 -0
  90. package/src/core/generation/index.ts +16 -0
  91. package/src/core/hierarchyGenerator.ts +3 -2
  92. package/src/core/parsers/index.ts +99 -0
  93. package/src/core/parsers/pythonParser.ts +302 -0
  94. package/src/core/parsers/typescriptParser.ts +445 -0
  95. package/src/core/pipeline.ts +241 -0
  96. package/src/core/semanticContexts.ts +1 -1
  97. package/src/utils/constants.ts +78 -0
  98. package/tests/analysis.test.ts +283 -0
  99. package/tests/architectureDetector.test.ts +137 -0
  100. package/tests/generation.test.ts +216 -0
  101. package/tests/parserRegistry.test.ts +139 -0
  102. package/tests/pipeline.integration.test.ts +245 -0
  103. package/tests/pythonParser.test.ts +210 -0
  104. package/tests/typescriptParser.test.ts +197 -0
  105. package/.ai-dev/index.db +0 -0
  106. package/ANALISIS_COMPLETO.md +0 -424
  107. package/ANALISIS_MEJORAS.md +0 -327
  108. package/BUGS.md +0 -455
  109. package/PLAN_MEJORAS.md +0 -216
  110. package/STATUS_ADAPTADORES +0 -126
  111. package/TEST_RESULTS.md +0 -198
  112. package/TEST_RESULTS_COMPARATIVE.md +0 -159
  113. package/TEST_RESULTS_COMPLETE.md +0 -127
  114. package/TEST_RESULTS_COMPREHENSIVE.md +0 -208
  115. package/TEST_RESULTS_PHASE1.md +0 -420
  116. package/ai/dependencies.json +0 -15
  117. package/ai/graph/knowledge-graph.json +0 -12
  118. package/ai-context/ai_context.md +0 -130
  119. package/ai-context/ai_rules.md +0 -54
  120. package/ai-context/architecture.md +0 -136
  121. package/ai-context/cache.json +0 -2349
  122. package/ai-context/ccp/jira-123/context.json +0 -7
  123. package/ai-context/context/features/commands.json +0 -18
  124. package/ai-context/context/features/src.json +0 -61
  125. package/ai-context/context/features/test-projects.json +0 -69
  126. package/ai-context/context/flows/account.json +0 -9
  127. package/ai-context/context/flows/ai-first.json +0 -9
  128. package/ai-context/context/flows/api.json +0 -9
  129. package/ai-context/context/flows/auth.json +0 -13
  130. package/ai-context/context/flows/category.json +0 -12
  131. package/ai-context/context/flows/comment.json +0 -16
  132. package/ai-context/context/flows/dashboard.json +0 -9
  133. package/ai-context/context/flows/doctor.json +0 -9
  134. package/ai-context/context/flows/explore.json +0 -9
  135. package/ai-context/context/flows/login.json +0 -9
  136. package/ai-context/context/flows/opportunity.json +0 -9
  137. package/ai-context/context/flows/post.json +0 -18
  138. package/ai-context/context/flows/routes.json +0 -19
  139. package/ai-context/context/flows/user.json +0 -20
  140. package/ai-context/context/flows/users.json +0 -9
  141. package/ai-context/context/flows/views.json +0 -14
  142. package/ai-context/context/repo.json +0 -56
  143. package/ai-context/context/utils.json +0 -7
  144. package/ai-context/conventions.md +0 -53
  145. package/ai-context/dependencies.json +0 -2978
  146. package/ai-context/embeddings.json +0 -23828
  147. package/ai-context/entrypoints.md +0 -42
  148. package/ai-context/files.json +0 -2944
  149. package/ai-context/git/commit-activity.json +0 -8646
  150. package/ai-context/git/recent-features.json +0 -1
  151. package/ai-context/git/recent-files.json +0 -52
  152. package/ai-context/git/recent-flows.json +0 -1
  153. package/ai-context/graph/knowledge-graph.json +0 -44129
  154. package/ai-context/graph/module-graph.json +0 -866
  155. package/ai-context/graph/symbol-graph.json +0 -200622
  156. package/ai-context/graph/symbol-references.json +0 -6778
  157. package/ai-context/hierarchy.json +0 -20
  158. package/ai-context/index-state.json +0 -4487
  159. package/ai-context/index.db +0 -0
  160. package/ai-context/modules.json +0 -933
  161. package/ai-context/project.json +0 -30
  162. package/ai-context/repo_map.json +0 -9116
  163. package/ai-context/repo_map.md +0 -2061
  164. package/ai-context/schema.json +0 -5
  165. package/ai-context/summary.md +0 -47
  166. package/ai-context/symbols.json +0 -65351
  167. package/ai-context/tech_stack.md +0 -47
  168. package/ai-context/tools.json +0 -10
  169. package/test-projects/django-app/.ai-dev/index.db +0 -0
  170. package/test-projects/django-app/ai-context/ai_context.md +0 -92
  171. package/test-projects/django-app/ai-context/ai_rules.md +0 -47
  172. package/test-projects/django-app/ai-context/architecture.md +0 -57
  173. package/test-projects/django-app/ai-context/cache.json +0 -169
  174. package/test-projects/django-app/ai-context/context/flows/views.json +0 -10
  175. package/test-projects/django-app/ai-context/conventions.md +0 -51
  176. package/test-projects/django-app/ai-context/dependencies.json +0 -312
  177. package/test-projects/django-app/ai-context/entrypoints.md +0 -4
  178. package/test-projects/django-app/ai-context/files.json +0 -209
  179. package/test-projects/django-app/ai-context/graph/knowledge-graph.json +0 -36
  180. package/test-projects/django-app/ai-context/graph/module-graph.json +0 -145
  181. package/test-projects/django-app/ai-context/graph/symbol-graph.json +0 -1488
  182. package/test-projects/django-app/ai-context/graph/symbol-references.json +0 -1
  183. package/test-projects/django-app/ai-context/index-state.json +0 -294
  184. package/test-projects/django-app/ai-context/index.db +0 -0
  185. package/test-projects/django-app/ai-context/modules.json +0 -35
  186. package/test-projects/django-app/ai-context/project.json +0 -11
  187. package/test-projects/django-app/ai-context/repo_map.json +0 -412
  188. package/test-projects/django-app/ai-context/repo_map.md +0 -105
  189. package/test-projects/django-app/ai-context/schema.json +0 -5
  190. package/test-projects/django-app/ai-context/summary.md +0 -15
  191. package/test-projects/django-app/ai-context/symbols.json +0 -1
  192. package/test-projects/django-app/ai-context/tech_stack.md +0 -32
  193. package/test-projects/django-app/ai-context/tools.json +0 -10
  194. package/test-projects/express-api/ai-context/ai_context.md +0 -112
  195. package/test-projects/express-api/ai-context/ai_rules.md +0 -50
  196. package/test-projects/express-api/ai-context/architecture.md +0 -62
  197. package/test-projects/express-api/ai-context/context/features/controllers.json +0 -13
  198. package/test-projects/express-api/ai-context/context/features/services.json +0 -13
  199. package/test-projects/express-api/ai-context/context/flows/auth.json +0 -12
  200. package/test-projects/express-api/ai-context/context/flows/user.json +0 -13
  201. package/test-projects/express-api/ai-context/conventions.md +0 -51
  202. package/test-projects/express-api/ai-context/dependencies.json +0 -54
  203. package/test-projects/express-api/ai-context/entrypoints.md +0 -17
  204. package/test-projects/express-api/ai-context/modules.json +0 -30
  205. package/test-projects/express-api/ai-context/project.json +0 -15
  206. package/test-projects/express-api/ai-context/repo_map.json +0 -100
  207. package/test-projects/express-api/ai-context/repo_map.md +0 -36
  208. package/test-projects/express-api/ai-context/schema.json +0 -5
  209. package/test-projects/express-api/ai-context/summary.md +0 -14
  210. package/test-projects/express-api/ai-context/symbols.json +0 -7
  211. package/test-projects/express-api/ai-context/tech_stack.md +0 -38
  212. package/test-projects/express-api/ai-context/tools.json +0 -10
  213. package/test-projects/fastapi-app/.ai-dev/index.db +0 -0
  214. package/test-projects/fastapi-app/ai-context/ai_context.md +0 -89
  215. package/test-projects/fastapi-app/ai-context/ai_rules.md +0 -47
  216. package/test-projects/fastapi-app/ai-context/architecture.md +0 -39
  217. package/test-projects/fastapi-app/ai-context/cache.json +0 -125
  218. package/test-projects/fastapi-app/ai-context/conventions.md +0 -51
  219. package/test-projects/fastapi-app/ai-context/dependencies.json +0 -244
  220. package/test-projects/fastapi-app/ai-context/entrypoints.md +0 -4
  221. package/test-projects/fastapi-app/ai-context/files.json +0 -154
  222. package/test-projects/fastapi-app/ai-context/graph/knowledge-graph.json +0 -15
  223. package/test-projects/fastapi-app/ai-context/graph/module-graph.json +0 -78
  224. package/test-projects/fastapi-app/ai-context/graph/symbol-graph.json +0 -1724
  225. package/test-projects/fastapi-app/ai-context/graph/symbol-references.json +0 -51
  226. package/test-projects/fastapi-app/ai-context/index-state.json +0 -217
  227. package/test-projects/fastapi-app/ai-context/index.db +0 -0
  228. package/test-projects/fastapi-app/ai-context/modules.json +0 -16
  229. package/test-projects/fastapi-app/ai-context/project.json +0 -9
  230. package/test-projects/fastapi-app/ai-context/repo_map.json +0 -298
  231. package/test-projects/fastapi-app/ai-context/repo_map.md +0 -74
  232. package/test-projects/fastapi-app/ai-context/schema.json +0 -5
  233. package/test-projects/fastapi-app/ai-context/summary.md +0 -12
  234. package/test-projects/fastapi-app/ai-context/symbols.json +0 -1
  235. package/test-projects/fastapi-app/ai-context/tech_stack.md +0 -32
  236. package/test-projects/fastapi-app/ai-context/tools.json +0 -10
  237. package/test-projects/flask-app/.ai-dev/index.db +0 -0
  238. package/test-projects/flask-app/ai-context/ai_context.md +0 -94
  239. package/test-projects/flask-app/ai-context/ai_rules.md +0 -47
  240. package/test-projects/flask-app/ai-context/architecture.md +0 -49
  241. package/test-projects/flask-app/ai-context/cache.json +0 -157
  242. package/test-projects/flask-app/ai-context/context/features/app.json +0 -25
  243. package/test-projects/flask-app/ai-context/context/flows/routes.json +0 -14
  244. package/test-projects/flask-app/ai-context/conventions.md +0 -51
  245. package/test-projects/flask-app/ai-context/dependencies.json +0 -298
  246. package/test-projects/flask-app/ai-context/entrypoints.md +0 -4
  247. package/test-projects/flask-app/ai-context/files.json +0 -194
  248. package/test-projects/flask-app/ai-context/graph/knowledge-graph.json +0 -60
  249. package/test-projects/flask-app/ai-context/graph/module-graph.json +0 -95
  250. package/test-projects/flask-app/ai-context/graph/symbol-graph.json +0 -1448
  251. package/test-projects/flask-app/ai-context/graph/symbol-references.json +0 -45
  252. package/test-projects/flask-app/ai-context/index-state.json +0 -273
  253. package/test-projects/flask-app/ai-context/index.db +0 -0
  254. package/test-projects/flask-app/ai-context/modules.json +0 -21
  255. package/test-projects/flask-app/ai-context/project.json +0 -13
  256. package/test-projects/flask-app/ai-context/repo_map.json +0 -400
  257. package/test-projects/flask-app/ai-context/repo_map.md +0 -98
  258. package/test-projects/flask-app/ai-context/schema.json +0 -5
  259. package/test-projects/flask-app/ai-context/summary.md +0 -13
  260. package/test-projects/flask-app/ai-context/symbols.json +0 -1
  261. package/test-projects/flask-app/ai-context/tech_stack.md +0 -32
  262. package/test-projects/flask-app/ai-context/tools.json +0 -10
  263. package/test-projects/laravel-app/.ai-dev/index.db +0 -0
  264. package/test-projects/laravel-app/ai-context/ai_context.md +0 -97
  265. package/test-projects/laravel-app/ai-context/ai_rules.md +0 -47
  266. package/test-projects/laravel-app/ai-context/architecture.md +0 -60
  267. package/test-projects/laravel-app/ai-context/cache.json +0 -161
  268. package/test-projects/laravel-app/ai-context/context/features/app.json +0 -21
  269. package/test-projects/laravel-app/ai-context/context/flows/.json +0 -9
  270. package/test-projects/laravel-app/ai-context/context/flows/category.json +0 -12
  271. package/test-projects/laravel-app/ai-context/context/flows/comment.json +0 -12
  272. package/test-projects/laravel-app/ai-context/context/flows/post.json +0 -12
  273. package/test-projects/laravel-app/ai-context/context/flows/unnamed.json +0 -9
  274. package/test-projects/laravel-app/ai-context/conventions.md +0 -51
  275. package/test-projects/laravel-app/ai-context/dependencies.json +0 -6
  276. package/test-projects/laravel-app/ai-context/entrypoints.md +0 -4
  277. package/test-projects/laravel-app/ai-context/files.json +0 -199
  278. package/test-projects/laravel-app/ai-context/graph/knowledge-graph.json +0 -98
  279. package/test-projects/laravel-app/ai-context/graph/module-graph.json +0 -30
  280. package/test-projects/laravel-app/ai-context/graph/symbol-graph.json +0 -5
  281. package/test-projects/laravel-app/ai-context/graph/symbol-references.json +0 -1
  282. package/test-projects/laravel-app/ai-context/index-state.json +0 -280
  283. package/test-projects/laravel-app/ai-context/index.db +0 -0
  284. package/test-projects/laravel-app/ai-context/modules.json +0 -29
  285. package/test-projects/laravel-app/ai-context/project.json +0 -17
  286. package/test-projects/laravel-app/ai-context/repo_map.json +0 -419
  287. package/test-projects/laravel-app/ai-context/repo_map.md +0 -106
  288. package/test-projects/laravel-app/ai-context/schema.json +0 -5
  289. package/test-projects/laravel-app/ai-context/summary.md +0 -15
  290. package/test-projects/laravel-app/ai-context/symbols.json +0 -1
  291. package/test-projects/laravel-app/ai-context/tech_stack.md +0 -34
  292. package/test-projects/laravel-app/ai-context/tools.json +0 -10
  293. package/test-projects/nestjs-backend/.ai-dev/index.db +0 -0
  294. package/test-projects/nestjs-backend/ai-context/ai_context.md +0 -111
  295. package/test-projects/nestjs-backend/ai-context/ai_rules.md +0 -52
  296. package/test-projects/nestjs-backend/ai-context/architecture.md +0 -49
  297. package/test-projects/nestjs-backend/ai-context/cache.json +0 -169
  298. package/test-projects/nestjs-backend/ai-context/context/features/src.json +0 -23
  299. package/test-projects/nestjs-backend/ai-context/context/flows/auth.controller.json +0 -14
  300. package/test-projects/nestjs-backend/ai-context/context/flows/auth.json +0 -10
  301. package/test-projects/nestjs-backend/ai-context/context/flows/users..json +0 -10
  302. package/test-projects/nestjs-backend/ai-context/context/flows/users.controller.json +0 -14
  303. package/test-projects/nestjs-backend/ai-context/context/flows/users.json +0 -10
  304. package/test-projects/nestjs-backend/ai-context/conventions.md +0 -52
  305. package/test-projects/nestjs-backend/ai-context/dependencies.json +0 -152
  306. package/test-projects/nestjs-backend/ai-context/entrypoints.md +0 -18
  307. package/test-projects/nestjs-backend/ai-context/files.json +0 -209
  308. package/test-projects/nestjs-backend/ai-context/graph/knowledge-graph.json +0 -132
  309. package/test-projects/nestjs-backend/ai-context/graph/module-graph.json +0 -29
  310. package/test-projects/nestjs-backend/ai-context/graph/symbol-graph.json +0 -304
  311. package/test-projects/nestjs-backend/ai-context/graph/symbol-references.json +0 -5
  312. package/test-projects/nestjs-backend/ai-context/index-state.json +0 -294
  313. package/test-projects/nestjs-backend/ai-context/index.db +0 -0
  314. package/test-projects/nestjs-backend/ai-context/modules.json +0 -19
  315. package/test-projects/nestjs-backend/ai-context/project.json +0 -18
  316. package/test-projects/nestjs-backend/ai-context/repo_map.json +0 -427
  317. package/test-projects/nestjs-backend/ai-context/repo_map.md +0 -104
  318. package/test-projects/nestjs-backend/ai-context/schema.json +0 -5
  319. package/test-projects/nestjs-backend/ai-context/summary.md +0 -13
  320. package/test-projects/nestjs-backend/ai-context/symbols.json +0 -1
  321. package/test-projects/nestjs-backend/ai-context/tech_stack.md +0 -38
  322. package/test-projects/nestjs-backend/ai-context/tools.json +0 -10
  323. package/test-projects/python-cli/.ai-dev/index.db +0 -0
  324. package/test-projects/python-cli/ai-context/ai_context.md +0 -95
  325. package/test-projects/python-cli/ai-context/ai_rules.md +0 -47
  326. package/test-projects/python-cli/ai-context/architecture.md +0 -55
  327. package/test-projects/python-cli/ai-context/cache.json +0 -149
  328. package/test-projects/python-cli/ai-context/context/features/cli.json +0 -16
  329. package/test-projects/python-cli/ai-context/context/flows/list_.json +0 -9
  330. package/test-projects/python-cli/ai-context/context/flows/remove_.json +0 -9
  331. package/test-projects/python-cli/ai-context/conventions.md +0 -51
  332. package/test-projects/python-cli/ai-context/dependencies.json +0 -66
  333. package/test-projects/python-cli/ai-context/entrypoints.md +0 -4
  334. package/test-projects/python-cli/ai-context/files.json +0 -184
  335. package/test-projects/python-cli/ai-context/graph/knowledge-graph.json +0 -83
  336. package/test-projects/python-cli/ai-context/graph/module-graph.json +0 -31
  337. package/test-projects/python-cli/ai-context/graph/symbol-graph.json +0 -358
  338. package/test-projects/python-cli/ai-context/graph/symbol-references.json +0 -11
  339. package/test-projects/python-cli/ai-context/index-state.json +0 -259
  340. package/test-projects/python-cli/ai-context/index.db +0 -0
  341. package/test-projects/python-cli/ai-context/modules.json +0 -21
  342. package/test-projects/python-cli/ai-context/project.json +0 -15
  343. package/test-projects/python-cli/ai-context/repo_map.json +0 -367
  344. package/test-projects/python-cli/ai-context/repo_map.md +0 -93
  345. package/test-projects/python-cli/ai-context/schema.json +0 -5
  346. package/test-projects/python-cli/ai-context/summary.md +0 -14
  347. package/test-projects/python-cli/ai-context/symbols.json +0 -1
  348. package/test-projects/python-cli/ai-context/tech_stack.md +0 -32
  349. package/test-projects/python-cli/ai-context/tools.json +0 -10
  350. package/test-projects/rails-app/.ai-dev/index.db +0 -0
  351. package/test-projects/rails-app/ai-context/ai_context.md +0 -94
  352. package/test-projects/rails-app/ai-context/ai_rules.md +0 -47
  353. package/test-projects/rails-app/ai-context/architecture.md +0 -49
  354. package/test-projects/rails-app/ai-context/cache.json +0 -193
  355. package/test-projects/rails-app/ai-context/context/features/app.json +0 -24
  356. package/test-projects/rails-app/ai-context/context/features/config.json +0 -13
  357. package/test-projects/rails-app/ai-context/context/flows/application.json +0 -9
  358. package/test-projects/rails-app/ai-context/context/flows/application_.json +0 -9
  359. package/test-projects/rails-app/ai-context/context/flows/comments.json +0 -11
  360. package/test-projects/rails-app/ai-context/context/flows/comments_.json +0 -11
  361. package/test-projects/rails-app/ai-context/context/flows/posts.json +0 -11
  362. package/test-projects/rails-app/ai-context/context/flows/posts_.json +0 -11
  363. package/test-projects/rails-app/ai-context/context/flows/routes.json +0 -9
  364. package/test-projects/rails-app/ai-context/context/flows/users.json +0 -11
  365. package/test-projects/rails-app/ai-context/context/flows/users_.json +0 -11
  366. package/test-projects/rails-app/ai-context/conventions.md +0 -51
  367. package/test-projects/rails-app/ai-context/dependencies.json +0 -6
  368. package/test-projects/rails-app/ai-context/entrypoints.md +0 -4
  369. package/test-projects/rails-app/ai-context/files.json +0 -239
  370. package/test-projects/rails-app/ai-context/graph/knowledge-graph.json +0 -130
  371. package/test-projects/rails-app/ai-context/graph/module-graph.json +0 -27
  372. package/test-projects/rails-app/ai-context/graph/symbol-graph.json +0 -5
  373. package/test-projects/rails-app/ai-context/graph/symbol-references.json +0 -1
  374. package/test-projects/rails-app/ai-context/index-state.json +0 -336
  375. package/test-projects/rails-app/ai-context/index.db +0 -0
  376. package/test-projects/rails-app/ai-context/modules.json +0 -26
  377. package/test-projects/rails-app/ai-context/project.json +0 -22
  378. package/test-projects/rails-app/ai-context/repo_map.json +0 -486
  379. package/test-projects/rails-app/ai-context/repo_map.md +0 -117
  380. package/test-projects/rails-app/ai-context/schema.json +0 -5
  381. package/test-projects/rails-app/ai-context/summary.md +0 -13
  382. package/test-projects/rails-app/ai-context/symbols.json +0 -1
  383. package/test-projects/rails-app/ai-context/tech_stack.md +0 -32
  384. package/test-projects/rails-app/ai-context/tools.json +0 -10
  385. package/test-projects/react-app/.ai-dev/index.db +0 -0
  386. package/test-projects/react-app/ai-context/ai_context.md +0 -96
  387. package/test-projects/react-app/ai-context/ai_rules.md +0 -49
  388. package/test-projects/react-app/ai-context/architecture.md +0 -39
  389. package/test-projects/react-app/ai-context/cache.json +0 -153
  390. package/test-projects/react-app/ai-context/context/features/src.json +0 -18
  391. package/test-projects/react-app/ai-context/context/flows/UsersPage.json +0 -14
  392. package/test-projects/react-app/ai-context/context/flows/dashboard.json +0 -9
  393. package/test-projects/react-app/ai-context/context/flows/login.json +0 -9
  394. package/test-projects/react-app/ai-context/context/flows/users.json +0 -9
  395. package/test-projects/react-app/ai-context/conventions.md +0 -52
  396. package/test-projects/react-app/ai-context/dependencies.json +0 -128
  397. package/test-projects/react-app/ai-context/entrypoints.md +0 -4
  398. package/test-projects/react-app/ai-context/files.json +0 -189
  399. package/test-projects/react-app/ai-context/graph/knowledge-graph.json +0 -112
  400. package/test-projects/react-app/ai-context/graph/module-graph.json +0 -31
  401. package/test-projects/react-app/ai-context/graph/symbol-graph.json +0 -868
  402. package/test-projects/react-app/ai-context/graph/symbol-references.json +0 -31
  403. package/test-projects/react-app/ai-context/index-state.json +0 -266
  404. package/test-projects/react-app/ai-context/index.db +0 -0
  405. package/test-projects/react-app/ai-context/modules.json +0 -17
  406. package/test-projects/react-app/ai-context/project.json +0 -16
  407. package/test-projects/react-app/ai-context/repo_map.json +0 -391
  408. package/test-projects/react-app/ai-context/repo_map.md +0 -94
  409. package/test-projects/react-app/ai-context/schema.json +0 -5
  410. package/test-projects/react-app/ai-context/summary.md +0 -13
  411. package/test-projects/react-app/ai-context/symbols.json +0 -1
  412. package/test-projects/react-app/ai-context/tech_stack.md +0 -39
  413. package/test-projects/react-app/ai-context/tools.json +0 -10
  414. package/test-projects/salesforce-cli/.ai-dev/index.db +0 -0
  415. package/test-projects/salesforce-cli/ai-context/ai_context.md +0 -89
  416. package/test-projects/salesforce-cli/ai-context/ai_rules.md +0 -47
  417. package/test-projects/salesforce-cli/ai-context/architecture.md +0 -39
  418. package/test-projects/salesforce-cli/ai-context/cache.json +0 -125
  419. package/test-projects/salesforce-cli/ai-context/context/features/force-app.json +0 -14
  420. package/test-projects/salesforce-cli/ai-context/context/flows/account.json +0 -9
  421. package/test-projects/salesforce-cli/ai-context/context/flows/opportunity.json +0 -9
  422. package/test-projects/salesforce-cli/ai-context/conventions.md +0 -51
  423. package/test-projects/salesforce-cli/ai-context/dependencies.json +0 -6
  424. package/test-projects/salesforce-cli/ai-context/entrypoints.md +0 -4
  425. package/test-projects/salesforce-cli/ai-context/files.json +0 -154
  426. package/test-projects/salesforce-cli/ai-context/graph/knowledge-graph.json +0 -64
  427. package/test-projects/salesforce-cli/ai-context/graph/module-graph.json +0 -13
  428. package/test-projects/salesforce-cli/ai-context/graph/symbol-graph.json +0 -148
  429. package/test-projects/salesforce-cli/ai-context/graph/symbol-references.json +0 -1
  430. package/test-projects/salesforce-cli/ai-context/index-state.json +0 -217
  431. package/test-projects/salesforce-cli/ai-context/index.db +0 -0
  432. package/test-projects/salesforce-cli/ai-context/modules.json +0 -12
  433. package/test-projects/salesforce-cli/ai-context/project.json +0 -14
  434. package/test-projects/salesforce-cli/ai-context/repo_map.json +0 -328
  435. package/test-projects/salesforce-cli/ai-context/repo_map.md +0 -80
  436. package/test-projects/salesforce-cli/ai-context/schema.json +0 -5
  437. package/test-projects/salesforce-cli/ai-context/summary.md +0 -13
  438. package/test-projects/salesforce-cli/ai-context/symbols.json +0 -1
  439. package/test-projects/salesforce-cli/ai-context/tech_stack.md +0 -31
  440. package/test-projects/salesforce-cli/ai-context/tools.json +0 -10
  441. package/test-projects/spring-boot-app/.ai-dev/index.db +0 -0
  442. package/test-projects/spring-boot-app/ai-context/ai_context.md +0 -91
  443. package/test-projects/spring-boot-app/ai-context/ai_rules.md +0 -48
  444. package/test-projects/spring-boot-app/ai-context/architecture.md +0 -39
  445. package/test-projects/spring-boot-app/ai-context/cache.json +0 -173
  446. package/test-projects/spring-boot-app/ai-context/context/features/src.json +0 -26
  447. package/test-projects/spring-boot-app/ai-context/context/flows/PostController.json +0 -19
  448. package/test-projects/spring-boot-app/ai-context/context/flows/UserController.json +0 -19
  449. package/test-projects/spring-boot-app/ai-context/context/flows/comment.json +0 -11
  450. package/test-projects/spring-boot-app/ai-context/context/flows/post.json +0 -14
  451. package/test-projects/spring-boot-app/ai-context/context/flows/user.json +0 -14
  452. package/test-projects/spring-boot-app/ai-context/conventions.md +0 -52
  453. package/test-projects/spring-boot-app/ai-context/dependencies.json +0 -326
  454. package/test-projects/spring-boot-app/ai-context/entrypoints.md +0 -4
  455. package/test-projects/spring-boot-app/ai-context/files.json +0 -214
  456. package/test-projects/spring-boot-app/ai-context/graph/knowledge-graph.json +0 -231
  457. package/test-projects/spring-boot-app/ai-context/graph/module-graph.json +0 -22
  458. package/test-projects/spring-boot-app/ai-context/graph/symbol-graph.json +0 -794
  459. package/test-projects/spring-boot-app/ai-context/graph/symbol-references.json +0 -70
  460. package/test-projects/spring-boot-app/ai-context/index-state.json +0 -301
  461. package/test-projects/spring-boot-app/ai-context/index.db +0 -0
  462. package/test-projects/spring-boot-app/ai-context/modules.json +0 -21
  463. package/test-projects/spring-boot-app/ai-context/project.json +0 -17
  464. package/test-projects/spring-boot-app/ai-context/repo_map.json +0 -461
  465. package/test-projects/spring-boot-app/ai-context/repo_map.md +0 -109
  466. package/test-projects/spring-boot-app/ai-context/schema.json +0 -5
  467. package/test-projects/spring-boot-app/ai-context/summary.md +0 -12
  468. package/test-projects/spring-boot-app/ai-context/symbols.json +0 -1
  469. package/test-projects/spring-boot-app/ai-context/tech_stack.md +0 -32
  470. package/test-projects/spring-boot-app/ai-context/tools.json +0 -10
@@ -8,6 +8,7 @@ import { generateIndex, IncrementalIndexer, EXAMPLE_QUERIES } from "../core/inde
8
8
  import { generateAIContext } from "../core/aiContextGenerator.js";
9
9
  import { generateHierarchy } from "../core/hierarchyGenerator.js";
10
10
  import { ensureDir, writeFile } from "../utils/fileUtils.js";
11
+ import { AI_CONTEXT_DIR, getIndexDbPath, getHierarchyPath } from "../utils/constants.js";
11
12
  import { analyzeArchitecture, generateArchitectureFile } from "../analyzers/architecture.js";
12
13
  import { detectTechStack, generateTechStackFile } from "../analyzers/techStack.js";
13
14
  import { discoverEntrypoints, generateEntrypointsFile } from "../analyzers/entrypoints.js";
@@ -416,7 +417,7 @@ Usage: ai-first index [options]
416
417
 
417
418
  Options:
418
419
  -r, --root <dir> Root directory to scan (default: current directory)
419
- -o, --output <path> Output path for index.db (default: ./ai/index.db)
420
+ -o, --output <path> Output path for index.db (default: ./ai-context/index.db)
420
421
  -s, --semantic Force semantic indexing
421
422
  -h, --help Show help message
422
423
 
@@ -435,7 +436,7 @@ Example queries (for AI agents):
435
436
  }
436
437
 
437
438
  if (!outputPath) {
438
- outputPath = path.join(rootDir, "ai", "index.db");
439
+ outputPath = getIndexDbPath(rootDir);
439
440
  }
440
441
 
441
442
  const aiDir = path.join(rootDir, "ai-context");
@@ -489,7 +490,7 @@ Example queries (for AI agents):
489
490
  const modules: Record<string, { path: string; files: string[] }> = {};
490
491
  for (const file of scanResult.files) {
491
492
  const parts = file.relativePath.split('/');
492
- if (parts.length > 1 && parts[0] !== 'ai') {
493
+ if (parts.length > 1 && parts[0] !== AI_CONTEXT_DIR && parts[0] !== 'ai') {
493
494
  if (!modules[parts[0]]) modules[parts[0]] = { path: parts[0], files: [] };
494
495
  modules[parts[0]].files.push(file.relativePath);
495
496
  }
@@ -543,7 +544,7 @@ Example queries (for AI agents):
543
544
 
544
545
  const initSqlJs = (await import("sql.js")).default;
545
546
  const SQL = await initSqlJs();
546
- const dbPath = outputPath || path.join(rootDir, "ai", "index.db");
547
+ const dbPath = outputPath || getIndexDbPath(rootDir);
547
548
  let db: Database;
548
549
  if (fs.existsSync(dbPath)) {
549
550
  const fileBuffer = fs.readFileSync(dbPath);
@@ -577,7 +578,7 @@ Example queries (for AI agents):
577
578
  // Watch command - incremental indexing
578
579
  args.shift();
579
580
  let rootDir = process.cwd();
580
- let outputPath = path.join(rootDir, "ai", "index.db");
581
+ let outputPath = getIndexDbPath(rootDir);
581
582
  let semanticMode = false;
582
583
  let debounceMs = 300;
583
584
 
@@ -605,7 +606,7 @@ Usage: ai-first watch [options]
605
606
 
606
607
  Options:
607
608
  -r, --root <dir> Root directory to watch (default: current directory)
608
- -o, --output <path> Output path for index.db (default: ./ai/index.db)
609
+ -o, --output <path> Output path for index.db (default: ./ai-context/index.db)
609
610
  -d, --debounce <ms> Debounce delay in ms (default: 300)
610
611
  -h, --help Show help message
611
612
 
@@ -701,7 +702,7 @@ Arguments:
701
702
 
702
703
  Options:
703
704
  -r, --root <dir> Root directory (default: current directory)
704
- -o, --output <dir> Output directory (default: ./ai)
705
+ -o, --output <dir> Output directory (default: ./ai-context)
705
706
  -d, --depth <n> Graph traversal depth (default: 1)
706
707
  -m, --max-symbols <n> Max related symbols (default: 50)
707
708
  -f, --format <fmt> Output format: json, markdown, text (default: json)
@@ -781,7 +782,7 @@ Examples:
781
782
  // Summarize command - generate hierarchical repository summaries
782
783
  args.shift();
783
784
  let rootDir = process.cwd();
784
- let outputPath = path.join(rootDir, "ai", "hierarchy.json");
785
+ let outputPath = getHierarchyPath(rootDir);
785
786
 
786
787
  for (let i = 0; i < args.length; i++) {
787
788
  const arg = args[i];
@@ -803,7 +804,7 @@ Usage: ai-first summarize [options]
803
804
 
804
805
  Options:
805
806
  -r, --root <dir> Root directory (default: current directory)
806
- -o, --output <path> Output path (default: ./ai/hierarchy.json)
807
+ -o, --output <path> Output path (default: ./ai-context/hierarchy.json)
807
808
  -h, --help Show help message
808
809
 
809
810
  Output:
@@ -834,7 +835,7 @@ Output:
834
835
  args.shift();
835
836
  const queryType = args.shift();
836
837
  let rootDir = process.cwd();
837
- let dbPath = path.join(rootDir, "ai", "index.db");
838
+ let dbPath = getIndexDbPath(rootDir);
838
839
 
839
840
  for (let i = 0; i < args.length; i++) {
840
841
  const arg = args[i];
@@ -842,7 +843,7 @@ Output:
842
843
  case "--root":
843
844
  case "-r":
844
845
  rootDir = args[++i];
845
- dbPath = path.join(rootDir, "ai", "index.db");
846
+ dbPath = getIndexDbPath(rootDir);
846
847
  break;
847
848
  case "--db":
848
849
  case "-d":
@@ -867,7 +868,7 @@ Subcommands:
867
868
 
868
869
  Options:
869
870
  -r, --root <dir> Root directory (default: current directory)
870
- -d, --db <path> Database path (default: ./ai/index.db)
871
+ -d, --db <path> Database path (default: ./ai-context/index.db)
871
872
  -h, --help Show help message
872
873
  `);
873
874
  process.exit(0);
@@ -1111,7 +1112,7 @@ Commands:
1111
1112
 
1112
1113
  Options:
1113
1114
  -r, --root <dir> Root directory to scan (default: current directory)
1114
- -o, --output <dir> Output directory (default: ./ai)
1115
+ -o, --output <dir> Output directory (default: ./ai-context)
1115
1116
  -h, --help Show help message
1116
1117
  `);
1117
1118
  process.exit(0);
@@ -0,0 +1,487 @@
1
+ export interface ArchitecturePattern {
2
+ name: string;
3
+ confidence: number;
4
+ evidence: string[];
5
+ }
6
+
7
+ export interface Layer {
8
+ name: string;
9
+ files: string[];
10
+ symbols: string[];
11
+ responsibility: string;
12
+ }
13
+
14
+ export interface ArchitectureAnalysis {
15
+ primary: ArchitecturePattern | null;
16
+ secondary: ArchitecturePattern[];
17
+ layers: Layer[];
18
+ entryPoints: string[];
19
+ }
20
+
21
+ interface PatternMatcher {
22
+ name: string;
23
+ analyze(
24
+ symbols: Array<{
25
+ id: string;
26
+ name: string;
27
+ type: string;
28
+ file: string;
29
+ }>,
30
+ dependencyGraph: {
31
+ edges: Array<{ from: string; to: string; type: string }>;
32
+ }
33
+ ): { confidence: number; evidence: string[] };
34
+ }
35
+
36
+ export class ArchitectureDetector {
37
+ private patterns: PatternMatcher[] = [
38
+ {
39
+ name: "MVC (Model-View-Controller)",
40
+ analyze: (symbols, graph) => {
41
+ const evidence: string[] = [];
42
+ let score = 0;
43
+
44
+ const controllers = symbols.filter(
45
+ (s) =>
46
+ s.name.toLowerCase().includes("controller") ||
47
+ s.file.toLowerCase().includes("controller")
48
+ );
49
+ const models = symbols.filter(
50
+ (s) =>
51
+ s.name.toLowerCase().includes("model") ||
52
+ s.file.toLowerCase().includes("model")
53
+ );
54
+ const views = symbols.filter(
55
+ (s) =>
56
+ s.name.toLowerCase().includes("view") ||
57
+ s.file.toLowerCase().includes("view")
58
+ );
59
+
60
+ if (controllers.length > 0) {
61
+ evidence.push(`Found ${controllers.length} controllers`);
62
+ score += 0.3;
63
+ }
64
+ if (models.length > 0) {
65
+ evidence.push(`Found ${models.length} models`);
66
+ score += 0.3;
67
+ }
68
+ if (views.length > 0) {
69
+ evidence.push(`Found ${views.length} views`);
70
+ score += 0.2;
71
+ }
72
+
73
+ const controllerToModel = graph.edges.some(
74
+ (e) =>
75
+ e.from.toLowerCase().includes("controller") &&
76
+ e.to.toLowerCase().includes("model")
77
+ );
78
+ if (controllerToModel) {
79
+ evidence.push("Controllers import Models");
80
+ score += 0.2;
81
+ }
82
+
83
+ return { confidence: Math.min(score, 1), evidence };
84
+ },
85
+ },
86
+ {
87
+ name: "Layered Architecture",
88
+ analyze: (symbols, graph) => {
89
+ const evidence: string[] = [];
90
+ let score = 0;
91
+
92
+ const layers = {
93
+ api: symbols.filter(
94
+ (s) =>
95
+ s.name.toLowerCase().includes("controller") ||
96
+ s.name.toLowerCase().includes("route") ||
97
+ s.name.toLowerCase().includes("handler") ||
98
+ s.file.toLowerCase().includes("controller") ||
99
+ s.file.toLowerCase().includes("routes")
100
+ ),
101
+ service: symbols.filter(
102
+ (s) =>
103
+ s.name.toLowerCase().includes("service") ||
104
+ s.name.toLowerCase().includes("usecase") ||
105
+ s.file.toLowerCase().includes("service") ||
106
+ s.file.toLowerCase().includes("usecase")
107
+ ),
108
+ data: symbols.filter(
109
+ (s) =>
110
+ s.name.toLowerCase().includes("repository") ||
111
+ s.name.toLowerCase().includes("dao") ||
112
+ s.name.toLowerCase().includes("model") ||
113
+ s.file.toLowerCase().includes("repository") ||
114
+ s.file.toLowerCase().includes("model")
115
+ ),
116
+ };
117
+
118
+ if (layers.api.length > 0) {
119
+ evidence.push(`API layer: ${layers.api.length} components`);
120
+ score += 0.25;
121
+ }
122
+ if (layers.service.length > 0) {
123
+ evidence.push(`Service layer: ${layers.service.length} components`);
124
+ score += 0.25;
125
+ }
126
+ if (layers.data.length > 0) {
127
+ evidence.push(`Data layer: ${layers.data.length} components`);
128
+ score += 0.25;
129
+ }
130
+
131
+ const hasFlow =
132
+ layers.api.some((api) =>
133
+ graph.edges.some(
134
+ (e) =>
135
+ e.from === api.id &&
136
+ layers.service.some((s) => s.id === e.to)
137
+ )
138
+ ) ||
139
+ layers.service.some((svc) =>
140
+ graph.edges.some(
141
+ (e) =>
142
+ e.from === svc.id &&
143
+ layers.data.some((d) => d.id === e.to)
144
+ )
145
+ );
146
+
147
+ if (hasFlow) {
148
+ evidence.push("Layer flow detected: API → Service → Data");
149
+ score += 0.25;
150
+ }
151
+
152
+ return { confidence: Math.min(score, 1), evidence };
153
+ },
154
+ },
155
+ {
156
+ name: "Clean Architecture",
157
+ analyze: (symbols, graph) => {
158
+ const evidence: string[] = [];
159
+ let score = 0;
160
+
161
+ const entities = symbols.filter(
162
+ (s) =>
163
+ s.file.toLowerCase().includes("entity") ||
164
+ s.file.toLowerCase().includes("domain")
165
+ );
166
+ const useCases = symbols.filter(
167
+ (s) =>
168
+ s.file.toLowerCase().includes("usecase") ||
169
+ s.file.toLowerCase().includes("interactor")
170
+ );
171
+ const interfaces = symbols.filter(
172
+ (s) =>
173
+ s.file.toLowerCase().includes("interface") ||
174
+ s.file.toLowerCase().includes("adapter")
175
+ );
176
+
177
+ if (entities.length > 0) {
178
+ evidence.push(`Entities layer: ${entities.length} components`);
179
+ score += 0.3;
180
+ }
181
+ if (useCases.length > 0) {
182
+ evidence.push(`Use Cases layer: ${useCases.length} components`);
183
+ score += 0.3;
184
+ }
185
+ if (interfaces.length > 0) {
186
+ evidence.push(`Interface Adapters: ${interfaces.length} components`);
187
+ score += 0.2;
188
+ }
189
+
190
+ const dependencyRule =
191
+ !graph.edges.some(
192
+ (e) =>
193
+ entities.some((ent) => ent.id === e.from) &&
194
+ useCases.some((uc) => uc.id === e.to)
195
+ );
196
+
197
+ if (dependencyRule && entities.length > 0) {
198
+ evidence.push("Dependency Rule: Entities have no external dependencies");
199
+ score += 0.2;
200
+ }
201
+
202
+ return { confidence: Math.min(score, 1), evidence };
203
+ },
204
+ },
205
+ {
206
+ name: "Hexagonal Architecture (Ports & Adapters)",
207
+ analyze: (symbols, graph) => {
208
+ const evidence: string[] = [];
209
+ let score = 0;
210
+
211
+ const ports = symbols.filter(
212
+ (s) =>
213
+ s.name.toLowerCase().includes("port") ||
214
+ s.file.toLowerCase().includes("port")
215
+ );
216
+ const adapters = symbols.filter(
217
+ (s) =>
218
+ s.name.toLowerCase().includes("adapter") ||
219
+ s.file.toLowerCase().includes("adapter")
220
+ );
221
+ const domain = symbols.filter(
222
+ (s) =>
223
+ s.file.toLowerCase().includes("domain") ||
224
+ (!s.file.toLowerCase().includes("adapter") &&
225
+ !s.file.toLowerCase().includes("port"))
226
+ );
227
+
228
+ if (ports.length > 0) {
229
+ evidence.push(`Ports: ${ports.length} interfaces`);
230
+ score += 0.3;
231
+ }
232
+ if (adapters.length > 0) {
233
+ evidence.push(`Adapters: ${adapters.length} implementations`);
234
+ score += 0.3;
235
+ }
236
+ if (domain.length > 0) {
237
+ evidence.push(`Domain: ${domain.length} components`);
238
+ score += 0.2;
239
+ }
240
+
241
+ const portImplementations = adapters.some((adapter) =>
242
+ graph.edges.some(
243
+ (e) =>
244
+ e.from === adapter.id &&
245
+ ports.some((p) => e.to.includes(p.name))
246
+ )
247
+ );
248
+
249
+ if (portImplementations) {
250
+ evidence.push("Adapters implement Ports");
251
+ score += 0.2;
252
+ }
253
+
254
+ return { confidence: Math.min(score, 1), evidence };
255
+ },
256
+ },
257
+ {
258
+ name: "Microservices",
259
+ analyze: (symbols, graph) => {
260
+ const evidence: string[] = [];
261
+ let score = 0;
262
+
263
+ const services = symbols.filter(
264
+ (s) =>
265
+ s.name.toLowerCase().includes("service") ||
266
+ s.file.toLowerCase().includes("service")
267
+ );
268
+
269
+ const independentServices = services.filter((svc) => {
270
+ const dependencies = graph.edges.filter((e) => e.from === svc.id);
271
+ return dependencies.length <= 3;
272
+ });
273
+
274
+ if (services.length >= 3) {
275
+ evidence.push(`Found ${services.length} services`);
276
+ score += 0.3;
277
+ }
278
+
279
+ if (independentServices.length / services.length > 0.5) {
280
+ evidence.push("Services are loosely coupled");
281
+ score += 0.3;
282
+ }
283
+
284
+ const noCycles = this.hasNoCircularDependencies(graph);
285
+ if (noCycles && services.length > 0) {
286
+ evidence.push("No circular dependencies between services");
287
+ score += 0.2;
288
+ }
289
+
290
+ return { confidence: Math.min(score, 1), evidence };
291
+ },
292
+ },
293
+ ];
294
+
295
+ detect(
296
+ symbols: Array<{
297
+ id: string;
298
+ name: string;
299
+ type: string;
300
+ file: string;
301
+ }>,
302
+ dependencyGraph: {
303
+ edges: Array<{ from: string; to: string; type: string }>;
304
+ }
305
+ ): ArchitectureAnalysis {
306
+ const results: ArchitecturePattern[] = [];
307
+
308
+ for (const pattern of this.patterns) {
309
+ const result = pattern.analyze(symbols, dependencyGraph);
310
+ if (result.confidence > 0.3) {
311
+ results.push({
312
+ name: pattern.name,
313
+ confidence: result.confidence,
314
+ evidence: result.evidence,
315
+ });
316
+ }
317
+ }
318
+
319
+ results.sort((a, b) => b.confidence - a.confidence);
320
+
321
+ return {
322
+ primary: results[0] || null,
323
+ secondary: results.slice(1),
324
+ layers: this.detectLayers(symbols),
325
+ entryPoints: this.detectEntryPoints(symbols),
326
+ };
327
+ }
328
+
329
+ private detectLayers(
330
+ symbols: Array<{
331
+ id: string;
332
+ name: string;
333
+ type: string;
334
+ file: string;
335
+ }>
336
+ ): Layer[] {
337
+ const layers: Layer[] = [];
338
+
339
+ const apiLayer = {
340
+ name: "API / Presentation",
341
+ files: [] as string[],
342
+ symbols: [] as string[],
343
+ responsibility: "HTTP request handling, routing, validation",
344
+ };
345
+
346
+ const serviceLayer = {
347
+ name: "Service / Business Logic",
348
+ files: [] as string[],
349
+ symbols: [] as string[],
350
+ responsibility: "Business rules, use cases, workflows",
351
+ };
352
+
353
+ const dataLayer = {
354
+ name: "Data / Persistence",
355
+ files: [] as string[],
356
+ symbols: [] as string[],
357
+ responsibility: "Database access, queries, caching",
358
+ };
359
+
360
+ for (const symbol of symbols) {
361
+ const name = symbol.name.toLowerCase();
362
+ const file = symbol.file.toLowerCase();
363
+
364
+ if (
365
+ name.includes("controller") ||
366
+ name.includes("route") ||
367
+ name.includes("handler") ||
368
+ name.includes("endpoint") ||
369
+ file.includes("controller") ||
370
+ file.includes("routes") ||
371
+ file.includes("api")
372
+ ) {
373
+ if (!apiLayer.files.includes(symbol.file)) {
374
+ apiLayer.files.push(symbol.file);
375
+ }
376
+ apiLayer.symbols.push(symbol.id);
377
+ } else if (
378
+ name.includes("service") ||
379
+ name.includes("usecase") ||
380
+ name.includes("manager") ||
381
+ name.includes("handler") ||
382
+ file.includes("service") ||
383
+ file.includes("usecase") ||
384
+ file.includes("business")
385
+ ) {
386
+ if (!serviceLayer.files.includes(symbol.file)) {
387
+ serviceLayer.files.push(symbol.file);
388
+ }
389
+ serviceLayer.symbols.push(symbol.id);
390
+ } else if (
391
+ name.includes("repository") ||
392
+ name.includes("dao") ||
393
+ name.includes("model") ||
394
+ name.includes("entity") ||
395
+ file.includes("repository") ||
396
+ file.includes("model") ||
397
+ file.includes("data") ||
398
+ file.includes("db")
399
+ ) {
400
+ if (!dataLayer.files.includes(symbol.file)) {
401
+ dataLayer.files.push(symbol.file);
402
+ }
403
+ dataLayer.symbols.push(symbol.id);
404
+ }
405
+ }
406
+
407
+ if (apiLayer.symbols.length > 0) layers.push(apiLayer);
408
+ if (serviceLayer.symbols.length > 0) layers.push(serviceLayer);
409
+ if (dataLayer.symbols.length > 0) layers.push(dataLayer);
410
+
411
+ return layers;
412
+ }
413
+
414
+ private detectEntryPoints(
415
+ symbols: Array<{
416
+ id: string;
417
+ name: string;
418
+ type: string;
419
+ file: string;
420
+ }>
421
+ ): string[] {
422
+ const entryPoints: string[] = [];
423
+
424
+ const patterns = [
425
+ /main$/i,
426
+ /index$/i,
427
+ /init$/i,
428
+ /start$/i,
429
+ /server$/i,
430
+ /app$/i,
431
+ /bootstrap$/i,
432
+ /handler$/i,
433
+ /controller$/i,
434
+ ];
435
+
436
+ for (const symbol of symbols) {
437
+ const name = symbol.name.toLowerCase();
438
+ const file = symbol.file.toLowerCase();
439
+
440
+ if (
441
+ patterns.some((p) => p.test(name)) ||
442
+ file.includes("main.") ||
443
+ file.includes("index.") ||
444
+ file.includes("app.") ||
445
+ file.includes("server.")
446
+ ) {
447
+ entryPoints.push(symbol.id);
448
+ }
449
+ }
450
+
451
+ return [...new Set(entryPoints)];
452
+ }
453
+
454
+ private hasNoCircularDependencies(graph: {
455
+ edges: Array<{ from: string; to: string; type: string }>;
456
+ }): boolean {
457
+ const nodes = [...new Set(graph.edges.flatMap((e) => [e.from, e.to]))];
458
+ const visited = new Set<string>();
459
+ const recursionStack = new Set<string>();
460
+
461
+ const dfs = (node: string): boolean => {
462
+ if (recursionStack.has(node)) return false;
463
+ if (visited.has(node)) return true;
464
+
465
+ visited.add(node);
466
+ recursionStack.add(node);
467
+
468
+ const outgoing = graph.edges.filter((e) => e.from === node);
469
+ for (const edge of outgoing) {
470
+ if (!dfs(edge.to)) return false;
471
+ }
472
+
473
+ recursionStack.delete(node);
474
+ return true;
475
+ };
476
+
477
+ for (const node of nodes) {
478
+ if (!visited.has(node)) {
479
+ if (!dfs(node)) return false;
480
+ }
481
+ }
482
+
483
+ return true;
484
+ }
485
+ }
486
+
487
+ export const architectureDetector = new ArchitectureDetector();