@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,56 +1,43 @@
1
1
  ---
2
- description: "Code style and architecture patterns for TypeScript, React, and MobX."
2
+ description: "React and TypeScript standard for the frontend, shared by code writers and reviewers, with the severities reviewers use: observer on every component that reads observables, layers (service IO, store logic, component render), where state lives, stores created once, effects that clean up, stable keys, accessibility basics, and TypeScript safety. Use when writing or reviewing React/TypeScript components."
3
3
  alwaysApply: false
4
4
  stack_requires: "react,mobx"
5
5
  ---
6
6
 
7
7
  # Code Style and Architecture Patterns
8
8
 
9
- ## Purpose
10
- Enforce consistent code style and architecture patterns across TypeScript, React, and MobX code in the frontend project.
11
-
12
- ## When To Apply
13
- Apply when reviewing or implementing TypeScript/React/MobX code in the frontend project.
14
-
15
- ## TypeScript
16
- - Enforce strict typing; avoid `any`.
17
- - Use interfaces for component props.
18
- - Prefer `?.` and `??` over unsafe assertions.
19
- - Do not use imports like `from \"src/...\"`; use relative paths or approved aliases.
20
-
21
- ## MobX Patterns
22
-
23
- For complete MobX store patterns, see `core/mobx-store-template.mdc`.
24
-
25
- Key principles (see canonical source for full detail with examples):
26
- - All state must use `makeObservable(this)` with explicit decorators
27
- - Store layout should stay predictable: private fields → public fields → constructor → public methods → private methods
28
- - Public UI entrypoints called from React should be `@action.bound`, usually as thin `on...` methods
29
- - Public non-mutating helpers/selectors are not actions and do not use `runInAction`
30
- - Private API/IO and orchestration belong in private methods; async private methods use `try/catch/finally`
31
- - Use `runInAction` for private mutation blocks after `await`, and for private orchestration-state updates
32
- - Wrap React components with `observer`
33
- - Inter-store callbacks and internal handlers must be private (see `core/mobx-store-template.mdc` for the canonical callback rules)
34
- - Use equality guards, not truthy checks, when optional values must propagate clearing
35
- - Implement bounce protection for bidirectional sync
36
-
37
- ## React
38
- - Wrap observable-consuming components with `observer`.
39
- - Keep business logic in stores/services.
40
- - Avoid heavy logic in render.
41
-
42
- ## Architecture
43
- Frontend only; backend layering, with a domain layer, is `clean-architecture.mdc`.
44
- - Service layer: IO/API only.
45
- - Store layer: business logic and state transitions.
46
- - Component layer: view rendering.
47
- - UI components should preferably have their own local MobX store to manage their specific view state and encapsulate UI-specific logic, implementing reactivity via MobX instead of `useState` where possible.
48
-
49
- ## Review Flags
50
- - API calls directly in UI components.
51
- - Missing `observer` where store values are consumed.
52
- - Direct observable mutation outside actions.
53
- - Large inline render logic better suited for computed/store methods.
54
- - Public inter-store callbacks/handlers that should be `private` (e.g. `onChangeEditorState`, `onFireExecutorChange`).
55
- - Bidirectional store sync without equality guard — risk of infinite callback bounce.
56
- - Truthy guard (`if (x && x !== y)`) on optional/nullable field — blocks propagation of `undefined`/falsy clearing.
9
+ Canon applies: the React documentation (rules of hooks, effects, keys), WAI-ARIA basics and the TypeScript handbook. Store internals are `mobx-store-template.mdc`; backend layering is `clean-architecture.mdc`. This rule holds only this project's frontend decisions.
10
+
11
+ ## Rules
12
+
13
+ 1. **`observer` on every component that reads an observable**, conditional reads included, as the outermost wrapper: `observer(withRouter(View))`. A component that reads only props needs none.
14
+ 2. **Layers.** A service does IO only; a store holds state, logic and state transitions; a component renders and forwards events to store actions. No API/IO call and no business logic (validation, transformation, branching on domain state) in a component, its handlers or its effects.
15
+ 3. **Where state lives.** UI-only state that one component uses (an open flag, a hover, an input draft) is `useState`. State with logic, or read by another component or a store, lives in a store; it is never copied into `useState`. `useMemo`/`useCallback` do not wrap store values or store methods.
16
+ 4. **A store is created once per mount**: `useState(() => new PageStore(api))[0]` or `useLocalObservable`, never `new Store()` in the component body.
17
+ 5. **An effect that subscribes, listens or starts a timer returns its cleanup.** Data loading is not started from an effect (see `mobx-store-template.mdc` Rule 8).
18
+ 6. **List keys** are on the element `.map()` returns and are stable ids; an index key only for a static list that never reorders or filters.
19
+ 7. **Accessibility.** `<img>` has `alt` (`""` when decorative); an icon-only button or link has `aria-label`; a form input has a label; a clickable element is a `<button>` or `<a>`, not a `<div onClick>`.
20
+ 8. **TypeScript.** No `any` (use `unknown` and a guard, or the named type). A `!` assertion carries a comment that proves it; otherwise use `?.`/`??` and handle the missing case. Props types are `XProps`, no `I` prefix. Imports use relative paths or the configured aliases, never `from "src/..."`.
21
+
22
+ ---
23
+
24
+ ## Review severities (shared with reviewers)
25
+
26
+ `review-frontend` rates these patterns by this table. Change a row here, never in a reviewer.
27
+
28
+ | Signal | A finding when | Default | Not a finding |
29
+ |---|---|---|---|
30
+ | Component reads observables without `observer` (Rule 1) | always | `major` (the UI does not update when the observable changes) | a component that reads only props |
31
+ | `observer` inside another HOC (Rule 1) | always | `minor`; `major` with a named defect | — |
32
+ | API/IO or business logic in a component (Rule 2) | always | `minor`; `major` with a named defect it causes | — |
33
+ | Shared or store-owned state kept in `useState`, or copied from a store (Rule 3) | two owners of the value can diverge, named | `major` | UI-only state one component uses |
34
+ | `useMemo`/`useCallback` around a store value or method (Rule 3) | always | `minor` | a memo over values that are not store state |
35
+ | Store constructed in the component body (Rule 4) | always | `major` (recreated on each render, state lost) | `useState(() => new Store())`, `useLocalObservable` |
36
+ | Subscription, listener or timer without cleanup (Rule 5) | always | `major` | — |
37
+ | Missing `key` (Rule 6) | always | `major` | — |
38
+ | Index key on a list that reorders, filters or paginates (Rule 6) | always | `minor` | a static list |
39
+ | `<img>` without `alt`; interactive element without an accessible name (Rule 7) | always | rated by the missing-accessible-name row of `ui-anti-slop.mdc` Review severities | — |
40
+ | Clickable non-semantic element without keyboard support (Rule 7) | always | rated by the keyboard-reachability row of `ui-anti-slop.mdc` Review severities | — |
41
+ | `!` on a value the types allow to be missing (Rule 8) | a named input reaches it | `blocker` when it throws during render; `major` elsewhere; `minor` with no input shown | a `!` with a comment that proves it |
42
+ | `any` in new code (Rule 8) | always | `minor`; `major` with a named input and the wrong value it lets through | — |
43
+ | `I`-prefixed props type, `from "src/..."` import (Rule 8) | introduced by the change | `minor` | — |
@@ -0,0 +1,32 @@
1
+ ---
2
+ description: "Concurrency standard for the CLI and for several sessions sharing one checkout, shared by code writers and reviewers, with the severities reviewers use: a lock file is taken by exclusive create, files are written via temp file and rename, one write per JSONL record, child-process fan-out is bounded, child output is capped. Use when writing or reviewing code that touches shared state files, lock files, JSONL logs or spawned child processes."
3
+ alwaysApply: false
4
+ ---
5
+
6
+ # Concurrency Patterns
7
+
8
+ Canon applies: POSIX `rename(2)` atomicity, `O_EXCL` / the Node.js `wx` open flag, and `child_process` stream semantics. This rule holds only this project's decisions for state shared by concurrent sessions and processes.
9
+
10
+ ## Rules
11
+
12
+ 1. **A lock file is taken by exclusive create** (`wx`), never check-then-create. It is released in `finally`, and a stale lock is recovered by the holder's PID or age without taking a live holder's lock.
13
+ 2. **A shared state file is written to a temp file in the same directory and renamed over the target.** A read-modify-write of it holds a lock (Rule 1).
14
+ 3. **One JSONL record is one write.** A record is serialised whole, with its newline, and appended in a single call.
15
+ 4. **Child-process fan-out is bounded.** One child per file, flow, finding or input item goes through a concurrency limit; default 4.
16
+ 5. **Child output is capped.** Child stdout and stderr, and logs, are held in a ring buffer or written to a file, never concatenated whole in memory.
17
+
18
+ ---
19
+
20
+ ## Review severities (shared with reviewers)
21
+
22
+ `review-highload` rates these patterns by this table. Change a row here, never in a reviewer.
23
+
24
+ | Signal | A finding when | Default | Not a finding |
25
+ |---|---|---|---|
26
+ | Read-modify-write of a shared state file with no lock, or a write with no temp file and rename (Rules 1, 2) | two sessions or processes can reach it, named | `blocker` if the interleaving can corrupt or lose data, or a reader parses a half-written file; otherwise `major` | a file only one process writes, shown |
27
+ | Lock file taken by check-then-create (Rule 1) | always | `major`; `blocker` where the duplicate holder is shown to persist a lost or doubled write | an exclusive create |
28
+ | Lock released outside `finally`, or no stale-lock recovery (Rule 1) | a crash or throw leaves it held and a later session waits on it | `major` | a lock with a holder PID or age check |
29
+ | Stale-lock recovery that can take a live holder's lock (Rule 1) | the recovery test can pass while the holder runs | `major`; `blocker` where two holders are shown to write | — |
30
+ | JSONL record appended in more than one write (Rule 3) | several processes append to the file | `major` | a file one process appends to |
31
+ | One child process per input item with no bound (Rule 4) | the item count is not fixed small, named | `major` when the stall or exhaustion it causes is named; `blocker` only if the crash is shown | a fixed small count |
32
+ | Child stdout, stderr or log accumulated whole in memory (Rule 5) | the child's output size is not bounded | `major` when a named child can print without limit; else `minor` | output known small, or read from a file |
@@ -1,163 +1,41 @@
1
1
  ---
2
- description: "Database access patterns: no N+1 queries, indexes before deploy, backward-compatible migrations, transaction discipline. Use when writing queries, migrations, or ORM models."
2
+ description: "Database standard shared by code writers and reviewers, with the severities reviewers use: no query per item on a request path, indexes with the query, migrations compatible with the code still running, transactions for multi-step writes, no SELECT * to clients, soft-delete discipline. Use when writing or reviewing queries, migrations or ORM models."
3
3
  alwaysApply: false
4
4
  stack_requires: "sql"
5
5
  ---
6
6
 
7
7
  # Database Patterns
8
8
 
9
- ## Purpose
10
- Prevent N+1 query explosions, missing indexes, and migration-induced outages. Enforce safe, observable, backward-compatible database changes.
11
-
12
- ## When To Apply
13
- Apply when writing ORM queries, creating migrations, designing schema changes, or reviewing data access code.
14
-
15
- ---
9
+ Canon applies: the PostgreSQL documentation on locking, `ALTER TABLE` and `CREATE INDEX CONCURRENTLY`, and the ORM's documentation. This rule holds only this project's decisions.
16
10
 
17
11
  ## Rules
18
12
 
19
- ### Rule 1: No N+1 Queries
20
- A query inside a loop is always an N+1 violation. Use eager loading, `JOIN`, or `IN` clause batching.
21
-
22
- ```typescript
23
- // BAD — N+1: 1 query for orders + 1 query per order for user
24
- const orders = await Order.findAll();
25
- for (const order of orders) {
26
- const user = await User.findById(order.userId); // N queries
27
- console.log(user.name);
28
- }
29
-
30
- // GOOD — single query with eager load
31
- const orders = await Order.findAll({ include: [{ model: User }] });
32
- for (const order of orders) {
33
- console.log(order.user.name); // no additional queries
34
- }
35
-
36
- // GOOD alternative — batch with IN clause
37
- const userIds = orders.map(o => o.userId);
38
- const users = await User.findAll({ where: { id: userIds } });
39
- const userMap = new Map(users.map(u => [u.id, u]));
40
- ```
41
-
42
- **Detection rule:** Any `findById`, `findOne`, or `findByPk` inside a loop MUST be refactored.
43
-
44
- ### Rule 2: Index Before Query
45
- Every WHERE, JOIN, ORDER BY column that does not already have an index MUST have a migration adding one before the feature ships.
46
-
47
- ```sql
48
- -- Migration checklist before deploy:
49
- -- 1. Identify all new WHERE clauses in the feature
50
- -- 2. Check EXPLAIN ANALYZE on representative data volume
51
- -- 3. Add indexes for any full-table scans
52
-
53
- CREATE INDEX CONCURRENTLY idx_orders_user_id ON orders(user_id);
54
- -- CONCURRENTLY avoids table lock in production
55
- ```
56
-
57
- **Index requirements:**
58
- - Foreign keys: always indexed
59
- - Columns used in WHERE with high cardinality: indexed
60
- - Composite indexes: column order matters (most selective first)
61
- - Unique constraints: also serve as indexes — declare explicitly
62
-
63
- ### Rule 3: Backward-Compatible Migrations
64
-
65
- Migrations run before code deploys in rolling deployments. The new schema MUST be compatible with both old and new application code simultaneously.
66
-
67
- **Safe migration sequence:**
68
-
69
- | Change | Safe? | Safe Method |
70
- |---|---|---|
71
- | Add nullable column | Yes | Single migration |
72
- | Add NOT NULL column | No | 3-step: add nullable → backfill → add constraint |
73
- | Rename column | No | 3-step: add new → copy data → remove old |
74
- | Remove column | No | 2-step: stop reading in code → migration to drop |
75
- | Add index | Yes (use CONCURRENTLY) | Single migration |
76
- | Drop index | Yes | Single migration |
77
- | Change column type | No | 3-step: add new → migrate data → remove old |
78
-
79
- **3-Step pattern for breaking changes:**
80
- ```sql
81
- -- Step 1 (Deploy A): Add new column as nullable
82
- ALTER TABLE users ADD COLUMN email_verified_at TIMESTAMP;
83
-
84
- -- Deploy new code that writes to both old and new column
85
-
86
- -- Step 2 (Deploy B): Backfill + add NOT NULL constraint
87
- UPDATE users SET email_verified_at = created_at WHERE email_verified_at IS NULL;
88
- ALTER TABLE users ALTER COLUMN email_verified_at SET NOT NULL;
89
-
90
- -- Deploy new code that only reads new column
91
-
92
- -- Step 3 (Deploy C): Remove old column (if applicable)
93
- ```
94
-
95
- ### Rule 4: Transactions for Multi-Step Mutations
96
- Any operation that writes to multiple tables or performs multiple writes to the same table MUST use a transaction.
97
-
98
- ```typescript
99
- // BAD — partial failure leaves data inconsistent
100
- await userRepo.save(user);
101
- await walletRepo.create({ userId: user.id, balance: 0 }); // if this fails, orphaned user
102
-
103
- // GOOD — atomic operation
104
- await db.transaction(async (trx) => {
105
- await userRepo.save(user, { transaction: trx });
106
- await walletRepo.create({ userId: user.id, balance: 0 }, { transaction: trx });
107
- });
108
- ```
109
-
110
- ### Rule 5: Never SELECT * in Application Code
111
- Always select specific columns to avoid:
112
- - Accidentally loading large TEXT/BLOB columns
113
- - Breaking when new columns are added to the schema
114
- - Leaking sensitive fields (passwords, tokens)
115
-
116
- ```typescript
117
- // BAD
118
- const users = await User.findAll(); // loads ALL columns
119
-
120
- // GOOD
121
- const users = await User.findAll({ attributes: ['id', 'name', 'email'] });
122
- ```
123
-
124
- ### Rule 6: Soft Deletes Need Index on deleted_at
125
- If using soft deletes (`deleted_at IS NULL` filter), that filter is on every query. Index it:
126
-
127
- ```sql
128
- CREATE INDEX idx_users_deleted_at ON users(deleted_at) WHERE deleted_at IS NULL;
129
- ```
130
-
131
- ---
132
-
133
- ## Migration Review Checklist
134
-
135
- Before merging any migration:
136
- - [ ] `CONCURRENTLY` used for new indexes on existing tables
137
- - [ ] NOT NULL columns have a default or backfill in the same migration
138
- - [ ] No column renames (use 3-step instead)
139
- - [ ] `EXPLAIN ANALYZE` run on production-scale data for new queries
140
- - [ ] Rollback plan documented (reverse migration or migration with inverse operation)
141
- - [ ] Migration is idempotent (safe to run twice: use `IF NOT EXISTS`, `IF EXISTS`)
142
-
143
- ---
144
-
145
- ## Iron Laws
146
-
147
- **IRON LAW 1: A query inside a loop is an N+1. Fix it before merging.**
148
- **IRON LAW 2: A NOT NULL column without a backfill migration will fail in production on deploy.**
149
- **IRON LAW 3: Multi-table writes without a transaction are a data integrity bug.**
13
+ 1. **No query per item** over a collection whose size the caller or the data decides: batch with `IN`, join or eager-load.
14
+ 2. **An index ships with the query.** A new `WHERE`, `JOIN` or `ORDER BY` column on a large table gets its index in the same change; foreign keys are indexed.
15
+ 3. **Migrations run before the rollout, so the schema works with the old and the new code at once:**
16
+ - a nullable column or a new table: one migration;
17
+ - a `NOT NULL` column: one migration with a constant `DEFAULT`; without one, add nullable, backfill, then add the constraint;
18
+ - rename or type change: add the new column, copy and write both, drop the old one later;
19
+ - dropping a column: stop reading it first, drop in a later release;
20
+ - an index on an existing table: `CREATE INDEX CONCURRENTLY`, outside a transaction; a table created in the same migration may use a plain index;
21
+ - every migration is re-runnable (`IF [NOT] EXISTS`) and has a down.
22
+ 4. **Writes that must change together run in one transaction** (several tables, or several rows of one).
23
+ 5. **Select the columns you need.** A raw row or `SELECT *` never goes to a client.
24
+ 6. **Soft-deleted entities** are deleted with the soft delete; a raw query on them adds `deleted_at IS NULL`.
150
25
 
151
26
  ---
152
27
 
153
- ## Red Flags — Stop and re-read this rule if you are thinking:
28
+ ## Review severities (shared with reviewers)
154
29
 
155
- | Rationalization | Why it's wrong |
156
- |---|---|
157
- | "The table is small, N+1 is fine for now" | Tables grow — N+1 that's "fine now" causes outages at 100k rows |
158
- | "I'll add the index after it's in production if it's slow" | Adding an index without CONCURRENTLY locks the table in production |
159
- | "The migration is simple, I don't need a rollback plan" | Every migration that fails in production requires a rollback — having no plan means downtime |
160
- | "NULL is fine, I'll add NOT NULL later" | Nullable columns become load-bearing nullability over time — enforce constraints early |
161
- | "SELECT * is easier during development" | SELECT * loaded to production is a query-time performance and security risk |
30
+ `review-backend`, `review-performance` and `review-highload` rate these patterns by this table. Change a row here, never in a reviewer.
162
31
 
163
- **IRON LAW: A MIGRATION THAT LOCKS A TABLE ON A BUSY PRODUCTION DATABASE IS A PLANNED OUTAGE.**
32
+ | Signal | A finding when | Default | Not a finding |
33
+ |---|---|---|---|
34
+ | Query per item in a loop (Rule 1) | the loop size is not fixed small | `major` when a frequency or hot path is named with the loop size; else `minor` | a fixed small list, or a one-off or startup path |
35
+ | New filter or sort column with no index (Rule 2) | the table is large or the query hot, named | `major`; else `minor`; `info` when the schema is not in the payload (say that reading the schema would settle it) | a small table |
36
+ | `NOT NULL` column with no default and no backfill (Rule 3) | the table can hold rows, or old code inserts into it | `major`; `blocker` only where wrong values or truncation are shown | a constant `DEFAULT` |
37
+ | Rename, type change or drop in one step (Rule 3) | code still running reads the old column | `major` | — |
38
+ | Non-concurrent index on an existing table (Rule 3) | the table is large or busy | `major`; else `minor` | a table created in the same migration |
39
+ | Writes that must change together without a transaction (Rule 4) | a named failure leaves a partial write | `major`; `blocker` where the partial write corrupts persisted state | — |
40
+ | Raw row or `SELECT *` returned to a client (Rule 5) | always | `major` when it exposes a column the contract does not have; else `minor` | — |
41
+ | Hard delete of a soft-deleted entity, raw query without `deleted_at IS NULL` (Rule 6) | always | `major` | — |
@@ -61,7 +61,7 @@ catch { /* best effort: a leftover temp file is swept by the next run */ }
61
61
  ```
62
62
 
63
63
  ### Rule 4: No unhandled promise rejections
64
- Every promise is awaited inside a `try/catch` or has a `.catch()`; a fire-and-forget call handles its own rejection. Examples are in `async-patterns.mdc` Rule 4.
64
+ Every promise is awaited inside a `try/catch` or has a `.catch()`; a fire-and-forget call handles its own rejection (`@typescript-eslint/no-floating-promises` enforces it).
65
65
 
66
66
  ### Rule 5: Keep the cause
67
67
  When catching and rethrowing, pass the original as `cause`. Do not both log and rethrow the same error in one `catch`: whoever handles it logs it.
@@ -79,6 +79,12 @@ Do not throw from an `assert` on input a caller can legitimately send. Validate
79
79
 
80
80
  ---
81
81
 
82
+ ## Iron Laws
83
+
84
+ **IRON LAW 1: A catch that hides a failure from a caller who then proceeds is forbidden.**
85
+ **IRON LAW 2: A failure is never signalled by a value a caller can read as success.**
86
+ **IRON LAW 3: A rethrow keeps the original error as `cause`.**
87
+
82
88
  ## Review severities (shared with reviewers)
83
89
 
84
90
  `review-clean-code`, `review-logic`, `review-backend` and `review-frontend` rate failure paths by this table and keep only framework-specific rows of their own (a NestJS exception type, a MobX store's `try/catch/finally`). Change a row here, never in a reviewer.
@@ -93,10 +99,3 @@ Do not throw from an `assert` on input a caller can legitimately send. Validate
93
99
  | `catch (err: any)` in TypeScript | always | `minor` | `catch (err: unknown)` |
94
100
 
95
101
  ---
96
-
97
- ## Iron Laws
98
-
99
- **IRON LAW 1: A catch that hides a failure from a caller who then proceeds is forbidden.**
100
- **IRON LAW 2: A failure is never signalled by a value a caller can read as success.**
101
- **IRON LAW 3: A rethrow keeps the original error as `cause`.**
102
- </content>
@@ -1,5 +1,5 @@
1
1
  ---
2
- description: "Frontend delivery guidelines for TypeScript, React, MobX, Ant Design, and Tailwind CSS."
2
+ description: "Frontend delivery rule for TypeScript, React, MobX, Ant Design and Tailwind CSS: the stack, which rule holds which standard, and the answer format. Use when implementing frontend features."
3
3
  alwaysApply: false
4
4
  globs:
5
5
  - "src/**/*.ts"
@@ -9,33 +9,18 @@ stack_requires: "react,mobx"
9
9
 
10
10
  # Frontend Assistant Guidelines
11
11
 
12
- ## Purpose
13
- Produce clean, maintainable, production-ready frontend code aligned with project architecture.
12
+ ## Stack
14
13
 
15
- ## When To Apply
16
- Apply when implementing features in the frontend project (TypeScript/React/MobX/Ant Design/Tailwind CSS).
14
+ TypeScript (strict), React, MobX, Ant Design for components, Tailwind CSS for layout and utilities, Axios for HTTP. Add no third-party dependency the stack already covers.
17
15
 
18
- ## Stack
19
- - TypeScript
20
- - React
21
- - MobX
22
- - Ant Design
23
- - Tailwind CSS
24
- - Axios
25
-
26
- ## Core Principles
27
- - Keep scope minimal and pragmatic.
28
- - Follow DRY and KISS.
29
- - Prefer explicit typing.
30
- - Keep business logic in stores/services, not in view components.
31
-
32
- ## Technical Rules
33
- - Use strict TypeScript types; avoid `any`.
34
- - Follow `core/mobx-store-template.mdc` for MobX store patterns.
35
- - Use Ant Design for components and Tailwind for layout/utilities.
36
- - Avoid unnecessary third-party dependencies.
37
-
38
- ## Output Contract
39
- - Final solutions must be Markdown.
40
- - Code must be in fenced code blocks with language labels.
41
- - Response language must match user query language.
16
+ ## Where the standard is
17
+
18
+ - Components, layers, state placement, accessibility and TypeScript: `code-style-patterns.mdc`.
19
+ - Stores: `mobx-store-template.mdc`.
20
+ - Stories: `storybook-guidelines.mdc`.
21
+
22
+ Each holds the severities reviewers use, so code written to these rules is what the reviewer checks.
23
+
24
+ ## Answer format
25
+
26
+ Code goes in fenced blocks with a language label; answer in the language of the question. Keep the change to what was asked.
@@ -0,0 +1,51 @@
1
+ ---
2
+ description: "Rendered-layout standard shared by code writers and reviewers, with the severities reviewers use: a layout claim is measured in a real layout engine, 320px is always a supported width, nothing clips or scrolls sideways at a supported width, identical data renders identical geometry in every locale, and a mirrored component mirrors entirely. Use when writing or reviewing flex/grid sizing, overflow, logical properties, RTL, or containers of translated text."
3
+ alwaysApply: false
4
+ globs:
5
+ - "**/*.tsx"
6
+ - "**/*.jsx"
7
+ - "**/*.vue"
8
+ - "**/*.svelte"
9
+ - "**/*.css"
10
+ - "**/*.scss"
11
+ - "**/*.html"
12
+ ---
13
+
14
+ # Layout Rendering
15
+
16
+ Canon applies: the CSS box model, Flexbox and Grid sizing (intrinsic and extrinsic sizing),
17
+ CSS Logical Properties, and WCAG 2.2 1.4.10 Reflow with its two-dimensional-content exception.
18
+ This rule holds only this project's decisions for rendered geometry. Taste and the UI tell
19
+ catalog are `ui-anti-slop.mdc`.
20
+
21
+ ## Rules
22
+
23
+ 1. **A layout claim is measured in a real layout engine.** The project's real-CSS tier
24
+ (Storybook, Playwright, a component-visual suite) or a probe that mounts the component and
25
+ reads computed CSS off the node. A DOM stub (happy-dom, jsdom) loads no stylesheet, so a
26
+ class assertion or a `getBoundingClientRect` there measures nothing. Measurements supplied
27
+ with the change count when they name the command and the viewport.
28
+ 2. **320px is always a supported width.** Other supported widths come from the project's own
29
+ list: `DESIGN.md`, the brief, the job context, or the hosts the product ships in. At every
30
+ supported width nothing is clipped and the page does not scroll sideways.
31
+ 3. **Identical data renders identical geometry in every locale.** A box sized by its own
32
+ labels is measured with the longest real translation in the catalog, not the English one.
33
+ 4. **A component that mirrors under RTL mirrors entirely.** Logical properties flip; a physical
34
+ gradient, shadow or transform in the same component is made logical or flipped explicitly.
35
+ Surfaces that do not mirror by platform practice (media controls and their seek bar, numbers,
36
+ code, phone numbers) keep `dir="ltr"` with the reason in a comment.
37
+
38
+ ---
39
+
40
+ ## Review severities (shared with reviewers)
41
+
42
+ `review-layout` rates these by this table, and `review-ui-ux` defers overflow and reflow to it.
43
+ Change a row here, never in a reviewer. A row counts only when the change touches the element.
44
+
45
+ | Signal | A finding when | Default | Not a finding |
46
+ |---|---|---|---|
47
+ | Element renders at 0px while its label shows (Rule 1) | at a supported width, measured | `major` | a width no supported host reaches (`info`) |
48
+ | Identical data renders different geometry per locale (Rule 3) | measured with the longest real translation in the catalog | `major` | — |
49
+ | Content clipped, or the page scrolls sideways (Rule 2) | at a supported width, 320px included, measured | `major` | content that needs two dimensions to read (data table, map, code block) scrolling inside its own region |
50
+ | Cosmetic offset (a few px off centre), or a physical gradient, shadow or transform that does not flip under RTL (Rule 4) | measured: a few px, or one direction named per locale | `minor` | a surface that does not mirror by platform practice, with its reason read |
51
+ | Any layout claim with no measurement (Rule 1) | always | `info` | — |