ai-first-cli 1.2.2 → 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 (475) 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/adapters/baseAdapter.d.ts +1 -1
  13. package/dist/core/adapters/baseAdapter.d.ts.map +1 -1
  14. package/dist/core/adapters/baseAdapter.js +50 -12
  15. package/dist/core/adapters/baseAdapter.js.map +1 -1
  16. package/dist/core/analysis/architectureDetector.d.ts +37 -0
  17. package/dist/core/analysis/architectureDetector.d.ts.map +1 -0
  18. package/dist/core/analysis/architectureDetector.js +316 -0
  19. package/dist/core/analysis/architectureDetector.js.map +1 -0
  20. package/dist/core/analysis/callGraphBuilder.d.ts +37 -0
  21. package/dist/core/analysis/callGraphBuilder.d.ts.map +1 -0
  22. package/dist/core/analysis/callGraphBuilder.js +101 -0
  23. package/dist/core/analysis/callGraphBuilder.js.map +1 -0
  24. package/dist/core/analysis/dependencyAnalyzer.d.ts +45 -0
  25. package/dist/core/analysis/dependencyAnalyzer.d.ts.map +1 -0
  26. package/dist/core/analysis/dependencyAnalyzer.js +98 -0
  27. package/dist/core/analysis/dependencyAnalyzer.js.map +1 -0
  28. package/dist/core/analysis/index.d.ts +5 -0
  29. package/dist/core/analysis/index.d.ts.map +1 -0
  30. package/dist/core/analysis/index.js +5 -0
  31. package/dist/core/analysis/index.js.map +1 -0
  32. package/dist/core/analysis/inheritanceAnalyzer.d.ts +35 -0
  33. package/dist/core/analysis/inheritanceAnalyzer.d.ts.map +1 -0
  34. package/dist/core/analysis/inheritanceAnalyzer.js +115 -0
  35. package/dist/core/analysis/inheritanceAnalyzer.js.map +1 -0
  36. package/dist/core/ccp.d.ts.map +1 -1
  37. package/dist/core/ccp.js +3 -2
  38. package/dist/core/ccp.js.map +1 -1
  39. package/dist/core/generation/aiContextGenerator.d.ts +71 -0
  40. package/dist/core/generation/aiContextGenerator.d.ts.map +1 -0
  41. package/dist/core/generation/aiContextGenerator.js +217 -0
  42. package/dist/core/generation/aiContextGenerator.js.map +1 -0
  43. package/dist/core/generation/architectureGenerator.d.ts +17 -0
  44. package/dist/core/generation/architectureGenerator.d.ts.map +1 -0
  45. package/dist/core/generation/architectureGenerator.js +160 -0
  46. package/dist/core/generation/architectureGenerator.js.map +1 -0
  47. package/dist/core/generation/flowGenerator.d.ts +52 -0
  48. package/dist/core/generation/flowGenerator.d.ts.map +1 -0
  49. package/dist/core/generation/flowGenerator.js +164 -0
  50. package/dist/core/generation/flowGenerator.js.map +1 -0
  51. package/dist/core/generation/index.d.ts +4 -0
  52. package/dist/core/generation/index.d.ts.map +1 -0
  53. package/dist/core/generation/index.js +4 -0
  54. package/dist/core/generation/index.js.map +1 -0
  55. package/dist/core/hierarchyGenerator.d.ts.map +1 -1
  56. package/dist/core/hierarchyGenerator.js +3 -2
  57. package/dist/core/hierarchyGenerator.js.map +1 -1
  58. package/dist/core/parsers/index.d.ts +20 -0
  59. package/dist/core/parsers/index.d.ts.map +1 -0
  60. package/dist/core/parsers/index.js +76 -0
  61. package/dist/core/parsers/index.js.map +1 -0
  62. package/dist/core/parsers/pythonParser.d.ts +37 -0
  63. package/dist/core/parsers/pythonParser.d.ts.map +1 -0
  64. package/dist/core/parsers/pythonParser.js +229 -0
  65. package/dist/core/parsers/pythonParser.js.map +1 -0
  66. package/dist/core/parsers/typescriptParser.d.ts +54 -0
  67. package/dist/core/parsers/typescriptParser.d.ts.map +1 -0
  68. package/dist/core/parsers/typescriptParser.js +291 -0
  69. package/dist/core/parsers/typescriptParser.js.map +1 -0
  70. package/dist/core/pipeline.d.ts +42 -0
  71. package/dist/core/pipeline.d.ts.map +1 -0
  72. package/dist/core/pipeline.js +172 -0
  73. package/dist/core/pipeline.js.map +1 -0
  74. package/dist/core/semanticContexts.d.ts.map +1 -1
  75. package/dist/core/semanticContexts.js +23 -61
  76. package/dist/core/semanticContexts.js.map +1 -1
  77. package/dist/utils/constants.d.ts +46 -0
  78. package/dist/utils/constants.d.ts.map +1 -0
  79. package/dist/utils/constants.js +67 -0
  80. package/dist/utils/constants.js.map +1 -0
  81. package/install.sh +143 -17
  82. package/package.json +1 -1
  83. package/run-all-tests.sh +184 -0
  84. package/src/analyzers/symbols.ts +12 -7
  85. package/src/analyzers/techStack.ts +203 -3
  86. package/src/commands/ai-first.ts +14 -13
  87. package/src/core/adapters/baseAdapter.ts +61 -12
  88. package/src/core/analysis/architectureDetector.ts +487 -0
  89. package/src/core/analysis/callGraphBuilder.ts +158 -0
  90. package/src/core/analysis/dependencyAnalyzer.ts +167 -0
  91. package/src/core/analysis/index.ts +28 -0
  92. package/src/core/analysis/inheritanceAnalyzer.ts +169 -0
  93. package/src/core/ccp.ts +3 -2
  94. package/src/core/generation/aiContextGenerator.ts +335 -0
  95. package/src/core/generation/architectureGenerator.ts +200 -0
  96. package/src/core/generation/flowGenerator.ts +238 -0
  97. package/src/core/generation/index.ts +16 -0
  98. package/src/core/hierarchyGenerator.ts +3 -2
  99. package/src/core/parsers/index.ts +99 -0
  100. package/src/core/parsers/pythonParser.ts +302 -0
  101. package/src/core/parsers/typescriptParser.ts +445 -0
  102. package/src/core/pipeline.ts +241 -0
  103. package/src/core/semanticContexts.ts +25 -67
  104. package/src/utils/constants.ts +78 -0
  105. package/tests/analysis.test.ts +283 -0
  106. package/tests/architectureDetector.test.ts +137 -0
  107. package/tests/generation.test.ts +216 -0
  108. package/tests/parserRegistry.test.ts +139 -0
  109. package/tests/pipeline.integration.test.ts +245 -0
  110. package/tests/pythonParser.test.ts +210 -0
  111. package/tests/typescriptParser.test.ts +197 -0
  112. package/.ai-dev/index.db +0 -0
  113. package/ANALISIS_COMPLETO.md +0 -424
  114. package/ANALISIS_MEJORAS.md +0 -327
  115. package/BUGS.md +0 -455
  116. package/PLAN_MEJORAS.md +0 -216
  117. package/STATUS_ADAPTADORES +0 -126
  118. package/TEST_RESULTS.md +0 -198
  119. package/TEST_RESULTS_COMPARATIVE.md +0 -159
  120. package/TEST_RESULTS_COMPLETE.md +0 -127
  121. package/TEST_RESULTS_COMPREHENSIVE.md +0 -208
  122. package/TEST_RESULTS_PHASE1.md +0 -420
  123. package/ai-context/ai_context.md +0 -130
  124. package/ai-context/ai_rules.md +0 -54
  125. package/ai-context/architecture.md +0 -136
  126. package/ai-context/cache.json +0 -2349
  127. package/ai-context/ccp/jira-123/context.json +0 -7
  128. package/ai-context/context/features/commands.json +0 -18
  129. package/ai-context/context/features/src.json +0 -61
  130. package/ai-context/context/features/test-projects.json +0 -69
  131. package/ai-context/context/flows/account.json +0 -9
  132. package/ai-context/context/flows/ai-first.json +0 -9
  133. package/ai-context/context/flows/api.json +0 -9
  134. package/ai-context/context/flows/auth.json +0 -13
  135. package/ai-context/context/flows/category.json +0 -12
  136. package/ai-context/context/flows/comment.json +0 -16
  137. package/ai-context/context/flows/dashboard.json +0 -9
  138. package/ai-context/context/flows/doctor.json +0 -9
  139. package/ai-context/context/flows/explore.json +0 -9
  140. package/ai-context/context/flows/login.json +0 -9
  141. package/ai-context/context/flows/opportunity.json +0 -9
  142. package/ai-context/context/flows/post.json +0 -18
  143. package/ai-context/context/flows/routes.json +0 -19
  144. package/ai-context/context/flows/user.json +0 -20
  145. package/ai-context/context/flows/users.json +0 -9
  146. package/ai-context/context/flows/views.json +0 -14
  147. package/ai-context/context/repo.json +0 -56
  148. package/ai-context/context/utils.json +0 -7
  149. package/ai-context/conventions.md +0 -53
  150. package/ai-context/dependencies.json +0 -2946
  151. package/ai-context/embeddings.json +0 -23828
  152. package/ai-context/entrypoints.md +0 -42
  153. package/ai-context/files.json +0 -2944
  154. package/ai-context/git/commit-activity.json +0 -8646
  155. package/ai-context/git/recent-features.json +0 -1
  156. package/ai-context/git/recent-files.json +0 -52
  157. package/ai-context/git/recent-flows.json +0 -1
  158. package/ai-context/graph/knowledge-graph.json +0 -44314
  159. package/ai-context/graph/module-graph.json +0 -866
  160. package/ai-context/graph/symbol-graph.json +0 -200622
  161. package/ai-context/graph/symbol-references.json +0 -6778
  162. package/ai-context/hierarchy.json +0 -20
  163. package/ai-context/index-state.json +0 -4340
  164. package/ai-context/index.db +0 -0
  165. package/ai-context/modules.json +0 -532
  166. package/ai-context/project.json +0 -30
  167. package/ai-context/repo_map.json +0 -5818
  168. package/ai-context/repo_map.md +0 -1327
  169. package/ai-context/schema.json +0 -5
  170. package/ai-context/summary.md +0 -42
  171. package/ai-context/symbols.json +0 -7
  172. package/ai-context/tech_stack.md +0 -46
  173. package/ai-context/tools.json +0 -10
  174. package/test-projects/django-app/.ai-dev/index.db +0 -0
  175. package/test-projects/django-app/ai-context/ai_context.md +0 -92
  176. package/test-projects/django-app/ai-context/ai_rules.md +0 -47
  177. package/test-projects/django-app/ai-context/architecture.md +0 -57
  178. package/test-projects/django-app/ai-context/cache.json +0 -169
  179. package/test-projects/django-app/ai-context/context/flows/views.json +0 -10
  180. package/test-projects/django-app/ai-context/conventions.md +0 -51
  181. package/test-projects/django-app/ai-context/dependencies.json +0 -312
  182. package/test-projects/django-app/ai-context/entrypoints.md +0 -4
  183. package/test-projects/django-app/ai-context/files.json +0 -209
  184. package/test-projects/django-app/ai-context/graph/knowledge-graph.json +0 -36
  185. package/test-projects/django-app/ai-context/graph/module-graph.json +0 -145
  186. package/test-projects/django-app/ai-context/graph/symbol-graph.json +0 -1488
  187. package/test-projects/django-app/ai-context/graph/symbol-references.json +0 -1
  188. package/test-projects/django-app/ai-context/index-state.json +0 -294
  189. package/test-projects/django-app/ai-context/index.db +0 -0
  190. package/test-projects/django-app/ai-context/modules.json +0 -35
  191. package/test-projects/django-app/ai-context/project.json +0 -11
  192. package/test-projects/django-app/ai-context/repo_map.json +0 -412
  193. package/test-projects/django-app/ai-context/repo_map.md +0 -105
  194. package/test-projects/django-app/ai-context/schema.json +0 -5
  195. package/test-projects/django-app/ai-context/summary.md +0 -15
  196. package/test-projects/django-app/ai-context/symbols.json +0 -1
  197. package/test-projects/django-app/ai-context/tech_stack.md +0 -32
  198. package/test-projects/django-app/ai-context/tools.json +0 -10
  199. package/test-projects/express-api/ai-context/ai_context.md +0 -112
  200. package/test-projects/express-api/ai-context/ai_rules.md +0 -50
  201. package/test-projects/express-api/ai-context/architecture.md +0 -62
  202. package/test-projects/express-api/ai-context/context/features/controllers.json +0 -13
  203. package/test-projects/express-api/ai-context/context/features/services.json +0 -13
  204. package/test-projects/express-api/ai-context/context/flows/auth.json +0 -12
  205. package/test-projects/express-api/ai-context/context/flows/user.json +0 -13
  206. package/test-projects/express-api/ai-context/conventions.md +0 -51
  207. package/test-projects/express-api/ai-context/dependencies.json +0 -54
  208. package/test-projects/express-api/ai-context/entrypoints.md +0 -17
  209. package/test-projects/express-api/ai-context/modules.json +0 -30
  210. package/test-projects/express-api/ai-context/project.json +0 -15
  211. package/test-projects/express-api/ai-context/repo_map.json +0 -100
  212. package/test-projects/express-api/ai-context/repo_map.md +0 -36
  213. package/test-projects/express-api/ai-context/schema.json +0 -5
  214. package/test-projects/express-api/ai-context/summary.md +0 -14
  215. package/test-projects/express-api/ai-context/symbols.json +0 -7
  216. package/test-projects/express-api/ai-context/tech_stack.md +0 -38
  217. package/test-projects/express-api/ai-context/tools.json +0 -10
  218. package/test-projects/fastapi-app/.ai-dev/index.db +0 -0
  219. package/test-projects/fastapi-app/ai-context/ai_context.md +0 -89
  220. package/test-projects/fastapi-app/ai-context/ai_rules.md +0 -47
  221. package/test-projects/fastapi-app/ai-context/architecture.md +0 -39
  222. package/test-projects/fastapi-app/ai-context/cache.json +0 -125
  223. package/test-projects/fastapi-app/ai-context/conventions.md +0 -51
  224. package/test-projects/fastapi-app/ai-context/dependencies.json +0 -244
  225. package/test-projects/fastapi-app/ai-context/entrypoints.md +0 -4
  226. package/test-projects/fastapi-app/ai-context/files.json +0 -154
  227. package/test-projects/fastapi-app/ai-context/graph/knowledge-graph.json +0 -15
  228. package/test-projects/fastapi-app/ai-context/graph/module-graph.json +0 -78
  229. package/test-projects/fastapi-app/ai-context/graph/symbol-graph.json +0 -1724
  230. package/test-projects/fastapi-app/ai-context/graph/symbol-references.json +0 -51
  231. package/test-projects/fastapi-app/ai-context/index-state.json +0 -217
  232. package/test-projects/fastapi-app/ai-context/index.db +0 -0
  233. package/test-projects/fastapi-app/ai-context/modules.json +0 -16
  234. package/test-projects/fastapi-app/ai-context/project.json +0 -9
  235. package/test-projects/fastapi-app/ai-context/repo_map.json +0 -298
  236. package/test-projects/fastapi-app/ai-context/repo_map.md +0 -74
  237. package/test-projects/fastapi-app/ai-context/schema.json +0 -5
  238. package/test-projects/fastapi-app/ai-context/summary.md +0 -12
  239. package/test-projects/fastapi-app/ai-context/symbols.json +0 -1
  240. package/test-projects/fastapi-app/ai-context/tech_stack.md +0 -32
  241. package/test-projects/fastapi-app/ai-context/tools.json +0 -10
  242. package/test-projects/flask-app/.ai-dev/index.db +0 -0
  243. package/test-projects/flask-app/ai-context/ai_context.md +0 -94
  244. package/test-projects/flask-app/ai-context/ai_rules.md +0 -47
  245. package/test-projects/flask-app/ai-context/architecture.md +0 -49
  246. package/test-projects/flask-app/ai-context/cache.json +0 -157
  247. package/test-projects/flask-app/ai-context/context/features/app.json +0 -25
  248. package/test-projects/flask-app/ai-context/context/flows/routes.json +0 -14
  249. package/test-projects/flask-app/ai-context/conventions.md +0 -51
  250. package/test-projects/flask-app/ai-context/dependencies.json +0 -298
  251. package/test-projects/flask-app/ai-context/entrypoints.md +0 -4
  252. package/test-projects/flask-app/ai-context/files.json +0 -194
  253. package/test-projects/flask-app/ai-context/graph/knowledge-graph.json +0 -60
  254. package/test-projects/flask-app/ai-context/graph/module-graph.json +0 -95
  255. package/test-projects/flask-app/ai-context/graph/symbol-graph.json +0 -1448
  256. package/test-projects/flask-app/ai-context/graph/symbol-references.json +0 -45
  257. package/test-projects/flask-app/ai-context/index-state.json +0 -273
  258. package/test-projects/flask-app/ai-context/index.db +0 -0
  259. package/test-projects/flask-app/ai-context/modules.json +0 -21
  260. package/test-projects/flask-app/ai-context/project.json +0 -13
  261. package/test-projects/flask-app/ai-context/repo_map.json +0 -400
  262. package/test-projects/flask-app/ai-context/repo_map.md +0 -98
  263. package/test-projects/flask-app/ai-context/schema.json +0 -5
  264. package/test-projects/flask-app/ai-context/summary.md +0 -13
  265. package/test-projects/flask-app/ai-context/symbols.json +0 -1
  266. package/test-projects/flask-app/ai-context/tech_stack.md +0 -32
  267. package/test-projects/flask-app/ai-context/tools.json +0 -10
  268. package/test-projects/laravel-app/.ai-dev/index.db +0 -0
  269. package/test-projects/laravel-app/ai-context/ai_context.md +0 -97
  270. package/test-projects/laravel-app/ai-context/ai_rules.md +0 -47
  271. package/test-projects/laravel-app/ai-context/architecture.md +0 -60
  272. package/test-projects/laravel-app/ai-context/cache.json +0 -161
  273. package/test-projects/laravel-app/ai-context/context/features/app.json +0 -21
  274. package/test-projects/laravel-app/ai-context/context/flows/.json +0 -9
  275. package/test-projects/laravel-app/ai-context/context/flows/category.json +0 -12
  276. package/test-projects/laravel-app/ai-context/context/flows/comment.json +0 -12
  277. package/test-projects/laravel-app/ai-context/context/flows/post.json +0 -12
  278. package/test-projects/laravel-app/ai-context/context/flows/unnamed.json +0 -9
  279. package/test-projects/laravel-app/ai-context/conventions.md +0 -51
  280. package/test-projects/laravel-app/ai-context/dependencies.json +0 -6
  281. package/test-projects/laravel-app/ai-context/entrypoints.md +0 -4
  282. package/test-projects/laravel-app/ai-context/files.json +0 -199
  283. package/test-projects/laravel-app/ai-context/graph/knowledge-graph.json +0 -98
  284. package/test-projects/laravel-app/ai-context/graph/module-graph.json +0 -30
  285. package/test-projects/laravel-app/ai-context/graph/symbol-graph.json +0 -5
  286. package/test-projects/laravel-app/ai-context/graph/symbol-references.json +0 -1
  287. package/test-projects/laravel-app/ai-context/index-state.json +0 -280
  288. package/test-projects/laravel-app/ai-context/index.db +0 -0
  289. package/test-projects/laravel-app/ai-context/modules.json +0 -29
  290. package/test-projects/laravel-app/ai-context/project.json +0 -17
  291. package/test-projects/laravel-app/ai-context/repo_map.json +0 -419
  292. package/test-projects/laravel-app/ai-context/repo_map.md +0 -106
  293. package/test-projects/laravel-app/ai-context/schema.json +0 -5
  294. package/test-projects/laravel-app/ai-context/summary.md +0 -15
  295. package/test-projects/laravel-app/ai-context/symbols.json +0 -1
  296. package/test-projects/laravel-app/ai-context/tech_stack.md +0 -34
  297. package/test-projects/laravel-app/ai-context/tools.json +0 -10
  298. package/test-projects/nestjs-backend/.ai-dev/index.db +0 -0
  299. package/test-projects/nestjs-backend/ai-context/ai_context.md +0 -111
  300. package/test-projects/nestjs-backend/ai-context/ai_rules.md +0 -52
  301. package/test-projects/nestjs-backend/ai-context/architecture.md +0 -49
  302. package/test-projects/nestjs-backend/ai-context/cache.json +0 -169
  303. package/test-projects/nestjs-backend/ai-context/context/features/src.json +0 -23
  304. package/test-projects/nestjs-backend/ai-context/context/flows/auth.controller.json +0 -14
  305. package/test-projects/nestjs-backend/ai-context/context/flows/auth.json +0 -10
  306. package/test-projects/nestjs-backend/ai-context/context/flows/users..json +0 -10
  307. package/test-projects/nestjs-backend/ai-context/context/flows/users.controller.json +0 -14
  308. package/test-projects/nestjs-backend/ai-context/context/flows/users.json +0 -10
  309. package/test-projects/nestjs-backend/ai-context/conventions.md +0 -52
  310. package/test-projects/nestjs-backend/ai-context/dependencies.json +0 -152
  311. package/test-projects/nestjs-backend/ai-context/entrypoints.md +0 -18
  312. package/test-projects/nestjs-backend/ai-context/files.json +0 -209
  313. package/test-projects/nestjs-backend/ai-context/graph/knowledge-graph.json +0 -132
  314. package/test-projects/nestjs-backend/ai-context/graph/module-graph.json +0 -29
  315. package/test-projects/nestjs-backend/ai-context/graph/symbol-graph.json +0 -304
  316. package/test-projects/nestjs-backend/ai-context/graph/symbol-references.json +0 -5
  317. package/test-projects/nestjs-backend/ai-context/index-state.json +0 -294
  318. package/test-projects/nestjs-backend/ai-context/index.db +0 -0
  319. package/test-projects/nestjs-backend/ai-context/modules.json +0 -19
  320. package/test-projects/nestjs-backend/ai-context/project.json +0 -18
  321. package/test-projects/nestjs-backend/ai-context/repo_map.json +0 -427
  322. package/test-projects/nestjs-backend/ai-context/repo_map.md +0 -104
  323. package/test-projects/nestjs-backend/ai-context/schema.json +0 -5
  324. package/test-projects/nestjs-backend/ai-context/summary.md +0 -13
  325. package/test-projects/nestjs-backend/ai-context/symbols.json +0 -1
  326. package/test-projects/nestjs-backend/ai-context/tech_stack.md +0 -38
  327. package/test-projects/nestjs-backend/ai-context/tools.json +0 -10
  328. package/test-projects/python-cli/.ai-dev/index.db +0 -0
  329. package/test-projects/python-cli/ai-context/ai_context.md +0 -95
  330. package/test-projects/python-cli/ai-context/ai_rules.md +0 -47
  331. package/test-projects/python-cli/ai-context/architecture.md +0 -55
  332. package/test-projects/python-cli/ai-context/cache.json +0 -149
  333. package/test-projects/python-cli/ai-context/context/features/cli.json +0 -16
  334. package/test-projects/python-cli/ai-context/context/flows/list_.json +0 -9
  335. package/test-projects/python-cli/ai-context/context/flows/remove_.json +0 -9
  336. package/test-projects/python-cli/ai-context/conventions.md +0 -51
  337. package/test-projects/python-cli/ai-context/dependencies.json +0 -66
  338. package/test-projects/python-cli/ai-context/entrypoints.md +0 -4
  339. package/test-projects/python-cli/ai-context/files.json +0 -184
  340. package/test-projects/python-cli/ai-context/graph/knowledge-graph.json +0 -83
  341. package/test-projects/python-cli/ai-context/graph/module-graph.json +0 -31
  342. package/test-projects/python-cli/ai-context/graph/symbol-graph.json +0 -358
  343. package/test-projects/python-cli/ai-context/graph/symbol-references.json +0 -11
  344. package/test-projects/python-cli/ai-context/index-state.json +0 -259
  345. package/test-projects/python-cli/ai-context/index.db +0 -0
  346. package/test-projects/python-cli/ai-context/modules.json +0 -21
  347. package/test-projects/python-cli/ai-context/project.json +0 -15
  348. package/test-projects/python-cli/ai-context/repo_map.json +0 -367
  349. package/test-projects/python-cli/ai-context/repo_map.md +0 -93
  350. package/test-projects/python-cli/ai-context/schema.json +0 -5
  351. package/test-projects/python-cli/ai-context/summary.md +0 -14
  352. package/test-projects/python-cli/ai-context/symbols.json +0 -1
  353. package/test-projects/python-cli/ai-context/tech_stack.md +0 -32
  354. package/test-projects/python-cli/ai-context/tools.json +0 -10
  355. package/test-projects/rails-app/.ai-dev/index.db +0 -0
  356. package/test-projects/rails-app/ai-context/ai_context.md +0 -94
  357. package/test-projects/rails-app/ai-context/ai_rules.md +0 -47
  358. package/test-projects/rails-app/ai-context/architecture.md +0 -49
  359. package/test-projects/rails-app/ai-context/cache.json +0 -193
  360. package/test-projects/rails-app/ai-context/context/features/app.json +0 -24
  361. package/test-projects/rails-app/ai-context/context/features/config.json +0 -13
  362. package/test-projects/rails-app/ai-context/context/flows/application.json +0 -9
  363. package/test-projects/rails-app/ai-context/context/flows/application_.json +0 -9
  364. package/test-projects/rails-app/ai-context/context/flows/comments.json +0 -11
  365. package/test-projects/rails-app/ai-context/context/flows/comments_.json +0 -11
  366. package/test-projects/rails-app/ai-context/context/flows/posts.json +0 -11
  367. package/test-projects/rails-app/ai-context/context/flows/posts_.json +0 -11
  368. package/test-projects/rails-app/ai-context/context/flows/routes.json +0 -9
  369. package/test-projects/rails-app/ai-context/context/flows/users.json +0 -11
  370. package/test-projects/rails-app/ai-context/context/flows/users_.json +0 -11
  371. package/test-projects/rails-app/ai-context/conventions.md +0 -51
  372. package/test-projects/rails-app/ai-context/dependencies.json +0 -6
  373. package/test-projects/rails-app/ai-context/entrypoints.md +0 -4
  374. package/test-projects/rails-app/ai-context/files.json +0 -239
  375. package/test-projects/rails-app/ai-context/graph/knowledge-graph.json +0 -130
  376. package/test-projects/rails-app/ai-context/graph/module-graph.json +0 -27
  377. package/test-projects/rails-app/ai-context/graph/symbol-graph.json +0 -5
  378. package/test-projects/rails-app/ai-context/graph/symbol-references.json +0 -1
  379. package/test-projects/rails-app/ai-context/index-state.json +0 -336
  380. package/test-projects/rails-app/ai-context/index.db +0 -0
  381. package/test-projects/rails-app/ai-context/modules.json +0 -26
  382. package/test-projects/rails-app/ai-context/project.json +0 -22
  383. package/test-projects/rails-app/ai-context/repo_map.json +0 -486
  384. package/test-projects/rails-app/ai-context/repo_map.md +0 -117
  385. package/test-projects/rails-app/ai-context/schema.json +0 -5
  386. package/test-projects/rails-app/ai-context/summary.md +0 -13
  387. package/test-projects/rails-app/ai-context/symbols.json +0 -1
  388. package/test-projects/rails-app/ai-context/tech_stack.md +0 -32
  389. package/test-projects/rails-app/ai-context/tools.json +0 -10
  390. package/test-projects/react-app/.ai-dev/index.db +0 -0
  391. package/test-projects/react-app/ai-context/ai_context.md +0 -96
  392. package/test-projects/react-app/ai-context/ai_rules.md +0 -49
  393. package/test-projects/react-app/ai-context/architecture.md +0 -39
  394. package/test-projects/react-app/ai-context/cache.json +0 -153
  395. package/test-projects/react-app/ai-context/context/features/src.json +0 -18
  396. package/test-projects/react-app/ai-context/context/flows/UsersPage.json +0 -14
  397. package/test-projects/react-app/ai-context/context/flows/dashboard.json +0 -9
  398. package/test-projects/react-app/ai-context/context/flows/login.json +0 -9
  399. package/test-projects/react-app/ai-context/context/flows/users.json +0 -9
  400. package/test-projects/react-app/ai-context/conventions.md +0 -52
  401. package/test-projects/react-app/ai-context/dependencies.json +0 -128
  402. package/test-projects/react-app/ai-context/entrypoints.md +0 -4
  403. package/test-projects/react-app/ai-context/files.json +0 -189
  404. package/test-projects/react-app/ai-context/graph/knowledge-graph.json +0 -112
  405. package/test-projects/react-app/ai-context/graph/module-graph.json +0 -31
  406. package/test-projects/react-app/ai-context/graph/symbol-graph.json +0 -868
  407. package/test-projects/react-app/ai-context/graph/symbol-references.json +0 -31
  408. package/test-projects/react-app/ai-context/index-state.json +0 -266
  409. package/test-projects/react-app/ai-context/index.db +0 -0
  410. package/test-projects/react-app/ai-context/modules.json +0 -17
  411. package/test-projects/react-app/ai-context/project.json +0 -16
  412. package/test-projects/react-app/ai-context/repo_map.json +0 -391
  413. package/test-projects/react-app/ai-context/repo_map.md +0 -94
  414. package/test-projects/react-app/ai-context/schema.json +0 -5
  415. package/test-projects/react-app/ai-context/summary.md +0 -13
  416. package/test-projects/react-app/ai-context/symbols.json +0 -1
  417. package/test-projects/react-app/ai-context/tech_stack.md +0 -39
  418. package/test-projects/react-app/ai-context/tools.json +0 -10
  419. package/test-projects/salesforce-cli/.ai-dev/index.db +0 -0
  420. package/test-projects/salesforce-cli/ai-context/ai_context.md +0 -89
  421. package/test-projects/salesforce-cli/ai-context/ai_rules.md +0 -47
  422. package/test-projects/salesforce-cli/ai-context/architecture.md +0 -39
  423. package/test-projects/salesforce-cli/ai-context/cache.json +0 -125
  424. package/test-projects/salesforce-cli/ai-context/context/features/force-app.json +0 -14
  425. package/test-projects/salesforce-cli/ai-context/context/flows/account.json +0 -9
  426. package/test-projects/salesforce-cli/ai-context/context/flows/opportunity.json +0 -9
  427. package/test-projects/salesforce-cli/ai-context/conventions.md +0 -51
  428. package/test-projects/salesforce-cli/ai-context/dependencies.json +0 -6
  429. package/test-projects/salesforce-cli/ai-context/entrypoints.md +0 -4
  430. package/test-projects/salesforce-cli/ai-context/files.json +0 -154
  431. package/test-projects/salesforce-cli/ai-context/graph/knowledge-graph.json +0 -64
  432. package/test-projects/salesforce-cli/ai-context/graph/module-graph.json +0 -13
  433. package/test-projects/salesforce-cli/ai-context/graph/symbol-graph.json +0 -148
  434. package/test-projects/salesforce-cli/ai-context/graph/symbol-references.json +0 -1
  435. package/test-projects/salesforce-cli/ai-context/index-state.json +0 -217
  436. package/test-projects/salesforce-cli/ai-context/index.db +0 -0
  437. package/test-projects/salesforce-cli/ai-context/modules.json +0 -12
  438. package/test-projects/salesforce-cli/ai-context/project.json +0 -14
  439. package/test-projects/salesforce-cli/ai-context/repo_map.json +0 -328
  440. package/test-projects/salesforce-cli/ai-context/repo_map.md +0 -80
  441. package/test-projects/salesforce-cli/ai-context/schema.json +0 -5
  442. package/test-projects/salesforce-cli/ai-context/summary.md +0 -13
  443. package/test-projects/salesforce-cli/ai-context/symbols.json +0 -1
  444. package/test-projects/salesforce-cli/ai-context/tech_stack.md +0 -31
  445. package/test-projects/salesforce-cli/ai-context/tools.json +0 -10
  446. package/test-projects/spring-boot-app/.ai-dev/index.db +0 -0
  447. package/test-projects/spring-boot-app/ai-context/ai_context.md +0 -91
  448. package/test-projects/spring-boot-app/ai-context/ai_rules.md +0 -48
  449. package/test-projects/spring-boot-app/ai-context/architecture.md +0 -39
  450. package/test-projects/spring-boot-app/ai-context/cache.json +0 -173
  451. package/test-projects/spring-boot-app/ai-context/context/features/src.json +0 -26
  452. package/test-projects/spring-boot-app/ai-context/context/flows/PostController.json +0 -19
  453. package/test-projects/spring-boot-app/ai-context/context/flows/UserController.json +0 -19
  454. package/test-projects/spring-boot-app/ai-context/context/flows/comment.json +0 -11
  455. package/test-projects/spring-boot-app/ai-context/context/flows/post.json +0 -14
  456. package/test-projects/spring-boot-app/ai-context/context/flows/user.json +0 -14
  457. package/test-projects/spring-boot-app/ai-context/conventions.md +0 -52
  458. package/test-projects/spring-boot-app/ai-context/dependencies.json +0 -326
  459. package/test-projects/spring-boot-app/ai-context/entrypoints.md +0 -4
  460. package/test-projects/spring-boot-app/ai-context/files.json +0 -214
  461. package/test-projects/spring-boot-app/ai-context/graph/knowledge-graph.json +0 -231
  462. package/test-projects/spring-boot-app/ai-context/graph/module-graph.json +0 -22
  463. package/test-projects/spring-boot-app/ai-context/graph/symbol-graph.json +0 -794
  464. package/test-projects/spring-boot-app/ai-context/graph/symbol-references.json +0 -70
  465. package/test-projects/spring-boot-app/ai-context/index-state.json +0 -301
  466. package/test-projects/spring-boot-app/ai-context/index.db +0 -0
  467. package/test-projects/spring-boot-app/ai-context/modules.json +0 -21
  468. package/test-projects/spring-boot-app/ai-context/project.json +0 -17
  469. package/test-projects/spring-boot-app/ai-context/repo_map.json +0 -461
  470. package/test-projects/spring-boot-app/ai-context/repo_map.md +0 -109
  471. package/test-projects/spring-boot-app/ai-context/schema.json +0 -5
  472. package/test-projects/spring-boot-app/ai-context/summary.md +0 -12
  473. package/test-projects/spring-boot-app/ai-context/symbols.json +0 -1
  474. package/test-projects/spring-boot-app/ai-context/tech_stack.md +0 -32
  475. 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);
@@ -60,23 +60,72 @@ export interface LayerRule {
60
60
  }
61
61
 
62
62
  /**
63
- * Default adapter configuration
63
+ * Universal entrypoint patterns - work across ALL languages and frameworks
64
+ */
65
+ const UNIVERSAL_ENTRYPOINTS = [
66
+ // CLI/Tool entrypoints
67
+ 'main', 'cli', 'cmd', 'command', 'run', 'exec', 'task', 'runner',
68
+
69
+ // App/Plugin/Extension entrypoints
70
+ 'app', 'plugin', 'extension', 'entrypoint', 'bootstrap', 'setup',
71
+ 'initialize', 'init', 'start', 'launch',
72
+
73
+ // Module entrypoints
74
+ 'index', '__main__', 'main',
75
+
76
+ // API/Server entrypoints
77
+ 'api', 'server', 'router', 'gateway',
78
+
79
+ // Web framework entrypoints
80
+ 'controller', 'handler', 'endpoint', 'view', 'page', 'screen', 'component',
81
+ 'route', 'routes', 'resource',
82
+
83
+ // Business logic entrypoints
84
+ 'service', 'usecase', 'interactor', 'action', 'actor',
85
+
86
+ // Async/Distributed entrypoints
87
+ 'job', 'worker', 'consumer', 'producer', 'queue', 'cron', 'schedule',
88
+
89
+ // Framework-agnostic patterns
90
+ 'serializer', 'mutation', 'query', 'resolver',
91
+ 'management', 'admin',
92
+
93
+ // Mobile entrypoints
94
+ 'activity', 'fragment', 'viewcontroller',
95
+
96
+ // Database entrypoints
97
+ 'repository', 'dao', 'mapper',
98
+ ];
99
+
100
+ /**
101
+ * Universal feature roots - directories that typically contain business features
102
+ */
103
+ const UNIVERSAL_FEATURE_ROOTS = [
104
+ 'src', 'app', 'lib', 'source', 'sources', 'modules', 'features',
105
+ 'services', 'internal', 'core', 'domain', 'business',
106
+ 'packages', 'components', 'pages', 'screens', 'views',
107
+ 'handlers', 'controllers', 'routes', 'api', 'api/src',
108
+ 'cmd', 'commands', 'scripts',
109
+ ];
110
+
111
+ /**
112
+ * Default adapter configuration - works for ANY project type
64
113
  */
65
114
  export const DEFAULT_ADAPTER: AnalysisAdapter = {
66
115
  name: 'default',
67
116
  displayName: 'Default',
68
117
  detectionSignals: [],
69
- featureRoots: ['src', 'app', 'lib', 'modules'],
70
- ignoredFolders: ['utils', 'helpers', 'types', 'interfaces', 'constants', 'config', 'dto', 'models', 'common', 'shared', 'node_modules', '.git'],
71
- entrypointPatterns: ['controller', 'route', 'handler', 'command', 'service'],
118
+ featureRoots: UNIVERSAL_FEATURE_ROOTS,
119
+ ignoredFolders: ['utils', 'helpers', 'types', 'interfaces', 'constants', 'config', 'dto', 'models', 'common', 'shared', 'node_modules', '.git', 'dist', 'build', 'coverage', '__tests__', 'test', 'tests', '.next', '.nuxt', '.vite', '__pycache__', '.venv', 'venv', 'scripts', 'docs', 'migrations', 'spec', 'test'],
120
+ entrypointPatterns: UNIVERSAL_ENTRYPOINTS,
72
121
  layerRules: [
73
- { name: 'api', priority: 1, patterns: ['controller', 'handler', 'route', 'router', 'api', 'endpoint'] },
74
- { name: 'service', priority: 2, patterns: ['service', 'services', 'usecase', 'interactor'] },
75
- { name: 'data', priority: 3, patterns: ['repository', 'repo', 'dal', 'dao', 'data', 'persistence'] },
76
- { name: 'domain', priority: 4, patterns: ['model', 'entity', 'schema', 'domain'] },
77
- { name: 'util', priority: 5, patterns: ['util', 'helper', 'lib', 'common'] }
122
+ { name: 'api', priority: 1, patterns: ['controller', 'handler', 'route', 'router', 'api', 'endpoint', 'page', 'screen', 'view', 'component', 'gateway', 'resource'] },
123
+ { name: 'service', priority: 2, patterns: ['service', 'services', 'usecase', 'interactor', 'action', 'actor', 'mutation', 'query', 'resolver'] },
124
+ { name: 'data', priority: 3, patterns: ['repository', 'repo', 'dal', 'dao', 'data', 'persistence', 'mapper', 'dto'] },
125
+ { name: 'domain', priority: 4, patterns: ['model', 'entity', 'schema', 'domain', 'event'] },
126
+ { name: 'util', priority: 5, patterns: ['util', 'helper', 'lib', 'common', 'static', 'constants'] }
78
127
  ],
79
- supportedExtensions: ['.ts', '.tsx', '.js', '.jsx', '.py', '.java', '.kt', '.go', '.rs', '.rb', '.php', '.cs', '.vue', '.svelte'],
80
- flowEntrypointPatterns: ['controller', 'route', 'handler', 'command'],
81
- flowExcludePatterns: ['repository', 'repo', 'utils', 'helper', 'model', 'entity', 'dto', 'type', 'interface', 'constant', 'config']
128
+ supportedExtensions: ['.ts', '.tsx', '.js', '.jsx', '.mjs', '.cjs', '.py', '.java', '.kt', '.go', '.rs', '.rb', '.php', '.cs', '.vue', '.svelte', '.swift', '.h', '.m', '.fs', '.fsx', '.rake', '.erb', '.html', '.css', '.scss', '.sass', '.less'],
129
+ flowEntrypointPatterns: UNIVERSAL_ENTRYPOINTS,
130
+ flowExcludePatterns: ['repository', 'repo', 'utils', 'helper', 'model', 'entity', 'dto', 'type', 'interface', 'constant', 'config', 'spec', 'test', 'tests', '__init__', '__pycache__', 'migrations']
82
131
  };
@@ -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();