@mrciphersmith/keryx 0.4.29 → 0.4.31

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 +2446 -1391
  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
@@ -1,5 +1,5 @@
1
1
  ---
2
- description: "Reference template and checklist for MobX store structure and async state handling."
2
+ description: "MobX store standard shared by code writers and reviewers, with the severities reviewers use: decorators and makeObservable, mutations only in actions, thin public UI actions over private arrow methods, async state with try/catch/finally and a disposed guard, disposed reactions and child stores, in-place collection updates, guarded two-way sync, the lifecycle bridge, and a minimal template. Use when writing or reviewing a MobX store."
3
3
  alwaysApply: false
4
4
  globs:
5
5
  - "**/*store*.ts"
@@ -8,509 +8,72 @@ stack_requires: "mobx"
8
8
 
9
9
  # MobX Store Template
10
10
 
11
- ## Purpose
12
- Provide a reliable baseline for MobX stores and context wiring.
11
+ Canon applies: the MobX documentation (actions, `runInAction`, observable annotations, reactions). This rule holds only this project's decisions.
13
12
 
14
- ## When To Apply
15
- Apply when creating or reviewing a MobX store file (`*.store.ts`, `*Store.ts`).
13
+ ## Rules
16
14
 
17
- ## Required Store Elements
18
- - `makeObservable(this)` in constructor.
19
- - Observable state fields.
20
- - Computed getters for derived state.
21
- - Public `@action.bound` actions for mutations triggered from UI.
22
- - `runInAction` in private async/orchestration methods, especially for post-`await` mutations.
23
- - Context + hook with null-check error.
15
+ 1. **Observable by declaration.** The constructor calls `makeObservable(this)`; observable state has a decorator; derived state is a `@computed` getter, not a method recomputed by its callers.
16
+ 2. **Every mutation runs in an action.** A public method called from a component is `@action.bound` and may mutate directly. Any mutation after an `await`, in a callback or in a private method goes in `runInAction`.
17
+ 3. **Public UI actions are thin, private methods do the work.** A public `@action.bound` method guards and delegates; API/IO, persistence and orchestration live in `private` methods written as arrow fields. `@action.bound` is for public UI methods only, never on a `private` method. A method no component calls (an inter-store callback such as `onChangeX`, `handleX`, `syncX`) is `private`. A public selector that does not mutate (`getById`) is a plain arrow method, not an action.
18
+ 4. **Async state is always settled.** A private async method that owns `loading`/`saving` flags uses `try/catch (err: unknown)/finally` and clears the flag in `finally`. After every `await` it returns early when `this.disposed` is set.
19
+ 5. **What a store starts, its `dispose()` stops.** Each `autorun`/`reaction`/`when` disposer is kept in `private disposers` and called in `dispose()`, which also sets `disposed`. A parent store disposes its child stores in its own `onUnmount()`/`dispose()`.
20
+ 6. **Collections are updated in place.** An `IObservableArray` or `ObservableMap` field is changed with `.replace()`, `.push()`, `.set()`, `.merge()`, never reassigned. A list that is only ever replaced whole is `@observable.ref` (or `.shallow`); a large external object is `@observable.ref`.
21
+ 7. **Two-way sync is guarded.** When two stores write to each other, at least one direction checks `if (next !== current)` before writing. A value that may legitimately become `undefined`, `null`, `0` or `""` uses an equality guard, never a truthy one (`if (x && x !== y)` stops a clear from propagating).
22
+ 8. **Lifecycle.** A component reports mount and unmount to its own store through the bridge below; the store decides what to load in `onMount()`. A child store's `init()`/`onMount()` is called by its parent store, not from a component.
23
+ 9. **Context and hook.** `createContext` and `useContext` come from `react`; the hook throws when the provider is missing.
24
24
 
25
- ## Member Accessibility Modifiers
25
+ Member order: private fields, public fields, constructor, public methods (`@computed`, lifecycle, selectors, `@action.bound` UI methods), private methods. The `public` keyword is not written (ESLint `explicit-member-accessibility: no-public`); injected dependencies are `private readonly`.
26
26
 
27
- ESLint enforces `@typescript-eslint/explicit-member-accessibility: ["error", { accessibility: "no-public" }]` — the `public` keyword is **forbidden**. Public members have no modifier.
28
-
29
- | Modifier | When to use |
30
- |----------|-------------|
31
- | *(no modifier)* | Public observable state, `@computed` getters, lifecycle methods (`dispose()`, `init()`), public non-mutating helpers/selectors, and public `@action.bound` UI methods |
32
- | `private` | Internal state (`disposed`, `initialized`, `_value`), helper methods, API-calling methods (`fetchX`, `performX`), inter-store callbacks (`onChangeX`, `onFireX`, `handleX`, `syncX`) |
33
- | `private readonly` | Constructor-injected dependencies, immutable config (`service`, `context`, `id`) |
34
- | `readonly` | Immutable identity fields that are public (`pipelineType`, `contextActions`) |
35
- | `protected` | Only in abstract base classes for extension points |
36
-
37
- ## Member Ordering
38
-
39
- Follow the project convention below for predictable store layout:
40
-
41
- ```
42
- 1. private fields
43
- 2. public fields
44
- 3. constructor
45
- 4. public methods
46
- - @computed getters
47
- - lifecycle methods (`dispose()`, `init()`, `onMount()`, `onUnmount()`)
48
- - public non-mutating helpers/selectors (`getById`, `findX`, `uniqueElement`)
49
- - public `@action.bound` UI entrypoints (`onChangeX`, `onClickX`, `onSave`, `onSubmit`)
50
- 5. private methods
51
- ```
52
-
53
- The exact naming can vary by module, but the shape should stay stable: internal state first, public state next, constructor once, public API grouped together, private orchestration last.
54
-
55
- ## Public UI Actions
56
-
57
- - Methods invoked from React components or route/UI event handlers MUST be `@action.bound`.
58
- - These methods are typically named with an `on...` prefix when they represent UI events: `onChangeName`, `onSave`, `onSubmit`, `onToggleExpanded`.
59
- - Public sync `@action.bound` methods may mutate store state directly. Do **not** wrap those direct mutations in `runInAction` — the action boundary already exists.
60
- - Public async `@action.bound` methods should stay thin: optional guard check → delegate to a `private async` method.
61
-
62
- ```typescript
63
- @action.bound
64
- async onSave() {
65
- if (this.saving) return;
66
- await this.performSave();
67
- }
68
-
69
- @action.bound
70
- onChangeName(value: string) {
71
- this.name = value;
72
- this.error = null;
73
- }
74
- ```
75
-
76
- ## Public Helper and Selector Methods
77
-
78
- Public methods that do **not** mutate store state are not actions:
79
-
80
- - helpers/selectors such as `getById`, `findBySlug`, `hasItem`, `uniqueElement`
81
- - read-only utility methods used by components or sibling stores
82
-
83
- Rules:
84
- - no `@action.bound`
85
- - no `runInAction`
86
- - arrow methods are acceptable and often preferred when a method reference can escape the class instance
87
-
88
- ```typescript
89
- getById = (id: string) => {
90
- return this.items.find((item) => item.id === id);
91
- };
92
- ```
93
-
94
- ## Private Methods and Async Orchestration
95
-
96
- - API/IO, persistence, sockets, background orchestration, and internal synchronization belong in `private` methods.
97
- - Private methods are often best expressed as arrow fields when preserving `this` matters.
98
- - `private async` methods should usually use `try/catch/finally`.
99
- - State mutations inside private methods should happen inside `runInAction` blocks.
100
- - After every `await`, any state mutation must re-enter MobX via `runInAction`.
101
- - If the method owns `loading` / `saving` / `processing` flags, set them via `runInAction` in `try` and clear them in `finally`.
102
- - Avoid `@action.bound` on private methods by default.
103
- - **Exception**: `@action.bound private` is acceptable when a private method is passed as a bound callback reference to a child/sibling store constructor.
104
-
105
- ```typescript
106
- private performSave = async () => {
107
- try {
108
- runInAction(() => {
109
- this.saving = true;
110
- this.error = null;
111
- });
112
-
113
- const saved = await SomeApi.save(this.draft);
114
-
115
- runInAction(() => {
116
- if (this.disposed) return;
117
- this.item = saved;
118
- });
119
- } catch (err: unknown) {
120
- runInAction(() => {
121
- if (this.disposed) return;
122
- this.error = err instanceof Error ? err.message : 'Save failed';
123
- });
124
- } finally {
125
- runInAction(() => {
126
- if (this.disposed) return;
127
- this.saving = false;
128
- });
129
- }
130
- };
131
- ```
132
-
133
- ## Inter-Store Callbacks and Internal Handlers
134
-
135
- Methods that serve as **internal callbacks** between stores or internal event handlers MUST be `private`. These are NOT part of the store's public API — they are internal synchronization glue.
136
-
137
- **Common patterns that MUST be `private`:**
138
- - `onChangeEditorState(state)` — callback receiving state from child/sibling store
139
- - `onFireExecutorChange()` — internal sync handler when executor changes
140
- - `onChangeX(value)` — handler for internal state propagation between stores when not called from React UI
141
- - `handleX()`, `syncX()` — any internal coordination method
142
-
143
- **Decision rule:** Ask "Is this method called from a React component via JSX/event handler?" If NO — it is `private`.
144
-
145
- ```typescript
146
- // WRONG — public inter-store callback
147
- @action.bound
148
- onChangeEditorState(editorState: ICodeEditorState) {
149
- this.setRawScript(editorState.script);
150
- }
151
-
152
- // CORRECT — private inter-store callback passed to another store
153
- @action.bound
154
- private onChangeEditorState(editorState: ICodeEditorState) {
155
- this.setRawScript(editorState.script);
156
- }
157
- ```
158
-
159
- **Note:** `@action.bound` on a `private` callback is acceptable in the callback-reference pattern because it preserves `this` and MobX action tracking when handing the method to another store.
160
-
161
- ## Bidirectional Sync Bounce Protection
162
-
163
- When two stores synchronize state bidirectionally (Store A writes to Store B and Store B writes back to Store A), an **equality guard** is required in the reverse-sync path to prevent infinite callback loops.
164
-
165
- **Pattern:** Before propagating a value back to the source store, check that the value actually changed:
166
-
167
- ```typescript
168
- // Store A → Store B (forward sync, triggered by user action)
169
- @action.bound
170
- private onChangeEditorState(editorState: ICodeEditorState) {
171
- this.setRawScript(editorState.script);
172
- const codeExecutorId = this.codeExecutor?.id;
173
- if (this.codeEditorStore.executorId !== codeExecutorId) {
174
- this.codeEditorStore.setExecutorId(codeExecutorId);
175
- }
176
- }
177
- ```
178
-
179
- **Anti-pattern — missing equality guard causes infinite loop:**
180
-
181
- ```typescript
182
- // WRONG — no guard, will bounce back and forth
183
- private onChangeEditorState(editorState: ICodeEditorState) {
184
- this.setRawScript(editorState.script);
185
- const codeExecutorId = this.codeExecutor?.id;
186
- this.codeEditorStore.setExecutorId(codeExecutorId); // triggers onChangeX → back to here
187
- }
188
- ```
189
-
190
- **Rule:** In any bidirectional sync between stores, at least one direction MUST have `if (newValue !== currentValue)` before writing to the other store.
191
-
192
- ## Truthy vs Equality Guards for Optional Values
193
-
194
- When guarding state updates, prefer **equality comparison** (`!==`) over **truthy checks** (`if (value && ...)`) for optional/nullable fields. A truthy guard blocks propagation of legitimate `undefined`/`null`/`0`/`""` values.
195
-
196
- ```typescript
197
- // WRONG — truthy guard blocks clearing (undefined cannot propagate)
198
- if (executor && executor.id !== this.executorId) {
199
- this.setExecutorId(executor.id);
200
- }
201
- // If executor is undefined (user cleared it), nothing happens — stale value remains
202
-
203
- // CORRECT — equality guard allows clearing
204
- if (executor?.id !== this.executorId) {
205
- this.setExecutorId(executor?.id);
206
- }
207
- // If executor is undefined, executorId becomes undefined — field is properly cleared
208
- ```
209
-
210
- **Rule:** Use `if (value !== currentValue)` instead of `if (value && value !== currentValue)` when `undefined`/`null` is a valid state that should propagate. Reserve truthy guards only for fields that must never be falsy.
211
-
212
- ## Lifecycle Initialization
213
-
214
- - A component tells its own store that it mounted and unmounted through the lifecycle bridge below. Calling `store.onMount()` / `store.onUnmount()` from that `useEffect` is correct: the component reports an event, the store decides what it means.
215
- - A **child** store's `init()` / `onMount()` is called by the **parent store**, not from a component `useEffect`. Parent store orchestrates child store lifecycle.
216
- - Components should **not** trigger data loading or run business logic in a `useEffect` (`store.loadX()`, a child store's `init()`). That work belongs inside the store's `onMount()`.
217
- - `dispose()` is called by the parent store in its `onUnmount()` to prevent stale-state updates.
218
-
219
- ```typescript
220
- // Component — the lifecycle bridge
221
- useEffect(() => {
222
- store.onMount();
223
- return () => store.onUnmount();
224
- }, [store]);
225
- ```
226
-
227
- ```typescript
228
- // Store — what mounting means
229
- @action.bound
230
- onMount() {
231
- void this.variablesStore.init();
232
- }
233
-
234
- @action.bound
235
- onUnmount() {
236
- this.variablesStore?.dispose();
237
- }
238
- ```
239
-
240
- ## API Calls in Private Methods
241
-
242
- API/IO calls must live in **private** store methods, never in components and never as the main body of a public UI action:
243
-
244
- - public `@action.bound` methods are thin: guard check → delegate to private method
245
- - private methods handle: API call → `runInAction` mutation blocks → toast/error handling → cleanup
246
-
247
-
248
- ## Observable Type Variants
249
-
250
- MobX provides different levels of observation depth:
251
-
252
- | Decorator | Behavior |
253
- |-----------|----------|
254
- | `@observable` | Deep observation — nested objects and arrays are made observable recursively |
255
- | `@observable.ref` | Reference only — only the reference itself is tracked, inner contents are NOT observable |
256
- | `@observable.shallow` | One level deep — array/object items are not made observable, but the container is |
257
- | `@observable.struct` | Structural comparison — triggers only when the value structurally differs from the previous |
258
-
259
- ```typescript
260
- // Deep observable (default) — full reactivity on nested data
261
- @observable items: IItem[] = [];
262
- @observable config: IConfig = { ... };
263
-
264
- // Reference observable — use when you own the object reactivity elsewhere
265
- // or when it's a large external object you don't want deeply proxied
266
- @observable.ref items: IItem[] = [];
267
- @observable.ref editorInstance: EditorType | null = null;
268
-
269
- // Shallow observable — container is reactive, items are plain
270
- @observable.shallow list: IItem[] = [];
271
-
272
- // Structural — only triggers reaction when value structurally changes
273
- @observable.struct position: { x: number; y: number } = { x: 0, y: 0 };
274
- ```
275
-
276
- ### Private Observable with Getter/Setter
277
-
278
- Use a private backing field `_value` with a public getter (and optional setter action) when you need to control access or add side effects on mutation:
279
-
280
- ```typescript
281
- @observable private _value: string = "";
282
-
283
- @computed get value() {
284
- return this._value;
285
- }
286
-
287
- @action.bound
288
- setValue(value: string) {
289
- this._value = value;
290
- }
291
- ```
292
-
293
- ### MobX Observable Collections (IObservableArray / ObservableMap)
294
-
295
- Use `IObservableArray` and `ObservableMap` when you need access to MobX-specific collection methods (`.replace()`, `.remove()`, `.clear()`, `.has()`, `.merge()`). Plain arrays/maps assigned to `@observable` are also deeply observed but lack these utility methods.
296
-
297
- ```typescript
298
- import { IObservableArray, ObservableMap, observable } from "mobx";
299
-
300
- // IObservableArray — MobX-enhanced array
301
- @observable someListsByMobx: IObservableArray<IItem> = observable([]);
302
-
303
- // ObservableMap — MobX-enhanced Map
304
- @observable someMapByMobx: ObservableMap<string, IItem> = observable(new Map());
305
- ```
306
-
307
- #### IObservableArray API
308
-
309
- ```typescript
310
- // Mutation — all trigger reactions
311
- this.someListsByMobx.push(item); // add one or more at end
312
- this.someListsByMobx.pop(); // remove last
313
- this.someListsByMobx.splice(index, deleteCount, ...newItems); // in-place splice
314
- this.someListsByMobx.replace([item1, item2]); // replace all contents atomically
315
- this.someListsByMobx.remove(item); // remove first matching item (by reference)
316
- this.someListsByMobx.clear(); // remove all items
317
-
318
- // Read — standard array methods work normally
319
- this.someListsByMobx.find(x => x.id === id);
320
- this.someListsByMobx.filter(x => x.active);
321
- this.someListsByMobx.map(x => x.name);
322
- this.someListsByMobx.slice(); // returns plain array snapshot
323
- this.someListsByMobx.toJSON(); // alias for slice()
324
- ```
325
-
326
- #### ObservableMap API
327
-
328
- ```typescript
329
- // Mutation
330
- this.someMapByMobx.set('key', value); // add or update
331
- this.someMapByMobx.delete('key'); // remove by key
332
- this.someMapByMobx.clear(); // remove all
333
- this.someMapByMobx.replace(new Map([['k', v]])); // replace all contents atomically
334
- this.someMapByMobx.merge({ key: value }); // merge object or map into existing
335
-
336
- // Read
337
- this.someMapByMobx.get('key'); // value or undefined
338
- this.someMapByMobx.has('key'); // boolean
339
- this.someMapByMobx.keys(); // IterableIterator<string>
340
- this.someMapByMobx.values(); // IterableIterator<V>
341
- this.someMapByMobx.entries(); // IterableIterator<[string, V]>
342
- this.someMapByMobx.forEach((value, key) => ...);
343
- this.someMapByMobx.toJSON(); // plain object snapshot
344
- ```
345
-
346
- ### Non-Observable Props (passed from parent store)
347
-
348
- Props injected from outside the store that do not need reactivity are stored as plain class fields (no decorator):
349
-
350
- ```typescript
351
- somePropValue: IConfig;
352
- somePropFn: () => void;
353
- ```
354
-
355
- ## Reactions and Disposers
356
-
357
- Use `autorun`, `reaction`, and `when` for side effects that respond to observable changes. Always dispose them in `dispose()` to prevent memory leaks and stale callbacks.
27
+ ## Template
358
28
 
359
29
  ```typescript
360
- import { autorun, reaction, when, IReactionDisposer } from "mobx";
30
+ import { action, computed, IReactionDisposer, makeObservable, observable, reaction, runInAction } from "mobx";
31
+ import { createContext, useContext, useEffect } from "react";
361
32
 
362
- export class ExampleStore {
33
+ export class ItemsStore {
363
34
  private disposed = false;
364
35
  private disposers: IReactionDisposer[] = [];
365
36
 
366
- constructor() {
367
- makeObservable(this);
368
- // Set up reactions after makeObservable
369
- this.disposers.push(
370
- // autorun — runs immediately and on every dependency change
371
- autorun(() => {
372
- if (this.items.length > 0) {
373
- console.log("items changed:", this.items.length);
374
- }
375
- }),
376
-
377
- // reaction — explicit dependency tracking, runs only on change (not on init)
378
- reaction(
379
- () => this.loading,
380
- (loading) => {
381
- if (!loading) this.onLoadComplete();
382
- }
383
- ),
384
-
385
- // when — runs once when predicate becomes true, then auto-disposes
386
- when(
387
- () => this.items.length > 0,
388
- () => { /* one-time side effect */ }
389
- )
390
- );
391
- }
392
-
393
- dispose() {
394
- this.disposed = true;
395
- this.disposers.forEach(d => d());
396
- this.disposers = [];
397
- }
398
- }
399
- ```
400
-
401
- **Rule:** Every `autorun`, `reaction`, or `when` created in the store MUST have its disposer stored and called in `dispose()`.
402
-
403
- ## Constructor Variants
404
-
405
- ```typescript
406
- // Basic — no dependencies
407
- constructor() {
408
- makeObservable(this);
409
- }
410
-
411
- // With private injected dependency
412
- constructor(private readonly service: SomeService) {
413
- makeObservable(this);
414
- }
415
-
416
- // With public readonly identity (no `public` keyword — ESLint forbids it)
417
- // Use `readonly` instead:
418
- constructor(readonly id: string) {
419
- makeObservable(this);
420
- }
421
-
422
- // With value prop + callback prop (from parent store)
423
- constructor(somePropValue: IConfig, somePropFn: () => void) {
424
- makeObservable(this);
425
- this.somePropValue = somePropValue;
426
- this.somePropFn = somePropFn;
427
- }
428
- ```
429
-
430
- ## Minimal Template
431
- ```typescript
432
- import { action, computed, createContext, IObservableArray, IReactionDisposer, makeObservable, observable, ObservableMap, reaction, runInAction } from "mobx";
433
- import { useContext } from "react";
434
-
435
- export class ExampleStore {
436
- // 1. Private fields
437
- private readonly service: SomeService;
438
- @observable private _value = "";
439
- private disposed = false;
440
- private disposers: IReactionDisposer[] = [];
441
-
442
- // 2. Public fields
37
+ @observable.ref items: Item[] = [];
443
38
  @observable loading = false;
444
- @observable saving = false;
445
39
  @observable error: string | null = null;
446
- @observable.ref items: IItem[] = [];
447
- @observable someListsByMobx: IObservableArray<IItem> = observable([]);
448
- @observable someMapByMobx: ObservableMap<string, IItem> = observable(new Map());
449
- readonly pipelineType = "example";
40
+ @observable query = "";
450
41
 
451
- // 3. Constructor
452
- constructor(service: SomeService) {
453
- this.service = service;
42
+ constructor(private readonly api: ItemsApi, private readonly onQueryChange: (query: string) => void) {
454
43
  makeObservable(this);
44
+ this.disposers.push(reaction(() => this.query, (query) => this.onQueryChange(query)));
455
45
  }
456
46
 
457
- // 4. Public methods
458
47
  @computed get isEmpty() {
459
48
  return this.items.length === 0;
460
49
  }
461
50
 
462
- @computed get value() {
463
- return this._value;
51
+ @action.bound
52
+ onMount() {
53
+ void this.fetchItems();
464
54
  }
465
55
 
466
- getById = (id: string) => {
467
- return this.items.find((item) => item.id === id);
468
- };
469
-
470
- dispose() {
56
+ @action.bound
57
+ onUnmount() {
471
58
  this.disposed = true;
472
59
  this.disposers.forEach((dispose) => dispose());
473
60
  this.disposers = [];
474
61
  }
475
62
 
476
- @action.bound
477
- async init() {
478
- await this.fetchItems();
479
- }
63
+ getById = (id: string) => this.items.find((item) => item.id === id);
480
64
 
481
65
  @action.bound
482
- onChangeValue(value: string) {
483
- this._value = value;
484
- this.error = null;
66
+ onChangeQuery(query: string) {
67
+ this.query = query;
485
68
  }
486
69
 
487
- @action.bound
488
- async onCreateItem(name: string) {
489
- if (this.saving) return;
490
- await this.performCreate(name);
491
- }
492
-
493
- // 5. Private methods
494
- private registerReactions = () => {
495
- this.disposers.push(
496
- reaction(
497
- () => this.items.length,
498
- () => {
499
- // side effect
500
- },
501
- ),
502
- );
503
- };
504
-
505
70
  private fetchItems = async () => {
71
+ runInAction(() => {
72
+ this.loading = true;
73
+ this.error = null;
74
+ });
506
75
  try {
507
- runInAction(() => {
508
- this.loading = true;
509
- this.error = null;
510
- });
511
-
512
- const items = await this.service.getAll();
513
-
76
+ const items = await this.api.list();
514
77
  runInAction(() => {
515
78
  if (this.disposed) return;
516
79
  this.items = items;
@@ -518,55 +81,50 @@ export class ExampleStore {
518
81
  } catch (err: unknown) {
519
82
  runInAction(() => {
520
83
  if (this.disposed) return;
521
- this.error = err instanceof Error ? err.message : "Fetch failed";
84
+ this.error = err instanceof Error ? err.message : "Load failed";
522
85
  });
523
86
  } finally {
524
87
  runInAction(() => {
525
- if (this.disposed) return;
526
- this.loading = false;
88
+ if (!this.disposed) this.loading = false;
527
89
  });
528
90
  }
529
91
  };
530
-
531
- private performCreate = async (name: string) => {
532
- try {
533
- runInAction(() => {
534
- this.saving = true;
535
- this.error = null;
536
- });
537
-
538
- const created = await this.service.create({ name });
539
-
540
- runInAction(() => {
541
- if (this.disposed) return;
542
- this.items = [...this.items, created];
543
- });
544
- } catch (err: unknown) {
545
- runInAction(() => {
546
- if (this.disposed) return;
547
- this.error = err instanceof Error ? err.message : "Create failed";
548
- });
549
- } finally {
550
- runInAction(() => {
551
- if (this.disposed) return;
552
- this.saving = false;
553
- });
554
- }
555
- };
556
-
557
- private syncCollections = () => {
558
- runInAction(() => {
559
- this.someListsByMobx.replace([{ id: "1", name: "Item 1" }]);
560
- this.someMapByMobx.set("1", { id: "1", name: "Item 1" });
561
- });
562
- };
563
92
  }
564
93
 
565
- export const ExampleStoreContext = createContext<ExampleStore | null>(null);
94
+ export const ItemsStoreContext = createContext<ItemsStore | null>(null);
566
95
 
567
- export const useExampleStore = () => {
568
- const store = useContext(ExampleStoreContext);
569
- if (!store) throw new Error("useExampleStore must be used within provider");
96
+ export const useItemsStore = () => {
97
+ const store = useContext(ItemsStoreContext);
98
+ if (!store) throw new Error("useItemsStore must be used within ItemsStoreContext");
570
99
  return store;
571
100
  };
101
+
102
+ // In the component that owns the store: the lifecycle bridge.
103
+ useEffect(() => {
104
+ store.onMount();
105
+ return () => store.onUnmount();
106
+ }, [store]);
572
107
  ```
108
+
109
+ ---
110
+
111
+ ## Review severities (shared with reviewers)
112
+
113
+ `review-frontend` rates these patterns by this table. Change a row here, never in a reviewer.
114
+
115
+ | Signal | A finding when | Default | Not a finding |
116
+ |---|---|---|---|
117
+ | `makeObservable(this)` or an observable decorator missing (Rule 1) | the field is read by a component or a computed | `major` | a plain field nothing observes (injected props, config) |
118
+ | Derived value as a plain method instead of `@computed` (Rule 1) | its callers recompute it in render | `minor` | a selector that takes arguments (`getById`) |
119
+ | Mutation outside an action: after `await`, in a callback (Rule 2) | always | `major`; `blocker` where the interleaving corrupts persisted state | a direct mutation in a public sync `@action.bound` method |
120
+ | API/IO in a public action body instead of a private method (Rule 3) | always | `minor`; `major` with a named defect it causes | — |
121
+ | `@action.bound` on a private method; an inter-store callback without `private` (Rule 3) | always | `minor` | a method a component calls |
122
+ | Loading flag not cleared on error, no `finally`, or no `disposed` guard after `await` (Rule 4) | a named failure or unmount leaves the flag set or writes to a disposed store | `major` | — |
123
+ | `catch (err: any)` or untyped (Rule 4) | always | rated by `error-handling` | — |
124
+ | Reaction or child store never disposed (Rule 5) | always | `major` | a store that lives as long as the app, stated |
125
+ | Observable collection reassigned (Rule 6) | a holder of the old reference stops updating, named | `major`; else `minor` | `@observable.ref` replaced whole |
126
+ | Deep `@observable` on a list only ever replaced whole, or on a large external object (Rule 6) | always | `minor` | — |
127
+ | Two-way sync with no equality guard (Rule 7) | always | `blocker` when a named trigger reaches the loop and the render dies; `major` for a reachable hang; `info` with no path | a guard in either direction |
128
+ | Truthy guard on a value that may be cleared (Rule 7) | the cleared value is valid input, named | `major` | a field that can never be falsy |
129
+ | Component calls `store.loadX()` or a child store's `init()` in an effect (Rule 8) | always | `minor`; `major` with a named defect | the `onMount()`/`onUnmount()` bridge |
130
+ | `public` keyword, member order (Rule 3, member order) | always | `minor` | — |