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