@starci/eslint-canon-be 2.0.1 → 2.1.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.
Files changed (73) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +1 -1
  3. package/data-access.mjs +1 -1
  4. package/index.mjs +2 -0
  5. package/lib/unit-spec.mjs +3 -3
  6. package/package.json +1 -1
  7. package/project-graph.mjs +23 -0
  8. package/runtime/knowledge/patterns/fe/folder.yaml +309 -0
  9. package/runtime/scripts/checks/architecture/backend.mjs +350 -0
  10. package/runtime/scripts/checks/architecture/background-unowned.mjs +107 -0
  11. package/runtime/scripts/checks/architecture/client-reaches-server.mjs +94 -0
  12. package/runtime/scripts/checks/architecture/clones.mjs +200 -0
  13. package/runtime/scripts/checks/architecture/config-unread.mjs +35 -0
  14. package/runtime/scripts/checks/architecture/config.mjs +310 -0
  15. package/runtime/scripts/checks/architecture/connection-map.mjs +208 -0
  16. package/runtime/scripts/checks/architecture/constructor-deps.mjs +100 -0
  17. package/runtime/scripts/checks/architecture/contract-fixture-guard.mjs +128 -0
  18. package/runtime/scripts/checks/architecture/contracts.mjs +792 -0
  19. package/runtime/scripts/checks/architecture/cross-app-duplicate.mjs +73 -0
  20. package/runtime/scripts/checks/architecture/dead-exports.mjs +265 -0
  21. package/runtime/scripts/checks/architecture/default-deny.mjs +129 -0
  22. package/runtime/scripts/checks/architecture/doc-language.mjs +39 -0
  23. package/runtime/scripts/checks/architecture/entrypoint.mjs +57 -0
  24. package/runtime/scripts/checks/architecture/error-codes.mjs +45 -0
  25. package/runtime/scripts/checks/architecture/error-masked.mjs +60 -0
  26. package/runtime/scripts/checks/architecture/fe-slot-allows.mjs +38 -0
  27. package/runtime/scripts/checks/architecture/feature-shape.mjs +49 -0
  28. package/runtime/scripts/checks/architecture/framework-pinned.mjs +83 -0
  29. package/runtime/scripts/checks/architecture/frontend.mjs +995 -0
  30. package/runtime/scripts/checks/architecture/hfs-graph.mjs +61 -0
  31. package/runtime/scripts/checks/architecture/hfs.mjs +521 -0
  32. package/runtime/scripts/checks/architecture/hooks-are-hooks.mjs +88 -0
  33. package/runtime/scripts/checks/architecture/i18n-keys.mjs +146 -0
  34. package/runtime/scripts/checks/architecture/index.mjs +321 -0
  35. package/runtime/scripts/checks/architecture/injection-token-exported.mjs +62 -0
  36. package/runtime/scripts/checks/architecture/machine-ast.mjs +138 -0
  37. package/runtime/scripts/checks/architecture/module-per-transport.mjs +130 -0
  38. package/runtime/scripts/checks/architecture/next-data.mjs +775 -0
  39. package/runtime/scripts/checks/architecture/owners.mjs +95 -0
  40. package/runtime/scripts/checks/architecture/package-shape.mjs +63 -0
  41. package/runtime/scripts/checks/architecture/reachability.mjs +233 -0
  42. package/runtime/scripts/checks/architecture/register-once.mjs +141 -0
  43. package/runtime/scripts/checks/architecture/registration.mjs +319 -0
  44. package/runtime/scripts/checks/architecture/required-files.mjs +172 -0
  45. package/runtime/scripts/checks/architecture/route-files-thin.mjs +97 -0
  46. package/runtime/scripts/checks/architecture/schema-owner.mjs +261 -0
  47. package/runtime/scripts/checks/architecture/source-names.mjs +607 -0
  48. package/runtime/scripts/checks/architecture/sql-owner.mjs +142 -0
  49. package/runtime/scripts/checks/architecture/sql-tokens.mjs +327 -0
  50. package/runtime/scripts/checks/architecture/surface.mjs +91 -0
  51. package/runtime/scripts/checks/architecture/symbols.mjs +193 -0
  52. package/runtime/scripts/checks/architecture/test-world-files.mjs +163 -0
  53. package/runtime/scripts/checks/architecture/tiers.mjs +130 -0
  54. package/runtime/scripts/checks/architecture/transport-owner.mjs +112 -0
  55. package/runtime/scripts/checks/architecture/typescript.mjs +573 -0
  56. package/runtime/scripts/checks/architecture/unit-spec-providers.mjs +122 -0
  57. package/runtime/scripts/checks/common.mjs +44 -0
  58. package/runtime/scripts/checks/typescript-programs.mjs +82 -0
  59. package/runtime/scripts/lib/hfs-path-findings.mjs +84 -0
  60. package/runtime/scripts/lib/hfs-rules/fe-no-tests.mjs +47 -0
  61. package/runtime/scripts/lib/hfs-rules/read.mjs +28 -0
  62. package/runtime/scripts/lib/hfs-rules/secrets.mjs +54 -0
  63. package/runtime/scripts/lib/hfs-rules/spec-placement.mjs +29 -0
  64. package/runtime/scripts/lib/json.mjs +22 -0
  65. package/runtime/scripts/lib/project-graph.mjs +0 -0
  66. package/runtime/scripts/lib/project-rule.mjs +39 -0
  67. package/runtime/scripts/lib/repo-identity.mjs +50 -0
  68. package/runtime/scripts/lib/secret-patterns.mjs +44 -0
  69. package/runtime/scripts/lib/stack-services.mjs +217 -0
  70. package/runtime/scripts/lib/test-secrets.mjs +120 -0
  71. package/test-world.mjs +2 -3
  72. package/testing.mjs +1 -1
  73. package/unit-spec.mjs +43 -6
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.1.0 - 2026-10-01
4
+
5
+ - New: the `project-graph` law: the TS-attached architecture checks (tiers, owners, dead exports, composition, data, paths) as eslint rules at error on the offending line, from one cached project graph per lint run.
6
+ - New: `spec-exact-values` (R48): `expect.any(String|Number|Date)` in a `*.service.spec.ts` is refused; ids come from `fakeIds()` and dates from `FakeClock` and are asserted exactly.
7
+
8
+ - Changed: Back-end apps have no composition spec, including the migrate app. `unit-test-colocated` has no app exception; only service unit specs and the integration, e2e and contract layers remain.
9
+
3
10
  ## 2.0.1 - 2026-10-01
4
11
 
5
12
  - Fixed: `e2e-asserts-persisted-state` accepts `<world>.db.<connection>` and `<world>.services.<name>.api` state reads, the world identified by its `TestWorld` type (from `@starci/test-world` or the `be.tests.world` slot), not by a variable name.
@@ -8,6 +15,7 @@
8
15
 
9
16
  - Changed (lane PORT): `ruleParams.be.infraOwners` names `@nestjs/cache-manager` (the `CACHE_MANAGER` token) beside `cache-manager`: it is reached only by `integrations/cache` and `integrations/redis`, which is the retired repository rule `must-use-cache-service`; `infra-import-owner` (R90) covers it with a passing and a violating case.
10
17
  - Changed (lane UT): `inbox-dedupe-required` (R80) moves from the door to the service. It judges the public methods of a `*.service.ts` whose first parameter TYPE has an `eventId` property: the first awaited expression must be `claim(source, eventId, ...)` on the `Inbox` port, with an early return on `false`. Consumers and `SignedWebhook` controllers are no longer judged by it, and `transport-is-thin` no longer allows an `Inbox` injection or an inbox guard in a door.
18
+ - New `spec-exact-values` (R48, unit-spec law): a `*.service.spec.ts` never asserts `expect.any(String)`, `expect.any(Number)` or `expect.any(Date)` (`expect` resolved as the jest global or the `@jest/globals` import); ids come from `fakeIds()` and dates from `FakeClock`, so the spec asserts the exact value.
11
19
  - Changed: `transport-is-thin` allows `unwrapOutcome` of `platform/primitives` (resolved by its symbol) beside the bus call and pure mapper functions.
12
20
  - Fixed: `infra-needs-injector` (R85) no longer judges the constructor of a CQRS message (`extends Command<R>` / `Query<R>` of `@nestjs/cqrs`): its `params` is data built with `new`.
13
21
  - Changed (lane UT, unit-test standard 2026-09-30): `unit-test-colocated` (R47) no longer keeps twin specs for handlers, guards, mappers, policies, clients and row mappers. Only a service is unit-tested: a `<name>.service.ts` has its `<name>.service.spec.ts` beside it (message `missing`), a unit spec (a `*.spec.ts` outside `src/tests/{e2e,integration,contract,world}` and `apps/migrate`) must be a `<name>.service.spec.ts` beside its service (`notService`, `orphan`), and a composition spec is no longer a unit kind.
package/README.md CHANGED
@@ -49,7 +49,7 @@ A sample, not the list:
49
49
  | **Log safety** | A call on the `Logger` port (found by the receiver's type) passes no `Secret` or `Pii` value and no value named like a credential or a personal identifier (`no-secret-in-log`) |
50
50
  | **Async and types** | An `async` function awaits; handlers and public methods declare a return type; no `Function` type, no `eval`; an inline object type takes a name; no `const enum`. Casts, `x!` and `any` are refused in every file, specs included, by the typescript-eslint rules the factory turns on (`async-needs-await`, `explicit-handler-return-type`, `no-function-or-eval`, `no-inline-param-type`, `no-inline-object-type`, `no-const-enum`) |
51
51
  | **Migrations and input** | A migration's `down()` reverses its `up()`; every property of an input class has the `class-validator` decorators its type calls for (string `@MaxLength`, enum `@IsEnum`, array `@ArrayMaxSize`, nested `@ValidateNested()` and `@Type`); reads page by cursor, never by `skip`, `offset` or `OFFSET` (`migration-down-reversible`, `input-bounded`, `no-offset-pagination`) |
52
- | **Spec quality** | A spec does not read repository source with `fs` (`spec-no-source-read`); the borrowed `consistent-type-assertions` (`never`) and `no-non-null-assertion` leave no `as` and no `x!` in a spec, and `no-ambient-clock` and `no-direct-env-read` cover specs, so no `Date.now()`, argless `new Date()` or `process.env`. A unit spec is `<name>.service.spec.ts`: it builds its subject with `Test.createTestingModule({ providers })` from `@nestjs/testing`, `.compile()` and `moduleRef.get(...)` (`spec-builds-with-testing-module`), never `new` on the service (`spec-no-new-subject`), no `imports` key and no `override*` (`spec-module-definition-only-providers`), no `jest.mock`/`doMock`/`unstable_mockModule`/`requireMock` of an own module or a library (`spec-no-module-mock`), no cast-laundering helper in a spec or fixture: a return-only generic, an `unknown` handed back as another type, `JSON.parse(JSON.stringify(x))`, `Object.assign(new X(), y)` returned as another type (`no-return-only-generic`); a provider `{ provide: TOKEN, useValue: X }` takes X from the matching `@starci/jest-preset` double, the token table being `ruleParams.be.specDoubles` of the slot manifest (`spec-infra-double-from-kit`); the EntityManager double is the kit's `mockEntityManager()`/`fakeTransaction()`, never ad hoc (`spec-typed-entity-manager`); test data goes through builders, see the **Test data builders** row |
52
+ | **Spec quality** | A spec does not read repository source with `fs` (`spec-no-source-read`); the borrowed `consistent-type-assertions` (`never`) and `no-non-null-assertion` leave no `as` and no `x!` in a spec, and `no-ambient-clock` and `no-direct-env-read` cover specs, so no `Date.now()`, argless `new Date()` or `process.env`. A unit spec is `<name>.service.spec.ts`: it builds its subject with `Test.createTestingModule({ providers })` from `@nestjs/testing`, `.compile()` and `moduleRef.get(...)` (`spec-builds-with-testing-module`), never `new` on the service (`spec-no-new-subject`), no `imports` key and no `override*` (`spec-module-definition-only-providers`), no `jest.mock`/`doMock`/`unstable_mockModule`/`requireMock` of an own module or a library (`spec-no-module-mock`), no cast-laundering helper in a spec or fixture: a return-only generic, an `unknown` handed back as another type, `JSON.parse(JSON.stringify(x))`, `Object.assign(new X(), y)` returned as another type (`no-return-only-generic`); a provider `{ provide: TOKEN, useValue: X }` takes X from the matching `@starci/jest-preset` double, the token table being `ruleParams.be.specDoubles` of the slot manifest (`spec-infra-double-from-kit`); a unit spec asserts exact values, never `expect.any(String)`, `expect.any(Number)` or `expect.any(Date)` (`expect` being the jest global or the `@jest/globals` import): ids come from `fakeIds()` and dates from `FakeClock` (`spec-exact-values`); the EntityManager double is the kit's `mockEntityManager()`/`fakeTransaction()`, never ad hoc (`spec-typed-entity-manager`); test data goes through builders, see the **Test data builders** row |
53
53
  | **Test data builders** (R98 to R101) | Builders live only in `src/tests/fixtures/builders/<area>.builder.ts`: a module of the test tree that exports a function creating persisted rows through an EntityManager, DataSource or QueryRunner is a builder wherever it sits (`persisting-builder-in-builders-slot`, R98); a spec never runs a raw INSERT/UPDATE/DELETE or a direct write (`save`, `insert`, `upsert`, `update`, `delete`, `remove`) on a typeorm receiver and never builds the same `@Entity` class as an object literal twice (`spec-no-raw-insert`, `spec-no-repeated-row-literal`, R99); a builder never asserts and has deterministic defaults (`builder-arranges-only`, R101); nothing under `src/tests` disables or drops a constraint (`tests-keep-constraints`, R100) |
54
54
  | **CQRS** | A message extends `Command<R>` / `Query<R>` from `@nestjs/cqrs`, carries one `readonly params: ExecuteParams<X>` (no entity reachable from `X`), a handler extends `ICQRSHandler` and overrides `process`; a handler is thin: it injects only `*Service` classes and the Logger, and `process` is one `return this.<service>.<method>(...)` with no branch, loop, EntityManager or second call (`handler-is-thin`); no `*.use-case.ts`, no forwarder service, no `EventBus` or `@nestjs/event-emitter` (`handler-overrides-process`, `message-carries-params-only`, `message-typed-result`, `execute-params-shape`, `no-use-case`, `no-event-bus`) |
55
55
  | **Module layering** | Another owner is imported through its public `index.ts` (`@modules/domain/plan`, `@features/plan`), never through a path into it, and a same-owner import is relative and never through the own index (`import-owner-entry`); an owner has one `index.ts` (a nested one is refused) that holds only named `export { }` lines, with no `export *`, and a bounded number of names (`no-folder-reexport`); self-aliases and relative escapes are refused (`no-self-module-alias`, `no-relative-capability-escape`). Owners come from the HFS slots, aliases from the program's `compilerOptions.paths`. |
package/data-access.mjs CHANGED
@@ -69,7 +69,7 @@ export const namedEntityManagerOnly = {
69
69
  schema: [],
70
70
  messages: {
71
71
  property:
72
- "`{{type}}` is injected as a class property. Property injection hides the dependency from the constructor and from the composition spec. Receive the named-injector `EntityManager` as a constructor parameter.",
72
+ "`{{type}}` is injected as a class property. Property injection hides the dependency from the constructor and the app module. Receive the named-injector `EntityManager` as a constructor parameter.",
73
73
  infra:
74
74
  "`{{type}}` is injected here. A `DataSource` or `QueryRunner` is built and held only by the platform database capability, the migrate app and the test world in `src/tests/world`; specs take `world.db.<connection>`; everything else injects the shared `EntityManager` through its named injector and calls it directly.",
75
75
  getRepository:
package/index.mjs CHANGED
@@ -52,9 +52,11 @@ import { recommended as transportRecommended, rules as transportRules } from "./
52
52
  import { recommended as typeSafetyRecommended, rules as typeSafetyRules } from "./type-safety.mjs"
53
53
  import { recommended as unitSpecRecommended, rules as unitSpecRules } from "./unit-spec.mjs"
54
54
  import { recommended as userCopyRecommended, rules as userCopyRules } from "./user-copy.mjs"
55
+ import { recommended as projectGraphRecommended, rules as projectGraphRules } from "./project-graph.mjs"
55
56
 
56
57
  /** Each law's contribution, kept separate so a duplicate name is detectable rather than silent. */
57
58
  const CONTRIBUTIONS = [
59
+ { law: "project-graph", rules: projectGraphRules, recommended: projectGraphRecommended },
58
60
  { law: "async-discipline", rules: asyncDisciplineRules, recommended: asyncDisciplineRecommended },
59
61
  { law: "authorization", rules: authorizationRules, recommended: authorizationRecommended },
60
62
  { law: "builders", rules: buildersRules, recommended: buildersRecommended },
package/lib/unit-spec.mjs CHANGED
@@ -2,13 +2,13 @@
2
2
  * What is a unit spec, decided by the slot manifest and the file's role suffix, never by a path pattern.
3
3
  *
4
4
  * A unit spec is a `*.spec.ts` outside the folders that own the other test kinds (`src/tests/{e2e,integration,contract,world}`)
5
- * and outside `apps/migrate` (the migrate app's own specs). Only a `<name>.service.spec.ts` beside `<name>.service.ts` is a
5
+ * only. Only a `<name>.service.spec.ts` beside `<name>.service.ts` is a
6
6
  * legitimate unit spec (R47); the quality rules of R48 judge exactly those.
7
7
  */
8
8
  import { basename } from "node:path"
9
9
 
10
- /** The slots whose `*.spec.ts` files are not unit specs: the other test kinds and the migrate app. */
11
- const OTHER_KIND_SLOTS = new Set(["be.tests.e2e", "be.tests.integration", "be.tests.contract", "be.tests.world", "be.tests.world.kit", "be.app.migrate"])
10
+ /** The slots whose `*.spec.ts` files are not unit specs: the other test kinds and world infrastructure. */
11
+ const OTHER_KIND_SLOTS = new Set(["be.tests.e2e", "be.tests.integration", "be.tests.contract", "be.tests.world", "be.tests.world.kit"])
12
12
 
13
13
  /** The file name of a linted path. */
14
14
  export const baseOf = (filename) => basename(String(filename || "").replace(/\\/g, "/"))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@starci/eslint-canon-be",
3
- "version": "2.0.1",
3
+ "version": "2.1.0",
4
4
  "description": "The StarCi back-end lint canon: every rule its laws publish, gathered as one flat-config plugin.",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",
@@ -0,0 +1,23 @@
1
+ /**
2
+ * The rules that read the project graph: the findings of the architecture machine that sit on a TypeScript file.
3
+ *
4
+ * One graph per lint run: `scripts/lib/project-graph.mjs` (a byte copy in this package's runtime/) builds the machine's module
5
+ * graph and slot manifest once for the repository, caches it, and each rule below reports the findings of its own codes on
6
+ * the file ESLint is visiting, on the line the machine names. There is no second graph and no second judge: the list of
7
+ * rules and their codes is `LINT_ENFORCERS` of the machine (scripts/checks/architecture/surface.mjs); `hfs check` keeps the
8
+ * findings that have no TypeScript file to sit on. A graph that cannot be built stops the run with the machine's message.
9
+ */
10
+ import { LINT_ENFORCERS } from "./runtime/scripts/checks/architecture/surface.mjs"
11
+ import { projectRule } from "./runtime/scripts/lib/project-rule.mjs"
12
+ import { hfsOf } from "./lib/hfs.mjs"
13
+ import { dirname, join } from "node:path"
14
+ import { fileURLToPath } from "node:url"
15
+
16
+ const RUNTIME = join(dirname(fileURLToPath(import.meta.url)), "runtime")
17
+ const mine = LINT_ENFORCERS.filter((enforcer) => enforcer.plugins.includes("be"))
18
+
19
+ /** The rules this law contributes to the plugin: one per graph enforcer of this profile. */
20
+ export const rules = Object.fromEntries(mine.map((e) => [e.id, projectRule({ enforcer: e, runtimeRoot: RUNTIME, hfsOf })]))
21
+
22
+ /** Every one at error. */
23
+ export const recommended = Object.fromEntries(mine.map((e) => [`starci-be/${e.id}`, "error"]))
@@ -0,0 +1,309 @@
1
+ schema: starci/knowledge-source@1
2
+ id: fe.folder
3
+ title: Folder
4
+ purpose: |
5
+ Given a piece of frontend code, which directory and which file name does it get? Apply the HFS frontend tree
6
+ (knowledge/hfs/README.md section 6, slots fe.*).
7
+ appliesTo:
8
+ - frontend
9
+ family: fe
10
+ provenance:
11
+ reviewedAt: 2026-09-29
12
+ sources:
13
+ - knowledge/hfs/README.md
14
+ - knowledge/hfs/slots.yaml
15
+ - https://nextjs.org/docs/app/getting-started/project-structure
16
+ - https://next-intl.dev/docs/routing
17
+ - packages/grammar/src/**
18
+ limitations: |
19
+ Folder rules place code by responsibility. They do not prove rendered behavior or accessibility. Inspect the
20
+ selected repository's actual source, manifests, aliases and lint and test configuration. Verify installed Grammar
21
+ exports at @starci/grammar/common.
22
+ rules:
23
+ - id: FE-FOLDER-1
24
+ title: Responsibility directories
25
+ kind: mandatory
26
+ hfsRules: [R01, R02, R59, R64]
27
+ requirement: |
28
+ Every frontend repository is an apps/<app>/ monorepo even with one app, named by its role (for example web), and
29
+ all product source lives under apps/<app>/src. A repository-root src/ does not exist. Each Next source root
30
+ (apps/<app>/src) uses app/ for framework adapters; features/{pages,layouts,overlays} for route-facing product
31
+ composition; components/{blocks,composites,branches,leaves} for product visuals; hooks/<domain> for React hooks;
32
+ and modules/<capability> for cohesive reusable technical and domain capabilities. Every app has the modules api,
33
+ config, i18n and routes, and one brand.css under modules/brand when it sets brand tokens. No other empty role
34
+ folder is required. Grammar remains a separate product-agnostic package. The only files that may sit directly in the
35
+ source root (the directory holding app/) are the framework-pinned root files listed in frameworkPinnedRootFiles
36
+ below: Next.js loads them from that exact place. Each is a thin framework adapter whose internal imports enter
37
+ modules or a feature public entry only; every other rule still applies to it, except that the export names the
38
+ framework mandates there (frameworkPinnedRootExports) keep their framework spelling. HFS uses proxy.ts for locale
39
+ routing; a middleware.* file is refused on Next 16 and later by the Next conventions check and the slot
40
+ fe.source-root-pinned, even though the machine list names it as a file Next loads. Any other file at the source
41
+ root, including a helper folder beside a pinned file, has no owner and is refused.
42
+ frameworkPinnedRootFiles:
43
+ # Machine list read by scripts/checks/architecture/framework-pinned.mjs (FE_SOURCE_LAYOUT_INVALID accepts exactly
44
+ # these basenames directly in a Next source root; FE_TIER_DIRECTION keeps them thin). Exact names,
45
+ # case-sensitive, no globs. It lists what the framework loads from the source root. Which of them a repository may
46
+ # keep is decided by the slot fe.source-root-pinned and FE_NEXT_CONVENTIONS, not by this list.
47
+ # Machine list read by scripts/checks/architecture/framework-pinned.mjs (FE_SOURCE_LAYOUT_INVALID
48
+ # accepts exactly these basenames directly in a Next source root;
49
+ # their imports follow the FE_TIER_DIRECTION matrix). Exact names, case-sensitive, no globs. Supervisor rulings for nivo
50
+ # wf-nivo-fe-debt-mug06w7h inc-2e42a24b74e4 and inc-846867b9a34e (proxy is the Next 16 name of
51
+ # middleware, listed so the list survives the upgrade).
52
+ - middleware.ts
53
+ - middleware.js
54
+ - middleware.mjs
55
+ - proxy.ts
56
+ - proxy.js
57
+ - proxy.mjs
58
+ - instrumentation.ts
59
+ - instrumentation.js
60
+ - instrumentation.mjs
61
+ - instrumentation-client.ts
62
+ - instrumentation-client.js
63
+ - instrumentation-client.mjs
64
+ - next-env.d.ts
65
+ frameworkPinnedRootExports:
66
+ # Export names the framework mandates in a pinned root file, keyed by file stem (read by
67
+ # scripts/checks/architecture/framework-pinned.mjs). FE_SOURCE_NAME_SHAPE accepts exactly these names in exactly
68
+ # these files when they sit directly in a Next source root; everywhere else the name-shape rule is unchanged.
69
+ middleware: [config, middleware, default]
70
+ proxy: [config, proxy, default]
71
+ instrumentation: [register, onRequestError]
72
+ instrumentation-client: [onRouterTransitionStart]
73
+ rationale: |
74
+ One fixed source root per app keeps every repository the same shape while preventing app helpers, component-local
75
+ hooks and feature-local transport buckets from becoming undeclared owners.
76
+ cases:
77
+ - id: case-1
78
+ when: "A routed authentication scenario"
79
+ write: "apps/<app>/src/features/pages/AuthenticationPage/index.tsx"
80
+ - id: case-2
81
+ when: "A reusable API client, reader or session capability"
82
+ write: >
83
+ apps/<app>/src/modules/api/ or apps/<app>/src/modules/session/ with one explicit public index.ts entry
84
+ - id: case-3
85
+ when: "A reusable product visual without scenario ownership"
86
+ write: "apps/<app>/src/components/{blocks,composites,branches,leaves}/<Name>/index.tsx"
87
+ - id: case-4
88
+ when: "A React hook"
89
+ write: "apps/<app>/src/hooks/<domain>/useAutoScroll.ts; built-in React hook calls may remain in visuals"
90
+ - id: case-5
91
+ kind: exception
92
+ when: "Next.js only loads the file from the source root (proxy, instrumentation, instrumentation-client, next-env.d.ts)"
93
+ write: >
94
+ apps/<app>/src/proxy.ts beside apps/<app>/src/app/ as a thin adapter; locale routing logic lives in
95
+ apps/<app>/src/modules/i18n/ and the adapter imports it; the names the framework mandates there
96
+ (frameworkPinnedRootExports, for example export const config = { matcher }) keep their framework spelling
97
+ - id: case-6
98
+ when: "Any other file or folder directly under the source root (apps/<app>/src/i18n/request.ts, apps/<app>/src/config.ts), and a repository-root src/"
99
+ write: >
100
+ Move it to its owner, for example apps/<app>/src/modules/i18n/request.ts, and point framework configuration
101
+ (apps/<app>/next.config.ts) at the new path
102
+ - id: case-7
103
+ when: "The per-slot data-status recipe"
104
+ write: >
105
+ apps/<app>/src/components/composites/SlotView/index.tsx, apps/<app>/src/modules/slot/index.ts (Slot, toSlot,
106
+ SlotLabels) and apps/<app>/src/hooks/slot/useSlotLabels.ts, one copy each (examples/shape-slot)
107
+ verification:
108
+ automated:
109
+ - HFS_SLOT_UNDECLARED
110
+ - HFS_SLOT_REQUIRED_MISSING
111
+ - FE_SOURCE_LAYOUT_INVALID
112
+ - FE_NEXT_CONVENTIONS
113
+ - FE_TIER_DIRECTION
114
+ - FE_CUSTOM_HOOK_LOCATION
115
+ - HFS_APPS_REQUIRED
116
+ - HFS_ROOT_SRC_FORBIDDEN_FE
117
+ manual:
118
+ - Confirm the unit's responsibility and public entry, rather than assigning it by consumer count.
119
+ relatedExamples:
120
+ - connected-block
121
+
122
+ - id: FE-FOLDER-2
123
+ title: Discoverable files for one unit
124
+ kind: mandatory
125
+ hfsRules: [R02, R55, R65]
126
+ requirement: |
127
+ A split unit (a connected block, and a feature page, layout or overlay) uses index.tsx for the connected X and
128
+ sibling component.tsx for the pure XBase, its XBaseProps and xDefaultState, plus XState when the shape is its own union
129
+ (a shape that is a domain status is typed with that status, never a second name for it). Only that index.tsx and the
130
+ unit's specs import component.tsx. Pure blocks, composites, branches and leaves use index.tsx only and never gain an
131
+ empty twin. classNames.ts is present only when the unit owns class strings. Budgets: component.tsx 300 lines,
132
+ connected index.tsx 200 lines, at most 6 data hooks and 6 useState per connected unit.
133
+ rationale: |
134
+ Stable basenames make class, tests and the connected and presentational split discoverable without forwarding
135
+ twins, and budgets keep a unit reviewable.
136
+ cases:
137
+ - id: case-1
138
+ when: "Connected block with product-world lifecycle"
139
+ write: "blocks/CatalogBlock/{index.tsx,component.tsx}; every nonempty index render reaches the sibling"
140
+ - id: case-2
141
+ when: "Feature page, layout or overlay"
142
+ write: >
143
+ features/pages/OperatePage/{index.tsx,component.tsx,classNames.ts}, features/layouts/WorkspaceLayout/…,
144
+ features/overlays/SendHandoffOverlay/… (examples/shape-slot)
145
+ - id: case-3
146
+ when: "Single visual unit"
147
+ write: "leaves/ButtonStateSample/{classNames.ts,index.tsx}; no component.tsx twin without a separate world owner"
148
+ - id: case-4
149
+ when: "Custom hook or reusable module"
150
+ write: "hooks/<domain>/useX.ts or modules/<capability>/...; do not create visual twins"
151
+ verification:
152
+ automated:
153
+ - class-names-in-colocated-file
154
+ - no-inline-class-name
155
+ - FE_CONNECTED_BLOCK_RENDER_PAIR
156
+ - FE_SIZE_AND_STATE_BUDGET
157
+ - HFS_SIZE_GROWTH
158
+ - starci-fe/base-import-pair
159
+ manual:
160
+ - Confirm each file owns a real responsibility; do not add a component.tsx twin by habit.
161
+ relatedExamples:
162
+ - connected-block
163
+
164
+ - id: FE-FOLDER-3
165
+ title: Route files adapt to one visual owner and every app has its boundaries
166
+ kind: mandatory
167
+ hfsRules: [R53, R54, R55, R57]
168
+ requirement: |
169
+ Route files under app/[locale]/ (page, layout, template, loading, not-found) are server components. A route may
170
+ resolve framework server inputs (params, searchParams, headers, cookies), then mounts one page-level visual owner.
171
+ A route whose complete responsibility is redirect or notFound mounts none. A route file holds no inline component, no
172
+ drawing decision and no hook, and a redirect from an old URL lives in next.config redirects(), never in a page. Every app has
173
+ app/global-error.tsx, app/[locale]/layout.tsx, app/[locale]/error.tsx and app/[locale]/not-found.tsx, and a loading.tsx
174
+ for each route group that reads data. Each page exports generateMetadata. force-dynamic on a client page is forbidden.
175
+ rationale: |
176
+ Keeping default exports in the App Router layer prevents components from becoming route-coupled, and mandatory
177
+ boundaries turn a render failure into a recoverable screen instead of a blank page.
178
+ cases:
179
+ - id: case-1
180
+ when: "A route"
181
+ write: >
182
+ app/[locale]/authentication/page.tsx: const AuthenticationRoute = async () => <AuthenticationPage />, then export
183
+ default AuthenticationRoute
184
+ - id: case-2
185
+ kind: exception
186
+ when: "Redirect or notFound adapter"
187
+ write: "Resolve framework inputs and redirect or terminate without a visual owner."
188
+ - id: case-3
189
+ when: "Global app files"
190
+ write: >
191
+ app/globals.css, app/global-error.tsx, app/[locale]/error.tsx, app/[locale]/not-found.tsx, app/sitemap.ts,
192
+ app/robots.ts, app/health/{live,ready}/route.ts
193
+ verification:
194
+ automated:
195
+ - FE_ERROR_BOUNDARY_MISSING
196
+ - FE_ROUTE_FILES_THIN
197
+ - FE_CLIENT_BOUNDARY
198
+ - FE_OWNER_REACHABLE
199
+ - FE_TIER_DIRECTION
200
+ manual:
201
+ - Confirm visual routes have one page owner and redirect-only routes have no visual tree.
202
+ relatedExamples: []
203
+
204
+ - id: FE-FOLDER-4
205
+ title: Hooks are hooks; readers and transport live in modules
206
+ kind: mandatory
207
+ hfsRules: [R56, R50, R49]
208
+ requirement: |
209
+ hooks/<domain>/ holds React hooks (use*.ts, one hook per file) and exactly one <domain>.shared.ts for shared
210
+ non-hook helpers of that domain (key builders, token readers). A file in hooks/ that is not a hook and is not the shared
211
+ file is a finding. Server-side readers (fetch and map, no React) live in modules/api/<domain>/read-*.ts and are
212
+ wrapped in React cache() when several blocks call them in one request. Generic client plumbing, the Outcome type,
213
+ the contract copy and generated wire types live in modules/api; environment reading lives in modules/config; every
214
+ href builder lives in modules/routes; locale routing lives in modules/i18n; colour values live in modules/brand.
215
+ A helper name defined twice across hook files is a finding.
216
+ rationale: |
217
+ A rule that says what a hooks folder is also says where everything else goes, so nobody copies a helper sixteen
218
+ times or fills hooks/ with server fetch functions.
219
+ cases:
220
+ - id: case-1
221
+ when: "Authentication request lifecycle"
222
+ write: "apps/<app>/src/hooks/authentication/useAuthentication.ts"
223
+ - id: case-2
224
+ when: "A helper shared by the hooks of one domain"
225
+ write: "apps/<app>/src/hooks/sales/sales.shared.ts, for example useSalesAccessToken's token reader"
226
+ - id: case-3
227
+ when: "A server read used by several blocks"
228
+ write: "apps/<app>/src/modules/api/sales/read-sales-summary.ts, exported through modules/api/index.ts"
229
+ - id: case-4
230
+ when: "The API client"
231
+ write: "apps/<app>/src/modules/api/client.ts and apps/<app>/src/modules/api/outcome.ts"
232
+ - id: case-5
233
+ when: "Intrinsic custom helper"
234
+ write: "apps/<app>/src/hooks/ui/useAutoScroll.ts; direct useRef and useState calls may remain in their visual owner"
235
+ verification:
236
+ automated:
237
+ - FE_HOOKS_ARE_HOOKS
238
+ - FE_CUSTOM_HOOK_LOCATION
239
+ - HFS_DUPLICATE_CODE
240
+ - FE_TIER_DIRECTION
241
+ manual:
242
+ - Confirm each lifecycle has one feature owner and transport mechanics have one module owner.
243
+ relatedExamples:
244
+ - connected-block
245
+
246
+ - id: FE-FOLDER-5
247
+ title: Package unit
248
+ kind: mandatory
249
+ hfsRules: [R63]
250
+ requirement: |
251
+ A shared package is packages/<pkg>/ with package.json (explicit exports), src/index.ts, tsconfig.json and colocated
252
+ specs, built to dist. Grammar components live under packages/grammar/src/core/<tier>/<Name>/ with collocated class
253
+ strings and specs; family entries and built-output proof stay at the package roots. See packages.yaml for the shared
254
+ UI package shape.
255
+ rationale: |
256
+ Package layout separates primitives from app composition and keeps public entry verification against dist.
257
+ cases:
258
+ - id: case-1
259
+ when: "A Grammar component"
260
+ write: "packages/grammar/src/core/<primitive|composite|branch|composition>/<Name>/index.tsx"
261
+ - id: case-2
262
+ when: "A Grammar component's class strings and spec"
263
+ write: "sibling classNames.ts and index.spec.tsx"
264
+ - id: case-3
265
+ when: "Built-output proof"
266
+ write: "common/index.test.mjs, core/index.test.mjs, package-boundary.test.mjs (node:test against dist/)"
267
+ verification:
268
+ automated:
269
+ - FE_PACKAGE_SHAPE
270
+ manual:
271
+ - Verify public app imports use @starci/grammar/common and installed exports, never the package root.
272
+ relatedExamples: []
273
+
274
+ - id: FE-FOLDER-6
275
+ title: Keep units cohesive
276
+ kind: mandatory
277
+ hfsRules: [R49, R21]
278
+ requirement: |
279
+ A unit folder contains files that change for the same responsibility. Do not create generic helpers/ or utils/
280
+ buckets inside components, read deployment configuration in presentation, or split files solely to meet a count.
281
+ Collocated subordinate renders and pure helpers are valid when they remain private to the owner; a separately stable
282
+ responsibility receives its own named owner.
283
+ rationale: |
284
+ Cohesion prevents helper sprawl and duplicated configuration while avoiding one-component-per-folder ceremony that
285
+ has no dependency boundary.
286
+ cases:
287
+ - id: case-1
288
+ when: "A small subordinate render is private to one owner"
289
+ write: "Keep it local with an unexported contract; extract it when it gains a stable public responsibility."
290
+ - id: case-2
291
+ when: "Class strings in component.tsx"
292
+ write: "Never; they go to classNames.ts (lint class-names-in-colocated-file, no-inline-class-name)"
293
+ - id: case-3
294
+ when: "A helpers/ or utils/ folder"
295
+ write: "Do not use it to hide mixed feature, transport or visual responsibilities."
296
+ - id: case-4
297
+ when: "A deployment constant"
298
+ write: >
299
+ Never. process.env.NEXT_PUBLIC_* is read only in apps/<app>/src/modules/config and reached through that module,
300
+ with no localhost fallback; a missing value in production throws when the module loads.
301
+ verification:
302
+ automated:
303
+ - FE_ENV_OWNER
304
+ - class-names-in-colocated-file
305
+ - no-inline-class-name
306
+ - no-helper-folder-in-components
307
+ manual:
308
+ - Confirm extraction is justified by ownership or lifecycle rather than file length or count.
309
+ relatedExamples: []