@hublo/sentinel 1.7.0-alpha.7 → 1.7.0-alpha.8

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.
@@ -1,146 +0,0 @@
1
- # Architecture check adoption cheat sheet
2
-
3
- `sentinel --arch` checks a module against an architecture decision of its repository: which
4
- folder may import which, which names a view may not import, which calls a view may not make. A
5
- new violation of a rule at `error` fails the run; what the module already had when it adopted is
6
- recorded and never fails it.
7
-
8
- ## Adopt a module in one step
9
-
10
- ```bash
11
- cd apps/front/host-admin
12
- sentinel --init --arch
13
- ```
14
-
15
- Nothing to choose. The repository's `sentinel.arch.json` says which decision governs this module,
16
- and `--init` writes:
17
-
18
- | File | What it holds |
19
- | -------------------- | ------------------------------------------------------------------------------------- |
20
- | `arch.config.json` | the rule set this module follows, and any rule the module turned to `warn` or `off` |
21
- | `arch.baseline.json` | the violations the module already has, one per line |
22
- | `package.json` | the `arch` script and its nx target (cached, invalidated by the rule set and the map) |
23
-
24
- If the map applies no decision to the module, `--init` says so and writes nothing.
25
-
26
- ## Everyday use
27
-
28
- ```bash
29
- sentinel --run --arch # fails on a new violation of a rule at error
30
- sentinel --run --arch --fix # also drops baseline entries that were fixed
31
- sentinel --run --arch --output json,markdown # also writes arch-report/arch.json and arch.md
32
- sentinel --inspect --arch # the rule set, and each rule's level here
33
- ```
34
-
35
- A run prints the files per role (a role with no file usually means a path with a typo in the
36
- rule set), then one line per rule, then each NEW violation with its file, what it reaches and the
37
- section of the decision that forbids it:
38
-
39
- ```
40
- architecture ADR 0050: the vertical feature slice is the unit of frontend architecture 5543 files
41
- ✗ G1 A view or route never calls a query client: fetching goes through a hook. 1 new, 4 known
42
- src/modules/contracts-settings/.../ContractTypesPage.tsx → @tanstack/react-query#useQuery
43
- why: RFC #19934, Governance readiness, G1
44
- ✓ G2a The api layer never imports a view, not even a type. 0 new, 3 known
45
- ```
46
-
47
- ## The baseline
48
-
49
- Each violation is recorded by what it is: the rule, the file that breaks it, what it reaches. Not
50
- a count, because a count lets one violation be fixed and another be added in the same change
51
- without anything moving.
52
-
53
- - A run never adds to it. Accepting a new violation is an edit of `arch.baseline.json`, in review.
54
- - `--run --fix` removes what was fixed, so the same violation cannot come back unseen.
55
- - A re-run of `--init` shrinks it and never grows it, with one exception: a rule the decision
56
- ADDED since the baseline was taken. The baseline records the rules it measured, so a new rule's
57
- violations show as `pending` (never failing) until `--init` adopts that rule with what it finds.
58
- - A file that cannot be parsed fails the run, and its entries are kept: an unread file proves
59
- nothing was fixed.
60
-
61
- ## Turning a rule down in one module
62
-
63
- ```json
64
- {
65
- "rules": "../../../docs/adr/0050-frontend-vertical-feature-slices.rules.json",
66
- "severity": { "G3": "warn" }
67
- }
68
- ```
69
-
70
- `warn` reports without failing, `off` skips the rule. A name that is not a rule of the set is
71
- refused, so a typo cannot leave a rule at `error` while you believe it is a warning.
72
-
73
- ## For the repository: the rules and the map
74
-
75
- The rules belong to the repository that took the decision, next to its ADR, so a decision and
76
- its check change in the same pull request and this package needs no release.
77
-
78
- A rule set (`docs/adr/0050-....rules.json`), in dependency-cruiser's vocabulary plus `roles`:
79
-
80
- ```json
81
- {
82
- "name": "ADR 0050: ...",
83
- "exclude": ["^(?!src/)", "\\.(test|spec|stories)\\.[cm]?[jt]sx?$"],
84
- "roles": [
85
- { "name": "route", "path": "^src/routes/" },
86
- { "name": "api", "path": ["(^|/)(services|queries|mutations)/"] },
87
- { "name": "view", "path": "\\.(tsx|svelte)$", "exports": "component" }
88
- ],
89
- "forbidden": [
90
- {
91
- "name": "G2a",
92
- "severity": "error",
93
- "comment": "The api layer never imports a view.",
94
- "from": { "role": "api" },
95
- "to": { "role": "view" }
96
- }
97
- ]
98
- }
99
- ```
100
-
101
- Roles are decided first match wins, by path (regular expressions relative to the module) and,
102
- for `exports: "component"`, by the file's default or same-named export. A file no role matches is
103
- `unclassified`: counted, never flagged. A role must have a `path` or `exports`.
104
-
105
- An import is followed to the file that DEFINES each imported name, through barrels
106
- (`export { x } from`, `export * from`), and that file's role is what a rule reads. Aliases come from
107
- the workspace's `tsconfig.base.json`, the module's own `tsconfig.json`, and SvelteKit's `$lib` and
108
- `kit.alias`. An alias that resolves to nothing is reported, not taken for a package.
109
-
110
- Which kind of rule a `to` makes:
111
-
112
- | `to` | Forbids |
113
- | ---------------------------------------------------------------- | ----------------------------------------------------------------------- |
114
- | `role` / `path` (`pathNot`, `dependencyTypesNot: ["type-only"]`) | importing a file of that side, inside the module or in a shared library |
115
- | `module` + `names` | importing those names from that package, as a value |
116
- | `calls` (+ `module`, a regular expression) | calling those globals, or importing a matching client as a value |
117
-
118
- The map (`sentinel.arch.json`, at the workspace root), first match wins:
119
-
120
- ```json
121
- {
122
- "decisions": [
123
- {
124
- "modules": ["apps/front/hr-management"],
125
- "rules": "docs/adr/0050-....rules.json",
126
- "severity": { "G3": "warn" }
127
- },
128
- { "modules": ["apps/front/*", "libs/front/*"], "rules": "docs/adr/0050-....rules.json" }
129
- ],
130
- "notices": [{ "modules": ["apps/nest/backends-for-frontends/planning"], "text": "..." }]
131
- }
132
- ```
133
-
134
- A decision's `severity` is written at a module's first adoption only; after that the level is the
135
- team's. Notices are said at adoption and change nothing.
136
-
137
- A rule set, a map or a module config with a defect is refused before anything runs.
138
-
139
- ## What the role will not do
140
-
141
- - Analyse a module whose files did not change: in CI, the modules analysed are those whose own
142
- files a pull request touches. A shared library that changes can create a violation in a module
143
- downstream that is not analysed then.
144
- - Read markup: a `.svelte` file is checked through its `<script>` blocks.
145
- - Decide a design question no file and import can answer (is this the right boundary for a
146
- feature). Those stay with the reviewers, as the decisions themselves say.