@md-code/follow-architecture 0.1.0 → 0.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 (436) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/LICENSE +202 -0
  3. package/README.md +597 -126
  4. package/dist/aliases.d.ts +3 -0
  5. package/dist/aliases.js +12 -0
  6. package/dist/args.d.ts +14 -0
  7. package/dist/args.js +77 -0
  8. package/dist/bin/follow-architecture.d.ts +2 -0
  9. package/dist/bin/follow-architecture.js +23 -0
  10. package/dist/code-roles/classify.d.ts +11 -0
  11. package/dist/code-roles/classify.js +43 -0
  12. package/dist/code-roles/connector.d.ts +5 -0
  13. package/dist/code-roles/connector.js +114 -0
  14. package/dist/code-roles/project.d.ts +12 -0
  15. package/dist/code-roles/project.js +122 -0
  16. package/dist/code-roles/roles.d.ts +8 -0
  17. package/dist/code-roles/roles.js +190 -0
  18. package/dist/config-options.d.ts +53 -0
  19. package/dist/config-options.js +35 -0
  20. package/dist/config-project.d.ts +4 -0
  21. package/dist/config-project.js +74 -0
  22. package/dist/config-report.d.ts +19 -0
  23. package/dist/config-report.js +134 -0
  24. package/dist/config-rule.d.ts +70 -0
  25. package/dist/config-rule.js +118 -0
  26. package/dist/config-state.d.ts +14 -0
  27. package/dist/config-state.js +96 -0
  28. package/dist/config.d.ts +82 -0
  29. package/dist/config.js +38 -0
  30. package/dist/css/index.d.ts +27 -0
  31. package/dist/css/index.js +140 -0
  32. package/dist/css/syntax/css/gate.d.ts +2 -0
  33. package/dist/css/syntax/css/gate.js +69 -0
  34. package/dist/css/syntax/css/index.d.ts +7 -0
  35. package/dist/css/syntax/css/index.js +41 -0
  36. package/dist/css/syntax/css/reference.d.ts +3 -0
  37. package/dist/css/syntax/css/reference.js +24 -0
  38. package/dist/css/syntax/language.d.ts +25 -0
  39. package/dist/css/syntax/language.js +69 -0
  40. package/dist/css/syntax/scss/index.d.ts +25 -0
  41. package/dist/css/syntax/scss/index.js +85 -0
  42. package/dist/css/syntax/scss/reference.d.ts +3 -0
  43. package/dist/css/syntax/scss/reference.js +11 -0
  44. package/dist/css/syntax/styled/document.d.ts +68 -0
  45. package/dist/css/syntax/styled/document.js +241 -0
  46. package/dist/css/syntax/styled/markup.d.ts +6 -0
  47. package/dist/css/syntax/styled/markup.js +76 -0
  48. package/dist/css/syntax/styled/template.d.ts +23 -0
  49. package/dist/css/syntax/styled/template.js +61 -0
  50. package/dist/css/syntax/tailwind/tailwind-engine.d.ts +23 -0
  51. package/dist/css/syntax/tailwind/tailwind-engine.js +37 -0
  52. package/dist/css/syntax/tailwind/tailwind.d.ts +26 -0
  53. package/dist/css/syntax/tailwind/tailwind.js +118 -0
  54. package/dist/css/value/check.d.ts +86 -0
  55. package/dist/css/value/check.js +122 -0
  56. package/dist/css/value/expression/arithmetic.d.ts +7 -0
  57. package/dist/css/value/expression/arithmetic.js +69 -0
  58. package/dist/css/value/expression/block.d.ts +9 -0
  59. package/dist/css/value/expression/block.js +91 -0
  60. package/dist/css/value/expression/conditional.d.ts +8 -0
  61. package/dist/css/value/expression/conditional.js +53 -0
  62. package/dist/css/value/expression/index.d.ts +5 -0
  63. package/dist/css/value/expression/index.js +69 -0
  64. package/dist/css/value/expression/map.d.ts +7 -0
  65. package/dist/css/value/expression/map.js +113 -0
  66. package/dist/css/value/object/index.d.ts +5 -0
  67. package/dist/css/value/object/index.js +103 -0
  68. package/dist/css/value/object/members.d.ts +7 -0
  69. package/dist/css/value/object/members.js +103 -0
  70. package/dist/css/value/object/node.d.ts +8 -0
  71. package/dist/css/value/object/node.js +129 -0
  72. package/dist/css/value/object/path.d.ts +10 -0
  73. package/dist/css/value/object/path.js +146 -0
  74. package/dist/css/value/pieces.d.ts +61 -0
  75. package/dist/css/value/pieces.js +55 -0
  76. package/dist/css/value/resolve.d.ts +33 -0
  77. package/dist/css/value/resolve.js +94 -0
  78. package/dist/css/value/scope.d.ts +27 -0
  79. package/dist/css/value/scope.js +187 -0
  80. package/dist/css/value/substitute.d.ts +10 -0
  81. package/dist/css/value/substitute.js +113 -0
  82. package/dist/css/value/values.d.ts +23 -0
  83. package/dist/css/value/values.js +131 -0
  84. package/dist/entities/architecture.d.ts +162 -0
  85. package/dist/entities/architecture.js +2 -0
  86. package/dist/entities/ast/assignments-nodes.d.ts +10 -0
  87. package/dist/entities/ast/assignments-nodes.js +64 -0
  88. package/dist/entities/ast/assignments-raw.d.ts +6 -0
  89. package/dist/entities/ast/assignments-raw.js +86 -0
  90. package/dist/entities/ast/assignments-tagged.d.ts +5 -0
  91. package/dist/entities/ast/assignments-tagged.js +180 -0
  92. package/dist/entities/ast/assignments.d.ts +9 -0
  93. package/dist/entities/ast/assignments.js +78 -0
  94. package/dist/entities/ast/branches.d.ts +4 -0
  95. package/dist/entities/ast/branches.js +32 -0
  96. package/dist/entities/ast/calls.d.ts +6 -0
  97. package/dist/entities/ast/calls.js +134 -0
  98. package/dist/entities/ast/classes.d.ts +5 -0
  99. package/dist/entities/ast/classes.js +57 -0
  100. package/dist/entities/ast/climb.d.ts +12 -0
  101. package/dist/entities/ast/climb.js +17 -0
  102. package/dist/entities/ast/comments.d.ts +4 -0
  103. package/dist/entities/ast/comments.js +100 -0
  104. package/dist/entities/ast/declaration.d.ts +4 -0
  105. package/dist/entities/ast/declaration.js +26 -0
  106. package/dist/entities/ast/depth.d.ts +17 -0
  107. package/dist/entities/ast/depth.js +149 -0
  108. package/dist/entities/ast/enums.d.ts +6 -0
  109. package/dist/entities/ast/enums.js +17 -0
  110. package/dist/entities/ast/file-exports.d.ts +7 -0
  111. package/dist/entities/ast/file-exports.js +78 -0
  112. package/dist/entities/ast/file-facts.d.ts +13 -0
  113. package/dist/entities/ast/file-facts.js +35 -0
  114. package/dist/entities/ast/file-imports.d.ts +5 -0
  115. package/dist/entities/ast/file-imports.js +77 -0
  116. package/dist/entities/ast/file.d.ts +5 -0
  117. package/dist/entities/ast/file.js +22 -0
  118. package/dist/entities/ast/functions.d.ts +8 -0
  119. package/dist/entities/ast/functions.js +102 -0
  120. package/dist/entities/ast/heritage.d.ts +4 -0
  121. package/dist/entities/ast/heritage.js +36 -0
  122. package/dist/entities/ast/index.d.ts +6 -0
  123. package/dist/entities/ast/index.js +125 -0
  124. package/dist/entities/ast/kind.d.ts +5 -0
  125. package/dist/entities/ast/kind.js +28 -0
  126. package/dist/entities/ast/loose.d.ts +37 -0
  127. package/dist/entities/ast/loose.js +2 -0
  128. package/dist/entities/ast/modifiers.d.ts +5 -0
  129. package/dist/entities/ast/modifiers.js +32 -0
  130. package/dist/entities/ast/project.d.ts +9 -0
  131. package/dist/entities/ast/project.js +75 -0
  132. package/dist/entities/ast/properties.d.ts +11 -0
  133. package/dist/entities/ast/properties.js +171 -0
  134. package/dist/entities/ast/resolve.d.ts +16 -0
  135. package/dist/entities/ast/resolve.js +307 -0
  136. package/dist/entities/ast/tree.d.ts +29 -0
  137. package/dist/entities/ast/tree.js +351 -0
  138. package/dist/entities/ast/types.d.ts +6 -0
  139. package/dist/entities/ast/types.js +45 -0
  140. package/dist/entities/ast/usage.d.ts +11 -0
  141. package/dist/entities/ast/usage.js +81 -0
  142. package/dist/entities/ast/variables.d.ts +8 -0
  143. package/dist/entities/ast/variables.js +91 -0
  144. package/dist/entities/context.d.ts +29 -0
  145. package/dist/entities/context.js +2 -0
  146. package/dist/entities/facts.d.ts +261 -0
  147. package/dist/entities/facts.js +2 -0
  148. package/dist/entities/findings.d.ts +19 -0
  149. package/dist/entities/findings.js +2 -0
  150. package/dist/entities/kinds.d.ts +40 -0
  151. package/dist/entities/kinds.js +221 -0
  152. package/dist/entities/location/homes.d.ts +28 -0
  153. package/dist/entities/location/homes.js +169 -0
  154. package/dist/entities/location/place.d.ts +10 -0
  155. package/dist/entities/location/place.js +56 -0
  156. package/dist/entities/location/where.d.ts +17 -0
  157. package/dist/entities/location/where.js +218 -0
  158. package/dist/entities/location.d.ts +16 -0
  159. package/dist/entities/location.js +140 -0
  160. package/dist/entities/operators.d.ts +14 -0
  161. package/dist/entities/operators.js +30 -0
  162. package/dist/entities/overview/data.d.ts +43 -0
  163. package/dist/entities/overview/data.js +2 -0
  164. package/dist/entities/overview/decision.d.ts +60 -0
  165. package/dist/entities/overview/decision.js +2 -0
  166. package/dist/entities/overview/file-tree.d.ts +10 -0
  167. package/dist/entities/overview/file-tree.js +2 -0
  168. package/dist/entities/overview/finding.d.ts +58 -0
  169. package/dist/entities/overview/finding.js +2 -0
  170. package/dist/entities/overview/graph.d.ts +65 -0
  171. package/dist/entities/overview/graph.js +2 -0
  172. package/dist/entities/overview/input.d.ts +15 -0
  173. package/dist/entities/overview/input.js +2 -0
  174. package/dist/entities/overview/summaries.d.ts +79 -0
  175. package/dist/entities/overview/summaries.js +2 -0
  176. package/dist/entities/place.d.ts +5 -0
  177. package/dist/entities/place.js +2 -0
  178. package/dist/entities/queries.d.ts +9 -0
  179. package/dist/entities/queries.js +305 -0
  180. package/dist/entities/repair.d.ts +16 -0
  181. package/dist/entities/repair.js +23 -0
  182. package/dist/entities/schema.d.ts +8 -0
  183. package/dist/entities/schema.js +23 -0
  184. package/dist/entities/story.d.ts +47 -0
  185. package/dist/entities/story.js +2 -0
  186. package/dist/entities/structure-facts.d.ts +11 -0
  187. package/dist/entities/structure-facts.js +2 -0
  188. package/dist/entities/token.d.ts +23 -0
  189. package/dist/entities/token.js +2 -0
  190. package/dist/entities/tree/build.d.ts +5 -0
  191. package/dist/entities/tree/build.js +252 -0
  192. package/dist/entities/tree/entries.d.ts +7 -0
  193. package/dist/entities/tree/entries.js +120 -0
  194. package/dist/entities/tree/index.d.ts +6 -0
  195. package/dist/entities/tree/index.js +21 -0
  196. package/dist/entities/tree/match.d.ts +17 -0
  197. package/dist/entities/tree/match.js +176 -0
  198. package/dist/frameworks/angular/index.d.ts +7 -0
  199. package/dist/frameworks/angular/index.js +17 -0
  200. package/dist/frameworks/facet.d.ts +16 -0
  201. package/dist/frameworks/facet.js +2 -0
  202. package/dist/frameworks/index.d.ts +9 -0
  203. package/dist/frameworks/index.js +120 -0
  204. package/dist/frameworks/react/index.d.ts +7 -0
  205. package/dist/frameworks/react/index.js +214 -0
  206. package/dist/frameworks/vue/index.d.ts +7 -0
  207. package/dist/frameworks/vue/index.js +17 -0
  208. package/dist/invariants/index.d.ts +6 -0
  209. package/dist/invariants/index.js +299 -0
  210. package/dist/invariants/list-vars.d.ts +5 -0
  211. package/dist/invariants/list-vars.js +143 -0
  212. package/dist/invariants/name.d.ts +16 -0
  213. package/dist/invariants/name.js +18 -0
  214. package/dist/invariants/normalize.d.ts +4 -0
  215. package/dist/invariants/normalize.js +95 -0
  216. package/dist/invariants/vars.d.ts +20 -0
  217. package/dist/invariants/vars.js +117 -0
  218. package/dist/main.d.ts +7 -0
  219. package/dist/main.js +229 -0
  220. package/dist/nodes/child-roles.d.ts +3 -0
  221. package/dist/nodes/child-roles.js +12 -0
  222. package/dist/nodes/children.d.ts +25 -0
  223. package/dist/nodes/children.js +112 -0
  224. package/dist/nodes/finally/emit.d.ts +6 -0
  225. package/dist/nodes/finally/emit.js +55 -0
  226. package/dist/nodes/finally/index.d.ts +8 -0
  227. package/dist/nodes/finally/index.js +35 -0
  228. package/dist/nodes/finally/queries.d.ts +5 -0
  229. package/dist/nodes/finally/queries.js +22 -0
  230. package/dist/nodes/finally/relations-access.d.ts +5 -0
  231. package/dist/nodes/finally/relations-access.js +46 -0
  232. package/dist/nodes/finally/relations-edge.d.ts +29 -0
  233. package/dist/nodes/finally/relations-edge.js +125 -0
  234. package/dist/nodes/finally/relations-group.d.ts +31 -0
  235. package/dist/nodes/finally/relations-group.js +103 -0
  236. package/dist/nodes/finally/relations.d.ts +5 -0
  237. package/dist/nodes/finally/relations.js +81 -0
  238. package/dist/nodes/finally/required.d.ts +5 -0
  239. package/dist/nodes/finally/required.js +90 -0
  240. package/dist/nodes/finally/roles.d.ts +13 -0
  241. package/dist/nodes/finally/roles.js +41 -0
  242. package/dist/nodes/finally/violation.d.ts +17 -0
  243. package/dist/nodes/finally/violation.js +2 -0
  244. package/dist/nodes/similar.d.ts +21 -0
  245. package/dist/nodes/similar.js +156 -0
  246. package/dist/pipeline-facts.d.ts +11 -0
  247. package/dist/pipeline-facts.js +112 -0
  248. package/dist/pipeline-roles.d.ts +6 -0
  249. package/dist/pipeline-roles.js +75 -0
  250. package/dist/pipeline-unroled.d.ts +14 -0
  251. package/dist/pipeline-unroled.js +193 -0
  252. package/dist/pipeline.d.ts +7 -0
  253. package/dist/pipeline.js +73 -0
  254. package/dist/plugin.d.ts +2 -0
  255. package/dist/plugin.js +3 -0
  256. package/dist/report/asks.d.ts +55 -0
  257. package/dist/report/asks.js +50 -0
  258. package/dist/report/cli-report.d.ts +2 -0
  259. package/dist/report/cli-report.js +13 -0
  260. package/dist/report/config-error-guard.d.ts +8 -0
  261. package/dist/report/config-error-guard.js +5 -0
  262. package/dist/report/configErrors.d.ts +98 -0
  263. package/dist/report/configErrors.js +75 -0
  264. package/dist/report/errorTypes/codes/structure.d.ts +15 -0
  265. package/dist/report/errorTypes/codes/structure.js +76 -0
  266. package/dist/report/errorTypes/decision-maker.d.ts +23 -0
  267. package/dist/report/errorTypes/decision-maker.js +99 -0
  268. package/dist/report/errorTypes/destinations.d.ts +38 -0
  269. package/dist/report/errorTypes/destinations.js +147 -0
  270. package/dist/report/errorTypes/finding-type.d.ts +11 -0
  271. package/dist/report/errorTypes/finding-type.js +2 -0
  272. package/dist/report/errorTypes/index.d.ts +15 -0
  273. package/dist/report/errorTypes/index.js +45 -0
  274. package/dist/report/errorTypes/types/fileContents.d.ts +9 -0
  275. package/dist/report/errorTypes/types/fileContents.js +34 -0
  276. package/dist/report/errorTypes/types/unknownRole.d.ts +9 -0
  277. package/dist/report/errorTypes/types/unknownRole.js +22 -0
  278. package/dist/report/errorTypes/types/wrongAction.d.ts +22 -0
  279. package/dist/report/errorTypes/types/wrongAction.js +135 -0
  280. package/dist/report/errorTypes/types/wrongPlacement.d.ts +9 -0
  281. package/dist/report/errorTypes/types/wrongPlacement.js +57 -0
  282. package/dist/report/errorTypes/vocabulary/ids.d.ts +5 -0
  283. package/dist/report/errorTypes/vocabulary/ids.js +16 -0
  284. package/dist/report/errorTypes/vocabulary/phrases.d.ts +10 -0
  285. package/dist/report/errorTypes/vocabulary/phrases.js +174 -0
  286. package/dist/report/errorTypes/vocabulary/places.d.ts +8 -0
  287. package/dist/report/errorTypes/vocabulary/places.js +36 -0
  288. package/dist/report/errorTypes/vocabulary/verbs.d.ts +7 -0
  289. package/dist/report/errorTypes/vocabulary/verbs.js +30 -0
  290. package/dist/report/finding-from.d.ts +9 -0
  291. package/dist/report/finding-from.js +103 -0
  292. package/dist/report/notices.d.ts +4 -0
  293. package/dist/report/notices.js +31 -0
  294. package/dist/report/render-report.d.ts +12 -0
  295. package/dist/report/render-report.js +142 -0
  296. package/dist/report/user-report/build/bundle.d.ts +3 -0
  297. package/dist/report/user-report/build/bundle.js +169 -0
  298. package/dist/report/user-report/build/bundle.prebuilt.js +760 -0
  299. package/dist/report/user-report/data/collect.d.ts +4 -0
  300. package/dist/report/user-report/data/collect.js +80 -0
  301. package/dist/report/user-report/data/file-tree.d.ts +9 -0
  302. package/dist/report/user-report/data/file-tree.js +72 -0
  303. package/dist/report/user-report/data/finding-boundary.d.ts +9 -0
  304. package/dist/report/user-report/data/finding-boundary.js +21 -0
  305. package/dist/report/user-report/data/finding-plan.d.ts +16 -0
  306. package/dist/report/user-report/data/finding-plan.js +45 -0
  307. package/dist/report/user-report/data/finding-title.d.ts +12 -0
  308. package/dist/report/user-report/data/finding-title.js +36 -0
  309. package/dist/report/user-report/data/findings.d.ts +10 -0
  310. package/dist/report/user-report/data/findings.js +171 -0
  311. package/dist/report/user-report/data/graph-edges.d.ts +19 -0
  312. package/dist/report/user-report/data/graph-edges.js +109 -0
  313. package/dist/report/user-report/data/graph-helpers.d.ts +7 -0
  314. package/dist/report/user-report/data/graph-helpers.js +67 -0
  315. package/dist/report/user-report/data/graph-roles.d.ts +5 -0
  316. package/dist/report/user-report/data/graph-roles.js +71 -0
  317. package/dist/report/user-report/data/graph.d.ts +11 -0
  318. package/dist/report/user-report/data/graph.js +90 -0
  319. package/dist/report/user-report/data/invariants.d.ts +7 -0
  320. package/dist/report/user-report/data/invariants.js +62 -0
  321. package/dist/report/user-report/data/nodes.d.ts +11 -0
  322. package/dist/report/user-report/data/nodes.js +106 -0
  323. package/dist/report/user-report/data/role-examples.d.ts +16 -0
  324. package/dist/report/user-report/data/role-examples.js +94 -0
  325. package/dist/report/user-report/data/role-filters.d.ts +15 -0
  326. package/dist/report/user-report/data/role-filters.js +79 -0
  327. package/dist/report/user-report/data/role-marks.d.ts +5 -0
  328. package/dist/report/user-report/data/role-marks.js +79 -0
  329. package/dist/report/user-report/data/roles.d.ts +7 -0
  330. package/dist/report/user-report/data/roles.js +83 -0
  331. package/dist/report/user-report/data/scan.d.ts +8 -0
  332. package/dist/report/user-report/data/scan.js +59 -0
  333. package/dist/report/user-report/html/shell.d.ts +3 -0
  334. package/dist/report/user-report/html/shell.js +27 -0
  335. package/dist/report/user-report/index.d.ts +8 -0
  336. package/dist/report/user-report/index.js +48 -0
  337. package/dist/report/user-report/shared/describe.d.ts +7 -0
  338. package/dist/report/user-report/shared/describe.js +86 -0
  339. package/dist/scripts/audit-report.d.ts +2 -0
  340. package/dist/scripts/audit-report.js +147 -0
  341. package/dist/utils/accumulate.d.ts +6 -0
  342. package/dist/utils/accumulate.js +18 -0
  343. package/dist/utils/article.d.ts +2 -0
  344. package/dist/utils/article.js +12 -0
  345. package/dist/utils/classify.d.ts +12 -0
  346. package/dist/utils/classify.js +25 -0
  347. package/dist/utils/configs.d.ts +25 -0
  348. package/dist/utils/configs.js +87 -0
  349. package/dist/utils/count.d.ts +7 -0
  350. package/dist/utils/count.js +13 -0
  351. package/dist/utils/dispatch.d.ts +2 -0
  352. package/dist/utils/dispatch.js +27 -0
  353. package/dist/utils/distinct.d.ts +2 -0
  354. package/dist/utils/distinct.js +12 -0
  355. package/dist/utils/field.d.ts +14 -0
  356. package/dist/utils/field.js +60 -0
  357. package/dist/utils/file-name.d.ts +2 -0
  358. package/dist/utils/file-name.js +11 -0
  359. package/dist/utils/files.d.ts +7 -0
  360. package/dist/utils/files.js +73 -0
  361. package/dist/utils/fixpoint.d.ts +2 -0
  362. package/dist/utils/fixpoint.js +19 -0
  363. package/dist/utils/gate.d.ts +2 -0
  364. package/dist/utils/gate.js +12 -0
  365. package/dist/utils/group.d.ts +3 -0
  366. package/dist/utils/group.js +33 -0
  367. package/dist/utils/host.d.ts +3 -0
  368. package/dist/utils/host.js +13 -0
  369. package/dist/utils/imports.d.ts +12 -0
  370. package/dist/utils/imports.js +121 -0
  371. package/dist/utils/judged.d.ts +5 -0
  372. package/dist/utils/judged.js +19 -0
  373. package/dist/utils/keyed.d.ts +2 -0
  374. package/dist/utils/keyed.js +23 -0
  375. package/dist/utils/map-record.d.ts +2 -0
  376. package/dist/utils/map-record.js +11 -0
  377. package/dist/utils/path-label.d.ts +6 -0
  378. package/dist/utils/path-label.js +35 -0
  379. package/dist/utils/pattern.d.ts +18 -0
  380. package/dist/utils/pattern.js +191 -0
  381. package/dist/utils/permission.d.ts +16 -0
  382. package/dist/utils/permission.js +16 -0
  383. package/dist/utils/plural.d.ts +2 -0
  384. package/dist/utils/plural.js +9 -0
  385. package/dist/utils/qualified.d.ts +2 -0
  386. package/dist/utils/qualified.js +21 -0
  387. package/dist/utils/rank.d.ts +2 -0
  388. package/dist/utils/rank.js +24 -0
  389. package/dist/utils/read-field.d.ts +12 -0
  390. package/dist/utils/read-field.js +50 -0
  391. package/dist/utils/read-when.d.ts +2 -0
  392. package/dist/utils/read-when.js +17 -0
  393. package/dist/utils/reason.d.ts +4 -0
  394. package/dist/utils/reason.js +9 -0
  395. package/dist/utils/record.d.ts +3 -0
  396. package/dist/utils/record.js +21 -0
  397. package/dist/utils/resolve.d.ts +2 -0
  398. package/dist/utils/resolve.js +24 -0
  399. package/dist/utils/search.d.ts +2 -0
  400. package/dist/utils/search.js +16 -0
  401. package/dist/utils/seen.d.ts +6 -0
  402. package/dist/utils/seen.js +27 -0
  403. package/dist/utils/span.d.ts +5 -0
  404. package/dist/utils/span.js +2 -0
  405. package/dist/utils/speak.d.ts +2 -0
  406. package/dist/utils/speak.js +18 -0
  407. package/dist/utils/split.d.ts +8 -0
  408. package/dist/utils/split.js +8 -0
  409. package/dist/utils/template.d.ts +5 -0
  410. package/dist/utils/template.js +5 -0
  411. package/dist/utils/text.d.ts +4 -0
  412. package/dist/utils/text.js +42 -0
  413. package/dist/utils/tokenize.d.ts +2 -0
  414. package/dist/utils/tokenize.js +13 -0
  415. package/dist/utils/try-read.d.ts +4 -0
  416. package/dist/utils/try-read.js +24 -0
  417. package/dist/utils/typed-field.d.ts +3 -0
  418. package/dist/utils/typed-field.js +16 -0
  419. package/dist/utils/verdicts.d.ts +4 -0
  420. package/dist/utils/verdicts.js +20 -0
  421. package/entities/operators.ts +31 -0
  422. package/package.json +62 -19
  423. package/report/errorTypes/vocabulary/ids.ts +12 -0
  424. package/report/errorTypes/vocabulary/phrases.ts +161 -0
  425. package/report/errorTypes/vocabulary/places.ts +46 -0
  426. package/report/errorTypes/vocabulary/verbs.ts +31 -0
  427. package/report/user-report/shared/describe.ts +107 -0
  428. package/ast.js +0 -107
  429. package/bin/follow-architecture.js +0 -6
  430. package/config.js +0 -82
  431. package/entities/aliases.js +0 -10
  432. package/entities/invariants.js +0 -134
  433. package/entities/nodes.js +0 -112
  434. package/main.js +0 -95
  435. package/report.js +0 -73
  436. package/utils.js +0 -104
package/README.md CHANGED
@@ -1,168 +1,639 @@
1
1
  # follow-architecture
2
2
 
3
- ESLint rule + CLI that validates code against a declarative architecture skeleton. The tool knows nothing about your project — everything (paths, names, rules, fixes) lives in `architecture.json`.
4
-
5
- Two kinds of checks:
6
-
7
- - **nodes** — where files may live and what names they may have (a folder tree with closed/open lists and per-name reports).
8
- - **invariants** — per-file content rules: forbidden text, forbidden imports, and conditional checks driven by the file's AST.
9
-
10
- ## `architecture.json`
11
-
12
- ```jsonc
13
- {
14
- "aliases": { "#_db": "core/ehr/_db" },
15
- "nodes": [
16
- {
17
- "slug": "slice",
18
- "name": "{slice}.v",
19
- "parent": "ehr",
20
- "closed": true,
21
- "report": { "message": "…", "fix": "…" },
22
- "children": [
23
- "{kebab-case}.types.ts",
24
- "index.ts",
25
- { "name": "{kebab-case}.resource.tsx", "forbidden": true, "report": { "message": "…", "fix": "…" } }
26
- ]
27
- },
28
- { "slug": "ehr", "name": "core/ehr", "children": ["slice", "db"] }
29
- ],
30
- "invariants": [
31
- {
32
- "id": "rm-no-bypass",
33
- "where": "core/ehr/{slice}.v/**/*.rm.ts",
34
- "forbid": [
35
- { "key": "client", "pattern": "new AppMedplumClient", "report": { "message": "…", "fix": "…" }, "except": ["**/legacy/**"] },
36
- { "type": "imports", "key": "no-vscode", "pattern": "vscode", "report": { "message": "…" } }
37
- ],
38
- "when": "(ctx) => { /* AST-level check, returns null | true | finding | finding[] */ }",
39
- "except": ["core/ehr/catalog.v/**/*.rm.ts"],
40
- "report": { "message": "…", "fix": "…" }
41
- }
42
- ]
43
- }
3
+ ESLint rule + CLI that validates code against a declarative architecture. The plugin knows nothing about your project — everything (paths, names, rules, fixes) lives in `architecture.yaml`.
4
+
5
+ The plugin is 100% generic. It collects **facts** from the AST via ts-morph and evaluates **filters** (Keystone-GraphQL-filters style) against them. There are no named rule kinds and no semantic predicates inside the plugin — all rule semantics live in the YAML.
6
+
7
+ Three chunks are what you AUTHOR, and each is a question asked of the same source
8
+ files — they do not mix:
9
+
10
+ | chunk | YAML key | folder | answers |
11
+ | --- | --- | --- | --- |
12
+ | nodes | `nodes` | [nodes/](nodes) | where files may live, what names they may have, and which role each child holds |
13
+ | codeRoles | `codeRoles` | [code-roles/](code-roles) | what a declaration *is* (store model, factory, pure function, …) and what may be done with it — never where it lives |
14
+ | invariants | `invariants` | [invariants/](invariants) | what a file may contain |
15
+
16
+ `aliases` maps import sources to paths so the three can resolve imports; it is
17
+ the only other key in the file.
18
+
19
+ ```mermaid
20
+ flowchart LR
21
+ Y["architecture.yaml"] --> F
22
+ S["Source files"] --> F
23
+ subgraph F["filter"]
24
+ direction TB
25
+ N["nodes"]
26
+ R["codeRoles"]
27
+ I["invariants"]
28
+ end
29
+ F --> O["Report"]
44
30
  ```
45
31
 
46
- Top-level options: `files` (globs scanned by the CLI, default `**/*.ts`, `**/*.tsx`), `exts` (default `.ts`, `.tsx`, `.js`, `.jsx`), `ignores` (file globs skipped by the CLI).
32
+ Everything else in this repository is the engine that answers those questions —
33
+ it carries no project knowledge.
34
+
35
+ ## Quick start
36
+
37
+ Pick your runner:
38
+
39
+ <details open>
40
+ <summary><b>bunx</b></summary>
41
+
42
+ ```sh
43
+ bunx follow-architecture --config architecture.yaml --out reports/follow-architecture.md
44
+ # exit 1 when findings exist (CI):
45
+ bunx follow-architecture --config architecture.yaml --check
46
+ # interactive, self-contained HTML overview (structure · roles · graph · findings):
47
+ bunx follow-architecture --config architecture.yaml --overview reports/architecture-overview.html
48
+ ```
49
+
50
+ </details>
51
+
52
+ <details>
53
+ <summary><b>pnpm dlx</b></summary>
54
+
55
+ ```sh
56
+ pnpm dlx follow-architecture --config architecture.yaml --out reports/follow-architecture.md
57
+ # exit 1 when findings exist (CI):
58
+ pnpm dlx follow-architecture --config architecture.yaml --check
59
+ # interactive, self-contained HTML overview (structure · roles · graph · findings):
60
+ pnpm dlx follow-architecture --config architecture.yaml --overview reports/architecture-overview.html
61
+ ```
62
+
63
+ </details>
64
+
65
+ <details>
66
+ <summary><b>npx</b></summary>
67
+
68
+ ```sh
69
+ npx follow-architecture --config architecture.yaml --out reports/follow-architecture.md
70
+ # exit 1 when findings exist (CI):
71
+ npx follow-architecture --config architecture.yaml --check
72
+ # interactive, self-contained HTML overview (structure · roles · graph · findings):
73
+ npx follow-architecture --config architecture.yaml --overview reports/architecture-overview.html
74
+ ```
75
+
76
+ </details>
77
+
78
+ As an ESLint rule (flat config):
79
+
80
+ ```js
81
+ const { flatConfig } = require("@md-code/follow-architecture");
82
+ module.exports = [...flatConfig(require("./architecture.yaml"))];
83
+ ```
84
+
85
+ ## `architecture.yaml`
86
+
87
+ ```yamlc
88
+ # import-source → repo-relative path (for resolving imports in facts)
89
+ aliases:
90
+ backend: apps/backend
91
+
92
+ # folder tree: where files may live
93
+ nodes:
94
+ - slug: backend # unique id, referenced by parent / children
95
+ name: apps/backend # path segment (or prefix); {name} placeholders capture segments
96
+ parent: root
97
+ closed: true # a file directly inside must match one of children
98
+ report: # finding text for "file does not belong here"
99
+ message: "…"
100
+ fix: "…"
101
+ children:
102
+ - index.ts
103
+ - "{kebab-case}.ts" # name template; {kebab-case} matches kebab-case text
104
+ - name: "{kebab-case}"
105
+ forbidden: true # a shape that must NEVER exist
106
+ report: { message: "…", fix: "…" }
107
+ - name: store.ts
108
+ required: true # without it the folder is not this node at all
109
+
110
+ # what a declaration is: a LIST of roles, first `infer` filter that matches wins
111
+ codeRoles:
112
+ - slug: storeModel
113
+ name: store model
114
+ # The chain roots that REACH this role without an import
115
+ # (mobx-state-tree's getRoot/getParent). Each entry is structured:
116
+ # `kind` is the base shape of the chain — call / identifier / methodCall —
117
+ # and `segments` is the callee (or base + leading properties).
118
+ # Per-role on purpose: different roles are reached differently.
119
+ infer:
120
+ - kind:
121
+ own: { is: { equals: VariableDeclaration } }
122
+ initializer:
123
+ is: { in: [CallExpression, NewExpression] }
124
+ origin: { equals: "t.model" }
125
+ where: [{ node: feature-store }] # where it may be declared
126
+ actions:
127
+ import: { where: [storeModel] } # who may import it
128
+
129
+ # what a file may contain
130
+ invariants:
131
+ - id: no-any
132
+ where: ["**/*.ts"] # globs or { node: slug }; empty/omitted = all files
133
+ ignore: ["**/*.test.ts"] # same entry interface: glob or { node: slug }
134
+ when: # optional gate: a plain filter over the file facts
135
+ roles: { any: { equals: orchestrator } } # e.g. "a role is present"
136
+ infer: # a finding when a filter MATCHES the facts
137
+ - kind:
138
+ descendants:
139
+ any:
140
+ is: { equals: AnyKeyword }
141
+ # "must be true" is the same filter under `not:`
142
+ # - not: { location: { files: { contains: store.ts } } }
143
+ report: { message: "…", fix: "…" }
144
+ ```
145
+
146
+ The yaml describes **what the code must look like** — it carries no scan scope. Where the tool looks is a tool concern, set separately:
147
+
148
+ - **CLI** — `--files <glob>` (files to scan; default: the whole tree), `--ext <.ext>` (repeatable, added to the built-in source extensions), `--ignore <glob>` (repeatable, file globs skipped), `--ignore-dir <name>` (repeatable, folders not entered).
149
+ - **ESLint rule options** — `{ config, exts?, ignoreDirs?, ignores?, include?, exportPath? }`: `exts` (added to the built-in source extensions), `ignoreDirs` (folder names not entered, added to the built-in `node_modules`, `.git`, `.vscode-test`, `out`, `dist`, `build`, `coverage`), `ignores` (file globs skipped), `include` (only these globs are checked) and `exportPath` (where the run writes its HTML overview — the same self-contained report `--overview` produces; default `reports/architecture-overview.html`, `false` turns it off). The export file is accumulated across every linted file and written when the run ends, so a plain `eslint <dirs>` run leaves the whole report on disk.
150
+ - The built-in extension list (`.ts`, `.tsx`, `.js`, `.jsx`, `.mts`, `.cts`, `.vue`, `.svelte`) is only a default: `--ext` / `exts` add to it.
151
+
152
+ ## Placeholders
153
+
154
+ A `{…}` in a path pattern is a **capture**, and it is written IN the convention it
155
+ asks for — the convention is read off the name, so there is no list of known ones:
156
+
157
+ | write | matches |
158
+ | --- | --- |
159
+ | `{kebab-case}`, `{feature-name}` | `todo-list` (any `-`-joined lowercase name) |
160
+ | `{snake_case}` | `todo_list` |
161
+ | `{UPPER_CASE}` | `MAX_RETRIES` |
162
+ | `{FEATURE-NAME}` | `TODO-LIST` |
163
+ | `{camelCase}`, `{myCase}` | `todoList` |
164
+ | `{PascalCase}`, `{Name}` | `TodoList` |
165
+ | `{Mixed_Name}` (states no convention) | anything but `/` — it captures and enforces nothing |
166
+
167
+ A placeholder may share a segment with literal text, so a test file is declared
168
+ next to the code it tests: `{kebab-case}.spec.ts` matches `todo-list.spec.ts` and
169
+ not `todoList.spec.ts`; inside a segment, dots and other text are literal.
47
170
 
48
171
  ## Nodes
49
172
 
50
- A **node** is a folder (or folder prefix) in the tree. Nodes reference each other by `slug` to form the tree; the path of a node is its `parent`'s path + its `name`.
173
+ A **node** is a folder (or folder prefix) in the tree. Nodes reference each other by `slug`; the path of a node is its `parent`'s path + its `name`.
174
+
175
+ - `slug` — unique name, used as `parent` by children.
176
+ - `name` — the path segment. Placeholders capture path segments (e.g. `{kebab-case}` in `apps/backend/features/{kebab-case}`) and are available in reports. See **Placeholders** below.
177
+ - `parent` (optional) — the `slug` of the containing node. No `parent` = root.
178
+ - `closed` (optional, default `false`) — when `true`, a file directly inside must match one of its `children`; otherwise it gets the node's `report`.
179
+ - `report` (optional) — the finding for "file does not belong here".
180
+
181
+ - `children` (optional) — allowed names inside the node. Each entry is either:
182
+ - a **string** — a name template (`{kebab-case}`, `*`, `?` work; a name without an extension is a folder, with an extension is a file, and a name may mix both — `{kebab-case}.spec.ts`);
183
+ - an **object** — `{ name, forbidden?, required?, report? }`. `forbidden: true` names a shape that must **never** exist; `required: true` names a shape that must **always** exist.
51
184
 
52
- - `slug` — unique name, used as `parent` by children and as `node` by invariants.
53
- - `name` — the path segment (relative to the parent). `{name}` placeholders capture path segments (e.g. `{slice}` in `{slice}.v` captures `allergies`). Captures are available in reports of every finding inside the node.
54
- - `parent` (optional) — the `slug` of the containing node. A node without `parent` is a root.
55
- - `closed` (optional, default `false`) — when `true`, a file directly inside the node must match one of its `children`; otherwise it gets the node's `report`. A folder (a child that is a folder) that is not in the list is also a violation.
56
- - `report` (optional) — the finding for "file does not belong here" (closed nodes) — see [report](#report).
57
- - `children` (optional) — the list of allowed names inside the node. Each entry is either:
58
- - a **string** — a name template (`{kebab-case}`, `*`, `?` work; a name without an extension is a folder, with an extension is a file);
59
- - an **object** — `{ name, forbidden?, report?, description? }`. `forbidden: true` names a shape that must **never** exist (e.g. `{kebab-case}.resource.tsx` in a sub-feature folder) and reports `report` when it does.
185
+ `required` is what makes a folder an instance of the node. A node whose template matches a folder that lacks a required child is not that folder's node: the folder is reported as "not a `<node>`" (once per folder, not per file) and is otherwise treated as outside the architecture — no role destinations are invented inside it. This is how a folder that merely *looks* like a feature is caught, with no per-folder rule to write.
60
186
 
61
- A node with no `children` is **open** — anything inside is fine. The deepest matching node wins: a file is checked against the most specific node whose path prefix matches.
187
+ A node with no `children` is **open** — anything inside is fine. The deepest matching node wins.
188
+
189
+ A node carries **structure only**: `slug`, `name`, `parent`, `children`, `closed`, `report`, `role`. Any other key is an error, not a silent no-op, so a YAML that still uses a retired key fails loudly instead of claiming a rule nobody enforces.
190
+
191
+ A child is a NAME (`actions`, `store.ts`, `{kebab-case}`) or a spec. The spec may
192
+ add what the child is FOR:
193
+
194
+ ```yaml
195
+ children:
196
+ - store.ts # just a name
197
+ - { name: actions, role: action } # this folder IS that code
198
+ - { name: store.ts, role: [storeModel, sharedTypes] } # a file may be several roles
199
+ - { node: backend-feature-actions, role: action } # borrow another node
200
+ - name: actions # required: this folder is not the node without it
201
+ required: true
202
+ report: { message: "…", fix: "…" }
203
+ ```
204
+
205
+ `role:` on the node itself means the same for the whole node: `role: sharedTypes`
206
+ on `packages/types` says every file there is that code — the "whole folder is a
207
+ codeRole" case, written once. **This is the only place a location is stated**:
208
+ the tree owns WHERE, a codeRole owns WHAT. Nothing else in the config names a
209
+ folder for a role, and `codeRoles[].where` is an error.
210
+
211
+ ### A role belongs to a piece of code, not to a file
212
+
213
+ `infer` runs over the declarations in a file — functions, methods, classes,
214
+ variables — and every one of them carries its own role. One file may therefore
215
+ hold several roles at once: a `store.ts` is the store, the accessors that hand
216
+ it out and the views beside it; a `settings.ts` is a view (`getHost`) next to an
217
+ action (`setHost`). `role: [a, b]` on a node says which roles may be declared in
218
+ that folder, and a finding always names the PIECE it judges (`setHost` is an
219
+ action) together with the relation it broke.
220
+
221
+ A piece no role describes is granted nothing: every relation it makes is
222
+ refused, and the finding says so by naming that piece. A piece that reaches
223
+ nothing is not asked — silence there is the absence of a question, not
224
+ permission.
225
+
226
+ ### `where` — one mechanism, used everywhere
227
+
228
+ A node is STRUCTURE only: paths, allowed children, `closed`, and which role its
229
+ code is. A codeRole carries no location at all — it says WHAT code is; the node
230
+ that holds it says WHERE:
231
+
232
+ ```yaml
233
+ nodes:
234
+ - slug: feature-actions
235
+ name: actions
236
+ parent: "{kebab-case}"
237
+ role: action # WHERE that code lives
238
+
239
+ codeRoles:
240
+ - slug: action
241
+ infer: [{ location: { node: feature-actions } }] # WHAT it is
242
+ report: { message: "…", fix: "…" } # said when it is misplaced
243
+
244
+ actions: # WHAT MAY BE DONE WITH IT
245
+ import:
246
+ where: [storeModel] # who may import it
247
+ usage:
248
+ where: [action, orchestrator] # who may call it
249
+ scopeAccess: # …reaching it without an import
250
+ - { kind: function, segments: [getRoot] } # getRoot(self).x
251
+ - { kind: object, segments: [self, root] } # self.root.x
252
+ - { kind: method, segments: [parent, get] } # parent.get("n").x
253
+ mutation:
254
+ where: [action] # who may write it
255
+ ```
256
+
257
+ - `actions` is an open map: the key IS the action name (`import`,
258
+ `export`, `call`, `mutate`, `read`, … or your own). Declaration is not
259
+ an action here — it is the role-level `where`. The rule does not
260
+ enumerate them — for each kind it asks the fact layer which source→target
261
+ edges exist, finds the target's role, and applies that action's `where`.
262
+ A declared action nobody can verify is reported, never silently ignored.
263
+ - `where` is the ONE way to say who/where — the same mechanism invariants use
264
+ for their `where` / `ignore` (`utils/where.js`, imported by both, given the
265
+ same facts): a list of roles (`{ role: x }`), nodes (`{ node: y }`) or filters
266
+ (`{ role: x, same: true }` = same node instance). Paths themselves live in
267
+ `nodes`, so a `where` never restates a folder. The same entry means the same
268
+ thing in both places — action and invariant gate — because it is literally
269
+ the same matcher:
270
+
271
+ An entry may add `via: import`: this actor *holds* the target from an import
272
+ instead of reaching it through the object tree (a controller calls
273
+ `getStore().file.readFile()`, an action walks `getRoot(state)`), so the
274
+ target's `scopeAccess` chains are not its way in — and the picture stops
275
+ claiming they are.
276
+
277
+ ```yaml
278
+ # action: may this role's code be IMPORTED / CALLED / WRITTEN by…
279
+ actions:
280
+ mutation: { where: [{ role: action }, { role: orchestrator, same: true }] }
281
+ # invariant: does this rule apply to this file — same syntax, same facts
282
+ invariants:
283
+ - id: store-size
284
+ where: [{ role: storeModel }] # a role reference
285
+ infer: [{ lines: { gt: 400 } }] # the SAME key a role uses
286
+ ```
287
+
288
+ There is no "action kind" list to learn: an action is checked against the
289
+ fact class of the same name, and any other name can name its fact class with
290
+ `of:` — `emit: { of: call }`, `subscribe: { of: call }`. An event-driven
291
+ design gets its own vocabulary with no engine change.
292
+ - `scopeAccess` lists the chain roots through which the role's code is reached
293
+ without an import, with the SHAPE of the root spelled out: `function`
294
+ (`getRoot(self).x`), `object` (`self.root.x`, `global.x`), `method`
295
+ (`parent.get("n").x`).
296
+ - A role has **no home of its own**. Where its code may be declared is stated by
297
+ the tree — `role:` on a node, or `role:` on a node child. Code of the role
298
+ declared outside every such place is reported with the place it belongs. A
299
+ role nobody gives a home may live anywhere the tree allows, so its misplacement
300
+ is never reported (and its card in the overview says so).
301
+ - An action carries exactly `where`, `of` and `scopeAccess`. Anything else
302
+ (`byName`, `report`, `allowedFrom` …) is an error rather than a rule the
303
+ config believes it declared, and so is `of:` naming a relation the fact layer
304
+ cannot produce (`import` / `export` / `call` / `mutate` / `read` / `typeImport`).
305
+
306
+ ## Code roles
307
+
308
+ A **candidate** is any function-like node (declaration, expression, arrow, method, accessor), any **class**, or a variable declaration. A class is a candidate so a decorator/DI design is describable without engine support: its facts carry `kind.decorators`, `extends`, `implements`, `members` (each with its own decorators) and `constructorParams`. Nothing in the engine knows what `Component`, `Injectable` or `NgModule` mean — the YAML does.
309
+
310
+ `.vue` / `.svelte` single-file components are parsed too: only the `<script>` block is handed to the parser and every other line is blanked, so reported line numbers still match the file in the editor. For each candidate the plugin collects raw facts (below) and assigns the **first** role (in YAML declaration order) whose `infer` filter matches.
311
+
312
+ - `infer` — an AND-list of filters on the candidate's facts. A role without `infer` is never inferred. An entry may be a bare STRING naming another role: `infer: [action, { lines: { gt: 5 } }]` means "code that is an action AND longer than 5 lines" — roles compose without any extra keyword. Filters may nest `and` / `or` / `xor` / `not` to any depth, so a role can describe a shape as precisely as needed:
313
+
314
+ ```yaml
315
+ infer:
316
+ - and:
317
+ - kind: { own: { is: { equals: ArrowFunction } } }
318
+ - or:
319
+ - calls: { any: { targetRole: { equals: action } } }
320
+ - kind: { descendants: { any: { is: { equals: AwaitExpression } } } }
321
+ - not:
322
+ calls: { any: { targetRole: { equals: pureFunction } } }
323
+ ```
324
+ - `where` (optional) — the role's HOME: where its code may be declared. Omitted = the `location` filters of `infer` (the common case, written once). Code of the role declared outside every home is reported with the place it belongs.
325
+ - `actions` (optional) — an open map of what may be done with code of this role and by whom: `import`, `export`, `call`, `mutate`, `read`, `typeImport`, or any name with `of:`. Each entry is `{ where, of?, scopeAccess? }`.
62
326
 
63
327
  ## Invariants
64
328
 
65
329
  An **invariant** is a per-file rule. Fields:
66
330
 
67
331
  - `id` — unique name.
68
- - `node` (optional) — a node `slug`; the invariant only runs for files that captured that node. Default `*` (all files).
69
- - `where` (optional) — a glob the file path must match; `{name}` captures work and are available in reports. No `where` = all files.
70
- - `except` (optional) — file globs the invariant does not apply to.
71
- - `report` (optional) — a finding emitted for **every** matching file (a "this file, as it exists, is a problem" rule).
72
- - `when` (optional) — a gate or an AST-level check, called as `when(ctx)` with the full file context (see [ctx](#ctx)). Return values:
73
- - `null` / `false` — the invariant (and its `forbid` list) is off for this file;
74
- - `true` — on;
75
- - an object or array of objects — emitted as finding(s) and the `forbid` list is skipped.
76
- - `forbid` (optional) — array of entries, each with a `type`:
77
- - `type: "fileContent"` (default) — `{ key?, pattern, except?, report? }`. `pattern` is a **regex** tested against every line of the file; every matching line is a finding. `except` is a list of file globs where this entry does not apply.
78
- - `type: "imports"` — `{ key?, pattern, except?, report? }`. `pattern` is a **glob** (with `{name}` captures) tested against each import's **resolved path** — or the raw source for external modules that cannot be resolved. Every matching import is a finding.
79
- - `type: "syntax"` — `{ key?, kind, pattern?, except?, report? }`. `kind` is a ts-morph node kind name (e.g. `ImportDeclaration`, `FunctionDeclaration`, `VariableStatement`); every AST node of that kind is a finding, optionally narrowed by `pattern` (a regex tested against the node's full text). Use it when a line-based regex cannot express the rule (e.g. "no `export default`", "no function declarations").
80
- - `children` (optional) — nested invariants; they run after the parent and inherit its captures.
81
-
82
- `key` (on the invariant or a `forbid` entry) is a stable dedup key: findings with the same `key` are collapsed to one per file.
83
-
84
- ### `ctx`
85
-
86
- `when(ctx)` receives, per file:
87
-
88
- | field | meaning |
89
- | --- | --- |
90
- | `ctx.file` | the full ts-morph `SourceFile` — the whole AST is available (`getImportDeclarations`, `getFunctions`, `getDescendantsOfKind`, …) |
91
- | `ctx.path` | repo-relative path (posix) |
92
- | `ctx.basename` | file name |
93
- | `ctx.dir` | directory (repo-relative) |
94
- | `ctx.slice` | the `{slice}` capture if the path matches `…/<slice>.v/…`, else `null` |
95
- | `ctx.captures` | all `{name}` captures from the invariant's `where` and the matched node |
96
- | `ctx.imports` | the file's import declarations: `{ source, named, defaultName, namespaceName, typeOnly, resolved }` — `resolved` is the repo-relative path after alias expansion, `null` for external modules |
97
- | `ctx.siblings` | basenames of the other files in the same folder (the folder listing the CLI walked) — for rules like "at most N files per folder" or "no duplicated basename prefixes" |
98
- | `ctx.arch` | the loaded architecture (nodes, invariants, aliases) |
99
- | `ctx.enclosingFunctionName(line)` | name of the function containing the 1-based `line`, or `null` |
332
+ - `where` (optional) — the SAME `where` the code roles use: globs (with the placeholders below), `{ node: slug }`, `{ role: slug }` (a bare string naming a role works too), or a filter over the file facts (`{ imports: { any: … } }`). Empty/omitted = all files.
333
+ - `ignore` (optional) — the same, inverted: the invariant does not apply there.
334
+ - `when` (optional) — a gate: a plain filter over the file facts (the same filter language as `rule`/`must`, run through the shared `matches` engine). The file facts include `roles` (the flat list of role names present) and `candidates` (the role-enriched candidate facts, each carrying `role`, `parentRole`, and `calls[].targetRole`). Example: `when: { roles: { any: { equals: orchestrator } } }` gates on "an orchestrator is present"; `when: { candidates: { any: { role: { equals: pureFunction }, parentRole: { equals: orchestrator } } } }` gates on "a pure function nested in an orchestrator". Omitted = no gate.
335
+ - `infer` (optional) — list of filters; a finding when a filter **matches** the file facts. **The same key and the same filter language as a codeRole's `infer`** — only what a match means differs: in a role it says "this code IS that role", here it says "this file breaks the rule". The filter is asked of the **file** first; when the file answers, the finding is about the file. When it does not, the SAME filter is asked of every **candidate** in that file, and the matching candidate supplies the `{what}` / line of the finding. There is no list of "which facts exist where" — the facts answer for themselves. The report can name the offending values (`{violations}`): for a top-level field written as `{ every: <sub> }` (also behind a `not:`), the items of that fact's list that fail it.
336
+ - That is the ONLY check. "This must be true" is the same filter under `not:` — the language already has `and`/`or`/`xor`/`not` at any depth, so a second key would be a second way to say one thing.
337
+ - `dedupeBy` (optional) — WHERE the findings are counted, written with the same `where` entries the roles use: `[{ node: backend-feature }]` reports once per feature folder, a glob once per matched folder, a filter once per the file's own folder. File-level findings are then reported once per distinct place across the run, so a per-folder rule fires once per folder instead of once per file.
338
+ - `report` (optional) — the finding text. An invariant with a `report` and no checks of its own is its own finding (it applies to every matching file).
339
+ - `children` (optional) — nested invariants, evaluated with the same file facts.
340
+
341
+ Old keys fail with the name to use instead: `except` → `ignore`, `forbid`/`rule` → `infer`, `assert` → `infer`, `must` → `infer: [{ not: … }]`. None of them had a meaning of its own: `assert` was `infer` with the offending values named, `must` was the same filter read backwards.
342
+
343
+ ## The filter engine
344
+
345
+ Every `infer` / `where`-by filter uses one grammar ([entities/queries.js](entities/queries.js)). A filter is:
346
+
347
+ - an **object of entries** — AND of all entries;
348
+ - a **list of filters** — AND of all sub-filters;
349
+ - `null` / omitted — always passes.
350
+
351
+ Each entry is either an **operator** or a **field** of the item — one field at a time, on every fact:
352
+ `{ name: { equals: "x" } }` → `item.name` must pass it; `{ kind: { own: { is: { in: […] } } } }` → `item.kind.own.is` must. There is no shorthand for a structured fact.
100
353
 
101
- `when` may be a function (in a `.js` config) or a string — either a full function body (`"(ctx) => …"` / `"function(ctx) { … }"`) or an expression evaluated with `ctx` in scope — so it can live in JSON.
354
+ Scalar operators: `equals`, `not`, `lt`, `lte`, `gt`, `gte`, `in`, `notIn`, `contains`, `startsWith`, `endsWith`, `isSet`, `setEquals`, `matches`.
102
355
 
103
- ## report
356
+ List operators (list values only; a missing/non-list field simply fails the filter): `length`, `every`, `any`, `none`, `where` (`{ filter, by }` — narrows the list, then applies `by`).
104
357
 
105
- `report` is a **field**, not a check. It is `null`, a string, a function `(vars) => string`, or `{ message, fix, level? }`. `message` is the finding text as the reader sees it; `fix` is the "instead do this" part. Both support multiline Markdown (fenced code blocks, lists, bold). The report prints them verbatim; the ESLint message is a single-line variant of `message`.
358
+ Composition: `or` — a list of filters; passes when **any** sub-filter passes.
106
359
 
107
- ### Variables
360
+ `$`-prefixed values reference another fact in scope: `{ equals: "$name" }` compares the field to the candidate's own `name`.
108
361
 
109
- `{name}` placeholders are substituted before the text is printed.
362
+ ## Facts
110
363
 
111
- **From the file path** (every finding):
364
+ A relation is a **runtime** dependency: `import type` is not one (nothing is bound at runtime), so an adapter may name a type of the code it must not import. Type-only imports are a relation of their own — `typeImport` — so a project can allow one and forbid the other: `import` says "this code runs against that file", `typeImport` says "this code names a shape from it".
112
365
 
113
- | variable | meaning |
366
+ **File facts** (the target of file-level invariant filters): `lines` (the file's lines, as **one array** — `lines[0]` is the first, `lines.length` the count), `imports` (one list for every way a module is brought in: `[{form, source, resolved, typeOnly, named, defaultName?, namespaceName?, line, piece}]` — `form` is `statement` / `require` / `dynamic`, `named` carries local binding names, `resolved` is the repo-relative path after alias expansion, `piece` names the function a `require` sits in), `exports` (one list for every way code leaves the module: `[{form, named, from, source, name, line, piece}]` — `form` is `named` / `namespace` / `star` / `default` / `equals` / `commonjs`), `location` (WHERE the file is — the one place fact: `location.path`, `location.dir`, `location.fileName`, `location.files` — the folder's own files, so the count is `{ location: { files: { length: { gt: 7 } } } }`), `kind` (the file's own node and every node below it — see the `kind` fact), `candidates` (the function-like / variable-declaration facts, each role-enriched), `roles` (the flat list of role names present).
367
+
368
+ **The `kind` fact** — one shape for every structural question about a node, so a rule never needs a second vocabulary. `kind` holds six facets, and every facet answers with the SAME descriptor `{ is: <ts-morph kind>, …extras }`:
369
+
370
+ | facet | is |
114
371
  | --- | --- |
115
- | `{file}` | repo-relative path of the flagged file |
116
- | `{basename}` | file name without directory |
117
- | `{dir}` | directory of the file (repo-relative) |
372
+ | `own` | the node itself |
373
+ | `parent` | its syntax parent (may be a `Block` or a `VariableStatement` — syntax, not meaning) |
374
+ | `ancestors` | every enclosing node up to the file |
375
+ | `children` | its direct children |
376
+ | `siblings` | its siblings |
377
+ | `descendants` | everything below it, flat (`depth: 0` = a direct child; extras: `snippet`, `nested`, `type` on `as` expressions, `members` on object literals) |
378
+ | `initializer` | for a declaration, the value it is initialised with: `{ is, origin, members }` (`origin` is the leftmost identifier chain: `t.model` in `t.model({…})`, and `is` is `CallExpression`) |
118
379
 
119
- **Captures** — any `{name}` used in a node `name`, invariant `where`, or `forbid` (imports) pattern. E.g. `{slice}` in `core/ehr/{slice}.v/**/*.rm.ts` captures `allergies` and is available as `{slice}` in that file's findings.
380
+ Every facet is the same descriptor — `{ is, name, line }` plus what that node has on top — and they all take the same filters — `{ is: { equals: "ClassDeclaration" } }`, `{ is: { in: [...] } }`, a nested filter, everything in `entities/queries.js`. A structured fact is always addressed through its fields — `kind: { own: { is: { in: [...] } } }`, `kind: { parent: { is: { notIn: [...] } } }` — so `kind` never looks different from any other fact. Because the facets are one list of node descriptors, `kind.initializer` is NOT a separate concept: it is the same descriptor, one level down.
120
381
 
121
- **Match context** (text-forbid findings only):
382
+ **Candidate facts** (one entry per function-like node / class / variable declaration) — a piece of code is described with four things and nothing else:
122
383
 
123
- | variable | meaning |
384
+ | fact | what it holds |
124
385
  | --- | --- |
125
- | `{count}` | how many lines matched the pattern |
126
- | `{plural}` | `""` if count is 1, `"s"` otherwise — for `time{plural}` |
127
- | `{line}` | first matching line number |
128
- | `{lines}` | all matching line numbers, comma-separated |
129
- | `{snippet}` | the first matching line, trimmed |
130
- | `{match}` | the exact matched text on the first line |
131
- | `{where}` | ` in `functionName`` if the match is inside a named function, empty otherwise |
386
+ | `location` | where it IS: `location.path` (the file) and `location.piece` (the piece it is nested in — `null` = module scope). `{ location: { piece: { isNull: true } } }` reads "at module scope", and `{ location: { node: … } }` matches the path |
387
+ | `lines` | the lines it spans, as ONE array: start, everything inside, end (`lines[0]`, `lines.length`) |
388
+ | `parameters` | `[{ name, type, typeFile }]` — `typeFile` is the file that declares the parameter's type, resolved by the checker |
389
+ | `calls` | `[{ kind, origin, action, module, target, forwardsAllParams, targetRole }]` — running somebody's code |
390
+ | `assignments` | `[{ line, target, method, value, via, module, onThis, type, param, local, relation }]` — every write, in one fact. `via` is `assign` / `call` / `delete` / `freeze` / `seal`; `value` is the root identifier written into; `module` is the other module whose value it is; `onThis` marks `this.x`; `type` is the file declaring the written value's type; `param` says the root is one of this function's parameters. `relation` is the ONE classification of the write — `mutate` (somebody else's value), `assign` (a value that was handed in or is declared in the repo) or `null` (the piece's own local, which no role has a say in) |
391
+ | `returns` | `[{kind, exprKind, origin, members}]` — the value it yields |
392
+ | `kind` | what it is, what is around/below it, and how it is SPELLED: `own` / `parent` / `ancestors` / `children` / `siblings` / `descendants`, plus `modifiers` (`["export", "abstract", "const"]` — the words as written, for every kind of declaration), `decorators` (`[{ name, full, line }]`), `assertion` (`as const` / `satisfies X`) and `disposable` (`using`) |
393
+ | `name`, `kind`, `role` | what it is CALLED, what it IS, and the role it got |
394
+
395
+ Plus, for a declaration: `exported` (is it written with `export`), `mutable` (may the binding be reassigned — `let`/`var`), `extends`, `implements`, `members`, `constructorParams` for classes, `references` / `implementations` (the checker's answer, not the tree's), and `file` (the facts of the file it lives in, so a role can ask `{ file: { imports: { any: { source: … } } } }` — "this function depends on the IDE API, so it is a host adapter, not a helper").
396
+
397
+ Everything a piece DOES is a **relation** (`entities/kinds.js`), and the eight relations are the whole vocabulary: `import`, `export`, `declare`, `call`, `mutate`, `assign`, `read`, `typeImport`. There is no second way to say "it writes" or "it is exported".
398
+
399
+ A call's `target` is a **location**, the same interface `allowedFrom` uses: `{ path, name }`, where `path` is the module the callee was imported from (only bare-identifier calls carry one — `store.doX()` names a member, not an imported symbol). So a call destination is addressed exactly like anything else in the architecture:
400
+
401
+ ```yaml
402
+ # "a function that calls something living in the actions node"
403
+ infer:
404
+ - calls:
405
+ any:
406
+ target:
407
+ location: { node: backend-feature-actions }
408
+ ```
132
409
 
133
- Without `report`, the tool composes a fallback from the rule's shape.
410
+ `targetRole` is the same question answered in role vocabulary: the role whose home covers the target's location — the `role:` a node declares for that path. An ambiguous location yields `null` — the engine never guesses.
134
411
 
135
- ## Aliases
412
+ `nested` is set on function-like / loop descendants: `true` when nested inside another function-like node. A descendant is the same descriptor as every other `kind` facet, one level deeper (`depth`).
136
413
 
137
- `aliases` maps import specifiers to paths for import resolution (e.g. `"#_db": "core/ehr/_db"`). Used by `type: "imports"` forbid entries and by `ctx.imports[].resolved`.
414
+ ## Report
138
415
 
139
- ## CLI
416
+ `report` is `null`, a string, or `{ message, fix }`. Both fields support multiline Markdown. `{name}` placeholders are substituted: path vars (`{file}`, `{basename}`, `{dir}`), every scalar of `location` (`{fileName}`, `{files}`), captures from `where` / node names, and match context (`{what}` — the matched candidate's name, `{snippet}`, `{lines}`, `{files}` — an array fact reports its length, …).
417
+
418
+ ### What a finding says
419
+
420
+ A finding is written for someone who has to ACT on it, so it carries the same
421
+ information the graph does — never a choice between two half-answers:
422
+
423
+ | Part | What it names |
424
+ |---|---|
425
+ | the message | the offending line, the rule that fired, and everything the rule DOES allow — a closed folder lists its declared children, an action lists the roles and the concrete folders that may do it, a feature lists the files it must own |
426
+ | the destination | when the offending code has a role with a declared home, that home resolved for this file (`packages/utils`, `apps/backend/grammar/controller.ts`), so "move it" means one path, not "somewhere" |
427
+ | the mechanisms | for an action with `scopeAccess`, the chains that may reach the same code WITHOUT an import — `getRoot(…)`, `self.root`, `parent.get(…)` — the same words the config uses |
428
+ | `How to fix` | one instruction per offending line, naming the exact file or folder to move to — and **nothing at all** when the architecture cannot prove a destination: then the message alone says where this code must not live |
429
+
430
+ Which home answers is decided, not guessed: a home in the file's own BRANCH wins
431
+ (`src/alpha/actions/**` says nothing about a file in `src/beta`; a
432
+ `{kebab-case}` segment matches the file's own instance), and among those the
433
+ closest one. When no home is in the file's branch — a role allowed in several
434
+ unrelated packages — the home declared FIRST answers, so **the order of the
435
+ nodes that declare a role is its priority list**: put the canonical home first,
436
+ the permissive ones (examples, tests) last.
437
+ | the config file | every instruction names the file the architecture was actually loaded from (`architecture.yaml`, or whatever `--config` pointed at) — never a hardcoded default |
438
+
439
+ When the architecture genuinely has no answer (a role with no declared home, in
440
+ a folder the tree does not declare), the finding says exactly that and names the
441
+ single edit that gives it one — it does not offer an "either … or".
442
+
443
+ ### Where the wording lives — `report/errorTypes/`
444
+
445
+ The engine observes and decides **facts**. The report turns facts into
446
+ **language**, once, for every consumer (the CLI text, the linter message, the
447
+ interactive overview). No module outside `report/errorTypes/` writes a sentence
448
+ about a finding.
140
449
 
141
- ```sh
142
- node follow-architecture/bin/follow-architecture.js [options]
143
450
  ```
451
+ report/errorTypes/
452
+ index.js public surface: describe(), renderToken(), ids
453
+ decision-maker.js the only decision maker: which kind of finding, what to say,
454
+ what can be done, and WHERE the code belongs
455
+ vocabulary/
456
+ ids.js the ids both sides use (the report and the picture)
457
+ verbs.js "imports" / "import" / "mutation"
458
+ phrases.js a fact → a phrase, a subject, a reason
459
+ places.js role → box, name → node, a role's declared home
460
+ types/
461
+ wrongAction.js a relation the architecture forbids
462
+ wrongPlacement.js the code is in the wrong place (move, or split)
463
+ unknownRole.js nothing declares this kind of code here
464
+ fileContents.js the finding judges the file itself
465
+ codes/
466
+ structure.js structure.* — "this entry does not belong in this folder"
467
+ ```
468
+
469
+ ### Where a move goes — `decision-maker.js` → `decide()`
144
470
 
145
- | flag | default | meaning |
146
- | --- | --- | --- |
147
- | `[cwd]` | `.` | repo root (positional) |
148
- | `--config <path>` | `architecture.json` / `architecture.config.js` found by walking up | architecture JSON or JS module |
149
- | `--out <path>` | print to stdout | report output |
150
- | `--ignore <glob>` | — | extra file globs to skip (repeatable) |
151
- | `--check` | off | exit 1 if there are findings |
471
+ A destination is a **decision**, not a lookup: it is decided by the **code role**
472
+ and confirmed by the tree. The percentage is a `0..1` confidence:
152
473
 
153
- The report (`--out`) groups findings by file and prints each finding as the full `message` followed by a **Fix.** section with the `fix` text.
474
+ | Source | Question it answers | Weight |
475
+ |---|---|---|
476
+ | `declared` | does the tree call this file that role (its owner node's roles)? | 0.45 |
477
+ | `inferred` | did the engine infer that role from the code itself? | 0.30 |
478
+ | `named` | does a home of that role name this file? | 0.13 |
479
+ | `hostable` | can a real node instance host that home today? | 0.07 |
480
+ | `branch` | is that home in the file's own top branch? | 0.05 |
154
481
 
155
- ## ESLint
482
+ `permits` is **not** a weight — it is a **gate**: the rule is "everything not
483
+ allowed is forbidden", so a place where the relation is still forbidden is not a
484
+ destination at all, whatever the other signals say. A permission says the move
485
+ would be legal; it never says the move is right (`testCode` may call an action,
486
+ and that says nothing about where production code belongs).
156
487
 
157
- The package exports a `flatConfig` factory:
488
+ A candidate also needs a known code role (`declared` or `inferred`) and at least
489
+ two sources (`MIN_EVIDENCE`) with **confidence ≥ 0.5**. When nothing qualifies,
490
+ no move is offered — the finding's repair is the removal, which is the honest
491
+ answer for "this role may not do this here".
492
+
493
+ One output format for every candidate, so the text and the picture read the
494
+ same numbers:
158
495
 
159
496
  ```js
160
- // eslint.config.js
161
- const { flatConfig } = require("./follow-architecture/config.js");
497
+ { role, node, path, confidence, tier, reason, signals, contributions,
498
+ evidence, thresholds, weights }
499
+ ```
500
+
501
+ Each type answers three questions and nothing else:
502
+
503
+ | Export | Question |
504
+ |---|---|
505
+ | `classify(ctx, places)` | is this finding of my kind, and what are the facts? |
506
+ | `message(story, ctx)` | the sentence to print — `null` keeps the engine's |
507
+ | `fixes(story, ctx)` | **a list** of repairs, cheapest first |
162
508
 
163
- module.exports = flatConfig(require("./architecture.json"), {
164
- files: ["core/ehr/**/*.ts", "core/ehr/**/*.tsx"],
165
- });
509
+ `fixes` is always a list because a broken rule usually has more than one honest
510
+ answer. A forbidden relation, for example, can be repaired by removing the
511
+ usage, by moving the code into a role that may do it, or by widening the rule in
512
+ the architecture — printing only the first one is how a report ends up saying
513
+ "Delete it." about a file that is perfectly placed.
514
+
515
+ **The engine emits tokens, not prose.** A refused relation travels as
516
+
517
+ ```js
518
+ { code: "relation.forbidden",
519
+ fact: { kind: "typeImport", resolved: "…/document/type.ts" },
520
+ subject: { pieces: [], roles: ["constants"], plural: false },
521
+ why: { code: "allowed", roles: ["storeModel", …], targetNode: "sharedTypes" },
522
+ via: null }
523
+ ```
524
+
525
+ `phrases.js` renders the sentence from it, `wrongAction.js` renders the
526
+ repairs, the picture renders the arrow. The node→node edges carry the same
527
+ structured `fact` (no words), so the AST layer cannot disagree with the report
528
+ about what the code did.
529
+
530
+ `report/user-report/src/graph/` is the picture side, one representation per id —
531
+ `representation/wrongAction.js` (one crossed-out arrow, no marks on the boxes),
532
+ `wrongPlacement.js` (✕ here, ✓ there), `unknownRole.js` (one crossed box),
533
+ `fileContents.js` (the box, unmarked). `graph/decision.js` picks the one that
534
+ draws the story; `graph/ids.js` and `graph/words.js` import the ids and the
535
+ verbs from `report/errorTypes/`, so a label can never drift from a sentence.
536
+
537
+ ### The modules, in one table
538
+
539
+ | Path | What it owns |
540
+ |---|---|
541
+ | `entities/ast/` | reading code: imports, calls, writes, declarations → **facts** |
542
+ | `entities/kinds.js` | a fact → an **edge** (`{ path, line, piece, role, fact, what }`) |
543
+ | `entities/tree/` | **where** files may live: `build.js` (nodes → path variants + role homes), `match.js` (a path → its node, and whether that node is real there), `entries.js` (walking a path, reporting undeclared entries) |
544
+ | `nodes/` | `children.js`, `homes.js` (where a role lives), `similar.js` |
545
+ | `nodes/finally/` | the built-in structure rule, four questions in four files: `required.js` (is this folder an instance of its node?), `queries.js` (does this file match a child's query?), `relations.js` (does this file reach code it may not?), `emit.js` (one finding per decision) |
546
+ | `report/errorTypes/` | **the words**: message, repairs, and the ids the picture uses |
547
+ | `report/user-report/` | the interactive overview: data → JSON → React |
548
+
549
+
550
+ ### `--overview` (interactive HTML)
551
+
552
+ `--overview [path]` writes one self-contained HTML file (no server, no network, no sidecar assets) that renders the architecture as a browsable model:
553
+
554
+ | Screen | What it answers |
555
+ |---|---|
556
+ | **Overview** | counts, findings by category, orphan files, the most important violations |
557
+ | **Architecture tree** | every declared node, the roles that may live in it, the arrows that touch it, and its findings as links. Each row carries a coloured dot per action it takes part in — the same colours the Graph uses |
558
+ | **Graph & code roles** | the roles list and the selected role's card on the left (how it is inferred, a real example, what may be done with it); the canvas on the right draws that role's boundary as **folders** — boxes are declared nodes, arrows are the actions the role declares, one filter button per action (`all` by default). Clicking a folder opens its boundary in both directions |
559
+ | **Code roles** | how each role is inferred, where it may live, what may be done with it, and real matches from this repo with code snippets |
560
+ | **Invariants** | each cross-cutting rule rewritten as plain conditions (`lines > 200`, `rule ≠ action`), with `where` / `ignore` named by kind |
561
+ | **Findings** | every violation with its message, **the boundary it crossed**, why it matters, and the fix |
562
+
563
+ The graph is **folder → folder**, never role → role: the boxes are the declared
564
+ nodes (labelled by path). Every action reads the same way: **`a ──kind──▶ b`**
565
+ means *code in `a` is `<kind>`ed inside `b`* — the arrow follows the dependency,
566
+ from the code that is imported or used into the code that imports or uses it. So
567
+ `store.ts ──import──▶ controller.ts` is the controller importing the store,
568
+ `store.ts ──call──▶ actions` is an action reading the store, and
569
+ `feature/store.ts ──import──▶ store.ts` is the main store composing the feature
570
+ one. The edge exists because `codeRole.actions.<kind>.where` says who may do it
571
+ and the target role's `where` says which folders that code lives in. Selecting a
572
+ role draws every arrow it takes part in, from either side: what may be used
573
+ inside its code, and where its own code may go.
574
+
575
+ Nothing on the canvas overlaps another thing on the canvas. An arrow never
576
+ crosses a box: a step to the next column runs inside the empty strip between the
577
+ two columns, anything else leaves and enters horizontally and travels in a lane
578
+ outside the band of boxes — and every vertical run gets its own lane inside its
579
+ strip, so two arrows never share a line. Every action between the same two
580
+ folders keeps its OWN arrow and its own label — `import` and `call` are
581
+ different facts, and only `call` carries the reach mechanisms, so one merged
582
+ line would claim a single rule where there are two. An action a folder may do to
583
+ itself is a `↻ kind · role` badge on the folder, because a loop arcing back into
584
+ its own box is exactly the kind of thing that used to be unreadable.
585
+
586
+ Each arrow is labelled where it stands — one line per action, plus, for an action
587
+ that declares `scopeAccess`, the chains that reach the same code without an
588
+ import (`via getRoot(…), getParent(…)`, `self.root, parent.get(…)`). The column
589
+ strip is sized to the widest of those labels, so the words are on the picture
590
+ itself and never need a separate legend to be understood.
591
+
592
+ `same: true` edges are drawn only inside one instance of a repeating node
593
+ (feature A's action may import feature A's store, never B's). A rule that names
594
+ a role living in BOTH a container and its children — `{ role: storeModel }` on a
595
+ store — declares that pair twice, and is drawn once, pointing into the
596
+ container: every child store reaches the main store, never the other way round.
597
+ A rule that names a glob or a filter cannot be drawn as a folder arrow and is
598
+ listed under the canvas instead of being invented.
599
+
600
+ The UI lives in `report/user-report/`:
601
+
602
+ - `data/` — builds the JSON payload (nodes, the access graph, roles, invariants, findings)
603
+ - `src/screens/` — Overview, Architecture tree, Graph, Code roles, Invariants, Findings
604
+ - `src/components/` — folder-access graph (SVG), tree, before/after cards, role detail
605
+ - `src/components/code-preview/` — highlighted code panels (highlight.js)
606
+ - `src/generate/` — **derives** the docs from the config: `inferToYaml`, allowed/forbidden import lines
607
+ - `build/bundle.js` — reads the build-time bundle from `dist/` (see below); falls back to compiling `src/` with esbuild in a dev workspace
608
+
609
+ Nothing in the report is hardcoded per project — there is no vocabulary about
610
+ specific roles, invariants or folders anywhere in the code. Titles come from the
611
+ configured messages, conditions from the configured `rule` blocks, and the
612
+ good/bad examples from the roles' `actions.*.where` plus real paths. Findings carry
613
+ the engine's own structured `data.violations` (kind + target node), so the UI
614
+ never parses message text. The same build documents any repository.
615
+
616
+ ### Prebuilt overview bundle
617
+
618
+ The `--overview` page inlines a React app. It is compiled at **package build
619
+ time**, not on first use: `scripts/build-report-bundle.mjs` runs the same esbuild
620
+ config and writes `dist/report/user-report/build/bundle.prebuilt.js`, which is
621
+ shipped inside `dist/`. The published CLI therefore never needs `esbuild`, React
622
+ or `styled-components` at runtime — they are `devDependencies`.
623
+
624
+ Contributors running from source without a build still get overviews: when the
625
+ asset is missing, `getBundle` compiles `src/` on the fly and caches it in
626
+ `os.tmpdir()`. Only that dev fallback resolves esbuild. `pnpm build` = `tsc`
627
+ followed by `prebuild:report`; run the workspace build (`turbo build` / `pnpm -r
628
+ run build`) so `@md-code/sections` (which owns the code-diff board) is compiled
629
+ before packages that bundle its view.
630
+
631
+ ## Tests
632
+
633
+ ```sh
634
+ npx vitest run
166
635
  ```
167
636
 
168
- `flatConfig(architecture, { parser, files, ignores })` returns a flat-config array. `architecture` is the object (or `{ file: "architecture.json" }` — it is resolved lazily per file so the repo root is found from the file being linted). `parser` defaults to `@typescript-eslint/parser`. The rule is `md-code/follow-architecture`.
637
+ ## License
638
+
639
+ [Apache License 2.0](./LICENSE)