@mrciphersmith/keryx 0.4.29 → 0.4.30

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 (123) hide show
  1. package/dist/cli.js +2408 -1369
  2. package/dist/core.js +90 -27
  3. package/dist/keryx-general-worker-entry.js +82 -25
  4. package/package.json +1 -1
  5. package/src/gdskills/bundled/install-manifest.json +2 -0
  6. package/src/gdskills/bundled/rules/core/api-contracts.mdc +21 -136
  7. package/src/gdskills/bundled/rules/core/async-patterns.mdc +18 -171
  8. package/src/gdskills/bundled/rules/core/clean-architecture.mdc +21 -3
  9. package/src/gdskills/bundled/rules/core/cli-interface-design.mdc +63 -194
  10. package/src/gdskills/bundled/rules/core/code-style-patterns.mdc +36 -49
  11. package/src/gdskills/bundled/rules/core/concurrency-patterns.mdc +32 -0
  12. package/src/gdskills/bundled/rules/core/database-patterns.mdc +26 -148
  13. package/src/gdskills/bundled/rules/core/error-handling.mdc +7 -8
  14. package/src/gdskills/bundled/rules/core/frontend-assistant.mdc +14 -29
  15. package/src/gdskills/bundled/rules/core/layout-rendering.mdc +51 -0
  16. package/src/gdskills/bundled/rules/core/mobx-store-template.mdc +69 -511
  17. package/src/gdskills/bundled/rules/core/nestjs-dto.mdc +18 -36
  18. package/src/gdskills/bundled/rules/core/playwright-testing.mdc +35 -308
  19. package/src/gdskills/bundled/rules/core/security-baseline.mdc +18 -140
  20. package/src/gdskills/bundled/rules/core/solid-principles.mdc +31 -7
  21. package/src/gdskills/bundled/rules/core/storybook-guidelines.mdc +20 -22
  22. package/src/gdskills/bundled/rules/core/tdd-workflow.mdc +37 -74
  23. package/src/gdskills/bundled/rules/core/ui-anti-slop.mdc +48 -37
  24. package/src/gdskills/bundled/skills/quality/deprecation-path/SKILL.md +1 -1
  25. package/src/gdskills/bundled/skills/review/review-architecture/SKILL.md +24 -60
  26. package/src/gdskills/bundled/skills/review/review-backend/SKILL.md +13 -65
  27. package/src/gdskills/bundled/skills/review/review-clean-code/SKILL.md +22 -35
  28. package/src/gdskills/bundled/skills/review/review-frontend/SKILL.md +16 -309
  29. package/src/gdskills/bundled/skills/review/review-frontend-conventions/SKILL.md +7 -21
  30. package/src/gdskills/bundled/skills/review/review-highload/SKILL.md +83 -227
  31. package/src/gdskills/bundled/skills/review/review-layout/SKILL.md +22 -28
  32. package/src/gdskills/bundled/skills/review/review-logic/SKILL.md +8 -8
  33. package/src/gdskills/bundled/skills/review/review-performance/SKILL.md +15 -37
  34. package/src/gdskills/bundled/skills/review/review-security-code/SKILL.md +7 -7
  35. package/src/gdskills/bundled/skills/review/review-style/SKILL.md +31 -66
  36. package/src/gdskills/bundled/skills/review/review-testing-practices/SKILL.md +21 -39
  37. package/src/gdskills/bundled/skills/review/review-ui-ux/SKILL.md +42 -82
  38. package/src/gdskills/bundled/stacks/angular/rules/coding-style.mdc +15 -57
  39. package/src/gdskills/bundled/stacks/angular/rules/patterns.mdc +16 -60
  40. package/src/gdskills/bundled/stacks/angular/rules/security.mdc +11 -49
  41. package/src/gdskills/bundled/stacks/angular/rules/testing.mdc +13 -52
  42. package/src/gdskills/bundled/stacks/c-cpp/rules/coding-style.mdc +33 -57
  43. package/src/gdskills/bundled/stacks/c-cpp/rules/patterns.mdc +35 -62
  44. package/src/gdskills/bundled/stacks/c-cpp/rules/security.mdc +35 -62
  45. package/src/gdskills/bundled/stacks/c-cpp/rules/testing.mdc +34 -54
  46. package/src/gdskills/bundled/stacks/ci-github-gitlab/rules/patterns.mdc +27 -56
  47. package/src/gdskills/bundled/stacks/ci-github-gitlab/rules/security.mdc +51 -119
  48. package/src/gdskills/bundled/stacks/csharp-dotnet/rules/coding-style.mdc +42 -74
  49. package/src/gdskills/bundled/stacks/csharp-dotnet/rules/patterns.mdc +45 -84
  50. package/src/gdskills/bundled/stacks/csharp-dotnet/rules/security.mdc +34 -59
  51. package/src/gdskills/bundled/stacks/csharp-dotnet/rules/testing.mdc +33 -62
  52. package/src/gdskills/bundled/stacks/django/rules/coding-style.mdc +15 -56
  53. package/src/gdskills/bundled/stacks/django/rules/patterns.mdc +16 -68
  54. package/src/gdskills/bundled/stacks/django/rules/security.mdc +13 -71
  55. package/src/gdskills/bundled/stacks/django/rules/testing.mdc +16 -62
  56. package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/coding-style.mdc +30 -53
  57. package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/patterns.mdc +20 -56
  58. package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/security.mdc +52 -122
  59. package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/testing.mdc +23 -42
  60. package/src/gdskills/bundled/stacks/fastapi/rules/coding-style.mdc +13 -47
  61. package/src/gdskills/bundled/stacks/fastapi/rules/patterns.mdc +18 -81
  62. package/src/gdskills/bundled/stacks/fastapi/rules/security.mdc +13 -75
  63. package/src/gdskills/bundled/stacks/fastapi/rules/testing.mdc +14 -58
  64. package/src/gdskills/bundled/stacks/flutter-dart/rules/coding-style.mdc +36 -74
  65. package/src/gdskills/bundled/stacks/flutter-dart/rules/patterns.mdc +30 -66
  66. package/src/gdskills/bundled/stacks/flutter-dart/rules/security.mdc +33 -67
  67. package/src/gdskills/bundled/stacks/flutter-dart/rules/testing.mdc +41 -73
  68. package/src/gdskills/bundled/stacks/go/rules/coding-style.mdc +36 -57
  69. package/src/gdskills/bundled/stacks/go/rules/patterns.mdc +27 -42
  70. package/src/gdskills/bundled/stacks/go/rules/security.mdc +26 -43
  71. package/src/gdskills/bundled/stacks/go/rules/testing.mdc +23 -41
  72. package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/coding-style.mdc +18 -37
  73. package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/patterns.mdc +26 -43
  74. package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/security.mdc +25 -37
  75. package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/testing.mdc +34 -50
  76. package/src/gdskills/bundled/stacks/kotlin-android/rules/coding-style.mdc +28 -65
  77. package/src/gdskills/bundled/stacks/kotlin-android/rules/patterns.mdc +34 -78
  78. package/src/gdskills/bundled/stacks/kotlin-android/rules/security.mdc +35 -68
  79. package/src/gdskills/bundled/stacks/kotlin-android/rules/testing.mdc +34 -68
  80. package/src/gdskills/bundled/stacks/mobx/rules/coding-style.mdc +18 -64
  81. package/src/gdskills/bundled/stacks/mobx/rules/patterns.mdc +13 -66
  82. package/src/gdskills/bundled/stacks/mobx/rules/security.mdc +8 -35
  83. package/src/gdskills/bundled/stacks/mobx/rules/testing.mdc +10 -39
  84. package/src/gdskills/bundled/stacks/nestjs/rules/coding-style.mdc +32 -45
  85. package/src/gdskills/bundled/stacks/nestjs/rules/patterns.mdc +40 -60
  86. package/src/gdskills/bundled/stacks/nestjs/rules/security.mdc +30 -50
  87. package/src/gdskills/bundled/stacks/nestjs/rules/testing.mdc +27 -47
  88. package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/coding-style.mdc +14 -48
  89. package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/patterns.mdc +15 -67
  90. package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/security.mdc +12 -50
  91. package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/testing.mdc +11 -43
  92. package/src/gdskills/bundled/stacks/php-laravel/rules/coding-style.mdc +17 -58
  93. package/src/gdskills/bundled/stacks/php-laravel/rules/patterns.mdc +15 -56
  94. package/src/gdskills/bundled/stacks/php-laravel/rules/security.mdc +13 -50
  95. package/src/gdskills/bundled/stacks/php-laravel/rules/testing.mdc +14 -55
  96. package/src/gdskills/bundled/stacks/python/rules/coding-style.mdc +13 -41
  97. package/src/gdskills/bundled/stacks/python/rules/patterns.mdc +20 -61
  98. package/src/gdskills/bundled/stacks/python/rules/security.mdc +15 -57
  99. package/src/gdskills/bundled/stacks/python/rules/testing.mdc +16 -50
  100. package/src/gdskills/bundled/stacks/react/rules/coding-style.mdc +14 -40
  101. package/src/gdskills/bundled/stacks/react/rules/patterns.mdc +15 -55
  102. package/src/gdskills/bundled/stacks/react/rules/security.mdc +13 -49
  103. package/src/gdskills/bundled/stacks/react/rules/testing.mdc +10 -37
  104. package/src/gdskills/bundled/stacks/ruby-rails/rules/coding-style.mdc +12 -45
  105. package/src/gdskills/bundled/stacks/ruby-rails/rules/patterns.mdc +18 -67
  106. package/src/gdskills/bundled/stacks/ruby-rails/rules/security.mdc +11 -60
  107. package/src/gdskills/bundled/stacks/ruby-rails/rules/testing.mdc +14 -65
  108. package/src/gdskills/bundled/stacks/rust/rules/coding-style.mdc +39 -65
  109. package/src/gdskills/bundled/stacks/rust/rules/patterns.mdc +33 -60
  110. package/src/gdskills/bundled/stacks/rust/rules/security.mdc +35 -57
  111. package/src/gdskills/bundled/stacks/rust/rules/testing.mdc +29 -52
  112. package/src/gdskills/bundled/stacks/sql-db/rules/coding-style.mdc +12 -48
  113. package/src/gdskills/bundled/stacks/sql-db/rules/patterns.mdc +22 -113
  114. package/src/gdskills/bundled/stacks/sql-db/rules/security.mdc +11 -56
  115. package/src/gdskills/bundled/stacks/sql-db/rules/testing.mdc +14 -59
  116. package/src/gdskills/bundled/stacks/swift-ios/rules/coding-style.mdc +29 -65
  117. package/src/gdskills/bundled/stacks/swift-ios/rules/patterns.mdc +41 -88
  118. package/src/gdskills/bundled/stacks/swift-ios/rules/security.mdc +28 -53
  119. package/src/gdskills/bundled/stacks/swift-ios/rules/testing.mdc +32 -65
  120. package/src/gdskills/bundled/stacks/vue/rules/coding-style.mdc +17 -52
  121. package/src/gdskills/bundled/stacks/vue/rules/patterns.mdc +17 -63
  122. package/src/gdskills/bundled/stacks/vue/rules/security.mdc +11 -41
  123. package/src/gdskills/bundled/stacks/vue/rules/testing.mdc +16 -48
@@ -7,14 +7,12 @@ metadata:
7
7
 
8
8
  # MobX patterns
9
9
 
10
- Idiomatic MobX design patterns and their anti-patterns, narrowing the
11
- common architecture rules to how state, actions, and reactions should be
12
- composed in a MobX + React codebase.
10
+ MobX design patterns and anti-patterns, narrowing the common architecture
11
+ rules to how state, actions, and reactions compose in a MobX + React codebase.
13
12
 
14
13
  ## The async action shape
15
14
 
16
- The standard shape for a store method that calls an API and updates
17
- loading/error/data state:
15
+ Store method that calls an API and updates loading/error/data state:
18
16
 
19
17
  ```typescript
20
18
  private performFetch = async () => {
@@ -44,79 +42,28 @@ private performFetch = async () => {
44
42
  };
45
43
  ```
46
44
 
47
- Anti-pattern: mutating `this.loading`/`this.items` directly after the
48
- `await` with no `runInAction` — this throws under `enforceActions: "observed"`
49
- and silently misses the reaction under looser settings, either way
50
- producing a UI that does not update.
45
+ Anti-pattern: mutating `this.loading`/`this.items` after the `await` without `runInAction`.
51
46
 
52
47
  ## `flow` as an alternative to `runInAction`
53
48
 
54
- For a store with many async actions, `flow` (a generator-based action)
55
- avoids repeating `runInAction` around every post-`await` mutation, since
56
- the whole generator body already runs inside one action:
57
-
58
- ```typescript
59
- import { flow } from "mobx";
60
-
61
- fetchItems = flow(function* (this: ItemStore) {
62
- this.loading = true;
63
- try {
64
- this.items = yield this.service.getAll();
65
- } finally {
66
- this.loading = false;
67
- }
68
- });
69
- ```
70
-
71
- Use `flow` when a store's async methods are mostly sequential awaits with
72
- state writes in between; keep plain `async`/`runInAction` when a method
73
- needs to interleave with non-MobX async code (`Promise.all`, cancellation
74
- tokens) where the generator form adds friction.
49
+ Use `flow` (generator-based action) for a store whose async methods are mostly sequential awaits with state writes in between; keep plain `async`/`runInAction` when a method interleaves with non-MobX async code (`Promise.all`, cancellation tokens).
75
50
 
76
51
  ## Reaction ownership and disposal
77
52
 
78
- - `reaction`/`autorun`/`when` created inside a store belong to that
79
- store's lifecycle: push the disposer into a `disposers: IReactionDisposer[]`
80
- array in the constructor (or an `init()` called by the parent) and call
81
- every disposer in `dispose()`.
82
- - Prefer `reaction(() => selector, handler)` over `autorun` when the
83
- handler should only run in response to a specific observable changing,
84
- not on every observable it happens to read — `autorun` re-subscribes to
85
- everything it touches on each run, which can widen its dependency set
86
- unintentionally.
87
- - A component should not create a raw `autorun`/`reaction` in its render
88
- body; either derive the value with `@computed` in the store and let
89
- `observer` handle re-rendering, or start the reaction in a `useEffect`
90
- and dispose it in the cleanup function.
53
+ - A `reaction`/`autorun`/`when` created in a store belongs to its lifecycle: push the disposer into a `disposers: IReactionDisposer[]` array in the constructor (or an `init()` called by the parent) and call every disposer in `dispose()`.
54
+ - Prefer `reaction(() => selector, handler)` over `autorun` when the handler should run only when a specific observable changes.
55
+ - A component does not create a raw `autorun`/`reaction` in its render body; derive with `@computed` in the store, or start the reaction in `useEffect` and dispose it in the cleanup.
91
56
 
92
57
  ## Bidirectional store sync needs an equality guard
93
58
 
94
- When Store A writes to Store B and Store B writes back to Store A, guard
95
- the reverse direction with `if (newValue !== currentValue)` before
96
- propagating, or the two stores bounce a change back and forth forever.
97
- See `rules/coding-style.mdc` for where that callback belongs (private,
98
- not a public UI action).
59
+ When Store A writes to Store B and B writes back to A, guard the reverse direction with `if (newValue !== currentValue)` before propagating. See `rules/coding-style.mdc` for where that callback belongs (private, not a public UI action).
99
60
 
100
61
  ## View↔Store boundary
101
62
 
102
- - A component reads store state and calls store actions; it does not
103
- hold a parallel copy of store state in `useState` "for convenience" —
104
- that copy silently desyncs from the store the first time an action
105
- outside that component's tree mutates the same field.
106
- - Data loading triggered by mounting belongs in the owning store's
107
- `init()`/`onMount()`, called by the *parent* store or the top-level
108
- provider — not scattered across every consuming component's
109
- `useEffect`, which makes it impossible to reason about how many times a
110
- fetch fires as the tree re-renders.
111
- - A store must not import a React component or hook; it may accept
112
- plain callback props for the rare case a parent needs to react to a
113
- child store's internal event.
63
+ - A component reads store state and calls store actions; it does not keep a parallel copy of store state in `useState`.
64
+ - Mount-triggered data loading belongs in the owning store's `init()`/`onMount()`, called by the parent store or top-level provider, not in each consuming component's `useEffect`.
65
+ - A store must not import a React component or hook; it may accept plain callback props when a parent must react to a child store's internal event.
114
66
 
115
67
  ## Anti-pattern: computed-as-action
116
68
 
117
- A `@computed` getter must never mutate state — a getter with a
118
- side-effecting write inside it runs outside an explicit action
119
- transaction and MobX will throw ("computed value is allowed to be
120
- mutated only through action") the moment `enforceActions` is on. If a
121
- "derived" value also needs to cache an expensive side effect, that is an
122
- action-triggered `reaction`, not a computed.
69
+ A `@computed` getter never mutates state. A derived value that also needs an expensive side effect is an action-triggered `reaction`, not a computed.
@@ -7,50 +7,23 @@ metadata:
7
7
 
8
8
  # MobX security
9
9
 
10
- Stack-specific risks narrowing the common OWASP-style rules to MobX state
11
- management. Most web security concerns (XSS, auth, injection) are
12
- React/general-web concerns already covered by the common and React rules
13
- this file `extends`; this file covers the risks that are specific to
14
- putting sensitive data in observable state.
10
+ Narrows the common OWASP-style rules to MobX state management. General
11
+ web-security concerns come from the common and React rules this file
12
+ `extends`; this file covers sensitive data in observable state.
15
13
 
16
14
  ## Do not put secrets in long-lived observable state
17
15
 
18
- - A token, API key, or credential held in an `@observable` field on a
19
- store that survives the session (not cleared on logout, persisted via
20
- `autorun`/`reaction` to `localStorage`) is exposed to any code with
21
- access to that store instance and to any DevTools-based MobX inspector
22
- attached to the page. Keep secrets out of observable state; pass them
23
- through a request layer that does not put them on a reactive object a
24
- component tree (and any debugging tool observing it) can read.
25
- - If a `reaction`/`autorun` persists store state to `localStorage`/
26
- `sessionStorage` (a common MobX pattern for "remember this UI state"),
27
- explicitly exclude any field carrying a token, PII, or payment data from
28
- what gets serialized — persist a derived, scrubbed snapshot, not the
29
- whole store.
16
+ - Keep a token, API key, or credential out of an `@observable` field on a store that survives the session (not cleared on logout, or persisted by `autorun`/`reaction` to `localStorage`); pass secrets through a request layer.
17
+ - When a `reaction`/`autorun` persists store state to `localStorage`/`sessionStorage`, exclude any field carrying a token, PII, or payment data; persist a derived, scrubbed snapshot, not the whole store.
30
18
 
31
19
  ## Untrusted data into observable state is still untrusted
32
20
 
33
- - Assigning server or user-supplied HTML/markdown into an observable
34
- field does not sanitize it. If that field is later rendered with
35
- `dangerouslySetInnerHTML` in an `observer` component, the same XSS risk
36
- applies as any other React render path — sanitize before it reaches the
37
- observable, not by trusting MobX's reactivity to be a security boundary
38
- (see `rules/security.mdc` in the `react` pack this one extends).
21
+ - Assigning server or user-supplied HTML/markdown into an observable does not sanitize it; sanitize before it reaches the observable if it is later rendered with `dangerouslySetInnerHTML` (see `rules/security.mdc` in the `react` pack).
39
22
 
40
23
  ## Reaction-driven side effects and SSRF/open-redirect risk
41
24
 
42
- - A `reaction`/`autorun` that fires a `fetch`/navigation based on an
43
- observable URL or hostname field must validate that value the same way
44
- a request-time input would be validated — an attacker who can influence
45
- the observable (e.g. via a query param synced into the store) can
46
- otherwise trigger a request to an attacker-chosen host purely through
47
- state changes, with no obvious call site to audit.
25
+ - Validate an observable URL or hostname that a `reaction`/`autorun` uses for `fetch`/navigation as a request-time input would be (e.g. a query param synced into the store).
48
26
 
49
27
  ## Disposal prevents stale-store data leaks across users/sessions
50
28
 
51
- - A store not disposed on logout/route-change can keep the previous
52
- user's data in memory and observable to any component that still holds
53
- a reference (e.g. a lingering `reaction` on a background tab). Call
54
- `dispose()` on session/user change for any store holding
55
- user-scoped data, not just to free memory — to stop rendering or
56
- syncing stale, now-unauthorized data.
29
+ - Call `dispose()` on session/user change for any store holding user-scoped data, to stop rendering or syncing stale, now-unauthorized data (e.g. a lingering `reaction` on a background tab).
@@ -7,57 +7,28 @@ metadata:
7
7
 
8
8
  # MobX testing
9
9
 
10
- Narrows the common testing rules to what is specific about testing MobX
11
- stores, actions, and reactions — test layout, runner, and framework
12
- concerns for React components themselves still come from the `react`
13
- pack's own `rules/testing.mdc`.
10
+ Narrows the common testing rules to MobX stores, actions, and reactions;
11
+ React component testing comes from the `react` pack's `rules/testing.mdc`.
14
12
 
15
13
  ## Store tests are plain unit tests
16
14
 
17
- - A store with no React dependency (no `observer`, no hook) is tested by
18
- constructing it directly and calling its actions/reading its computeds
19
- — no React Testing Library render is needed. Co-locate the test next to
20
- the store (`xyz.store.test.ts` beside `xyz.store.ts`), matching the
21
- project's existing test-file convention.
22
- - Mock the store's injected dependencies (an API service passed into the
23
- constructor), not MobX itself — MobX's reactivity is the thing under
24
- test, not something to stub out.
15
+ - Test a store with no React dependency by constructing it and calling its actions/reading its computeds, with no React Testing Library render. Co-locate the test (`xyz.store.test.ts` beside `xyz.store.ts`), matching the project's convention.
16
+ - Mock the store's injected dependencies (an API service passed to the constructor), not MobX.
25
17
 
26
18
  ## Awaiting async actions and reactions
27
19
 
28
- - After calling an async action in a test, `await` the action's own
29
- returned promise (for a plain `async` method) or `await` a `when(...)`
30
- predicate on the resulting state (`await when(() => !store.loading)`)
31
- before asserting — do not assert immediately after the call and rely on
32
- a fixed `setTimeout`/sleep, which is both slower and flaky.
33
- - When asserting on a value only a `reaction`/`autorun` sets, wait for
34
- that reaction to have run (`await when(() => condition)`, or `await
35
- Promise.resolve()` for microtask-only sync reactions) rather than
36
- asserting synchronously right after the triggering mutation.
20
+ - After an async action, `await` its returned promise (plain `async` method) or `await when(() => !store.loading)` before asserting; no fixed `setTimeout`/sleep.
21
+ - For a value only a `reaction`/`autorun` sets, wait for it (`await when(() => condition)`, or `await Promise.resolve()` for microtask-only sync reactions) before asserting.
37
22
 
38
23
  ## `enforceActions` in tests
39
24
 
40
- - Keep `enforceActions` at the project's real (usually `"observed"` or
41
- `"always"`) setting in tests rather than relaxing it to `"never"` for
42
- convenience — a test that mutates observable state outside an action
43
- should fail the same way production code would, since that failure is
44
- exactly the bug class these tests exist to catch.
45
- - If a test genuinely needs to seed store state directly (bypassing
46
- actions, e.g. to set up a precondition), wrap that seeding assignment
47
- in `runInAction` rather than disabling `enforceActions` for the whole
48
- suite.
25
+ - Keep `enforceActions` at the project's real setting (usually `"observed"` or `"always"`); do not relax it to `"never"`.
26
+ - To seed store state directly, wrap the assignment in `runInAction` rather than disabling `enforceActions` for the suite.
49
27
 
50
28
  ## Testing disposal and reaction cleanup
51
29
 
52
- - Assert that `dispose()` actually stops a store's reactions: trigger a
53
- mutation after `dispose()` and confirm the disposed reaction's effect
54
- did not run again — a leaked, undisposed `autorun`/`reaction` is a real
55
- bug that a naive "does dispose() throw" test will not catch.
30
+ - Assert that `dispose()` stops a store's reactions: mutate after `dispose()` and confirm the reaction's effect did not run again.
56
31
 
57
32
  ## Component tests still need `observer`-aware setup
58
33
 
59
- - A test rendering an `observer` component must trigger the store
60
- mutation the same way production code would (through the store's own
61
- action) and then assert on the rendered output after that action
62
- resolves — do not directly reassign an observable field the component
63
- reads and expect the same ordering guarantees an action provides.
34
+ - When rendering an `observer` component, trigger the mutation through the store's own action and assert after it resolves; do not reassign an observable field the component reads.
@@ -8,63 +8,50 @@ metadata:
8
8
  # NestJS coding style
9
9
 
10
10
  Narrows `core-common-rules`' stack-agnostic style rules, and `ts-js-node`'s
11
- own TypeScript conventions, to NestJS's own idiom: decorator-driven modules,
12
- providers, and dependency injection. Applies only to `*.ts` files in a
13
- NestJS project.
11
+ own TypeScript conventions, to the official NestJS idiom: decorator-driven
12
+ modules, providers, and dependency injection. Applies only to `*.ts` files
13
+ in a NestJS project.
14
14
 
15
15
  ## Naming and file layout
16
16
 
17
- - One artifact per file, named after its role: `<name>.controller.ts`,
18
- `<name>.service.ts`, `<name>.module.ts`, `<name>.dto.ts`,
19
- `<name>.guard.ts`, `<name>.interceptor.ts`, `<name>.filter.ts`,
20
- `<name>.pipe.ts` — the Nest CLI's own generator convention. Do not fold a
21
- guard or interceptor into a controller file "since it's only used there".
22
- - Class names end in the same suffix as the file role
23
- (`UsersController`, `UsersService`, `UsersModule`), `PascalCase`.
17
+ - One artifact per file, named after its role (`<name>.controller.ts`,
18
+ `.service.ts`, `.module.ts`, `.dto.ts`, `.guard.ts`, `.interceptor.ts`,
19
+ `.filter.ts`, `.pipe.ts`), the Nest CLI generator convention; no guard or
20
+ interceptor folded into a controller file.
21
+ - Class names end in the file-role suffix (`UsersController`, `UsersService`,
22
+ `UsersModule`).
24
23
  - Injection tokens for non-class providers (`useValue`/`useFactory`) are
25
24
  `UPPER_SNAKE_CASE` string constants or `Symbol()`s exported from a single
26
- `tokens.ts`/`constants.ts`, never an inline string literal repeated at
27
- every injection site.
25
+ `tokens.ts`/`constants.ts`, not inline string literals.
28
26
 
29
27
  ## Decorators and typing
30
28
 
31
- - Every constructor-injected dependency is typed explicitly
32
- (`constructor(private readonly usersService: UsersService) {}`); do not
33
- widen an injected dependency to `any` to sidestep a circular-import type
34
- error — fix the import cycle instead (see `rules/patterns.mdc`).
35
- - Every controller method's return type is explicit or trivially inferred
36
- from a typed service call — never `Promise<any>`.
29
+ - Every constructor-injected dependency is typed explicitly; never widen it
30
+ to `any` to sidestep a circular-import error, fix the cycle (see
31
+ `rules/patterns.mdc`).
32
+ - Every controller method's return type is explicit or inferred from a typed
33
+ service call, never `Promise<any>`.
37
34
  - DTOs are typed classes with `class-validator`/`class-transformer`
38
- decorators, never plain `interface`s for request bodies — interfaces are
39
- erased at runtime and `ValidationPipe` has nothing to validate against
40
- (see `rules/security.mdc` and the repo's own `nestjs-dto.mdc` rule, which
41
- owns the full DTO decorator checklist).
42
- - Use `@Injectable()` on every class that is registered as a provider, even
43
- a class with no constructor dependencies — omitting it is a common cause
44
- of a confusing DI resolution failure covered in
45
- `skills/nestjs-build-fix/SKILL.md`.
35
+ decorators, never plain `interface`s for request bodies (see
36
+ `rules/security.mdc` and the repo's `nestjs-dto.mdc` rule, which owns the
37
+ DTO decorator checklist).
38
+ - `@Injectable()` on every class registered as a provider, even one with no
39
+ constructor dependencies (see `skills/nestjs-build-fix/SKILL.md`).
46
40
 
47
41
  ## Imports and module boundaries
48
42
 
49
- - Import providers only from the module that exports them; do not reach
50
- into another feature module's `src/<feature>/*.service.ts` file directly
51
- — import the feature module and let Nest's DI resolve it, or add the
52
- provider to that module's `exports` array if it is meant to be shared.
53
- - Keep a module's `providers`, `controllers`, `imports`, and `exports`
54
- arrays sorted by the order they were added or grouped logically; do not
55
- let an `@Module()` decorator grow past what fits on one screen without
56
- splitting the feature into sub-modules.
57
- - Barrel files (`index.ts` re-exporting a feature's public surface) export
58
- only what other modules are meant to import — not internal providers,
59
- guards, or DTOs used solely inside the module.
43
+ - Import providers only from the module that exports them; import the
44
+ feature module, or add the provider to its `exports`, rather than reaching
45
+ into another feature's `*.service.ts`.
46
+ - Keep an `@Module()` within one screen; split the feature into sub-modules
47
+ past that.
48
+ - Barrel files export only what other modules are meant to import.
60
49
 
61
50
  ## Errors
62
51
 
63
- - Throw a specific built-in NestJS exception (`NotFoundException`,
64
- `BadRequestException`, `ConflictException`, etc.) or a project-defined
65
- subclass of `HttpException`, never a bare `throw new Error(...)` from a
66
- controller or service that is expected to produce an HTTP response — a
67
- plain `Error` becomes an opaque `500` with no semantic status code.
68
- - Do not catch an exception in a service only to log it and rethrow the
69
- same thing unchanged; catch only where you add context (wrap with a
70
- domain-specific exception) or where you genuinely handle it.
52
+ - Throw a built-in NestJS exception (`NotFoundException`,
53
+ `BadRequestException`, `ConflictException`) or a project subclass of
54
+ `HttpException`, never a bare `throw new Error(...)` where an HTTP response
55
+ is expected.
56
+ - Catch in a service only to add context (wrap in a domain-specific
57
+ exception) or to handle it, not to log and rethrow unchanged.
@@ -7,77 +7,57 @@ metadata:
7
7
 
8
8
  # NestJS patterns
9
9
 
10
- Idiomatic module/provider/request-pipeline design for NestJS, and the
11
- anti-patterns that recur in Nest codebases specifically. Applies only to
12
- `*.ts` files in a NestJS project; general TypeScript design guidance still
13
- comes from `ts-js-node`'s own rules.
10
+ Module/provider/request-pipeline design for NestJS (official NestJS
11
+ documentation) and its recurring anti-patterns. Applies only to `*.ts` files
12
+ in a NestJS project; general TypeScript design guidance comes from
13
+ `ts-js-node`'s own rules.
14
14
 
15
15
  ## Module and provider design
16
16
 
17
- - A feature module owns its controllers, services, and the providers those
18
- services need; it imports other feature modules only for the providers
19
- it actually consumes, and exports only what other modules are meant to
20
- inject.
21
- - Break a real circular dependency between two modules with `forwardRef()`
22
- on both sides of the `imports`/`providers` reference — but treat
23
- `forwardRef()` as a signal to reconsider the boundary first: a genuine
24
- circular need between two feature modules is often better modeled as a
25
- shared third module both depend on.
26
- - Prefer constructor injection over property injection (`@Inject()` on a
27
- class field) except where a truly optional dependency needs
28
- `@Optional()` — constructor injection makes required dependencies
29
- visible in the type signature and fails fast at module-compile time.
30
- - Default provider scope (`Default`/Singleton) is correct for stateless
31
- services. Reach for `Scope.REQUEST` only when the provider genuinely
32
- needs per-request state (e.g. the current user from a request-scoped
33
- `REQUEST` token); a `REQUEST`-scoped provider re-instantiates its entire
34
- injection subtree per request, which has a real performance cost — do
35
- not default to it "to be safe."
17
+ - A feature module owns its controllers, services, and their providers;
18
+ imports other feature modules only for providers it consumes, exports only
19
+ what others should inject.
20
+ - Break a real circular dependency with `forwardRef()` on both sides, but
21
+ first reconsider the boundary; prefer a shared third module both depend on.
22
+ - Constructor injection over property injection (`@Inject()` on a field)
23
+ except a truly optional dependency with `@Optional()`.
24
+ - Default (Singleton) scope for stateless services; `Scope.REQUEST` only when
25
+ the provider needs per-request state (e.g. the `REQUEST` token), since it
26
+ re-instantiates its injection subtree per request.
36
27
 
37
28
  ## Guards, interceptors, pipes, and filters
38
29
 
39
- - Cross-cutting concerns (auth, logging, response shaping, validation)
40
- belong in a guard/interceptor/pipe/filter, not duplicated inline in every
41
- controller method that needs it.
42
- - Register a cross-cutting concern that applies to (nearly) every route as
43
- a global provider via `APP_GUARD`/`APP_INTERCEPTOR`/`APP_PIPE`/
44
- `APP_FILTER` in a module's `providers` array (this keeps it inside Nest's
45
- DI graph, unlike `app.useGlobalGuards()` called on the bootstrapped
46
- instance), not by decorating every controller by hand.
47
- - When a global guard protects most routes, mark the exceptions explicitly
48
- with a custom decorator read via `Reflector` (e.g. `@Public()`) rather
49
- than leaving some controllers undecorated and hoping the guard's default
50
- is safe — an undecorated route should never be silently open just
51
- because the guard's fallback happens to allow it.
52
- - A guard, interceptor, or pipe class stays free of business logic: a guard
53
- decides allow/deny, an interceptor transforms/observes the
54
- request-response stream, a pipe transforms/validates one argument. Move
55
- any decision that needs several service calls into the service layer and
56
- have the guard call that service.
30
+ - Cross-cutting concerns (auth, logging, response shaping, validation) go in
31
+ a guard/interceptor/pipe/filter, not inline per controller method.
32
+ - Register a concern that applies to nearly every route as a global provider
33
+ via `APP_GUARD`/`APP_INTERCEPTOR`/`APP_PIPE`/`APP_FILTER` in a module's
34
+ `providers` (inside Nest's DI graph, unlike `app.useGlobalGuards()`), not
35
+ by decorating every controller.
36
+ - When a global guard protects most routes, mark exceptions with a custom
37
+ decorator read via `Reflector` (e.g. `@Public()`); an undecorated route
38
+ must not be silently open via the guard's fallback.
39
+ - A guard only decides allow/deny, an interceptor transforms/observes the
40
+ request-response stream, a pipe transforms/validates one argument; a
41
+ decision needing several service calls moves to the service layer, which
42
+ the guard calls.
57
43
 
58
44
  ## Controllers vs. services
59
45
 
60
- - A controller method parses/validates input (via DTO + `ValidationPipe`),
61
- delegates to exactly one service call for the actual work, and shapes
62
- the HTTP response — it does not call a repository/ORM directly, does not
63
- branch on business rules, and does not orchestrate multiple service
64
- calls that a service method could compose instead.
46
+ - A controller method parses/validates input (DTO + `ValidationPipe`),
47
+ delegates to exactly one service call, and shapes the HTTP response; no
48
+ direct repository/ORM calls, business-rule branching, or orchestration of
49
+ several service calls a service method could compose.
65
50
  - A service method has an explicit return type and throws a Nest HTTP
66
51
  exception (see `rules/coding-style.mdc`) or a domain error the caller
67
- translates — it never imports `Request`/`Response` from the HTTP
68
- framework except for a documented streaming/file-download case.
52
+ translates; it imports `Request`/`Response` only for a documented
53
+ streaming/file-download case.
69
54
 
70
55
  ## Anti-patterns to avoid
71
56
 
72
- - Injecting the whole `ModuleRef` or reaching for
73
- `moduleRef.get(Provider, { strict: false })` to route around a missing
74
- `imports`/`exports` entry — fix the module graph instead; a lazy
75
- `ModuleRef.get` lookup hides a real DI wiring mistake.
76
- - A provider registered with `useValue`/`useFactory` whose factory has side
77
- effects beyond constructing the value (e.g. opening a connection with no
78
- corresponding `OnModuleDestroy` cleanup) — pair any resource-acquiring
79
- factory provider with the matching lifecycle hook.
80
- - Business rules encoded only as `@Roles()`/`@Permissions()` decorator
81
- strings scattered per-endpoint with no single source of truth for what
82
- each role can do — centralize the role/permission matrix so a guard
83
- reads it instead of re-deriving it per route.
57
+ - Injecting `ModuleRef` or `moduleRef.get(Provider, { strict: false })` to
58
+ route around a missing `imports`/`exports` entry; fix the module graph.
59
+ - A `useValue`/`useFactory` provider whose factory acquires a resource (e.g.
60
+ opens a connection) without a matching `OnModuleDestroy` hook.
61
+ - Role/permission rules as scattered per-endpoint `@Roles()`/`@Permissions()`
62
+ strings with no single source of truth; centralize the matrix and have a
63
+ guard read it.
@@ -7,67 +7,47 @@ metadata:
7
7
 
8
8
  # NestJS security
9
9
 
10
- Stack-specific request-pipeline risks for a NestJS application — where an
11
- unvalidated or unauthorized request can reach application code — narrowing
12
- the OWASP-style guidance in the common rules. Applies only to `*.ts` files
13
- in a NestJS project; SQL/ORM-specific injection risk is covered by the
14
- `review-backend` skill and the project's ORM rules, not duplicated here.
10
+ Request-pipeline risks for a NestJS application, narrowing the OWASP-style
11
+ guidance in the common rules. Applies only to `*.ts` files in a NestJS
12
+ project; SQL/ORM-specific injection risk is covered by the `review-backend`
13
+ skill and the project's ORM rules, not duplicated here.
15
14
 
16
15
  ## Input validation
17
16
 
18
- - Every controller method that accepts a body, query, or route param has a
19
- typed DTO class validated by a global `ValidationPipe` (registered once,
20
- in `main.ts` via `app.useGlobalPipes(new ValidationPipe(...))`, or as an
21
- `APP_PIPE` provider) — a per-controller `@UsePipes(ValidationPipe)` that
22
- some controllers omit is the same gap as no `ValidationPipe` at all for
23
- the endpoints that skip it.
24
- - Enable `whitelist: true` (strip unknown properties) and
25
- `forbidNonWhitelisted: true` (reject a request carrying an unknown
26
- property) on the global `ValidationPipe` — without them, a DTO's
27
- `class-validator` decorators only validate the fields they name; any
28
- extra field the client sends still reaches the handler untouched.
29
- - Never trust a query/param value's type from the route alone — a route
30
- param typed `id: string` in the controller signature is still a raw
31
- string at runtime; convert and validate it (`ParseIntPipe`,
32
- `ParseUUIDPipe`, or a DTO with `@IsInt()`/`@IsUUID()`) rather than
33
- passing it straight to a repository call.
17
+ - Every controller method accepting a body, query, or route param has a typed
18
+ DTO class validated by a global `ValidationPipe`, registered once
19
+ (`app.useGlobalPipes(new ValidationPipe(...))` in `main.ts`, or an
20
+ `APP_PIPE` provider); a per-controller `@UsePipes(ValidationPipe)` that
21
+ some controllers omit is a gap.
22
+ - `whitelist: true` and `forbidNonWhitelisted: true` on the global
23
+ `ValidationPipe`.
24
+ - Convert and validate a route/query param (`ParseIntPipe`, `ParseUUIDPipe`,
25
+ or a DTO with `@IsInt()`/`@IsUUID()`) rather than passing the raw string to
26
+ a repository call.
34
27
 
35
28
  ## AuthN/AuthZ
36
29
 
37
- - Protect every route that must not be public with a guard
38
- (`@UseGuards(...)` or a global `APP_GUARD`); a route with neither a guard
39
- nor an explicit `@Public()`-style marker is not provably intentional —
40
- treat an undecorated route in an otherwise-guarded controller as a gap to
41
- confirm, not assume-safe.
42
- - Read the authenticated principal from the guard-populated request object
43
- (e.g. a custom `@CurrentUser()` param decorator backed by
44
- `request.user`) — never from a client-supplied header, body field, or
45
- query param that claims who the caller is.
46
- - A role/permission check belongs in a guard evaluated before the handler
47
- runs, not as an `if` inside the service after data has already been
48
- fetched or mutated.
30
+ - Protect every non-public route with a guard (`@UseGuards(...)` or a global
31
+ `APP_GUARD`); an undecorated route in an otherwise-guarded controller is a
32
+ gap to confirm, not assume safe.
33
+ - Read the authenticated principal from the guard-populated request (e.g. a
34
+ `@CurrentUser()` decorator backed by `request.user`), never from a
35
+ client-supplied header, body field, or query param.
36
+ - A role/permission check belongs in a guard before the handler runs, not an
37
+ `if` in the service after data is fetched or mutated.
49
38
 
50
39
  ## Response and error handling
51
40
 
52
41
  - An exception filter (global `APP_FILTER`, or `app.useGlobalFilters(...)`)
53
- must translate an unexpected internal error into a generic response —
54
- never let a raw `error.message`/`error.stack` from an ORM, an HTTP
55
- client, or an uncaught exception reach the HTTP response body; that
56
- leaks internal schema, file paths, or connection details to the caller.
57
- - Use NestJS's built-in `HttpException` subclasses (or your own subclass of
58
- `HttpException`) for expected error conditions so the status code and
59
- the response shape stay in the framework's own exception-filter
60
- pipeline, instead of manually setting `response.status(...)` in a
61
- controller and bypassing filters.
42
+ translates an unexpected internal error into a generic response; no raw
43
+ `error.message`/`error.stack` in the response body.
44
+ - Use `HttpException` subclasses for expected errors, not manual
45
+ `response.status(...)` in a controller that bypasses filters.
62
46
 
63
47
  ## Secrets and configuration
64
48
 
65
49
  - Read secrets (API keys, DB credentials, JWT signing keys) through
66
- `ConfigService`/`@nestjs/config`, never hardcoded in a provider or
67
- committed default value — a `useFactory` provider that falls back to a
68
- literal secret when an env var is unset is the same risk as hardcoding
69
- it.
70
- - Do not log a full request/response body in an interceptor or middleware
71
- applied globally without redacting known-sensitive DTO fields (passwords,
72
- tokens, card numbers) — a broad request logger is a common accidental
73
- secret-leak path into log storage.
50
+ `ConfigService`/`@nestjs/config`; no hardcoded value, and no `useFactory`
51
+ fallback to a literal secret when an env var is unset.
52
+ - No global request/response body logging in an interceptor or middleware
53
+ without redacting sensitive DTO fields (passwords, tokens, card numbers).