@md-code/follow-architecture 0.1.1 → 0.3.2

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 (487) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/LICENSE +202 -0
  3. package/README.md +1420 -139
  4. package/dist/aliases.d.ts +3 -0
  5. package/dist/aliases.js +12 -0
  6. package/dist/args.d.ts +18 -0
  7. package/dist/args.js +94 -0
  8. package/dist/bin/follow-architecture.d.ts +2 -0
  9. package/dist/bin/follow-architecture.js +23 -0
  10. package/dist/closure-project.d.ts +4 -0
  11. package/dist/closure-project.js +132 -0
  12. package/dist/code-entities/classify.d.ts +11 -0
  13. package/dist/code-entities/classify.js +45 -0
  14. package/dist/code-entities/connector.d.ts +8 -0
  15. package/dist/code-entities/connector.js +119 -0
  16. package/dist/code-entities/entities.d.ts +9 -0
  17. package/dist/code-entities/entities.js +227 -0
  18. package/dist/code-entities/project.d.ts +21 -0
  19. package/dist/code-entities/project.js +259 -0
  20. package/dist/code-entities/walk.d.ts +31 -0
  21. package/dist/code-entities/walk.js +105 -0
  22. package/dist/config-options.d.ts +76 -0
  23. package/dist/config-options.js +52 -0
  24. package/dist/config-project.d.ts +4 -0
  25. package/dist/config-project.js +92 -0
  26. package/dist/config-report.d.ts +19 -0
  27. package/dist/config-report.js +161 -0
  28. package/dist/config-rule.d.ts +95 -0
  29. package/dist/config-rule.js +211 -0
  30. package/dist/config-state.d.ts +25 -0
  31. package/dist/config-state.js +269 -0
  32. package/dist/config.d.ts +107 -0
  33. package/dist/config.js +38 -0
  34. package/dist/css/index.d.ts +31 -0
  35. package/dist/css/index.js +251 -0
  36. package/dist/css/syntax/css/gate.d.ts +2 -0
  37. package/dist/css/syntax/css/gate.js +69 -0
  38. package/dist/css/syntax/css/index.d.ts +7 -0
  39. package/dist/css/syntax/css/index.js +51 -0
  40. package/dist/css/syntax/css/reference.d.ts +3 -0
  41. package/dist/css/syntax/css/reference.js +36 -0
  42. package/dist/css/syntax/language.d.ts +25 -0
  43. package/dist/css/syntax/language.js +81 -0
  44. package/dist/css/syntax/scss/index.d.ts +25 -0
  45. package/dist/css/syntax/scss/index.js +95 -0
  46. package/dist/css/syntax/scss/reference.d.ts +3 -0
  47. package/dist/css/syntax/scss/reference.js +17 -0
  48. package/dist/css/syntax/styled/document.d.ts +68 -0
  49. package/dist/css/syntax/styled/document.js +261 -0
  50. package/dist/css/syntax/styled/markup.d.ts +6 -0
  51. package/dist/css/syntax/styled/markup.js +84 -0
  52. package/dist/css/syntax/styled/tags.d.ts +2 -0
  53. package/dist/css/syntax/styled/tags.js +22 -0
  54. package/dist/css/syntax/styled/template.d.ts +23 -0
  55. package/dist/css/syntax/styled/template.js +67 -0
  56. package/dist/css/syntax/tailwind/tailwind-engine.d.ts +23 -0
  57. package/dist/css/syntax/tailwind/tailwind-engine.js +37 -0
  58. package/dist/css/syntax/tailwind/tailwind.d.ts +26 -0
  59. package/dist/css/syntax/tailwind/tailwind.js +118 -0
  60. package/dist/css/value/check.d.ts +86 -0
  61. package/dist/css/value/check.js +122 -0
  62. package/dist/css/value/expression/arithmetic.d.ts +7 -0
  63. package/dist/css/value/expression/arithmetic.js +73 -0
  64. package/dist/css/value/expression/block.d.ts +9 -0
  65. package/dist/css/value/expression/block.js +92 -0
  66. package/dist/css/value/expression/conditional.d.ts +8 -0
  67. package/dist/css/value/expression/conditional.js +53 -0
  68. package/dist/css/value/expression/index.d.ts +5 -0
  69. package/dist/css/value/expression/index.js +73 -0
  70. package/dist/css/value/expression/map.d.ts +7 -0
  71. package/dist/css/value/expression/map.js +113 -0
  72. package/dist/css/value/object/index.d.ts +5 -0
  73. package/dist/css/value/object/index.js +113 -0
  74. package/dist/css/value/object/members.d.ts +7 -0
  75. package/dist/css/value/object/members.js +103 -0
  76. package/dist/css/value/object/node.d.ts +8 -0
  77. package/dist/css/value/object/node.js +134 -0
  78. package/dist/css/value/object/path.d.ts +10 -0
  79. package/dist/css/value/object/path.js +152 -0
  80. package/dist/css/value/pieces.d.ts +61 -0
  81. package/dist/css/value/pieces.js +65 -0
  82. package/dist/css/value/resolve.d.ts +33 -0
  83. package/dist/css/value/resolve.js +104 -0
  84. package/dist/css/value/scope.d.ts +28 -0
  85. package/dist/css/value/scope.js +205 -0
  86. package/dist/css/value/substitute.d.ts +10 -0
  87. package/dist/css/value/substitute.js +145 -0
  88. package/dist/css/value/values.d.ts +23 -0
  89. package/dist/css/value/values.js +131 -0
  90. package/dist/entities/architecture.d.ts +165 -0
  91. package/dist/entities/architecture.js +2 -0
  92. package/dist/entities/ast/assignments-nodes.d.ts +10 -0
  93. package/dist/entities/ast/assignments-nodes.js +64 -0
  94. package/dist/entities/ast/assignments-raw.d.ts +6 -0
  95. package/dist/entities/ast/assignments-raw.js +139 -0
  96. package/dist/entities/ast/assignments-tagged.d.ts +5 -0
  97. package/dist/entities/ast/assignments-tagged.js +195 -0
  98. package/dist/entities/ast/assignments.d.ts +9 -0
  99. package/dist/entities/ast/assignments.js +80 -0
  100. package/dist/entities/ast/branches.d.ts +4 -0
  101. package/dist/entities/ast/branches.js +32 -0
  102. package/dist/entities/ast/calls.d.ts +6 -0
  103. package/dist/entities/ast/calls.js +150 -0
  104. package/dist/entities/ast/classes.d.ts +5 -0
  105. package/dist/entities/ast/classes.js +61 -0
  106. package/dist/entities/ast/climb.d.ts +12 -0
  107. package/dist/entities/ast/climb.js +17 -0
  108. package/dist/entities/ast/comments.d.ts +5 -0
  109. package/dist/entities/ast/comments.js +130 -0
  110. package/dist/entities/ast/declaration.d.ts +4 -0
  111. package/dist/entities/ast/declaration.js +26 -0
  112. package/dist/entities/ast/depth.d.ts +17 -0
  113. package/dist/entities/ast/depth.js +166 -0
  114. package/dist/entities/ast/enums.d.ts +6 -0
  115. package/dist/entities/ast/enums.js +17 -0
  116. package/dist/entities/ast/export-chain.d.ts +15 -0
  117. package/dist/entities/ast/export-chain.js +171 -0
  118. package/dist/entities/ast/file-exports.d.ts +7 -0
  119. package/dist/entities/ast/file-exports.js +101 -0
  120. package/dist/entities/ast/file-facts.d.ts +16 -0
  121. package/dist/entities/ast/file-facts.js +64 -0
  122. package/dist/entities/ast/file-imports.d.ts +5 -0
  123. package/dist/entities/ast/file-imports.js +100 -0
  124. package/dist/entities/ast/file.d.ts +5 -0
  125. package/dist/entities/ast/file.js +23 -0
  126. package/dist/entities/ast/functions.d.ts +8 -0
  127. package/dist/entities/ast/functions.js +111 -0
  128. package/dist/entities/ast/heritage.d.ts +4 -0
  129. package/dist/entities/ast/heritage.js +44 -0
  130. package/dist/entities/ast/index.d.ts +9 -0
  131. package/dist/entities/ast/index.js +181 -0
  132. package/dist/entities/ast/kind.d.ts +5 -0
  133. package/dist/entities/ast/kind.js +34 -0
  134. package/dist/entities/ast/loose.d.ts +37 -0
  135. package/dist/entities/ast/loose.js +2 -0
  136. package/dist/entities/ast/modifiers.d.ts +5 -0
  137. package/dist/entities/ast/modifiers.js +32 -0
  138. package/dist/entities/ast/project.d.ts +9 -0
  139. package/dist/entities/ast/project.js +106 -0
  140. package/dist/entities/ast/properties.d.ts +11 -0
  141. package/dist/entities/ast/properties.js +176 -0
  142. package/dist/entities/ast/resolve.d.ts +16 -0
  143. package/dist/entities/ast/resolve.js +317 -0
  144. package/dist/entities/ast/tree.d.ts +31 -0
  145. package/dist/entities/ast/tree.js +518 -0
  146. package/dist/entities/ast/types.d.ts +6 -0
  147. package/dist/entities/ast/types.js +46 -0
  148. package/dist/entities/ast/usage.d.ts +11 -0
  149. package/dist/entities/ast/usage.js +81 -0
  150. package/dist/entities/ast/variables.d.ts +8 -0
  151. package/dist/entities/ast/variables.js +91 -0
  152. package/dist/entities/context.d.ts +29 -0
  153. package/dist/entities/context.js +2 -0
  154. package/dist/entities/facts.d.ts +284 -0
  155. package/dist/entities/facts.js +2 -0
  156. package/dist/entities/findings.d.ts +19 -0
  157. package/dist/entities/findings.js +2 -0
  158. package/dist/entities/kinds.d.ts +40 -0
  159. package/dist/entities/kinds.js +332 -0
  160. package/dist/entities/location/homes.d.ts +28 -0
  161. package/dist/entities/location/homes.js +195 -0
  162. package/dist/entities/location/place.d.ts +10 -0
  163. package/dist/entities/location/place.js +63 -0
  164. package/dist/entities/location/where.d.ts +19 -0
  165. package/dist/entities/location/where.js +277 -0
  166. package/dist/entities/location.d.ts +16 -0
  167. package/dist/entities/location.js +140 -0
  168. package/dist/entities/operators.d.ts +14 -0
  169. package/dist/entities/operators.js +30 -0
  170. package/dist/entities/overview/data.d.ts +43 -0
  171. package/dist/entities/overview/data.js +2 -0
  172. package/dist/entities/overview/decision.d.ts +60 -0
  173. package/dist/entities/overview/decision.js +2 -0
  174. package/dist/entities/overview/file-tree.d.ts +10 -0
  175. package/dist/entities/overview/file-tree.js +2 -0
  176. package/dist/entities/overview/finding.d.ts +58 -0
  177. package/dist/entities/overview/finding.js +2 -0
  178. package/dist/entities/overview/graph.d.ts +82 -0
  179. package/dist/entities/overview/graph.js +2 -0
  180. package/dist/entities/overview/input.d.ts +15 -0
  181. package/dist/entities/overview/input.js +2 -0
  182. package/dist/entities/overview/summaries.d.ts +81 -0
  183. package/dist/entities/overview/summaries.js +2 -0
  184. package/dist/entities/place.d.ts +5 -0
  185. package/dist/entities/place.js +2 -0
  186. package/dist/entities/queries.d.ts +9 -0
  187. package/dist/entities/queries.js +375 -0
  188. package/dist/entities/repair.d.ts +16 -0
  189. package/dist/entities/repair.js +29 -0
  190. package/dist/entities/schema.d.ts +22 -0
  191. package/dist/entities/schema.js +81 -0
  192. package/dist/entities/story.d.ts +47 -0
  193. package/dist/entities/story.js +2 -0
  194. package/dist/entities/structure-facts.d.ts +11 -0
  195. package/dist/entities/structure-facts.js +2 -0
  196. package/dist/entities/token.d.ts +23 -0
  197. package/dist/entities/token.js +2 -0
  198. package/dist/entities/tree/build.d.ts +6 -0
  199. package/dist/entities/tree/build.js +313 -0
  200. package/dist/entities/tree/entries.d.ts +7 -0
  201. package/dist/entities/tree/entries.js +145 -0
  202. package/dist/entities/tree/index.d.ts +6 -0
  203. package/dist/entities/tree/index.js +21 -0
  204. package/dist/entities/tree/match.d.ts +17 -0
  205. package/dist/entities/tree/match.js +190 -0
  206. package/dist/fa-index.d.ts +16 -0
  207. package/dist/fa-index.js +165 -0
  208. package/dist/fa-open.d.ts +51 -0
  209. package/dist/fa-open.js +242 -0
  210. package/dist/fa-store.d.ts +22 -0
  211. package/dist/fa-store.js +232 -0
  212. package/dist/fa-values.d.ts +37 -0
  213. package/dist/fa-values.js +104 -0
  214. package/dist/facts-record.d.ts +45 -0
  215. package/dist/facts-record.js +297 -0
  216. package/dist/frameworks/angular/index.d.ts +7 -0
  217. package/dist/frameworks/angular/index.js +18 -0
  218. package/dist/frameworks/facet.d.ts +18 -0
  219. package/dist/frameworks/facet.js +15 -0
  220. package/dist/frameworks/index.d.ts +9 -0
  221. package/dist/frameworks/index.js +134 -0
  222. package/dist/frameworks/react/index.d.ts +7 -0
  223. package/dist/frameworks/react/index.js +237 -0
  224. package/dist/frameworks/test/index.d.ts +6 -0
  225. package/dist/frameworks/test/index.js +157 -0
  226. package/dist/frameworks/vue/index.d.ts +7 -0
  227. package/dist/frameworks/vue/index.js +18 -0
  228. package/dist/ignore.d.ts +3 -0
  229. package/dist/ignore.js +62 -0
  230. package/dist/index-file.d.ts +43 -0
  231. package/dist/index-file.js +218 -0
  232. package/dist/index-run.d.ts +39 -0
  233. package/dist/index-run.js +217 -0
  234. package/dist/index-zone.d.ts +25 -0
  235. package/dist/index-zone.js +219 -0
  236. package/dist/main.d.ts +10 -0
  237. package/dist/main.js +411 -0
  238. package/dist/nodes/child-entities.d.ts +3 -0
  239. package/dist/nodes/child-entities.js +12 -0
  240. package/dist/nodes/children.d.ts +25 -0
  241. package/dist/nodes/children.js +165 -0
  242. package/dist/nodes/finally/emit.d.ts +6 -0
  243. package/dist/nodes/finally/emit.js +71 -0
  244. package/dist/nodes/finally/entities.d.ts +13 -0
  245. package/dist/nodes/finally/entities.js +42 -0
  246. package/dist/nodes/finally/index.d.ts +8 -0
  247. package/dist/nodes/finally/index.js +35 -0
  248. package/dist/nodes/finally/queries.d.ts +5 -0
  249. package/dist/nodes/finally/queries.js +25 -0
  250. package/dist/nodes/finally/relations-access.d.ts +5 -0
  251. package/dist/nodes/finally/relations-access.js +50 -0
  252. package/dist/nodes/finally/relations-edge.d.ts +29 -0
  253. package/dist/nodes/finally/relations-edge.js +148 -0
  254. package/dist/nodes/finally/relations-group.d.ts +31 -0
  255. package/dist/nodes/finally/relations-group.js +106 -0
  256. package/dist/nodes/finally/relations.d.ts +5 -0
  257. package/dist/nodes/finally/relations.js +85 -0
  258. package/dist/nodes/finally/required.d.ts +5 -0
  259. package/dist/nodes/finally/required.js +92 -0
  260. package/dist/nodes/finally/violation.d.ts +17 -0
  261. package/dist/nodes/finally/violation.js +2 -0
  262. package/dist/nodes/similar.d.ts +21 -0
  263. package/dist/nodes/similar.js +178 -0
  264. package/dist/piece-forms.d.ts +9 -0
  265. package/dist/piece-forms.js +68 -0
  266. package/dist/pipeline-entities.d.ts +6 -0
  267. package/dist/pipeline-entities.js +79 -0
  268. package/dist/pipeline-facts.d.ts +12 -0
  269. package/dist/pipeline-facts.js +114 -0
  270. package/dist/pipeline-unclassified.d.ts +14 -0
  271. package/dist/pipeline-unclassified.js +188 -0
  272. package/dist/pipeline.d.ts +7 -0
  273. package/dist/pipeline.js +28 -0
  274. package/dist/plugin.d.ts +2 -0
  275. package/dist/plugin.js +3 -0
  276. package/dist/release-file.d.ts +3 -0
  277. package/dist/release-file.js +13 -0
  278. package/dist/report/asks.d.ts +55 -0
  279. package/dist/report/asks.js +60 -0
  280. package/dist/report/cli-report.d.ts +2 -0
  281. package/dist/report/cli-report.js +13 -0
  282. package/dist/report/config-error-guard.d.ts +8 -0
  283. package/dist/report/config-error-guard.js +5 -0
  284. package/dist/report/configErrors.d.ts +126 -0
  285. package/dist/report/configErrors.js +121 -0
  286. package/dist/report/errorTypes/codes/structure.d.ts +15 -0
  287. package/dist/report/errorTypes/codes/structure.js +76 -0
  288. package/dist/report/errorTypes/decision-maker.d.ts +23 -0
  289. package/dist/report/errorTypes/decision-maker.js +109 -0
  290. package/dist/report/errorTypes/destinations.d.ts +38 -0
  291. package/dist/report/errorTypes/destinations.js +165 -0
  292. package/dist/report/errorTypes/finding-type.d.ts +11 -0
  293. package/dist/report/errorTypes/finding-type.js +2 -0
  294. package/dist/report/errorTypes/index.d.ts +15 -0
  295. package/dist/report/errorTypes/index.js +55 -0
  296. package/dist/report/errorTypes/types/fileContents.d.ts +9 -0
  297. package/dist/report/errorTypes/types/fileContents.js +40 -0
  298. package/dist/report/errorTypes/types/unknownEntity.d.ts +9 -0
  299. package/dist/report/errorTypes/types/unknownEntity.js +27 -0
  300. package/dist/report/errorTypes/types/wrongAction.d.ts +22 -0
  301. package/dist/report/errorTypes/types/wrongAction.js +140 -0
  302. package/dist/report/errorTypes/types/wrongPlacement.d.ts +9 -0
  303. package/dist/report/errorTypes/types/wrongPlacement.js +67 -0
  304. package/dist/report/errorTypes/vocabulary/ids.d.ts +5 -0
  305. package/dist/report/errorTypes/vocabulary/ids.js +16 -0
  306. package/dist/report/errorTypes/vocabulary/phrases.d.ts +10 -0
  307. package/dist/report/errorTypes/vocabulary/phrases.js +187 -0
  308. package/dist/report/errorTypes/vocabulary/places.d.ts +8 -0
  309. package/dist/report/errorTypes/vocabulary/places.js +36 -0
  310. package/dist/report/errorTypes/vocabulary/verbs.d.ts +7 -0
  311. package/dist/report/errorTypes/vocabulary/verbs.js +30 -0
  312. package/dist/report/finding-from.d.ts +9 -0
  313. package/dist/report/finding-from.js +108 -0
  314. package/dist/report/notices.d.ts +9 -0
  315. package/dist/report/notices.js +57 -0
  316. package/dist/report/observed.d.ts +19 -0
  317. package/dist/report/observed.js +87 -0
  318. package/dist/report/render-report.d.ts +12 -0
  319. package/dist/report/render-report.js +145 -0
  320. package/dist/report/user-report/build/bundle.d.ts +3 -0
  321. package/dist/report/user-report/build/bundle.js +188 -0
  322. package/dist/report/user-report/build/bundle.prebuilt.js +1262 -0
  323. package/dist/report/user-report/data/collect.d.ts +4 -0
  324. package/dist/report/user-report/data/collect.js +93 -0
  325. package/dist/report/user-report/data/entities.d.ts +7 -0
  326. package/dist/report/user-report/data/entities.js +88 -0
  327. package/dist/report/user-report/data/entity-examples.d.ts +16 -0
  328. package/dist/report/user-report/data/entity-examples.js +136 -0
  329. package/dist/report/user-report/data/entity-filters.d.ts +15 -0
  330. package/dist/report/user-report/data/entity-filters.js +79 -0
  331. package/dist/report/user-report/data/entity-marks.d.ts +5 -0
  332. package/dist/report/user-report/data/entity-marks.js +79 -0
  333. package/dist/report/user-report/data/file-tree.d.ts +9 -0
  334. package/dist/report/user-report/data/file-tree.js +80 -0
  335. package/dist/report/user-report/data/finding-boundary.d.ts +9 -0
  336. package/dist/report/user-report/data/finding-boundary.js +21 -0
  337. package/dist/report/user-report/data/finding-plan.d.ts +16 -0
  338. package/dist/report/user-report/data/finding-plan.js +45 -0
  339. package/dist/report/user-report/data/finding-title.d.ts +12 -0
  340. package/dist/report/user-report/data/finding-title.js +36 -0
  341. package/dist/report/user-report/data/findings.d.ts +10 -0
  342. package/dist/report/user-report/data/findings.js +181 -0
  343. package/dist/report/user-report/data/graph-edges.d.ts +19 -0
  344. package/dist/report/user-report/data/graph-edges.js +109 -0
  345. package/dist/report/user-report/data/graph-entities.d.ts +6 -0
  346. package/dist/report/user-report/data/graph-entities.js +158 -0
  347. package/dist/report/user-report/data/graph-helpers.d.ts +7 -0
  348. package/dist/report/user-report/data/graph-helpers.js +67 -0
  349. package/dist/report/user-report/data/graph.d.ts +12 -0
  350. package/dist/report/user-report/data/graph.js +97 -0
  351. package/dist/report/user-report/data/nodes.d.ts +11 -0
  352. package/dist/report/user-report/data/nodes.js +116 -0
  353. package/dist/report/user-report/data/rules.d.ts +7 -0
  354. package/dist/report/user-report/data/rules.js +62 -0
  355. package/dist/report/user-report/data/scan.d.ts +8 -0
  356. package/dist/report/user-report/data/scan.js +69 -0
  357. package/dist/report/user-report/html/shell.d.ts +3 -0
  358. package/dist/report/user-report/html/shell.js +27 -0
  359. package/dist/report/user-report/index.d.ts +8 -0
  360. package/dist/report/user-report/index.js +58 -0
  361. package/dist/report/user-report/shared/describe.d.ts +7 -0
  362. package/dist/report/user-report/shared/describe.js +86 -0
  363. package/dist/rules/index.d.ts +7 -0
  364. package/dist/rules/index.js +327 -0
  365. package/dist/rules/list-vars.d.ts +5 -0
  366. package/dist/rules/list-vars.js +149 -0
  367. package/dist/rules/name.d.ts +16 -0
  368. package/dist/rules/name.js +18 -0
  369. package/dist/rules/normalize.d.ts +5 -0
  370. package/dist/rules/normalize.js +108 -0
  371. package/dist/rules/vars.d.ts +22 -0
  372. package/dist/rules/vars.js +117 -0
  373. package/dist/scan-run.d.ts +20 -0
  374. package/dist/scan-run.js +130 -0
  375. package/dist/scripts/audit-report.d.ts +2 -0
  376. package/dist/scripts/audit-report.js +157 -0
  377. package/dist/usage-index.d.ts +4 -0
  378. package/dist/usage-index.js +282 -0
  379. package/dist/usage-mode.d.ts +7 -0
  380. package/dist/usage-mode.js +16 -0
  381. package/dist/usage-pass.d.ts +19 -0
  382. package/dist/usage-pass.js +136 -0
  383. package/dist/usage-prepare.d.ts +2 -0
  384. package/dist/usage-prepare.js +22 -0
  385. package/dist/usage-sweep.d.ts +10 -0
  386. package/dist/usage-sweep.js +264 -0
  387. package/dist/utils/accumulate.d.ts +6 -0
  388. package/dist/utils/accumulate.js +18 -0
  389. package/dist/utils/aliases.d.ts +22 -0
  390. package/dist/utils/aliases.js +173 -0
  391. package/dist/utils/article.d.ts +2 -0
  392. package/dist/utils/article.js +12 -0
  393. package/dist/utils/classify.d.ts +12 -0
  394. package/dist/utils/classify.js +25 -0
  395. package/dist/utils/configs.d.ts +25 -0
  396. package/dist/utils/configs.js +97 -0
  397. package/dist/utils/count.d.ts +7 -0
  398. package/dist/utils/count.js +13 -0
  399. package/dist/utils/dispatch.d.ts +2 -0
  400. package/dist/utils/dispatch.js +27 -0
  401. package/dist/utils/distinct.d.ts +2 -0
  402. package/dist/utils/distinct.js +14 -0
  403. package/dist/utils/field.d.ts +14 -0
  404. package/dist/utils/field.js +60 -0
  405. package/dist/utils/file-name.d.ts +2 -0
  406. package/dist/utils/file-name.js +11 -0
  407. package/dist/utils/files.d.ts +7 -0
  408. package/dist/utils/files.js +77 -0
  409. package/dist/utils/fixpoint.d.ts +2 -0
  410. package/dist/utils/fixpoint.js +19 -0
  411. package/dist/utils/gate.d.ts +2 -0
  412. package/dist/utils/gate.js +12 -0
  413. package/dist/utils/group.d.ts +3 -0
  414. package/dist/utils/group.js +33 -0
  415. package/dist/utils/host.d.ts +3 -0
  416. package/dist/utils/host.js +16 -0
  417. package/dist/utils/imports.d.ts +12 -0
  418. package/dist/utils/imports.js +185 -0
  419. package/dist/utils/judged.d.ts +5 -0
  420. package/dist/utils/judged.js +19 -0
  421. package/dist/utils/keyed.d.ts +2 -0
  422. package/dist/utils/keyed.js +23 -0
  423. package/dist/utils/map-record.d.ts +2 -0
  424. package/dist/utils/map-record.js +11 -0
  425. package/dist/utils/packages.d.ts +15 -0
  426. package/dist/utils/packages.js +207 -0
  427. package/dist/utils/path-label.d.ts +6 -0
  428. package/dist/utils/path-label.js +37 -0
  429. package/dist/utils/pattern.d.ts +19 -0
  430. package/dist/utils/pattern.js +231 -0
  431. package/dist/utils/permission.d.ts +16 -0
  432. package/dist/utils/permission.js +18 -0
  433. package/dist/utils/plural.d.ts +2 -0
  434. package/dist/utils/plural.js +9 -0
  435. package/dist/utils/qualified.d.ts +2 -0
  436. package/dist/utils/qualified.js +21 -0
  437. package/dist/utils/rank.d.ts +2 -0
  438. package/dist/utils/rank.js +24 -0
  439. package/dist/utils/read-field.d.ts +12 -0
  440. package/dist/utils/read-field.js +50 -0
  441. package/dist/utils/read-when.d.ts +2 -0
  442. package/dist/utils/read-when.js +17 -0
  443. package/dist/utils/reason.d.ts +4 -0
  444. package/dist/utils/reason.js +9 -0
  445. package/dist/utils/record.d.ts +3 -0
  446. package/dist/utils/record.js +21 -0
  447. package/dist/utils/resolve.d.ts +2 -0
  448. package/dist/utils/resolve.js +24 -0
  449. package/dist/utils/search.d.ts +2 -0
  450. package/dist/utils/search.js +21 -0
  451. package/dist/utils/seen.d.ts +6 -0
  452. package/dist/utils/seen.js +27 -0
  453. package/dist/utils/span.d.ts +5 -0
  454. package/dist/utils/span.js +2 -0
  455. package/dist/utils/speak.d.ts +2 -0
  456. package/dist/utils/speak.js +18 -0
  457. package/dist/utils/split.d.ts +8 -0
  458. package/dist/utils/split.js +21 -0
  459. package/dist/utils/template.d.ts +5 -0
  460. package/dist/utils/template.js +5 -0
  461. package/dist/utils/text.d.ts +4 -0
  462. package/dist/utils/text.js +42 -0
  463. package/dist/utils/tokenize.d.ts +2 -0
  464. package/dist/utils/tokenize.js +18 -0
  465. package/dist/utils/try-read.d.ts +4 -0
  466. package/dist/utils/try-read.js +24 -0
  467. package/dist/utils/typed-field.d.ts +3 -0
  468. package/dist/utils/typed-field.js +16 -0
  469. package/dist/utils/verdicts.d.ts +4 -0
  470. package/dist/utils/verdicts.js +20 -0
  471. package/entities/operators.ts +31 -0
  472. package/package.json +101 -47
  473. package/report/errorTypes/vocabulary/ids.ts +17 -0
  474. package/report/errorTypes/vocabulary/phrases.ts +181 -0
  475. package/report/errorTypes/vocabulary/places.ts +51 -0
  476. package/report/errorTypes/vocabulary/verbs.ts +31 -0
  477. package/report/user-report/shared/describe.ts +107 -0
  478. package/ast.js +0 -107
  479. package/bin/follow-architecture.js +0 -6
  480. package/config.js +0 -101
  481. package/entities/aliases.js +0 -10
  482. package/entities/invariants.js +0 -134
  483. package/entities/nodes.js +0 -112
  484. package/main.js +0 -96
  485. package/plugin.js +0 -5
  486. package/report.js +0 -73
  487. package/utils.js +0 -104
package/README.md CHANGED
@@ -1,196 +1,1477 @@
1
- # follow-architecture
1
+ # @md-code/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`.
3
+ ESLint rule + CLI that validates code against a declarative architecture. The plugin
4
+ knows nothing about your project — everything (paths, names, rules, fixes) lives in
5
+ `architecture.yaml`.
4
6
 
5
- Two kinds of checks:
7
+ It collects **facts** from the AST (ts-morph, plus one reader per non-TypeScript
8
+ language) and evaluates **filters** (Keystone-GraphQL-style) against them. There are
9
+ no named rule kinds and no semantic predicates inside the plugin: all law lives in
10
+ the YAML.
6
11
 
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.
12
+ Three chunks are what you AUTHOR, and each one answers a different question about
13
+ the same files — they do not mix:
14
+
15
+ | chunk | YAML key | folder | answers |
16
+ | --- | --- | --- | --- |
17
+ | nodes | `nodes` | [nodes/](nodes) | where files may live, what names they may have, and which entity each child holds |
18
+ | entities | `entities` | [code-entities/](code-entities) | what a piece of code *is* (atom, handler, theme, barrel, …) and what may be done with it — never where it lives |
19
+ | rules | `rules` | [rules/](rules) | what a file may contain |
20
+
21
+ `aliases` maps import sources to repo paths so the three can resolve imports; it is
22
+ the only other key in the file.
9
23
 
10
24
  ```mermaid
11
25
  flowchart LR
12
- A["architecture.json"] --> N["Nodes<br/>where files may live"]
13
- A --> I["Invariants<br/>what files may contain"]
14
- F["Source files"] --> N
15
- F --> I
16
- N --> R["Report"]
17
- I --> R
26
+ Y["architecture.yaml"] --> F
27
+ S["Source files"] --> F
28
+ subgraph F["filter"]
29
+ direction TB
30
+ N["nodes"]
31
+ R["entities"]
32
+ I["rules"]
33
+ end
34
+ F --> O["Report"]
35
+ ```
36
+
37
+ Everything else in this repository is the engine that answers those questions — it
38
+ carries no project knowledge.
39
+
40
+ ## Install
41
+
42
+ ```sh
43
+ pnpm add -D @md-code/follow-architecture
18
44
  ```
19
45
 
46
+ | Package | Where it comes from | Why |
47
+ | --- | --- | --- |
48
+ | `@md-code/utils` | `dependencies` | shared repo-root, walk and index helpers (installed for you) |
49
+ | `ts-morph`, `@typescript-eslint/parser` | `dependencies` | every file is read with the TypeScript compiler API |
50
+ | `js-yaml`, `minimatch`, `remeda` | `dependencies` | the architecture file, the globs, the pipeline |
51
+ | `postcss`, `postcss-scss`, `postcss-selector-parser`, `postcss-value-parser`, `stylis`, `css-tree`, `tailwindcss` | `dependencies` | the CSS and class-list facts (a styles contract can be part of the architecture) |
52
+ | `highlight.js` | `dependencies` | code panels in the `--overview` page |
53
+ | `eslint` | peer `>=8.40.0` | the rule is an ESLint rule; bring your own ESLint |
54
+
55
+ Node `>=18`. The interactive overview ships prebuilt inside `dist/`: React,
56
+ `styled-components`, `@md-code/sections` and `esbuild` are `devDependencies` here and
57
+ are never needed by a published install.
58
+
59
+ Minimal configuration — one ESLint rule, one YAML file:
60
+
61
+ ```js
62
+ // eslint.config.js
63
+ const followArchitecture = require("@md-code/follow-architecture");
64
+
65
+ module.exports = [
66
+ {
67
+ files: ["**/*.ts", "**/*.tsx"],
68
+ plugins: { "md-code": followArchitecture },
69
+ rules: {
70
+ // The option is the architecture file's path, relative to the repo root.
71
+ // The rule walks up from each linted file to find it, so the same config
72
+ // works in any package of a monorepo.
73
+ "md-code/follow-architecture": ["error", { config: "architecture.yaml" }],
74
+ },
75
+ },
76
+ ];
77
+ ```
78
+
79
+ `require("@md-code/follow-architecture")` **is** the plugin (`{ meta, rules }`); there
80
+ is no `flatConfig` helper to call, and no per-project code in the package.
81
+
20
82
  ## Quick start
21
83
 
22
84
  ```sh
23
- bun add -D @md-code/follow-architecture
24
- bunx follow-architecture --config architecture.json --out reports/follow-architecture.md
25
- ```
26
-
27
- ## `architecture.json`
28
-
29
- ```jsonc
30
- {
31
- "aliases": { "#db": "src/db" },
32
- "nodes": [
33
- {
34
- "slug": "feature",
35
- "name": "{feature}",
36
- "parent": "features",
37
- "closed": true,
38
- "report": { "message": "…", "fix": "…" },
39
- "children": [
40
- "{kebab-case}.types.ts",
41
- "index.ts",
42
- { "name": "{kebab-case}.store.tsx", "forbidden": true, "report": { "message": "…", "fix": "…" } }
43
- ]
44
- },
45
- { "slug": "features", "name": "src/features", "children": ["feature", "db"] }
46
- ],
47
- "invariants": [
48
- {
49
- "id": "service-no-bypass",
50
- "where": "src/features/{feature}/**/*.service.ts",
51
- "forbid": [
52
- { "key": "client", "pattern": "new HttpClient", "report": { "message": "…", "fix": "…" }, "except": ["**/legacy/**"] },
53
- { "type": "imports", "key": "no-vscode", "pattern": "vscode", "report": { "message": "…" } }
54
- ],
55
- "when": "(ctx) => { /* AST-level check, returns null | true | finding | finding[] */ }",
56
- "except": ["src/features/shared/**/*.service.ts"],
57
- "report": { "message": "…", "fix": "…" }
58
- }
59
- ]
60
- }
85
+ # the report to stdout (exit 1 with findings under --check):
86
+ npx follow-architecture --config architecture.yaml --out reports/follow-architecture.md
87
+ npx follow-architecture --config architecture.yaml --check
88
+
89
+ # the interactive, self-contained HTML overview:
90
+ npx follow-architecture --config architecture.yaml --overview reports/architecture-overview.html
91
+ ```
92
+
93
+ From this repository, build the package once and drive its `bin/` entry:
94
+
95
+ ```sh
96
+ pnpm build
97
+ node dist/bin/follow-architecture.js --config architecture.yaml --out reports/follow-architecture.md
98
+ node dist/bin/follow-architecture.js --config architecture.yaml --check
99
+ node dist/bin/follow-architecture.js --config architecture.yaml --overview
100
+ ```
101
+
102
+ Run the `bin/` entry, not `dist/main.js`: `main.js` is the module the `bin` script
103
+ calls — `node dist/main.js` exits 0 and prints nothing.
104
+
105
+ A full walk of this monorepo can exhaust Node's default heap, which is why the
106
+ package's own product-lint script raises it
107
+ (`NODE_OPTIONS=--max-old-space-size=13312` in `lint:products`).
108
+
109
+ ## Command line
110
+
111
+ ```sh
112
+ follow-architecture [--config <path>] [--cwd <dir>] [--ext <.ext>]... [--ignore <glob>]...
113
+ [--ignore-dir <name>]... [--files <path>]... [--out <path>] [--overview [path]]
114
+ [--index <path|off>] [--usage <checker|index>]
115
+ [--barrel-depth <n>] [--check]
116
+ ```
117
+
118
+ | Flag | Meaning |
119
+ | --- | --- |
120
+ | `--config <path>` | The architecture file. Default `architecture.yaml` |
121
+ | `--cwd <dir>` | Where the scan begins, and the anchor `--config` is resolved against |
122
+ | `--ext <.ext>` | Add a source extension (repeatable, on top of the built-in list) |
123
+ | `--ignore <glob>` | Repo-relative glob not read (repeatable) |
124
+ | `--ignore-dir <name>` | Do not enter this folder (repeatable, any depth) |
125
+ | `--files <path>` | Check only this file or folder (repeatable). The tree is still walked, so imports resolve across it |
126
+ | `--out <path>` | Write the text report here; without it the report goes to stdout |
127
+ | `--overview [path]` | Write the self-contained HTML overview; alone it writes `architecture-overview.html` at the repo root |
128
+ | `--index <path\|off>` | Where the run's index lives, or `off` for a run that neither reads nor writes one |
129
+ | `--usage <checker\|index>` | Who answers `references`: the type checker (default, exact) or an occurrence index (cheaper, approximate) |
130
+ | `--barrel-depth <n>` | How many barrels a name may pass through while the run looks for the file that DECLARES it (default `8`, integer ≥ 1) |
131
+ | `--check` | Exit 1 when there is at least one finding |
132
+ | `--help`, `-h` | Print the usage line |
133
+
134
+ There is no `--roots`: the scan starts at the repo root (or `--cwd`); `--ignore`,
135
+ `--ignore-dir` and `--ext` narrow what is walked, and `--files` narrows what is
136
+ checked. A flag that takes a value consumes the next argument; `--overview` alone
137
+ takes none. The scan scope is the TOOL's, never the YAML's.
138
+
139
+ ### Exit codes
140
+
141
+ | Code | Meaning |
142
+ | --- | --- |
143
+ | `0` | The run finished and (with `--check`) no finding was produced |
144
+ | `1` | `--check` and at least one finding, an unreadable/invalid `architecture.yaml`, or an internal crash |
145
+
146
+ Without `--check` findings never change the exit code — the CLI is a report
147
+ generator; the ESLint rule is what fails a build. A config mistake prints one
148
+ sentence naming what the file claims and what it may claim instead; anything else
149
+ prints `follow-architecture: the run failed for a reason that is not in the
150
+ architecture` with its stack.
151
+
152
+ ### Which paths are relative to what
153
+
154
+ | Value | Resolved against |
155
+ | --- | --- |
156
+ | `--config`, `--cwd` | the process working directory |
157
+ | `--out` | the process working directory |
158
+ | `--overview` | the **repo root** (the directory of the resolved `--config`, or `--cwd` when given) |
159
+ | `--index`, rule option `indexPath` | the repo root (absolute paths used as given) |
160
+ | rule option `exportPath` | the repo root |
161
+ | `--files`, `--ignore`, `--ignore-dir` | the repo root |
162
+
163
+ The repo root is where the architecture file lives — the SAME anchor the ESLint rule
164
+ uses — so `--config ../arch.yaml` scans the repo that file describes. An explicit
165
+ `--cwd` overrides that anchor. The root is canonicalised (`fs.realpathSync`) before
166
+ it becomes a path, so the index, its header and every absolute path in it agree even
167
+ when the same directory is reachable under a symlinked spelling.
168
+
169
+ ### `--config` discovery
170
+
171
+ `--config <path>` is the only way to name the architecture file; the default is
172
+ `architecture.yaml` in the working directory. The file may be YAML or JSON
173
+ (`architecture.yaml`, `architecture.yml`, `architecture.json`) — the same file the
174
+ ESLint rule reads through its `config` option, and which file was loaded is visible
175
+ in the report and in every finding.
176
+
177
+ ## `architecture.yaml`
178
+
179
+ Four keys, nothing else:
180
+
181
+ | Key | Answers | Chapter |
182
+ | --- | --- | --- |
183
+ | `aliases` | which repo path an import specifier names | [Aliases](#aliases) |
184
+ | `entities` | what a piece of code IS | [Code entities](#code-entities) |
185
+ | `nodes` | where code lives | [Nodes](#nodes) |
186
+ | `rules` | conditions a file must satisfy | [Rules](#rules) |
187
+
188
+ An unknown key — at the top level or inside an entry — is a config error that names
189
+ the allowed keys with their meanings, never a silent no-op.
190
+
191
+ Abridged from this repository's own file (every key shown is real; the comments and
192
+ the middle of each list are cut):
193
+
194
+ ```yaml
195
+ aliases:
196
+ "@md-code/components": packages/components
197
+ "@md/styles": packages/styles/index.ts
198
+
199
+ entities:
200
+ - slug: barrel
201
+ name: barrel
202
+ infer:
203
+ - exports:
204
+ length: { gt: 0 }
205
+ none:
206
+ or:
207
+ - form: { in: [equals, commonjs] }
208
+ - and:
209
+ - form: { equals: default }
210
+ - from: { isSet: false }
211
+ - kind:
212
+ descendants:
213
+ none: { is: { in: [FunctionDeclaration, ArrowFunction, ClassDeclaration, VariableDeclaration] } }
214
+ - location: { fileName: { equals: index } }
215
+ actions:
216
+ import: { where: [{ node: root }] }
217
+ mutate: { where: [{ entity: testCode }] }
218
+ declare: { where: [{ entity: barrel }] }
219
+ report:
220
+ description: "A barrel re-exports a module's surface and declares nothing of its own; it is named `index` and a folder has one."
221
+
222
+ nodes:
223
+ - slug: components-atoms
224
+ name: atoms
225
+ parent: components
226
+ children:
227
+ - "{PascalCase}"
228
+ - { name: index.ts, entity: barrel }
229
+
230
+ rules:
231
+ - id: no-hidden-store
232
+ infer:
233
+ - mutable: { equals: true }
234
+ kind:
235
+ ancestors: { none: { is: { in: [FunctionDeclaration, Block, CaseClause, ModuleBlock] } } }
236
+ report:
237
+ code: rewrite
238
+ description: "`{what}` is a module-scope `let`/`var`: a store that outlives every call."
239
+ fix:
240
+ message: "Make it a `const`, or move the changing value into the function that owns it."
61
241
  ```
62
242
 
63
- 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), `ignoreDirs` (folder names the CLI does not enter, added to `node_modules`, `.git`, `dist`, `build`).
243
+ ### Placeholders
244
+
245
+ A `{…}` in a path pattern is a **capture**, written IN the convention it asks for —
246
+ the convention is read off the name, so there is no list of known ones:
247
+
248
+ | write | matches |
249
+ | --- | --- |
250
+ | `{kebab-case}`, `{feature-name}` | `todo-list` (any `-`-joined lowercase name) |
251
+ | `{snake_case}` | `todo_list` |
252
+ | `{UPPER_CASE}` | `MAX_RETRIES` |
253
+ | `{FEATURE-NAME}` | `TODO-LIST` |
254
+ | `{camelCase}`, `{myCase}` | `todoList` |
255
+ | `{PascalCase}`, `{Name}` | `TodoList` |
256
+ | `{Mixed_Name}` (states no convention) | anything but `/` — it captures and enforces nothing |
257
+
258
+ A placeholder may share a segment with literal text, so a test file is declared next
259
+ to the code it tests: `{kebab-case}.spec.ts` matches `todo-list.spec.ts` and not
260
+ `todoList.spec.ts`; inside a segment, dots and other text are literal.
64
261
 
65
262
  ## Nodes
66
263
 
67
- 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`.
264
+ A **node** is a place in the tree: a folder, or a file. Nodes reference each other by
265
+ `slug`; a node's path is its parent's path + its `name`. `name` may be a path
266
+ template (`packages/components/atoms`, `atoms/{PascalCase}`) and may start with `@`, which makes
267
+ it an alias specifier instead of a segment — `name: "@md-code/components"` puts the
268
+ node at the package's folder wherever the alias points.
269
+
270
+ | Key | Meaning |
271
+ | --- | --- |
272
+ | `slug` | the node's identifier, named by `parent` and by children |
273
+ | `name` | the path segment or path template this node matches |
274
+ | `parent` | the node this one sits under — one slug, or a list of them (one variant per parent) |
275
+ | `children` | the names, patterns and nodes this folder declares |
276
+ | `entity` | which entities this place is a home for (the whole folder, `**`) |
277
+ | `required` | whether this node must exist for its parent to be an instance |
278
+ | `report` | what to say when this node's structure is broken |
279
+
280
+ Any other key is an error, not a silent no-op.
281
+
282
+ ### Closed lists
283
+
284
+ A node closes exactly what it declares, and nothing else:
285
+
286
+ | declared | the node is closed to |
287
+ | --- | --- |
288
+ | `children:` only | those NAMES — an entry it does not declare is reported with the place it belongs to |
289
+ | `entity:` only | those KINDS — names are free, and a piece of another kind is reported with the home it belongs to |
290
+ | both | both: the names, and the kinds of what they hold |
291
+ | neither | nothing — a folder that only passes structure through |
292
+
293
+ That is the whole of what a flag used to spell: the list you write is the close. Both
294
+ answers are needed because they catch different mistakes — a molecule in `atoms/` is
295
+ the `entity:` list's finding, a stray file beside the atoms is `children:`'s. A piece
296
+ no entity describes is left to the entity checks: silence there is the absence of a
297
+ question, not permission. The deepest matching node wins, so a nested node's list
298
+ governs its own folder.
299
+
300
+ A node may also carry `required: true`, which makes the folder an instance of the
301
+ node only when the node itself is present.
302
+
303
+ ### Children
304
+
305
+ Each entry of `children` is either a name template (`"*.d.ts"`, `"{PascalCase}"`,
306
+ `atoms`) or a spec:
307
+
308
+ | Key | Meaning |
309
+ | --- | --- |
310
+ | `name` | the child's name or path pattern |
311
+ | `node` | borrow another declared node's own pattern |
312
+ | `entity` | which entities this child is a home for |
313
+ | `required` | the child must be present, or the folder is not this node |
314
+ | `forbidden` | the child must be absent |
315
+ | `query` | a filter over the file's facts that recognises the child, whatever it is called |
316
+ | `report` | what to say when this child's rule is broken |
317
+
318
+ A name without an extension is a folder, with an extension a file. Real entries from
319
+ this repo:
320
+
321
+ ```yaml
322
+ - slug: components-atoms
323
+ name: atoms
324
+ parent: components
325
+ children:
326
+ - "{PascalCase}" # one folder per atom
327
+ - { name: index.ts, entity: barrel }
328
+
329
+ - slug: components-atom
330
+ name: "{PascalCase}"
331
+ parent: components-atoms
332
+ entity: [atom, barrel, styleBlock, data, pureFunction, class, constant, sharedTypes, handler, state, testCode]
333
+ ```
68
334
 
69
- - `slug` — unique name, used as `parent` by children and as `node` by invariants.
70
- - `name` — the path segment (relative to the parent). `{name}` placeholders capture path segments (e.g. `{feature}` in a `where` of `src/features/{feature}/**` captures `orders`). Captures are available in reports of every finding inside the node.
71
- - `parent` (optional) — the `slug` of the containing node. A node without `parent` is a root.
72
- - `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.
73
- - `report` (optional) — the finding for "file does not belong here" (closed nodes) — see [report](#report).
74
- - `children` (optional) — the list of allowed names inside the node. Each entry is either:
75
- - a **string** — a name template (`{kebab-case}`, `*`, `?` work; a name without an extension is a folder, with an extension is a file);
76
- - an **object** — `{ name, forbidden?, report?, description? }`. `forbidden: true` names a shape that must **never** exist (e.g. `{kebab-case}.store.tsx` in a sub-feature folder) and reports `report` when it does.
335
+ `atoms/` declares its children and nothing else, so an undeclared folder beside the
336
+ atoms is a finding; an
337
+ atom's own folder declares the kinds it may hold, so a molecule inside it is a
338
+ finding. `query` is how a file is routed when its NAME says nothing: a file that
339
+ matches the child's query but sits elsewhere is told the folder it belongs to.
77
340
 
78
- 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.
341
+ A missing `required` child makes the folder "not an instance of that node" — reported
342
+ once per folder, not per file, and no entity destinations are invented inside it.
79
343
 
80
- ## Invariants
344
+ ## Code entities
81
345
 
82
- An **invariant** is a per-file rule. Fields:
346
+ An **entity** says what a piece of code IS, by facts. It never says where the code
347
+ lives: that is the tree's job, and keeping the two apart is what lets a folder move
348
+ without touching a law.
83
349
 
84
- - `id` — unique name.
85
- - `node` (optional) — a node `slug`; the invariant only runs for files that captured that node. Default `*` (all files).
86
- - `where` (optional) — a glob the file path must match; `{name}` captures work and are available in reports. No `where` = all files.
87
- - `except` (optional) — file globs the invariant does not apply to.
88
- - `report` (optional) — a finding emitted for **every** matching file (a "this file, as it exists, is a problem" rule).
89
- - `when` (optional) — a gate or an AST-level check, called as `when(ctx)` with the full file context (see [ctx](#ctx)). Return values:
90
- - `null` / `false` — the invariant (and its `forbid` list) is off for this file;
91
- - `true` — on;
92
- - an object or array of objects — emitted as finding(s) and the `forbid` list is skipped.
93
- - `forbid` (optional) — array of entries, each with a `type`:
94
- - `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.
95
- - `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.
96
- - `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").
97
- - `children` (optional) — nested invariants; they run after the parent and inherit its captures.
350
+ An entity carries `slug`, `name`, `infer`, `actions` and `report` — and no location.
98
351
 
99
- `key` (on the invariant or a `forbid` entry) is a stable dedup key: findings with the same `key` are collapsed to one per file.
352
+ ### A piece of code, not a file
100
353
 
101
- ### `ctx`
354
+ `infer` runs over the **candidates** in a file: functions (declarations, arrows,
355
+ expressions, methods, accessors), classes, variable declarations, type declarations,
356
+ and the file's comments. Each candidate carries its own entity, so one file holds
357
+ several at once: `styles.ts` is a `styleBlock` beside a `constant`, `Header.tsx` is an
358
+ `atom` beside a `handler`.
102
359
 
103
- `when(ctx)` receives, per file:
360
+ `infer` is a list in PRIORITY order: the first entry that matches wins. In this repo
361
+ `handler` comes before `pureFunction`, because a function value has no name of its
362
+ own and would otherwise also match "a declared, named function". An entity without
363
+ `infer` is never inferred.
364
+
365
+ Two subjects are the FILE, not a piece:
366
+
367
+ - **`barrel`** — a file that declares nothing of its own and only re-exports (by
368
+ name, by namespace, wholesale, or as a default that hands on an imported binding).
369
+ It is a place, not a piece, so it is read from the file's `exports` and `kind`.
370
+ - **`entry`** — a module that only wires: it imports what a package offers and calls
371
+ it at the top level, declaring nothing. `bin/*.ts` is the case; a file that declares
372
+ anything at all is not an entry.
373
+
374
+ A module entity has no `name` and no `lines`, and no finding ever names it. That is
375
+ why `imports` and `exports` describe the MODULE: an `imports` filter in `infer` says
376
+ "the file that brings the provider in", and it is asked of the file, never of the
377
+ `const` beside the render. A repo that wants a PIECE judged by what its file brings in
378
+ says so explicitly — `{ file: { imports: { any: { source: { equals: "vscode" } } } } }`
379
+ — which reads the candidate's own `file` fact.
380
+
381
+ `.vue` / `.svelte` single-file components are parsed too: only the `<script>` block is
382
+ handed to the parser and every other line is blanked, so reported line numbers still
383
+ match the file in the editor.
384
+
385
+ ### The forms
386
+
387
+ These are this repo's form entities (yours are whatever you declare — the engine has
388
+ no vocabulary of its own):
389
+
390
+ | entity | what the code is | recognised by |
391
+ | --- | --- | --- |
392
+ | `pureFunction` | a DECLARED, NAMED function: `function f() {}`, a method, or an arrow bound by `const f = …` | declaration kind + a name |
393
+ | `handler` | a function VALUE: a JSX attribute, a call argument, an object property, a returned closure | its position, or a `use*` call, or an `on…`/`handle…` name |
394
+ | `class` | a class declaration, or a class expression bound to a name | `kind.own.is` + `name` |
395
+ | `styleBlock` | `const Box = styled.div`…`` — the style half of a component | a `VariableDeclaration` carrying `framework.css.templates` |
396
+ | `data` | an object or array literal a module keeps (a thresholds map, a column list) | initializer kind |
397
+ | `sharedTypes` | an interface, a type alias, or an ambient `export const x: T;` in a `.d.ts` | declaration kind + no initializer |
398
+ | `constant` | a module-scope name for a VALUE: a literal, an alias, a computed value, a `keyframes` tag | `mutable: false` + initializer kind (a function initializer belongs to the form entities above) |
399
+ | `state` | the value a state factory returns (`createContext(…)`, `t.model(…)`) | initializer origin |
400
+ | `atom` / `molecule` / `section` | the UI layers: renders no component / renders imported components / composes molecules for one place | `framework.component`, `framework.links` |
401
+ | `theme` | the one object carrying every token table | initializer origin, or an object literal with the token groups |
402
+ | `testCode` | test code — by what it DOES, not only where it sits | `framework.test.*`, or a path |
403
+
404
+ A pure function and a handler are not two layers of one thing: the first is code you
405
+ can call by name, the second exists only where it was passed to. The FORM is the
406
+ whole definition — whether a function writes or returns is what the code DOES, not
407
+ what kind of code it is.
408
+
409
+ ### `infer`
410
+
411
+ A list of filters, ANDed. An entry may also be a bare STRING naming another entity —
412
+ `infer: [action, { lines: { gt: 5 } }]` means "code that is an action AND longer than
413
+ 5 lines" — so entities compose with no extra keyword. Filters nest to any depth:
414
+
415
+ ```yaml
416
+ infer:
417
+ - and:
418
+ - kind: { own: { is: { equals: ArrowFunction } } }
419
+ - or:
420
+ - calls: { any: { targetEntity: { equals: action } } }
421
+ - kind: { descendants: { any: { is: { equals: AwaitExpression } } } }
422
+ - not:
423
+ calls: { any: { targetEntity: { equals: pureFunction } } }
424
+ ```
425
+
426
+ ### `actions`
427
+
428
+ `actions` is an open map of the EIGHT relations, and nothing else exists: `import`,
429
+ `export`, `declare`, `call`, `mutate`, `assign`, `read`, `typeImport`. Each entry is
430
+ `{ where, except?, of?, scopeAccess? }`; any other key is an error.
431
+
432
+ - `where` — who may do it: a list of `where` entries (below).
433
+ - `except` — where the allowance stops: the same entries, subtracted.
434
+ - `of` — the fact class this action is checked against, when the name is your own
435
+ (`emit: { of: call }`), so an event-driven design needs no engine change.
436
+ - `scopeAccess` — how the code is reached WITHOUT an import: see below.
437
+
438
+ A `where` entry is one of:
439
+
440
+ | entry | means |
441
+ | --- | --- |
442
+ | `{ entity: x }` | a file that DECLARES that entity — the only entry that names a KIND rather than a place |
443
+ | `{ entity: x, same: true }` | …in the same instance of a repeating node (feature A's action, never feature B's) |
444
+ | `{ entity: x, via: import }` | …that HOLDS it from an import rather than reaching it through an object tree |
445
+ | `{ node: slug }` | any file under that declared node |
446
+ | `{ template: "…" }` | a path built from the tree |
447
+ | `"packages/ui/**"` | a glob (a bare string that names a declared entity is an entity reference instead) |
448
+ | `{ imports: { any: … } }` | any filter over the file's facts |
449
+
450
+ The `where` mechanism is the SAME one rules use for their `where` / `ignore`
451
+ (`entities/location/where.ts`, one matcher, the same facts), and the same one that
452
+ decides a destination in the report. Paths themselves live in `nodes`, so a `where`
453
+ never restates a folder.
454
+
455
+ A piece no entity describes is granted nothing: every relation it makes is refused,
456
+ and the finding names that piece.
457
+
458
+ ### `scopeAccess`
459
+
460
+ Data a component is GIVEN — a theme, a store, a locale — is never imported by the code
461
+ that renders with it. `actions.import` lists only the places that mount the provider
462
+ and pass the object in; `scopeAccess` lists the chain roots through which everyone
463
+ else reaches the same code, with the SHAPE of the root spelled out:
464
+
465
+ ```yaml
466
+ read:
467
+ where: [{ entity: atom }, { entity: molecule }, { entity: section }, { entity: styleBlock }]
468
+ scopeAccess:
469
+ - { scope: function, type: styled-components.DefaultTheme } # ${(value: DefaultTheme) => value.colors.x}
470
+ - { scope: function, entity: [atom, molecule, section], segments: [useTheme] } # useTheme().colors.x
471
+ - { scope: object, segments: [theme] } # theme.colors.x
472
+ ```
473
+
474
+ - `scope` is `function`, `object` or `method` — the spelling of the root.
475
+ - `type` — the door IS a type, and it is the PARAMETER'S TYPE that makes the function
476
+ one, never the name it is spelled with: `${(value: DefaultTheme) => …}` and
477
+ `${({ theme }) => …}` are the same door. The value is `module.Type`; a bare
478
+ `DefaultTheme` is an error, because two packages may each declare one. An entry
479
+ with a `type` needs no `segments`.
480
+ - `entity` — the door belongs to code of these entities only (the hook inside a
481
+ component, not inside a helper). An entry with an `entity` still spells its
482
+ `segments`.
483
+
484
+ An import below those places is then not a new rule to write: it is a relation the
485
+ action refuses, and the finding names both the refusing list and the chains.
486
+
487
+ ### The theme law
488
+
489
+ The pattern in full, from this repo: a theme is handed in at the root and read
490
+ through the provider, never imported by the code that renders with it.
491
+
492
+ ```yaml
493
+ - slug: theme
494
+ infer:
495
+ - kind: { own: { is: { equals: VariableDeclaration } } }
496
+ - or:
497
+ - kind: { initializer: { origin: { in: [defineTheme, withStatuses] } } }
498
+ - and:
499
+ - kind: { initializer: { is: { equals: ObjectLiteralExpression } } }
500
+ - kind: { initializer: { members: { where: { filter: { name: { in: [colors, shadows, zIndex, …] } }, by: { length: { gte: 8 } } } } } }
501
+ actions:
502
+ import:
503
+ where: [{ entity: theme }, { entity: themeProvider }, { entity: barrel }, { entity: testCode }]
504
+ read:
505
+ where: [{ entity: theme }, { entity: atom }, { entity: molecule }, { entity: section }, { entity: styleBlock }, { entity: testCode }]
506
+ scopeAccess:
507
+ - { scope: function, type: styled-components.DefaultTheme }
508
+ - { scope: function, entity: [atom, molecule, section, themeProvider], segments: [useTheme] }
509
+ report:
510
+ description: "A theme is the design context of a situation: a component never imports it — it reads the theme it was given."
511
+ fix:
512
+ message: "Delete the import: read `theme` in the styled block's callback or call `useTheme()`."
513
+ ```
514
+
515
+ Three consequences, all of them free:
516
+
517
+ - a component that imports a theme is a refused relation, not a rule to write;
518
+ - `props.theme` is NOT one of the chains — a component that receives the palette as
519
+ a prop relays it through its signature and cannot be used outside a provider;
520
+ - token tables (`colors`, `zIndexes`) are private to themes: only a theme imports
521
+ one, everyone else reads it as `theme.colors.section`.
522
+
523
+ The edge of the relation: a library import has no target in the tree. A component
524
+ importing `ThemeProvider` from `styled-components` names no repo file, and the
525
+ relation engine judges only edges that land on the repository's own code. A law about
526
+ a library symbol is therefore a RULE over the `imports` fact — that is exactly
527
+ [`no-theme-mount-in-a-component`](#no-theme-mount-in-a-component) below.
528
+
529
+ ## Aliases
530
+
531
+ The `aliases` block gives an import specifier a place in the repo — and the SAME one
532
+ function answers every other place the architecture names files, so a specifier is
533
+ never written twice and never resolved two different ways.
534
+
535
+ ```yaml
536
+ aliases:
537
+ "@md-code/components": packages/components # a FOLDER: everything under it is the package
538
+ "@md/styles": packages/styles/index.ts # an ENTRY FILE: the package still lives in its folder
539
+ ```
540
+
541
+ One alias function answers four consumers, and nothing else reads `aliases`:
542
+
543
+ 1. **the import resolver** — `facts.imports[].source`: `@md-code/components/logo` →
544
+ `packages/components/atoms/Logo/index.tsx` (the subpath goes through the package's `exports`);
545
+ 2. **node `name`s and `children`** — a name that starts with `@` is an alias
546
+ specifier:
547
+
548
+ ```yaml
549
+ - slug: components
550
+ name: "@md-code/components" # the node IS the package folder, wherever the alias points
551
+ ```
552
+
553
+ 3. **rule `where` / `ignore`** — a glob that starts with `@` is expanded:
554
+ `ignore: ["@md-code/components/**"]` reads as `packages/components/**`;
555
+ 4. **`location` filters** — every string inside a `location` subtree:
556
+ `location: { path: { startsWith: "@md/styles/" } }`.
557
+
558
+ A trailing `/` is a PREFIX and keeps its slash; `@pkg/*` means every public source of
559
+ that package; an alias with several places expands to a `{a,b}` brace alternation in a
560
+ glob. A string that starts with `@` and names no alias is a **config error**, not
561
+ silence — without it the pattern would match nothing and the rule would quietly never
562
+ fire. A filter's other strings are values, not places: `equals: "@angular/core"` stays
563
+ as written.
564
+
565
+ ### Where a subpath points
566
+
567
+ The value of an alias is a folder or an entry file. A subpath is read from there:
568
+
569
+ - **a package that publishes folders** (`@pkg/button` with `"@pkg": packages/pkg`) is
570
+ `packages/pkg/button` — folder subpaths are folders, exactly as the path reads;
571
+ - **a package that publishes SUBPATHS** (`exports` in its `package.json`, like
572
+ `@md-code/components/chip`) has no such folder. The subpath goes through the
573
+ manifest: `exports["./chip"].types` names the build artifact, and the SOURCE is the
574
+ scanned file whose path ends with that artifact's tail. `typesVersions` is read the
575
+ same way when `exports` has no answer, and a subpath the manifest does not describe
576
+ falls back to the plain folder reading.
577
+
578
+ When a subpath's manifest entry exists but no scanned file mirrors it, the run says so
579
+ once instead of silently resolving nothing.
580
+
581
+ A manifest's `exports` is only consulted when the run knows the scanned files, which
582
+ is the import resolver's case. Config-time consumers (nodes, rules, filters) are read
583
+ before the repo is scanned, so they get the folder reading — which is why a package
584
+ that publishes only subpaths is aliased to its FOLDER.
585
+
586
+ ## Rules
587
+
588
+ A **rule** is a per-file condition. Fields:
589
+
590
+ | Key | Meaning |
591
+ | --- | --- |
592
+ | `id` | the rule's identifier, used by findings and `dedupeBy` |
593
+ | `where` | the code the rule applies to: the same `where` entries entities use; omitted = all files |
594
+ | `ignore` | the code it does NOT apply to — the same entries, inverted |
595
+ | `when` | an extra gate: a plain filter over the file facts; the rule runs only when it matches |
596
+ | `infer` | filters that, when they MATCH, are the violation |
597
+ | `report` | what to say: a string, or a spec (below) |
598
+ | `dedupeBy` | the place findings are counted once per (a `where` entry) |
599
+ | `children` | nested rules, evaluated with the same file facts |
600
+
601
+ Any other key is an error naming the allowed keys. There is no legacy-key mapping and
602
+ no second check key: "this must be true" is the same filter under `not:`.
603
+
604
+ Two subjects: the filter is asked of the **file** first; when the file does not
605
+ answer, the SAME filter is asked of every **candidate** in it, and the matching
606
+ candidate supplies the `{what}` and the line of the finding. That is why a rule about
607
+ a module reads `imports` and a rule about a function reads `kind`.
608
+
609
+ `dedupeBy` counts findings per place instead of per file: `dedupeBy: [{ node: feature }]`
610
+ reports a per-folder rule once per feature folder, and a glob once per matched folder.
611
+ File-level findings are then reported once per distinct place across the run.
612
+
613
+ ### Before writing a rule: an entity and a node
614
+
615
+ Most architecture laws are not rules. They are answers to two questions the tree and
616
+ the entities already ask:
617
+
618
+ - **"What is this piece?"** is an entity. Write it once, by facts (`infer`), and the
619
+ order of the `entities` list states which kind wins when several match.
620
+ - **"Where does this kind live?"** is a node with `entity:` on it (or on one of its
621
+ children). A piece declared anywhere else is reported with the home it belongs to —
622
+ the finding, the destination and the fix come for free.
623
+ - **"Who may use whom?"** is an `actions.*.where` list. It is also the picture: a box
624
+ that imports nothing but its own kind is a leaf, a box that imports the leaf is the
625
+ layer above it.
626
+ - **"How is it reached without an import?"** is `scopeAccess`.
627
+ - **"Who is the consumer — a folder or a kind of code?"** An action's `where` names
628
+ entities and nodes, never a path. `apps/**` spells a place; the place will move, the
629
+ law will not.
630
+
631
+ A rule is for the rest: a value that must not be typed, a file that must not grow, a
632
+ name that must not repeat. A rule that only says "this kind of code sits in that
633
+ folder" or "this kind may not import that kind" duplicates what the entities and the
634
+ nodes say — and unlike them it cannot be read off the tree.
635
+
636
+ The order is therefore fixed — **entity → home → allowance → rule last**, in names
637
+ that are not any project's:
638
+
639
+ ```yaml
640
+ entities:
641
+ # 1. WHAT it is, by facts. Asked first: a panel is also "a component that renders
642
+ # components", so the composition layer comes before the leaf.
643
+ - slug: panel
644
+ infer:
645
+ - framework: { component: { equals: true } }
646
+ - framework: { links: { any: { module: { isSet: true } } } }
647
+ # 3. WHO may use it: a panel may be rendered by another panel or by a screen.
648
+ actions:
649
+ import: { where: [{ entity: panel }, { entity: screen }] }
650
+ - slug: tile
651
+ infer:
652
+ - framework: { component: { equals: true } }
653
+ - not: { framework: { links: { any: { module: { isSet: true } } } } }
654
+ actions:
655
+ import: { where: [{ entity: tile }, { entity: panel }] }
656
+
657
+ nodes:
658
+ # 2. WHERE each kind may be declared. One line to move a folder, and no action
659
+ # changes.
660
+ - slug: ui
661
+ name: ui
662
+ parent: packages
663
+ children:
664
+ - { name: tiles, entity: [tile] }
665
+ - { name: panels, entity: [panel] }
666
+
667
+ rules:
668
+ # 4. Only what the two above cannot say: a tile may not take more than three props.
669
+ - id: small-tiles
670
+ where: [{ entity: tile }]
671
+ infer:
672
+ - framework: { props: { length: { gt: 3 } } }
673
+ report:
674
+ code: rewrite
675
+ description: "`{what}` is a tile with {n} props: a tile takes what it renders, not a bag."
676
+ fix: { message: "Pass the object the tile needs, or let it read what it needs itself." }
677
+ ```
678
+
679
+ A tile declared under `panels/` is a finding that names `tiles/`; a tile importing a
680
+ screen is a finding with the exact import; nothing else had to be written. The same
681
+ two lists, read from the other end, are the dependency graph of the overview: what
682
+ imports what, and what nothing imports.
683
+
684
+ ### `no-hidden-store`
685
+
686
+ Not every law is a shape of code. One is worth spelling out, because it is the only
687
+ thing this repo states about a file's SCOPE: **at module scope there are only
688
+ constants.** A `let`/`var` bound at module level is a store that outlives every call
689
+ and hides its writers from the reader; bound inside a function or a block it is
690
+ ordinary local work.
691
+
692
+ That is a rule and not an entity — no piece becomes "the thing", so there is nothing
693
+ to classify — written over two facts the engine already has:
694
+
695
+ ```yaml
696
+ - id: no-hidden-store
697
+ infer:
698
+ - mutable: { equals: true }
699
+ kind:
700
+ ancestors: { none: { is: { in: [FunctionDeclaration, MethodDeclaration, ArrowFunction, FunctionExpression, Constructor, GetAccessor, SetAccessor, Block, CaseClause, ModuleBlock, ForStatement, ForOfStatement, ForInStatement, WhileStatement, DoStatement, ClassDeclaration, ClassExpression] } } }
701
+ report:
702
+ code: rewrite
703
+ description: "`{what}` is a module-scope `let`/`var`: a store that outlives every call, is writable from every importer and is invisible in every signature that reads it."
704
+ fix:
705
+ message: "Make it a `const` — a value computed once, at load — or move the changing value into the function that owns it (a local) or into a state container the UI reads."
706
+ ```
707
+
708
+ `mutable` is true for a declaration in a `let`/`var` list, and `kind.ancestors` says
709
+ what the declaration sits inside — no ancestor that opens a scope means module scope.
710
+ A function's own `let` has its `Block` above it and is never asked.
711
+
712
+ ### `proper-values`
713
+
714
+ The style reading is what makes a design-token law expressible. This rule asks the
715
+ CSS each component reads to RESOLVE against the provider (the theme) it was handed:
716
+
717
+ ```yaml
718
+ - id: proper-values
719
+ where: [{ entity: atom }, { entity: molecule }, { entity: section }]
720
+ ignore: ["packages/**/tests/**", "**/*.test.*"]
721
+ infer:
722
+ # a) the provider's value is wrong for the property (the CSS grammar rejects it)
723
+ - framework:
724
+ css:
725
+ templates:
726
+ any:
727
+ declarations:
728
+ any:
729
+ resolution:
730
+ resolvedValues:
731
+ any:
732
+ valid: { equals: false }
733
+ report:
734
+ code: rewrite
735
+ description: "`{what}` resolves `{prop}` to `{value}` in provider `{provider}`, which the CSS grammar rejects."
736
+ fix:
737
+ message: "Fix the THEME value or the property the component feeds it to — do not hardcode a value."
738
+ ```
739
+
740
+ The other two branches are the same shape: a FIXED path some provider does not carry
741
+ (`resolution.unresolved.kind: absent` — the provider is incomplete, not the
742
+ component), and any part that never reaches a concrete value.
743
+
744
+ ### `no-theme-mount-in-a-component`
745
+
746
+ The law about a LIBRARY symbol, which is a rule because the import has no repo target:
747
+
748
+ ```yaml
749
+ - id: no-theme-mount-in-a-component
750
+ where: [{ entity: atom }, { entity: molecule }, { entity: section }]
751
+ infer:
752
+ - imports:
753
+ any:
754
+ source: { in: [styled-components, styled-components/native] }
755
+ imported: { any: { equals: ThemeProvider } }
756
+ not:
757
+ or:
758
+ - location: { path: { contains: "/tests/" } }
759
+ - location: { fileName: { matches: "*.test.*" } }
760
+ report:
761
+ code: remove
762
+ description: "`{basename}` imports `ThemeProvider` — a component mounts no theme."
763
+ fix:
764
+ message: "Delete the import and the `<ThemeProvider>` it renders: read the theme in the styled block's callback or call `useTheme()`."
765
+ ```
766
+
767
+ `imported` is matched, not `named` — `import { ThemeProvider as TP }` renames the
768
+ binding, never the symbol.
769
+
770
+ ### Report specs
771
+
772
+ `report` is a string, or an object whose fields the report and the picture share:
104
773
 
105
774
  | field | meaning |
106
775
  | --- | --- |
107
- | `ctx.file` | the full ts-morph `SourceFile` — the whole AST is available (`getImportDeclarations`, `getFunctions`, `getDescendantsOfKind`, …) |
108
- | `ctx.path` | repo-relative path (posix) |
109
- | `ctx.basename` | file name |
110
- | `ctx.dir` | directory (repo-relative) |
111
- | `ctx.captures` | all `{name}` captures from the invariant's `where` and the matched node, e.g. `ctx.captures.feature` |
112
- | `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 |
113
- | `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" |
114
- | `ctx.arch` | the loaded architecture (nodes, invariants, aliases) |
115
- | `ctx.enclosingFunctionName(line)` | name of the function containing the 1-based `line`, or `null` |
776
+ | `description` (or `message`) | the finding sentence |
777
+ | `fix` | the repair sentence, or `{ message, location }` |
778
+ | `code` (or `ask`) | the repair kind the picture labels: `move`, `remove`, `rewrite`, `merge`, `split`, `delete`, `declare`, `create`, `add`, `rules`, or your own |
779
+ | `path`, `place`, `to`, `from` | the boxes the repair points at, when a rule states them itself |
116
780
 
117
- `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.
781
+ `{…}` placeholders are substituted: path vars (`{file}`, `{basename}`, `{dir}`),
782
+ scalars of `location` (`{fileName}`, `{files}`), captures from node names, and match
783
+ context (`{what}` — the matched candidate's name, `{n}`, `{snippet}`, `{violations}` —
784
+ the items of a list fact that fail an `every`).
118
785
 
119
- ## report
786
+ ## The filter engine
120
787
 
121
- `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`.
788
+ Every `infer`, `when` and `where`-by filter uses one grammar
789
+ ([entities/queries.ts](entities/queries.ts)). A filter is:
122
790
 
123
- ### Variables
791
+ - an **object of entries** — AND of all entries;
792
+ - a **list of filters** — AND of all sub-filters;
793
+ - `null` / omitted — always passes.
124
794
 
125
- `{name}` placeholders are substituted before the text is printed.
795
+ Each entry is either an **operator** or a **field** of the item — one field at a time,
796
+ on every fact: `{ name: { equals: "x" } }` → `item.name` must pass it; `{ kind: { own:
797
+ { is: { in: […] } } } }` → `item.kind.own.is` must. Dotted keys are paths into a
798
+ nested fact.
126
799
 
127
- **From the file path** (every finding):
800
+ | group | operators |
801
+ | --- | --- |
802
+ | scalar | `equals`, `not`, `lt`, `lte`, `gt`, `gte`, `in`, `notIn`, `contains`, `startsWith`, `endsWith`, `isSet`, `matches` |
803
+ | null / empty | `isNull`, `isEmpty` |
804
+ | list | `length`, `at`, `every`, `any`, `none`, `where` (`{ filter, by }` — narrows the list, then applies `by`), `unique` |
805
+ | composition | `and`, `or`, `xor`, `not` |
806
+ | place | `location` — asks the path question with the location vocabulary |
128
807
 
129
- | variable | meaning |
808
+ A missing or non-list field simply fails the operator. `$`-prefixed values reference
809
+ another fact in scope, dot-paths included: `{ equals: "$name" }` compares the field to
810
+ the candidate's own `name`.
811
+
812
+ ## Facts
813
+
814
+ A relation is a **runtime** dependency: `import type` is not one (nothing is bound at
815
+ runtime). Type-only imports are a relation of their own — `typeImport` — so a project
816
+ can allow one and forbid the other: `import` says "this code runs against that file",
817
+ `typeImport` says "this code names a shape from it".
818
+
819
+ ### File facts
820
+
821
+ | fact | holds |
130
822
  | --- | --- |
131
- | `{file}` | repo-relative path of the flagged file |
132
- | `{basename}` | file name without directory |
133
- | `{dir}` | directory of the file (repo-relative) |
823
+ | `lines` | the file's lines as ONE array (`lines[0]` is the first, `lines.length` the count) |
824
+ | `imports` | `[{ form, source, resolved, typeOnly, named, defaultName?, namespaceName?, line, piece, imported, declaring }]` — `form` is `statement` / `require` / `dynamic` |
825
+ | `exports` | `[{ form, named, from, source, name, line, piece, declaring, original }]` — `form` is `named` / `namespace` / `star` / `default` / `equals` / `commonjs` |
826
+ | `location` | where the file is: `path`, `dir`, `fileName`, `files` (the folder's own files) |
827
+ | `kind` | the file's own node and every node below it |
828
+ | `candidates` | the entity-enriched candidate facts |
829
+ | `entities` | the flat list of entity names present |
830
+ | `reads` | `[{ module, what, line, piece }]` — whole member paths (`a.b.c`, `a["b"]`) whose root belongs to another module, i.e. a read that is not a call |
831
+
832
+ `location` is the ONE place fact, in every subject: `{ location: { files: { length: {
833
+ gt: 7 } } } }` is "this folder holds more than seven files", and `{ location: { piece:
834
+ { isNull: true } } }` is "at module scope".
134
835
 
135
- **Captures** — any `{name}` used in a node `name`, invariant `where`, or `forbid` (imports) pattern. E.g. `{feature}` in `src/features/{feature}/**/*.service.ts` captures `orders` and is available as `{feature}` in that file's findings.
836
+ ### The `kind` fact
136
837
 
137
- **Match context** (text-forbid findings only):
838
+ One shape for every structural question about a node, so a rule never needs a second
839
+ vocabulary. A node descriptor is `{ is, name?, line?, …what that node has }`, and
840
+ every facet takes the same filters:
138
841
 
139
- | variable | meaning |
842
+ | facet | is |
140
843
  | --- | --- |
141
- | `{count}` | how many lines matched the pattern |
142
- | `{plural}` | `""` if count is 1, `"s"` otherwise — for `time{plural}` |
143
- | `{line}` | first matching line number |
144
- | `{lines}` | all matching line numbers, comma-separated |
145
- | `{snippet}` | the first matching line, trimmed |
146
- | `{match}` | the exact matched text on the first line |
147
- | `{where}` | ` in `functionName`` if the match is inside a named function, empty otherwise |
844
+ | `own` | the node itself |
845
+ | `parent` | its syntax parent (may be a `Block` or a `VariableStatement` — syntax, not meaning) |
846
+ | `ancestors` | every enclosing node, up to the file |
847
+ | `children` | its direct children |
848
+ | `siblings` | its siblings |
849
+ | `descendants` | everything below it, flat (`depth: 0` = a direct child; extras: `snippet`, `nested`, `type` on `as` expressions, `members` on object literals) |
850
+ | `initializer` | for a declaration, the value it is initialised with: `{ is, origin, members }` (`origin` is the leftmost identifier chain — `t.model` in `t.model({…})`) |
851
+ | `chain` | the links the engine followed to reach this piece (calls and rendered components) — `kind.chain.length` is the depth a `no-props-drilling` rule asks about |
148
852
 
149
- Without `report`, the tool composes a fallback from the rule's shape.
853
+ Beside them, the SPELLING of the node: `modifiers` (`["export", "abstract", "const"]`),
854
+ `decorators` (`[{ name, full, line }]`), `assertion` (`as const` / `satisfies X`) and
855
+ `disposable` (`using`).
150
856
 
151
- ## Aliases
857
+ ### Candidate facts
858
+
859
+ A piece is described with its own facts and nothing else:
152
860
 
153
- `aliases` maps import specifiers to paths for import resolution (e.g. `"#db": "src/db"`). Used by `type: "imports"` forbid entries and by `ctx.imports[].resolved`.
861
+ | fact | holds |
862
+ | --- | --- |
863
+ | `name`, `entity` | what it is called and what it got |
864
+ | `location` | `path` (the file) and `piece` (the piece it is nested in — `null` = module scope) |
865
+ | `lines` | the lines it spans, as ONE array |
866
+ | `parameters` | `[{ name, type, typeFile, optional, rest, bindings }]` — `typeFile` is the file declaring the type, resolved by the checker |
867
+ | `calls` | `[{ kind, origin, action, module, target, receiverOnly, bare, arguments, targetEntity }]` — `target` is `{ path, name }` |
868
+ | `assignments` | `[{ line, target, method, value, via, module, onThis, type, param, local, relation }]` — every write in one fact; `via` is `assign` / `call` / `delete` / `freeze` / `seal`, and `relation` is the ONE classification: `mutate` (somebody else's value), `assign` (a value handed in or declared in the repo) or `null` (the piece's own local) |
869
+ | `returns` | `[{ kind, exprKind, origin, members }]` |
870
+ | `branches` | `[{ is, line }]` — the branching the piece contains |
871
+ | `kind` | the facets above |
872
+ | `exported`, `mutable` | is it written with `export`; may the binding be reassigned (`let`/`var`) |
873
+ | `extends`, `implements`, `members`, `constructorParams` | classes |
874
+ | `references`, `implementations` | the checker's answer, not the tree's |
875
+ | `file` | the facts of the file it lives in |
154
876
 
155
- ## CLI
877
+ A call's `target` is a **location**, the same interface `where` entries use, so a call
878
+ destination is addressed like anything else:
156
879
 
157
- ```sh
158
- bunx follow-architecture [options]
880
+ ```yaml
881
+ # "a function that calls something living in the utils node"
882
+ infer:
883
+ - calls:
884
+ any:
885
+ target:
886
+ location: { node: utils }
159
887
  ```
160
888
 
161
- Without installing: `bunx @md-code/follow-architecture [options]`.
889
+ `targetEntity` is the same question in entity vocabulary: the entity whose home covers
890
+ the target's location. An ambiguous location yields `null` — the engine never guesses.
162
891
 
163
- | flag | default | meaning |
892
+ ### `imports`, `exports` and `declaring`
893
+
894
+ A name is judged where it is DECLARED, not at the module that passes it on. `import {
895
+ codeEditor } from "@md/styles"` names the package's `index.ts`, but the file that
896
+ declares `codeEditor` is the theme file — and that is the file a relation is about. So
897
+ every import and re-export fact carries the answer:
898
+
899
+ - `imports[].imported` — the names as the target module writes them (`import { X as Y }`
900
+ gives `X`: an alias renames the binding, never the symbol);
901
+ - `imports[].declaring` / `exports[].declaring` — one entry per name, the file that
902
+ DECLARES it, or `null` when the chain does not answer;
903
+ - `exports[].original` — the name before `as`.
904
+
905
+ The chain ([entities/ast/export-chain.ts](entities/ast/export-chain.ts)) follows
906
+ `exports[].from` hop by hop, through aliases. It stops at a CYCLE and at the budget
907
+ `barrelDepth` (the rule option, the CLI's `--barrel-depth`, `8` unless given — a TOOL
908
+ setting: where a name is judged is the law, not a per-repo knob). Both answer `null`,
909
+ and the edge then stays on the module file.
910
+
911
+ An import edge is SPLIT by declaring file: one edge per file a name came from, and the
912
+ module edge remains only for the names that stayed or never resolved. So a filter may
913
+ say what a barrel is for:
914
+
915
+ ```yaml
916
+ infer:
917
+ - imports:
918
+ any:
919
+ declaring: { any: { startsWith: "packages/styles/themes/" } }
920
+ ```
921
+
922
+ ### The `framework` namespace
923
+
924
+ Every fact a reader that is NOT the TypeScript AST contributes lives in ONE namespace,
925
+ `framework`, with one branch per reader. A rule names the reading, never the reader.
926
+
927
+ `framework.links` is the composition graph: one entry per component a piece RENDERS —
928
+ `{ name, module }`, where `module` is the file that declares the rendered component and
929
+ `null` means "this same file". Without an import map the list is EMPTY, never guessed.
930
+
931
+ ## Facets
932
+
933
+ The engine knows TypeScript. It does not know React, Vue, Angular, styled-components,
934
+ Tailwind or Vitest — and it must not. A **facet** is the module that knows: a reader of
935
+ the same AST that says what its own world calls the things it sees.
936
+
937
+ | branch | written by | answers |
164
938
  | --- | --- | --- |
165
- | `[cwd]` | `.` | repo root (positional) |
166
- | `--config <path>` | `architecture.json` / `architecture.config.js` found by walking up | architecture JSON or JS module |
167
- | `--out <path>` | print to stdout | report output |
168
- | `--ignore <glob>` | — | extra file globs to skip (repeatable) |
169
- | `--check` | off | exit 1 if there are findings |
939
+ | `framework.id` | the component readers, and the test reader where nobody else spoke | whose reading this is: `react` / `vue` / `angular` / `test` |
940
+ | `framework.component`, `framework.props`, `framework.forwarded`, `framework.jsx`, `framework.handler` | the component readers | what the piece renders and hands down; `handler` marks a piece referenced by an event attribute |
941
+ | `framework.links` | the component readers | the components it renders — the composition graph |
942
+ | `framework.css.templates` | the style facet ([css/](css)) | the CSS a tagged template holds |
943
+ | `framework.tailwind.classes` | the style facet | the class list a class attribute holds, each class read as a utility |
944
+ | `framework.test` | the test reader ([frameworks/test/](frameworks/test)) | which runner the file was written for, and what it declares |
945
+
946
+ A rule therefore says `framework.css.templates` or `framework.test.runner` whatever
947
+ read it. There is no second facade beside `framework` — not `css` on the candidate, not
948
+ `test` at the top — so a filter written once keeps working when the reader behind it
949
+ changes.
950
+
951
+ ### The registry
952
+
953
+ A framework module lives in `frameworks/<id>/index.ts` and exports a `FrameworkFacet`:
954
+
955
+ ```ts
956
+ interface FrameworkFacet {
957
+ id: string; // the word `framework.id` carries
958
+ applies(ctx: FacetContext): boolean; // the cheap gate: read the path / the text
959
+ enrich(candidates: Candidate[], ctx: FacetContext): Candidate[];
960
+ classAttributes?: string[]; // `className`, `class` — the words a class list is written into
961
+ }
962
+ ```
963
+
964
+ `REGISTRY` ([frameworks/index.ts](frameworks/index.ts)) is the list — `react`, `vue`,
965
+ `angular`, `test` — and adding a framework is one module plus one entry, with no change
966
+ to the engine, the pipeline or the report. `applies` is asked first and answers from the
967
+ path or the text; only a file that applies is enriched.
170
968
 
171
- The report (`--out`) groups findings by file and prints each finding as the full `message` followed by a **Fix.** section with the `fix` text.
969
+ `classAttributes` is why the style facet can stay framework-blind: a class list is
970
+ written into `className` in React and `class` in a template, and the css facet asks the
971
+ registry for the union instead of spelling either word.
172
972
 
173
- ## ESLint
973
+ The style facet is deliberately NOT in the registry: `css/` reads structure, not a
974
+ framework — a tagged template is a tagged template in a `.ts`, a `.tsx` or a `.vue`
975
+ file — so no `applies` gate could narrow it. It writes `framework.css` /
976
+ `framework.tailwind` and never `framework.id`.
174
977
 
175
- The package exports a `flatConfig` factory:
978
+ ### The style reading
979
+
980
+ A template becomes a fact when its SUBSTITUTED text reads as CSS — `${…}` is replaced
981
+ by blanks and the result goes through the CSS grammar — so SQL, JSON and prose in a
982
+ tagged template stay unread whatever the tag is called. The one exception is a body
983
+ with no text left (`` css`${({ $wide }) => …}` ``): for that case only, and only when
984
+ the tag is a styled-components word, the tag decides.
985
+
986
+ | fact | holds |
987
+ | --- | --- |
988
+ | `framework.css.templates[]` | `tag`, `line`, `startLine`, `comment` (the doc above the declaration), `declarations[]`, `rules[]`, `literals[]`, `vars[]`, `exprs[]` — the whole document reading |
989
+ | `framework.tailwind.classes[]` | one entry per class token: `raw`, `variants`, `utility`, `base`, `value`, `arbitrary`, `negative`, `known`, `properties`, `line` |
990
+
991
+ `known` is the Tailwind engine's answer to "does this project's config know this
992
+ utility", so a rule about a second styling system needs no vocabulary of its own. A
993
+ declaration also carries its RESOLVED value: `resolution.resolvedValues` (the
994
+ provider's answer for a theme token) and `resolution.unresolved` (a path no provider
995
+ declares).
996
+
997
+ ### The test reading
998
+
999
+ A test file is a file that imports a test API from a module that RUNS it, or calls one:
1000
+
1001
+ | fact | holds |
1002
+ | --- | --- |
1003
+ | `framework.test.runner` | `vitest` or `jest`, `null` when nobody was imported |
1004
+ | `framework.test.cases` | `it` / `test` calls (`it.each([...])(…)` is ONE case) |
1005
+ | `framework.test.asserts` | `expect` calls |
1006
+ | `framework.test.hooks` | the hooks the file installs, by name |
1007
+ | `framework.test.snapshots` | `toMatchSnapshot` / `toMatchInlineSnapshot` — counted as assertions too |
1008
+ | `framework.test.mocks` | `vi.*` / `jest.*` mock calls |
1009
+
1010
+ A TYPE-only import is a TypeScript reading, not a test: `import type { Mock } from
1011
+ "vitest"` binds nothing at runtime, so the file is not a test file however the type is
1012
+ used; `import { type Mock, describe } from "vitest"` IS one, because a value came along.
1013
+ That is the same rule the engine applies to `import` vs `typeImport`.
1014
+
1015
+ The facts are the FILE's, which is what lets an entity be defined on what a file DOES
1016
+ instead of where it lives:
1017
+
1018
+ ```yaml
1019
+ - slug: testCode
1020
+ infer:
1021
+ - or:
1022
+ - location: { path: { matches: "**/*.test.ts*" } }
1023
+ - framework: { test: { runner: { isSet: true } } }
1024
+ - framework: { test: { cases: { gt: 0 } } }
1025
+ ```
1026
+
1027
+ ### One candidate, several readers
1028
+
1029
+ A `.tsx` test renders components AND runs tests, so two readers write the same
1030
+ candidate. They do not fight: `attach()` ([frameworks/facet.ts](frameworks/facet.ts))
1031
+ MERGES into `framework`, never replaces it, so the react reading keeps `jsx`/`props`
1032
+ and the test reading sits beside it as `framework.test`. `framework.id` names the
1033
+ file's reading deterministically — the component readers run before the test reader.
1034
+
1035
+ A reader that throws is isolated, and reported once: `applies` and `enrich` are each
1036
+ wrapped, so a broken facet cannot take a file's analysis down with it — the file keeps
1037
+ every other fact it had, and the run prints one notice instead of a stack trace per
1038
+ file. A reader may add facts and may fail, but it may never edit the AST facts or hide
1039
+ a file from the rules.
1040
+
1041
+ ### One walk over one file
1042
+
1043
+ Loading the syntax, collecting the candidates, attaching the readers' facts, reading
1044
+ the file's facts and classifying them is a single function —
1045
+ [`walkFile`](code-entities/walk.ts) — and one context names everything a consumer may
1046
+ say: `rel`, `arch`, `repoRoot`, `repoFiles`, `aliases`, `project`, `sf`, `text` (the
1047
+ editor's buffer), `usage` (the checker facts), `record` and `depth`. The CLI pipeline,
1048
+ the editor's project index and the report's entity cards call it and nothing else, so
1049
+ the same file classifies the same way everywhere.
1050
+
1051
+ ## Report
1052
+
1053
+ A finding is written for someone who has to ACT on it, so it carries the same
1054
+ information the graph does:
1055
+
1056
+ | part | what it names |
1057
+ | --- | --- |
1058
+ | the message | the offending line, and everything the rule DOES allow — a closed folder lists its declared children, an action lists the entities and the folders that may do it |
1059
+ | the destination | when the offending code has an entity with a declared home, that home resolved for this file, so "move it" means one path |
1060
+ | the mechanisms | for an action with `scopeAccess`, the chains that reach the same code WITHOUT an import |
1061
+ | `How to fix` | one instruction per offending line, naming the exact file or folder — and nothing at all when the architecture cannot prove a destination |
1062
+ | the config file | every instruction names the file the architecture was actually loaded from |
1063
+
1064
+ Which home answers is decided, not guessed: a home in the file's own BRANCH wins, and
1065
+ among those the closest one. When no home is in the file's branch, the home declared
1066
+ FIRST answers — so **the order of the nodes that declare an entity is its priority
1067
+ list**.
1068
+
1069
+ ### Where the wording lives
1070
+
1071
+ The engine observes and decides **facts**; the report turns facts into **language**,
1072
+ once, for every consumer (the CLI text, the linter message, the interactive overview).
1073
+ No module outside `report/errorTypes/` writes a sentence about a finding.
1074
+
1075
+ ```
1076
+ report/errorTypes/
1077
+ index.ts public surface: describe(), renderToken(), ids
1078
+ decision-maker.ts the only decision maker: which kind of finding, what to say,
1079
+ what can be done
1080
+ destinations.ts where a move goes, and how sure the report is
1081
+ finding-type.ts the interface each finding type implements
1082
+ vocabulary/
1083
+ ids.ts the ids both sides use (the report and the picture)
1084
+ verbs.ts "imports" / "import" / "mutation"
1085
+ phrases.ts a fact → a phrase, a subject, a reason
1086
+ places.ts entity → box, name → node, an entity's declared home
1087
+ types/
1088
+ wrongAction.ts a relation the architecture forbids
1089
+ wrongPlacement.ts the code is in the wrong place (move, or split)
1090
+ unknownEntity.ts nothing declares this kind of code here
1091
+ fileContents.ts the finding judges the file itself
1092
+ codes/
1093
+ structure.ts structure.* — "this entry does not belong in this folder"
1094
+ ```
1095
+
1096
+ Each type answers three questions and nothing else:
1097
+
1098
+ | export | question |
1099
+ | --- | --- |
1100
+ | `classify(ctx, places)` | is this finding of my kind, and what are the facts? |
1101
+ | `message(story, ctx)` | the sentence to print — `null` keeps the engine's |
1102
+ | `fixes(story, ctx)` | **a list** of repairs, cheapest first |
1103
+
1104
+ `fixes` is a list because a broken rule usually has more than one honest answer: a
1105
+ forbidden relation can be repaired by removing the usage, by moving the code, or by
1106
+ widening the rule — printing only the first is how a report says "Delete it." about a
1107
+ file that is perfectly placed.
1108
+
1109
+ **The engine emits tokens, not prose.** A refused relation travels as
176
1110
 
177
1111
  ```js
178
- // eslint.config.js
179
- const plugin = require("@md-code/follow-architecture");
1112
+ { code: "relation.forbidden",
1113
+ fact: { kind: "typeImport", resolved: "…/document/type.ts" },
1114
+ subject: { pieces: [], entities: ["constants"], plural: false },
1115
+ why: { code: "allowed", entities: ["theme"], targetNode: "sharedTypes" },
1116
+ via: null }
1117
+ ```
1118
+
1119
+ `phrases.ts` renders the sentence from it, `wrongAction.ts` renders the repairs, the
1120
+ picture renders the arrow.
1121
+
1122
+ ### Where a move goes
1123
+
1124
+ A destination is a **decision**, not a lookup: it is decided by the code entity and
1125
+ confirmed by the tree. The confidence is a `0..1` number built from five sources:
1126
+
1127
+ | source | question | weight |
1128
+ | --- | --- | --- |
1129
+ | `declared` | does the tree call this file that entity (its owner node's entities)? | 0.45 |
1130
+ | `inferred` | did the engine infer that entity from the code itself? | 0.30 |
1131
+ | `named` | does a home of that entity name this file? | 0.13 |
1132
+ | `hostable` | can a real node instance host that home today? | 0.07 |
1133
+ | `branch` | is that home in the file's own top branch? | 0.05 |
1134
+
1135
+ `permits` is **not** a weight — it is a **precondition**: the law is "everything not
1136
+ allowed is forbidden", so a place where the relation is still forbidden is not a
1137
+ destination at all, whatever the other signals say. A candidate also needs a known
1138
+ code entity (`declared` or `inferred`) and at least two sources with confidence ≥ 0.5.
1139
+ When nothing qualifies, no move is offered and the repair is the removal.
1140
+
1141
+ ### The modules
1142
+
1143
+ | path | what it owns |
1144
+ | --- | --- |
1145
+ | [entities/ast/](entities/ast) | reading code: imports, exports, calls, writes, declarations, comments → **facts** |
1146
+ | [entities/kinds.ts](entities/kinds.ts) | a fact → an **edge** (`{ path, line, piece, entity, fact, what }`); the eight relations |
1147
+ | [entities/tree/](entities/tree) | **where** files may live: `build.ts` (nodes → path variants + entity homes), `match.ts` (a path → its node, and whether that node is real there), `entries.ts` (walking a path, reporting undeclared entries) |
1148
+ | [nodes/](nodes) | `children.ts`, `child-entities.ts`, `similar.ts`; the home lookup lives in [entities/location/homes.ts](entities/location/homes.ts) |
1149
+ | [nodes/finally/](nodes/finally) | the built-in structure rule: `required.ts` (is this folder an instance of its node?), `queries.ts` (does this file match a child's query?), `relations.ts` (does this file reach code it may not?), `entities.ts` (does its kind fit the node?), `emit.ts` (one finding per decision) |
1150
+ | [rules/](rules) | a rule's own keys: `normalize.ts`, `name.ts`, `vars.ts`, `list-vars.ts`, `index.ts` (the evaluation) |
1151
+ | [report/errorTypes/](report/errorTypes) | **the words**: message, repairs, destinations, the ids the picture uses |
1152
+ | [report/user-report/](report/user-report) | the interactive overview: data → JSON → React |
1153
+
1154
+ ### The overview page
1155
+
1156
+ `--overview [path]` writes one self-contained HTML file (no server, no network, no
1157
+ sidecar assets) that renders the architecture as a browsable model:
1158
+
1159
+ | screen | what it answers |
1160
+ | --- | --- |
1161
+ | **Overview** (`SummaryScreen`) | counts, findings by category, orphan files, the most important violations |
1162
+ | **Architecture tree** (`TreeScreen`) | every declared node, the entities that may live in it, the arrows that touch it, and its findings |
1163
+ | **Graph & code entities** (`GraphScreen`) | the entities list and the selected entity's card (how it is inferred, a real example, what may be done with it); the canvas draws **one box per code entity** and the relations the scan actually saw between entities |
1164
+ | **Rules** (`RulesScreen`) | each rule rewritten as plain conditions (`lines > 200`, `rule ≠ action`), with `where` / `ignore` named by kind |
1165
+ | **Findings** (`FindingsScreen`) | every violation with its message, the boundary it crossed, why it matters, and the fix |
1166
+
1167
+ ### The graph screen
1168
+
1169
+ The canvas is **entity → entity**: one box per code entity (`data record`, `handler`,
1170
+ `atom`, `theme`, `barrel`, …), with the paths it may be met at listed inside. The
1171
+ selected entity's box is **always drawn**, even when no relation touches it, and then
1172
+ the screen says so in words — “No relation touches `data record` in this scan: nothing
1173
+ it declares is read, called or imported by another entity, and the architecture
1174
+ declares no rule for it either.” There is never an unexplained empty canvas.
1175
+
1176
+ The arrows are the relations the scan **judged**, not only the rules the config
1177
+ declares: `import`, `export`, `declare`, `call`, `mutate`, `assign`, `read`,
1178
+ `typeImport`, aggregated **per entity pair** — one arrow per kind, from, to. An arrow
1179
+ points from the code that **does** the thing to the code it does it to —
1180
+ `molecule ──import──▶ atom` means *the molecule's code imports the atom's code* —
1181
+ and hovering it prints the sentence and the `file:line` the scan read it from.
1182
+
1183
+ How to read one arrow:
1184
+
1185
+ | on the arrow | what it means |
1186
+ | --- | --- |
1187
+ | the kind and **`×N`** | `N` places in the scan do exactly this — the number is the count, not a guess |
1188
+ | red, dashed, `✕` and `×N` red | the architecture **refuses** these `N` places — the same arrows the Findings screen reports |
1189
+ | faint dashed | the config **declares** the relation but this scan never saw it — a rule without code behind it |
1190
+ | hover | the exact sentence of the first place, with its `file:line` (`imports \`src/x.ts\`` — `src/reader.ts:2`) |
1191
+ | click a box | opens that entity (`#graph?entity=<slug>`) |
1192
+
1193
+ The arrows do not carry the labels — the **kinds** do. Every arrow of one kind at one
1194
+ box is ONE **ribbon**: its arrows share one port on the box and one lane in the strip
1195
+ between the columns, so they run together and fan out only where they land. One ribbon
1196
+ per (box, side, kind), one **pill** per (box, kind) — `typeImport ×109` (every place of
1197
+ that kind at the box, both ways), `✕ import ×2` (red: every one of them refused),
1198
+ `import ×6 · ✕2` (mixed) — and no arrow has a label of its own. The ribbons of a box
1199
+ stand in the order of the kind chips (`declare`, `export`, `import`, `call`, `read`,
1200
+ `typeImport`…), so a ribbon sits where its chip sits. Pointing at a pill lights every
1201
+ arrow of its kind at that box and names the boxes it reaches under the drawing
1202
+ (`atom · typeImport ×109 · ✕2: barrel ×11, class ×10, constant ×10, +8 more`); pointing
1203
+ at a kind **chip** does the same for the ribbons of that kind at the selected entity.
1204
+
1205
+ The default canvas is calm on purpose: one arrow per (source, target, kind) — an
1206
+ observed relation and a declared hint about the same pair are one solid wire, a dashed
1207
+ one means declared and never once observed — drawn as a hairline at a third opacity.
1208
+ Refused arrows stay off the canvas until their own kind is pointed at (the pill already
1209
+ counts them), and the kind under the pointer comes forward while the rest fades.
1210
+
1211
+ The badge over the canvas counts what is drawn (`N entities · M relations`), the kind
1212
+ chips filter the arrows without losing the entity you selected (an empty filter says
1213
+ which filter is empty and how many relations it hides), and **Show all entities** draws
1214
+ every box. When nothing at all is left to draw, the chip row hides itself.
1215
+
1216
+ The data behind it is `access.observed`: one entry per kind + from + to with `count`
1217
+ (places seen), `broken` (how many of them were refused) and `sample` (`{ file, line,
1218
+ sentence }` of the first place). The engine fills it while it judges the relations —
1219
+ `report/observed.ts` per file, republished idempotently — and the report merges it with
1220
+ the declared arrows (`declared: true`, no `count` when never seen) in
1221
+ `report/user-report/data/graph-entities.ts`, so the page can tell “declared but not
1222
+ observed” from “observed and broken” from “observed and allowed”.
1223
+
1224
+ Nothing in the report is hardcoded per project: titles come from the configured
1225
+ messages, conditions from the configured filters, examples from real paths. Findings
1226
+ carry the engine's structured `data.repair`, so the UI never parses message text.
1227
+
1228
+ ### Prebuilt bundle
1229
+
1230
+ The page inlines a React app compiled at **package build time**, not on first use:
1231
+ `scripts/build-report-bundle.mjs` writes `dist/report/user-report/build/bundle.prebuilt.js`,
1232
+ which ships inside `dist/`. A published CLI therefore never needs `esbuild`, React or
1233
+ `styled-components` at runtime.
1234
+
1235
+ Contributors running from source without a build still get overviews: when the asset is
1236
+ missing, the bundle is compiled on the fly and cached in `os.tmpdir()`. `pnpm build` =
1237
+ `clean` → `tsc` → `prebuild:report`; run the workspace build so `@md-code/sections`
1238
+ (which owns the code-diff board) is compiled before the packages that bundle its view.
1239
+
1240
+ ## The ESLint rule
1241
+
1242
+ Rule name: **`md-code/follow-architecture`**, severity `error` in the config above
1243
+ (`meta.type: "problem"`). It is the same engine as the CLI: same architecture file,
1244
+ same facts, same wording — a finding the CLI prints is a diagnostic the editor
1245
+ underlines, on the line the violation starts at.
1246
+
1247
+ | Option | Type | Default | Meaning |
1248
+ | --- | --- | --- | --- |
1249
+ | `config` | `string` | `architecture.yaml` | The architecture file's path |
1250
+ | `configs` | `object` | — | Tool config paths (`tailwind.config.js`, an SCSS entry): key → path, read once per run |
1251
+ | `include` | `string[]` | — | Only files matching these globs are checked |
1252
+ | `exts` | `string[]` | the built-in list | Source extensions, added to `.ts`, `.tsx`, `.js`, `.jsx`, `.mts`, `.cts`, `.vue`, `.svelte` |
1253
+ | `similarity` | `number` | `0.6` | Threshold for the "similar file" facts |
1254
+ | `barrelDepth` | `integer ≥ 1` | `8` | How many barrels a name may pass through before the name stays on the module |
1255
+ | `ignoreDirs` | `string[]` | the tool's list | Folder names not entered, added to `node_modules`, `.git`, `dist`, `reports`, `.turbo`, … |
1256
+ | `ignores` | `string[]` | — | Repo-relative file globs skipped, added to the tool's list |
1257
+ | `exportPath` | `string \| false` | `reports/architecture-overview.html` | Where the rule writes its HTML overview; `false` turns it off |
1258
+ | `indexPath` | `string \| false` | `.turbo/md-code/file-index.jsonl` | The shared file index; `false` turns the index gate off |
1259
+ | `usage` | `"checker" \| "index"` | `checker` | Who answers `references` |
1260
+ | `warmIndex` | `boolean` | `true` | `false` never starts a background `pnpm index:warm` |
1261
+
1262
+ The option may also be a bare string (`["error", "architecture.yaml"]`), which is the
1263
+ same as `{ config: "architecture.yaml" }`. There is no `root` option: the rule anchors
1264
+ the repo on the file being linted (`findRepoRoot(dirname(filePath))`, then the working
1265
+ directory), which is the only value that is right both in an editor that starts the
1266
+ ESLint server in a package directory and in a root-level CLI run. The schema rejects
1267
+ unknown option keys.
1268
+
1269
+ **What is linted.** The same two default lists the CLI uses — `IGNORE_DIRS` and
1270
+ `IGNORE_PATHS` from `ignore.ts` (published as `@md-code/follow-architecture/ignore.js`) —
1271
+ plus `ignoreDirs` / `ignores`, then `include` narrowing. Both lists are additive, and
1272
+ neither is private to this tool: `@md-code/config/eslint` spreads `IGNORE_PATHS` into
1273
+ its global `ignores`, which is why a lint run and a scan run skip the same files. They
1274
+ name what they skip (`apps/**`, `packages/api/**`, `scripts/**`, `**/*.js`, …) and say
1275
+ nothing about tests, so this package's own tests are in the lint area like any other
1276
+ file — a test that breaks a law the architecture describes is reported, and the
1277
+ user-report source and `tests/cli/` are named in `ignore.ts` as deliberately kept.
1278
+
1279
+ **What the editor shows.** One diagnostic per finding: the finding's message, then
1280
+ `How to fix:` and the named repairs when the decision maker has any. Findings from a
1281
+ file's own facts, from peer files and from the accumulated verdicts all arrive this
1282
+ way. On a cold workspace the first line of every file is one sentence (see [Index](#the-rule-reads-the-index-never-builds-it)) and
1283
+ nothing else is reported for that file.
1284
+
1285
+ **What the rule writes.** Exactly one file: the HTML overview at `exportPath`, the same
1286
+ self-contained page `--overview` produces, accumulated across every linted file and
1287
+ flushed when the run ends — debounced while the run continues, one last write on
1288
+ process exit. It never writes the index (that is the CLI and `pnpm index:warm`), never
1289
+ writes Markdown, and never edits a source file. `exportPath: false` runs the rule with
1290
+ no writes at all.
1291
+
1292
+ ## Index
1293
+
1294
+ A run keeps what it read in one index file (`.turbo/md-code/file-index.jsonl`, or
1295
+ `--index <path>`): per file, plain-data facts and the verdicts, so the next run reads
1296
+ the files that changed and the answers it already had. `--index off` neither reads nor
1297
+ writes it.
1298
+
1299
+ Each record has four sections — `fa` (the slimmable facts), `fa-peers` (the
1300
+ candidates), `fa-out` (the verdicts) and `fa-usage` (the `references` answers) — and
1301
+ every section value carries the stat of the file it was computed from. The record's own
1302
+ mtime/size say whether the FILE changed, which is what the write path needs; the
1303
+ value's stamp says whether *that* section still describes the file, so a section
1304
+ written by another tool cannot make this one look fresh. A value without a stamp is
1305
+ read as stale once. Fingerprints are the tool identity (package version, the
1306
+ fact-changing option values, a content hash of `dist/`) plus the file's own mtime and
1307
+ size: bumping the package or changing an option makes every section stale once, exactly
1308
+ like editing a file does.
1309
+
1310
+ The one fact a file cannot answer about itself is `references` — who uses a published
1311
+ name is a statement about every other file. It has two sources:
1312
+
1313
+ | `--usage` / option `usage` | how it is answered | exactness |
1314
+ | --- | --- | --- |
1315
+ | `checker` (default) | the type checker, on one project over the whole repository, once per run (`fa-usage` in the index) | what TypeScript says: the declaration a use actually binds to |
1316
+ | `index` | identifiers counted in the repo's text (`ts.createScanner`): per name, per file, member positions (`a.foo`) counted apart from value positions | an approximation: it cannot tell two same-named declarations apart |
1317
+
1318
+ `usage: index` is much faster cold and answers differently: a name no module imports
1319
+ reads as used because some other module writes the same name, and `this.value` is
1320
+ missed because a member is counted from its occurrences after a dot. Use it when the
1321
+ `references` rules are advisory and a cold run must be quick; keep `checker` when a
1322
+ finding about an unused export has to be true. The same choice exists in the ESLint
1323
+ rule, so an editor session and a CLI run can be compared like for like.
1324
+
1325
+ Editing `architecture.yaml` is not watched by the editor: restart the ESLint server
1326
+ (`ESLint: Restart ESLint Server`) after changing it.
1327
+
1328
+ ### The rule reads the index, never builds it
1329
+
1330
+ Before the rule reads or parses anything it asks the index whether this workspace can
1331
+ answer right now: the file's record (`fa`), the pieces of other files a code entity
1332
+ names (`fa-peers`) and the verdicts of files the run did not revisit (`fa-out`) must
1333
+ all be present, current, and recorded by this build of the tool. When they are not — a
1334
+ fresh clone, a fresh pull, an edited `architecture.yaml` — the rule reports one
1335
+ sentence on the first line,
1336
+
1337
+ > the architecture index is not built or is out of date for this workspace; run
1338
+ > `pnpm index:warm` — this file is not checked until then
1339
+
1340
+ and starts `pnpm index:warm` once in the background for the whole workspace, so the
1341
+ next pass is answered from the index. No file is walked, no project is opened, nothing
1342
+ is written. Option `warmIndex: false` keeps the message but never starts the run;
1343
+ `indexPath: false` turns the gate off with the index itself and checks the file in a
1344
+ project of its own closure, as the command line does without an index.
1345
+
1346
+ ### Warming the index
1347
+
1348
+ `pnpm index:warm` (repo root) runs `scripts/index-warm.mjs`: it reads the rule options
1349
+ from `@md-code/config/eslint` — the same file the editor loads — so the warm run
1350
+ asks for the same sections, with the same fingerprints, that the editor later reads.
1351
+ It writes `.turbo/md-code/file-index.jsonl`,
1352
+ logs to `.turbo/md-code/index-warm.log`, and takes a lock
1353
+ (`.turbo/md-code/index-warm.<label>.<hash>.lock`, 30 min TTL) so concurrent editors and
1354
+ CI cannot run it twice. `node scripts/index-warm.mjs --root <dir> --verbose` does the
1355
+ same for one root.
1356
+
1357
+ There is no `cache` option — the index *is* the cache, and every section it holds is a
1358
+ pure function of the file's content and the architecture.
1359
+
1360
+ ## Outputs
1361
+
1362
+ | Flag | File | Default |
1363
+ | --- | --- | --- |
1364
+ | `--out <path>` | Markdown text report | none — the report goes to stdout |
1365
+ | `--overview [path]` | self-contained HTML page | `architecture-overview.html`, resolved against the repo root |
1366
+ | — | HTML overview from the ESLint rule | `exportPath`, default `reports/architecture-overview.html`; `false` turns it off |
1367
+
1368
+ `--check` turns either CLI run into a CI gate: the same findings, exit code 1 when
1369
+ there is at least one.
1370
+
1371
+ The Markdown report is `renderReport`:
180
1372
 
181
- module.exports = [
182
- {
183
- files: ["src/**/*.ts", "src/**/*.tsx"],
184
- plugins: { "md-code": plugin },
185
- rules: {
186
- "md-code/follow-architecture": ["error", {
187
- config: "architecture.json",
188
- }],
189
- },
190
- },
191
- ];
192
1373
  ```
1374
+ # follow-architecture report
1375
+ Generated against `<repoRoot>`.
1376
+ ## Orphan files (only when there are some)
1377
+ ## Rules (each declared rule, rewritten as plain conditions)
1378
+ ## Findings (grouped by heading)
1379
+ #### `<what>` — `<file>:<line>`
1380
+ <message>
1381
+ **Fix** — N option(s):
1382
+ - <repair>
1383
+ ---
1384
+ ## Not read (N) (only when files were skipped, with the reason)
1385
+ ```
1386
+
1387
+ There is no catalog file: the package produces a report, not a record set, so
1388
+ `exportPath` is the only output path a rule can name. The shared index is written by
1389
+ the CLI and by `pnpm index:warm` only, and is a cache — never an input you are
1390
+ expected to edit.
1391
+
1392
+ ## Limitations and known debt
1393
+
1394
+ - **No auto-fix, no warning severity.** Every finding is an ESLint `error` and every
1395
+ repair is prose; moves are described, never applied.
1396
+ - **The rule writes one file.** `exportPath` HTML only, rewritten when the set of
1397
+ findings changes (debounced during the run, once at exit). It never writes Markdown
1398
+ and never touches a source file.
1399
+ - **Only the CLI and `pnpm index:warm` build the index.** The rule reports the cold
1400
+ sentence and, once per workspace, starts `pnpm index:warm` in the background. Where
1401
+ the root script does not exist (a published install outside a monorepo) the request
1402
+ fails quietly and the file stays unchecked until the CLI runs.
1403
+ - **The index is per-file and content-keyed.** The architecture's own fingerprint is
1404
+ part of every section, so editing the YAML invalidates the facts wholesale — but a
1405
+ running editor is not watching the file; restart the ESLint server.
1406
+ - **`usage: index` is an approximation.** It counts identifiers in the text, so two
1407
+ same-named declarations are indistinguishable. `references` rules get less
1408
+ trustworthy, not slower to compute.
1409
+ - **A run without an index is a whole-repo parse**: minutes and gigabytes on a
1410
+ monorepo this size (`--index off`, and the editor without an index). With a warm
1411
+ index the same run is seconds. The index is not an optimisation to skip casually.
1412
+ - **`dist/main.js` has no entry guard.** `node dist/main.js` exits 0 silently; the
1413
+ executable entry is `dist/bin/follow-architecture.js`.
1414
+ - **The overview's dev fallback needs esbuild.** When the prebuilt bundle is missing the
1415
+ page is compiled on the fly and cached in `os.tmpdir()`; only that path resolves the
1416
+ bundler.
1417
+ - **No catalogs, no `--check` staleness gate for anything but the index.** Findings are
1418
+ compared, not a record set, so there is nothing else to regenerate.
1419
+
1420
+ ## Scripts
1421
+
1422
+ Package scripts (`pnpm <script>`; each runs in the
1423
+ package folder):
1424
+
1425
+ | Script | Runs |
1426
+ | --- | --- |
1427
+ | `build` | `clean` → `tsc -p tsconfig.json` → `prebuild:report` |
1428
+ | `clean` | removes `dist/` |
1429
+ | `prebuild:report` | `node scripts/build-report-bundle.mjs` |
1430
+ | `typecheck` | `tsc -p tsconfig.json --noEmit` |
1431
+ | `test` | `vitest run` |
1432
+ | `lint` | `eslint .` |
1433
+ | `format` | Prettier `--write` over `**/*.{ts,tsx,js,jsx,css,json}` |
1434
+ | `format:check` | the same globs with `--check` |
1435
+ | `lint:products` | ESLint with `--config packages/follow-architecture/eslint.products.config.mjs` over `packages`, `NODE_OPTIONS=--max-old-space-size=13312`, `LINT_OVERVIEW=0` — the products as rules, findings in the console |
1436
+ | `lint:products:overview` | the same run with `LINT_OVERVIEW=1`: identical console output, and each product also writes its page under `reports/` |
1437
+ | `overview` | `node dist/bin/follow-architecture.js --overview architecture-overview.html` (needs an `architecture.yaml` in the current folder) |
1438
+ | `prepublishOnly` | `build` → `vitest run --no-file-parallelism` |
1439
+
1440
+ Repo-root commands:
1441
+
1442
+ | Command | Runs |
1443
+ | --- | --- |
1444
+ | `pnpm test:packages` | `turbo test --filter=./packages/*` |
1445
+ | `pnpm check:all` | `turbo run build typecheck lint test format:check` |
1446
+ | `pnpm lint` | `turbo run lint` (every package's own lint, with the product rules off), then `turbo run lint:products --filter=@md-code/follow-architecture` |
1447
+ | `pnpm lint:overview` | the same two phases with `lint:products:overview` — identical console output, plus one `reports/*-overview.html` per product |
1448
+ | `pnpm typecheck` | `turbo run typecheck` |
1449
+ | `pnpm format:check` | Prettier `--check` over `packages/**/*.{ts,tsx,js,jsx,css,json}` |
1450
+ | `pnpm index:warm` | `node scripts/index-warm.mjs` — writes the workspace index (log: `.turbo/md-code/index-warm.log`) |
1451
+
1452
+ To run the CLI against a real architecture file, point `--config` at it:
1453
+
1454
+ ```sh
1455
+ node dist/bin/follow-architecture.js --config architecture.yaml --overview architecture-overview.html
1456
+ ```
1457
+
1458
+ ## Tests
1459
+
1460
+ ```sh
1461
+ pnpm test # vitest run
1462
+ pnpm test:packages # every package's suite
1463
+ ```
1464
+
1465
+ The suite is the engine's contract: the filter operators, the config errors, the tree,
1466
+ the facets and the report. `tests/readme.test.ts` holds this document against the built
1467
+ `dist/`: every `--flag` the CLI accepts, every rule option the schema accepts, every
1468
+ command example it can run, every `@md-code/*` subpath it names, and the Install table
1469
+ against `package.json`.
1470
+
1471
+ ## Version
1472
+
1473
+ `0.3.2` — package `follow-architecture`, Apache-2.0, Node `>=18`, ESLint peer `>=8.40.0`. Source: https://github.com/DrBoria/follow-architecture.
193
1474
 
194
- The package's main export is the ESLint plugin (`{ meta, rules }`). The rule is `md-code/follow-architecture`; pass the architecture file via the `config` option (repo-root-relative, or absolute).
1475
+ ## License
195
1476
 
196
- `require("@md-code/follow-architecture/config").flatConfig(architecture, { parser, files, ignores, plugins })` is also exported as a flat-config factory. `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`.
1477
+ [Apache License 2.0](./LICENSE)