@md-code/follow-architecture 0.3.0 → 0.3.3

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