|
| 1 | +--- |
| 2 | +name: layer-audit |
| 3 | +description: 'Detect violations of the layered architecture import rules (base -> platform -> workbench -> renderer). Runs ESLint with the import-x/no-restricted-paths rule and generates a grouped report.' |
| 4 | +--- |
| 5 | + |
| 6 | +# Layer Architecture Audit |
| 7 | + |
| 8 | +Finds imports that violate the layered architecture boundary rules enforced by `import-x/no-restricted-paths` in `eslint.config.ts`. |
| 9 | + |
| 10 | +## Layer Hierarchy (bottom to top) |
| 11 | + |
| 12 | +``` |
| 13 | +renderer (top -- can import from all lower layers) |
| 14 | + ^ |
| 15 | +workbench |
| 16 | + ^ |
| 17 | +platform |
| 18 | + ^ |
| 19 | + base (bottom -- cannot import from any upper layer) |
| 20 | +``` |
| 21 | + |
| 22 | +Each layer may only import from layers below it. |
| 23 | + |
| 24 | +## How to Run |
| 25 | + |
| 26 | +```bash |
| 27 | +# Run ESLint filtering for just the layer boundary rule violations |
| 28 | +pnpm lint 2>&1 | grep 'import-x/no-restricted-paths' -B1 | head -200 |
| 29 | +``` |
| 30 | + |
| 31 | +To get a full structured report, run: |
| 32 | + |
| 33 | +```bash |
| 34 | +# Collect all violations from base/, platform/, workbench/ layers |
| 35 | +pnpm eslint src/base/ src/platform/ src/workbench/ --no-error-on-unmatched-pattern --rule '{"import-x/no-restricted-paths": "warn"}' --format compact 2>&1 | grep 'no-restricted-paths' | sort |
| 36 | +``` |
| 37 | + |
| 38 | +## How to Read Results |
| 39 | + |
| 40 | +Each violation line shows: |
| 41 | + |
| 42 | +- The **file** containing the bad import |
| 43 | +- The **import path** crossing the boundary |
| 44 | +- The **message** identifying which layer pair is violated |
| 45 | + |
| 46 | +### Grouping by Layer Pair |
| 47 | + |
| 48 | +After collecting violations, group them by the layer pair pattern: |
| 49 | + |
| 50 | +| Layer pair | Meaning | |
| 51 | +| --------------------- | ----------------------------------- | |
| 52 | +| base -> platform | base/ importing from platform/ | |
| 53 | +| base -> workbench | base/ importing from workbench/ | |
| 54 | +| base -> renderer | base/ importing from renderer/ | |
| 55 | +| platform -> workbench | platform/ importing from workbench/ | |
| 56 | +| platform -> renderer | platform/ importing from renderer/ | |
| 57 | +| workbench -> renderer | workbench/ importing from renderer/ | |
| 58 | + |
| 59 | +## When to Use |
| 60 | + |
| 61 | +- Before creating a PR that adds imports between `src/base/`, `src/platform/`, `src/workbench/`, or `src/renderer/` |
| 62 | +- When auditing the codebase to find and plan migration of existing violations |
| 63 | +- After moving files between layers to verify no new violations were introduced |
| 64 | + |
| 65 | +## Fixing Violations |
| 66 | + |
| 67 | +Common strategies to resolve a layer violation: |
| 68 | + |
| 69 | +1. **Move the import target down** -- if the imported module doesn't depend on upper-layer concepts, move it to a lower layer |
| 70 | +2. **Introduce an interface** -- define an interface/type in the lower layer and implement it in the upper layer via dependency injection or a registration pattern |
| 71 | +3. **Move the importing file up** -- if the file logically belongs in a higher layer, relocate it |
| 72 | +4. **Extract shared logic** -- pull the shared functionality into `base/` or a shared utility |
| 73 | + |
| 74 | +## Reference |
| 75 | + |
| 76 | +| Resource | Path | |
| 77 | +| ------------------------------- | ------------------ | |
| 78 | +| ESLint config (rule definition) | `eslint.config.ts` | |
| 79 | +| Base layer | `src/base/` | |
| 80 | +| Platform layer | `src/platform/` | |
| 81 | +| Workbench layer | `src/workbench/` | |
| 82 | +| Renderer layer | `src/renderer/` | |
0 commit comments