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