fullstack-critic 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,227 @@
1
+ # Full-Stack Critic
2
+
3
+ A free, universal senior engineering critic for any software project.
4
+ Install it as a package or drop it into any repository, and it reviews **100% of your
5
+ resources — every source file, package, and dependency** across 12 dimensions, finds real
6
+ issues with exact evidence, and returns a detailed report with a prioritised action plan
7
+ grouped into **FIX · OPTIMIZE · DELETE · ADD**.
8
+
9
+ **No account. No paid service. Zero runtime dependencies.**
10
+ Install with npm / pnpm / yarn / npx, or use it as an AI rubric with Composio,
11
+ Claude Code, Gemini CLI, GitHub Copilot, Cursor, Qoder, Antigravity, or any assistant.
12
+
13
+ ---
14
+
15
+ ## Install & run (no AI required)
16
+
17
+ > **Status: not yet on the public npm registry.** `npx fullstack-critic` and
18
+ > `npm i -g fullstack-critic` will `404` until this repo is published (`npm publish`).
19
+ > Until then, install **from this folder** — the commands below are tested and work.
20
+
21
+ ```bash
22
+ # From inside this folder — install the CLI globally so `critic` works in any project:
23
+ npm install -g . # or: npm link
24
+ # or install by path from anywhere:
25
+ npm install -g C:\path\to\fullstack-critic
26
+
27
+ # No install at all — run straight from the folder:
28
+ node bin\fullstack-critic.js review . # Windows
29
+ node bin/fullstack-critic.js review . # macOS / Linux
30
+ npx --yes /path/to/fullstack-critic review . # npx against a local folder/git
31
+ ```
32
+
33
+ ```bash
34
+ critic review . # one-shot review of code + packages + dependencies, with verdict
35
+ critic watch . # attach to an in-progress workflow: continuous feedback as you edit
36
+ critic init . # attach the AI rubric (.critic/ + .critic-memory/ + PROJECT_REVIEW.md)
37
+ critic audit . # run each detected package manager's own audit (npm audit, pip-audit…)
38
+ critic review . --md report.md --fail-on high # write a full report; fail CI on HIGH+
39
+ ```
40
+
41
+ `critic watch` re-analyses a few hundred ms after every change and prints only what
42
+ appeared (`+ NEW`) or was fixed (`- FIXED`), keeping a live `.critic-report.md`. It ignores
43
+ `node_modules`, build output, `.git`, and its own outputs. Full guide: [`docs/GETTING_STARTED.md`](docs/GETTING_STARTED.md).
44
+
45
+ ---
46
+
47
+ ## Use it as an AI rubric instead
48
+
49
+ ```bash
50
+ # Recommended: git submodule (keeps your working tree clean)
51
+ git submodule add https://github.com/amansingh79033-ship-it/fullstack-critic .critic
52
+
53
+ # Or a plain clone into a subfolder, or run `critic init .` to do this for you
54
+ git clone https://github.com/amansingh79033-ship-it/fullstack-critic .critic
55
+ ```
56
+
57
+ Then tell your AI:
58
+
59
+ ```
60
+ Read .critic/CRITIC.md and do a full review of this project.
61
+ ```
62
+
63
+ The critic attaches passively. REVIEW mode is read-only — it never touches your source files,
64
+ starts no processes, and does not affect any running dev server, CI job, or coding session.
65
+ FIX mode only changes files you explicitly ask it to fix.
66
+
67
+ **Minimum required files** (if you only want to copy, not clone):
68
+ - `CRITIC.md` — the core rubric
69
+ - `layers/manifest.md` — layer selection guide
70
+
71
+ ---
72
+
73
+ ## What it reviews — 12 dimensions, every project
74
+
75
+ | # | Dimension | What gets checked |
76
+ |---|-----------|-------------------|
77
+ | 1 | **Correctness** | Logic errors, race conditions, null handling, boundary cases, error propagation |
78
+ | 2 | **Security** | Injection, broken auth, IDOR, XSS/CSRF/SSRF, secrets, CVEs, data exposure |
79
+ | 3 | **Architecture** | Separation of concerns, coupling, patterns, config discipline, dead abstractions |
80
+ | 4 | **API design** | HTTP semantics, versioning, validation, error shapes, rate limiting |
81
+ | 5 | **Backend** | Blocking I/O, timeouts, retry logic, connection pools, graceful shutdown |
82
+ | 6 | **Database** | Missing indexes, N+1 queries, unbounded queries, transactions, migrations |
83
+ | 7 | **Frontend** | Bundle size, code splitting, render performance, Core Web Vitals, accessibility |
84
+ | 8 | **Performance** | Bottlenecks, cache strategy, horizontal scaling blockers, resource leaks |
85
+ | 9 | **Code quality** | Dead code, duplication, magic values, naming, complexity, stale comments |
86
+ | 10 | **Testing** | Coverage gaps, test quality, missing test types, logging, metrics, alerting |
87
+ | 11 | **Infrastructure** | Environment parity, secrets management, rollback, CI pipeline completeness |
88
+ | 12 | **Enterprise practices** | Idempotency, audit trails, multi-tenancy isolation, pagination, documentation |
89
+
90
+ ---
91
+
92
+ ## Modes
93
+
94
+ | Mode | Command to your AI | What happens |
95
+ |------|--------------------|--------------|
96
+ | `REVIEW` | `"Review this project"` | Full read-only assessment — no file changes |
97
+ | `FIX` | `"Fix the issues you found"` | Targeted fixes for confirmed issues — minimal diffs |
98
+ | `OPTIMIZE` | `"Optimize performance"` | Performance, bundle, query, and resource improvements |
99
+ | `CLEAN` | `"Clean dead code"` | Remove unused code, debug logs, stale TODOs |
100
+ | `VERIFY` | `"Verify the fixes"` | Tests and checks that confirm fixes work |
101
+ | `FULL` | `"Full review and fix"` | All modes in sequence — report after each phase |
102
+
103
+ ---
104
+
105
+ ## Quick start
106
+
107
+ **Composio** (native — full autonomous GitHub read/write)
108
+ ```
109
+ Read .critic/CRITIC.md and .critic/agent/fullstack-critic-agent.md.
110
+ Connect GitHub via COMPOSIO_MANAGE_CONNECTIONS.
111
+ Run a FULL review of [repository name].
112
+ ```
113
+
114
+ **Claude Code**
115
+ ```
116
+ Read .critic/CRITIC.md. Use Glob to map the project.
117
+ Use Grep before opening any file. Use TodoWrite for each finding.
118
+ Do a REVIEW of this project — do not modify any files.
119
+ ```
120
+
121
+ **Gemini CLI**
122
+ ```
123
+ @.critic/CRITIC.md
124
+ Review this project. Load layers from .critic/layers/manifest.md.
125
+ Use grep before reading files. Summarise before switching layers.
126
+ ```
127
+
128
+ **Any IDE AI (Copilot, Cursor, Qoder, Antigravity)**
129
+ ```
130
+ Read .critic/CRITIC.md then do a full REVIEW of this project.
131
+ Cover all 12 dimensions. Cite exact file and line for every finding.
132
+ Do not modify any files.
133
+ ```
134
+
135
+ ---
136
+
137
+ ## Optional: give the AI context about your project
138
+
139
+ Copy `PROJECT_REVIEW.md` into your project root (not `.critic/`) and fill it in.
140
+ The AI reads it first and calibrates the review to your stack, scale target, and known risks.
141
+
142
+ ```bash
143
+ cp .critic/PROJECT_REVIEW.md ./PROJECT_REVIEW.md
144
+ # Edit the file, then run your review
145
+ ```
146
+
147
+ ---
148
+
149
+ ## File structure
150
+
151
+ ```
152
+ package.json ← npm/pnpm package — bin: critic / fullstack-critic (zero deps)
153
+ bin/
154
+ fullstack-critic.js ← CLI entry point
155
+ src/
156
+ cli.js ← review / watch / init / audit router
157
+ analyzer.js rules.js ← 12-dimension code analysis engine
158
+ deps.js ← package & dependency analysis (every ecosystem)
159
+ report.js ← markdown report + FIX/OPTIMIZE/DELETE/ADD action plan
160
+ watcher.js ← continuous background review
161
+ init.js util.js index.js ← attach-to-project, fs walk, programmatic API
162
+ CRITIC.md ← Core rubric — always read first
163
+ CLAUDE.md ← Claude Code and claude.ai specifics
164
+ GEMINI.md ← Gemini CLI specifics
165
+ AGENTS.md ← Universal entry point — any AI, any IDE
166
+ PROJECT_REVIEW.md ← Template: copy into your project root
167
+ agent/
168
+ fullstack-critic-agent.md ← Composio agent contract
169
+ layers/
170
+ manifest.md ← Layer selection table and dependency rules
171
+ transactional-domain.md ← Domain layer: payments, orders, inventory, state machines
172
+ memory/
173
+ templates/ ← Bootstrap templates for .critic-memory/ on first run
174
+ PROJECT_PROFILE.md DECISIONS.md REVIEW_HISTORY.md RUN_STATE.md
175
+ prompts/
176
+ composio-upgrade-agent.md ← Composio prompt that upgrades this repo itself
177
+ docs/
178
+ GETTING_STARTED.md ← Install + CLI + watch guide
179
+ tests/
180
+ critic.test.js ← zero-dependency self-tests (node --test)
181
+ ```
182
+
183
+ ---
184
+
185
+ ## Session memory
186
+
187
+ On first run in a project, the AI creates `.critic-memory/` in your project root
188
+ using the templates in `memory/templates/`. This records what the AI learned about
189
+ your project — architecture, past decisions, review history — so future sessions
190
+ start with context instead of re-discovering everything.
191
+
192
+ Add `.critic-memory/` to your `.gitignore`, or commit it — your choice.
193
+ **Never store credentials, API keys, tokens, or PII in memory files.**
194
+
195
+ ---
196
+
197
+ ## Composio native setup
198
+
199
+ The Composio agent reads and writes your GitHub repository directly using
200
+ Composio's GitHub toolkit — no local git operations required.
201
+
202
+ ```
203
+ 1. Open or create a Composio workspace
204
+ 2. Load agent/fullstack-critic-agent.md as the agent system prompt
205
+ 3. Connect GitHub via COMPOSIO_MANAGE_CONNECTIONS
206
+ 4. Pass the repository to review
207
+ 5. Run a request from the "Quick start" section above
208
+ ```
209
+
210
+ See `docs/GETTING_STARTED.md` for full Composio setup instructions.
211
+
212
+ ---
213
+
214
+ ## Contributing
215
+
216
+ Pull requests welcome. If you add a new domain layer (e.g. `ml-pipeline.md`,
217
+ `mobile.md`, `embedded.md`, `data-pipeline.md`), follow the format in
218
+ `layers/transactional-domain.md`. Every check must be universal — no assumptions
219
+ about a specific framework, language, cloud provider, or business domain.
220
+
221
+ To run the upgrade agent on this repo itself, see `prompts/composio-upgrade-agent.md`.
222
+
223
+ ---
224
+
225
+ ## License
226
+
227
+ MIT — free to use, modify, and distribute.
@@ -0,0 +1,125 @@
1
+ # Full-Stack Critic — Composio Agent Contract
2
+
3
+ You are a senior full-stack engineering agent operating inside a Composio workspace.
4
+ Read `CRITIC.md` fully before doing anything else. It defines every check, every mode,
5
+ and every output format. This file only adds Composio-specific tool guidance on top.
6
+
7
+ ---
8
+
9
+ ## Attaching to a project — zero impact on running sessions
10
+
11
+ The critic attaches passively. It reads; it does not write unless you explicitly run
12
+ FIX, CLEAN, or FULL mode. No running process, CI job, or active coding session is
13
+ affected by attaching or running a REVIEW.
14
+
15
+ To connect the critic to a repository in Composio:
16
+ 1. Open or create a Composio workspace.
17
+ 2. Load this agent contract (`agent/fullstack-critic-agent.md`) as the agent system prompt.
18
+ 3. Ensure GitHub is connected via `COMPOSIO_MANAGE_CONNECTIONS`.
19
+ 4. Select or pass the repository to review.
20
+ 5. Run a request using the mode commands in `AGENTS.md`.
21
+
22
+ ---
23
+
24
+ ## Composio tool discipline
25
+
26
+ **Discovery**
27
+ ```
28
+ COMPOSIO_SEARCH_TOOLS → find GITHUB_* tools needed for this task
29
+ GITHUB_GET_REPOSITORY → confirm access and read repo metadata
30
+ GITHUB_LIST_REPO_CONTENTS → map directory structure before reading files
31
+ ```
32
+
33
+ **Reading files (always fetch SHA — required for updates)**
34
+ ```
35
+ GITHUB_GET_FILE_CONTENTS → read a file and capture its SHA
36
+ ```
37
+ Never read `node_modules`, `dist`, `.next`, `build`, `.git`, `coverage`, or vendor directories.
38
+ Use `COMPOSIO_REMOTE_WORKBENCH` with Python `grep`/`glob` to locate symbols before reading whole files.
39
+
40
+ **Layer discipline**
41
+ - Load one primary layer at a time using `layers/manifest.md`.
42
+ - Maximum 15 files per active layer.
43
+ - Summarise findings in the workbench before switching layers.
44
+ - State the evidence that justifies loading a second layer.
45
+
46
+ **Validation (before every write)**
47
+ Run in `COMPOSIO_REMOTE_WORKBENCH`:
48
+ ```python
49
+ # Check markdown validity — no unclosed fences, no broken tables
50
+ # Check CRITIC.md contains all 12 dimension headings
51
+ # Check no file contains domain-specific terms that make it non-universal
52
+ # Report any failure before proceeding to write
53
+ ```
54
+
55
+ **Writing files (FIX and FULL modes only)**
56
+ ```
57
+ GITHUB_CREATE_OR_UPDATE_FILE_CONTENTS → write file (requires SHA from prior GET)
58
+ ```
59
+ Every write must:
60
+ - Use the SHA captured from `GITHUB_GET_FILE_CONTENTS` of the same file
61
+ - Contain the minimum change that fixes the confirmed issue
62
+ - Be followed by a verification step recorded in `.critic-memory/DECISIONS.md`
63
+
64
+ **Committing**
65
+ ```
66
+ GITHUB_CREATE_COMMIT → single commit per session with a descriptive message
67
+ ```
68
+ Never use force push, branch deletion, or rebase without explicit instruction.
69
+
70
+ ---
71
+
72
+ ## Agent workflow
73
+
74
+ ```
75
+ READ CRITIC.md
76
+ READ PROJECT_REVIEW.md (if present)
77
+ SELECT primary layer from layers/manifest.md
78
+ IMPORT files for that layer (GITHUB_GET_FILE_CONTENTS × N)
79
+ WORK through CRITIC.md checks for the active layer
80
+ STAGE findings in COMPOSIO_REMOTE_WORKBENCH scratchpad
81
+ SUMMARISE findings before layer switch
82
+ DISCARD active file context
83
+ REPEAT for required dependent layers
84
+ EXPORT final report
85
+ UPDATE .critic-memory/ files
86
+ ```
87
+
88
+ ---
89
+
90
+ ## Example requests
91
+
92
+ **REVIEW**
93
+ ```
94
+ Read .critic/CRITIC.md. Review the checkout API in this repository.
95
+ Start with the api layer. Load only the route, schema, middleware, and focused tests.
96
+ Load backend or database chunks only when evidence requires it.
97
+ Summarise and discard each layer before switching.
98
+ Do not modify any files. Return findings with exact file and line references.
99
+ ```
100
+
101
+ **FIX**
102
+ ```
103
+ Read .critic/CRITIC.md. Fix the BLOCKER and CRITICAL issues from the last review.
104
+ Use GITHUB_GET_FILE_CONTENTS to read each file and capture its SHA before writing.
105
+ Make the smallest change that fixes each issue. Record every fix in DECISIONS.md.
106
+ Run verification checks in COMPOSIO_REMOTE_WORKBENCH before committing.
107
+ ```
108
+
109
+ **FULL**
110
+ ```
111
+ Read .critic/CRITIC.md. Run a FULL review and fix of this repository.
112
+ Phase 1: REVIEW all 12 dimensions. Report with exact evidence.
113
+ Phase 2: FIX all BLOCKERs and CRITICALs. Record diffs and verification steps.
114
+ Phase 3: CLEAN dead code and debug logs. Minimal changes only.
115
+ Phase 4: VERIFY by describing the exact test, lint, and type check for each fix.
116
+ Commit all changes with a descriptive message. Update .critic-memory/ at session end.
117
+ ```
118
+
119
+ ---
120
+
121
+ ## Performance target
122
+
123
+ Assess realistic capacity and identify the primary bottleneck.
124
+ Never state that a system supports a specific throughput target without
125
+ load-test evidence recorded in `PROJECT_REVIEW.md` or `.critic-memory/REVIEW_HISTORY.md`.
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+ const code = require('../src/cli').run(process.argv.slice(2));
4
+ process.exitCode = Number.isFinite(code) ? code : 0;
@@ -0,0 +1,145 @@
1
+ # Getting Started — Full-Stack Critic
2
+
3
+ Full-Stack Critic reviews **100% of a project's resources** — every source file, every
4
+ package, and every dependency — across the 12 engineering dimensions in
5
+ [`CRITIC.md`](./CRITIC.md), then produces a detailed report with a prioritised action plan
6
+ grouped into **FIX · OPTIMIZE · DELETE · ADD**.
7
+
8
+ It ships two ways to use it:
9
+
10
+ 1. **As a CLI package** (this guide) — run a one-shot `review`, or a continuous `watch`
11
+ that keeps giving feedback as you code, no AI assistant required.
12
+ 2. **As an AI rubric** — clone it next to your project and tell any AI assistant
13
+ (`Claude Code`, `Gemini CLI`, `Cursor`, `Copilot`, `Qoder`, …) to read `CRITIC.md`.
14
+ See the [README](../README.md) for the AI flow.
15
+
16
+ ---
17
+
18
+ ## Install
19
+
20
+ The CLI is a zero-dependency Node package (Node ≥ 18).
21
+
22
+ > **Not published to the public npm registry yet.** So `npx fullstack-critic` and
23
+ > `npm i -g fullstack-critic` return **404** until this repo is published with `npm publish`.
24
+ > Use one of the tested local methods below instead.
25
+
26
+ ```bash
27
+ # A) Global install from this folder — makes `critic` available in every project:
28
+ cd fullstack-critic
29
+ npm install -g . # equivalent: npm link
30
+
31
+ # B) Install by absolute path from anywhere:
32
+ npm install -g C:\path\to\fullstack-critic
33
+
34
+ # C) No install — run straight from the folder:
35
+ node bin/fullstack-critic.js review .
36
+
37
+ # D) pnpm / yarn equivalents:
38
+ pnpm add -g ./fullstack-critic
39
+ yarn global add file:./fullstack-critic
40
+ ```
41
+
42
+ > To make `npx fullstack-critic` / `npm i -g fullstack-critic` work for everyone,
43
+ > a maintainer must run `npm publish` from this folder first (see “Publishing”).
44
+
45
+ Once installed it provides the `critic` (and `fullstack-critic`) command.
46
+
47
+ ---
48
+
49
+ ## Commands
50
+
51
+ ```bash
52
+ critic review [path] # one-shot full review across all 12 dimensions
53
+ critic watch [path] # attach to an in-progress workflow; continuous feedback on every change
54
+ critic init [path] # attach the AI rubric: copies .critic/ + scaffolds .critic-memory/ + PROJECT_REVIEW.md
55
+ critic audit [path] # run each detected package manager's native audit (npm audit, pip-audit, govulncheck, …)
56
+ ```
57
+
58
+ ### One-shot review
59
+
60
+ ```bash
61
+ cd your-project
62
+ critic review . # console summary + verdict
63
+ critic review . --md report.md # also write the full markdown report
64
+ critic review . --json findings.json # machine-readable findings
65
+ critic review . --fail-on high # exit code 1 if any HIGH+ (use in CI)
66
+ ```
67
+
68
+ ### Watch mode — feedback while you code
69
+
70
+ ```bash
71
+ critic watch ./src
72
+ ```
73
+
74
+ Watches every file, and a few hundred ms after each edit it re-runs the analysis and
75
+ prints only what **appeared** (`+ NEW …`) or got **fixed** (`- FIXED …`), and keeps a live
76
+ report at `.critic-report.md`. New directories are picked up automatically; it ignores
77
+ `node_modules`, build output, `.git`, and its own report files. Ctrl+C to stop.
78
+
79
+ Run it in the background alongside your dev server so it "keeps interacting in the backend":
80
+
81
+ ```bash
82
+ critic watch . --md CRITIC_REPORT.md & # unix
83
+ start /b critic watch . # windows
84
+ ```
85
+
86
+ ---
87
+
88
+ ## Flags
89
+
90
+ | Flag | Effect |
91
+ |------|--------|
92
+ | `--md <path>` | write the full markdown report (watch default: `.critic-report.md`) |
93
+ | `--json <path>` | emit machine-readable findings |
94
+ | `--fail-on <level>` | `blocker\|critical\|high\|medium\|low\|never` — exit 1 at that severity (default `critical`) |
95
+ | `--no-code` | skip code line-scanning (dependencies + structure only) |
96
+ | `--debounce <ms>` | watch settle time (default 400) |
97
+ | `--quiet` | print only the summary line |
98
+
99
+ ---
100
+
101
+ ## What "100% of resources" means here
102
+
103
+ Every run prints a **Coverage** block that accounts for every resource it touched:
104
+
105
+ - every non-ignored source file is line-scanned (and the count is reported);
106
+ - every skipped resource (dependency dirs, build output, binaries, oversized files, VCS)
107
+ is **counted with a reason** — nothing is dropped silently;
108
+ - every dependency manifest found (npm, pip, poetry, pipenv, Go, Cargo, Composer, Bundler,
109
+ Maven, Gradle) is parsed for declared packages, lock files, and unpinned versions;
110
+ - any of the 12 dimensions with no automated signal is named explicitly so you know the
111
+ AI/manual pass from `CRITIC.md` is still required for it.
112
+
113
+ ---
114
+
115
+ ## Suppress a false positive
116
+
117
+ Add `// critic-ignore` at the end of a line, or `/* critic-ignore-file */` in the first two
118
+ lines of a file (useful for files that *define* detection patterns).
119
+
120
+ ---
121
+
122
+ ## Publishing (to enable `npx fullstack-critic`)
123
+
124
+ The package is intentionally **not** on the public registry until a maintainer publishes it.
125
+ Once you want `npm i -g fullstack-critic` / `npx fullstack-critic` to work for everyone:
126
+
127
+ npm **requires two-factor authentication to publish**. 2FA-bypass access tokens are
128
+ being deprecated by npm, so `npm publish` fails with `E403 ... Two-factor authentication`
129
+ unless 2FA is active on the account. Do this once:
130
+
131
+ ```bash
132
+ npm login
133
+ # enable 2FA (authenticator app) at https://www.npmjs.com/settings/~/two-factor
134
+ npm publish --access public --otp=123456 # live 6-digit code from your app
135
+ ```
136
+
137
+ After that, the registry-install commands in “Install” above become valid as written.
138
+ Until then, use the local `npm install -g .` / `npm link` / `node bin/...` methods.
139
+
140
+ Troubleshooting:
141
+ - `E403 … Two-factor authentication … required` → 2FA not active, or the `--otp`
142
+ code expired; generate a fresh code and retry.
143
+ - `E401`/`E404` right after a bad `npm config set //registry.npmjs.org/:_authToken=…`
144
+ → the login token was overwritten; run
145
+ `npm config delete //registry.npmjs.org/:_authToken` then `npm login` again.
@@ -0,0 +1,68 @@
1
+ # Semantic Layer Manifest
2
+
3
+ Load only the smallest context that answers the current question.
4
+ A layer is a temporary working set — not the whole codebase.
5
+ Record the active layer in `.critic-memory/RUN_STATE.md` before loading.
6
+
7
+ ---
8
+
9
+ ## Layer table
10
+
11
+ | Layer | Load when reviewing | What to load |
12
+ |------------------|------------------------------------------------------------------|--------------|
13
+ | `discovery` | Unknown project — mapping structure and architecture | README, package.json / go.mod / requirements.txt / Cargo.toml, main entrypoints, directory tree, deployment config |
14
+ | `api` | Routes, endpoints, request/response contracts, middleware | Route files, controllers, request schemas, response serialisers, middleware chain, API tests, OpenAPI spec |
15
+ | `backend` | Business logic, service layer, workers, concurrency | Service classes, handlers, queue consumers, background jobs, external API clients, focused unit tests |
16
+ | `database` | Queries, indexes, migrations, transactions, ORM models | Repository layer, ORM models, raw SQL files, migration files, query tests |
17
+ | `cache-queue` | Caching, message queues, background job scheduling | Cache adapters, Redis/Memcached config, producers, consumers, retry config, dead-letter setup |
18
+ | `frontend` | UI components, state management, rendering, browser performance | Affected components, custom hooks, stores, API client wrappers, CSS critical path, frontend tests |
19
+ | `api-client` | How a frontend or service calls an API | Fetch/axios wrappers, SDK usage, request interceptors, error handling, retry logic on client side |
20
+ | `auth` | Authentication, authorisation, sessions, tokens, permissions | Auth middleware, guards/decorators, policy files, token generation and validation, session config, auth tests |
21
+ | `security` | Full threat surface: injection, secrets, trust boundaries | Validators, sanitisers, auth middleware, secret config, dependency manifests (package-lock, Pipfile.lock) |
22
+ | `infra` | Deployment, scaling, CI/CD, networking, observability | Dockerfile, docker-compose, Kubernetes manifests, Terraform/Pulumi, CI config, alert rules, dashboards |
23
+ | `testing` | Test strategy, coverage quality, missing test types | Unit, integration, e2e, load test files directly relevant to the current finding |
24
+ | `performance` | Latency, throughput, memory, profiling, bundle size | Hot path code, benchmark scripts, query explain plans, bundle analyser output, metrics config |
25
+ | `architecture` | System design, module boundaries, dependency graph | Entrypoints, module index files, DI container config, interface definitions, ADRs |
26
+ | `transactional` | Orders, payments, reservations, inventory, state machines | See `layers/transactional-domain.md` for full chunk list |
27
+
28
+ ---
29
+
30
+ ## Loading algorithm
31
+
32
+ ```
33
+ 1. Classify the request → pick the primary layer
34
+ 2. Use glob/find/grep to locate the specific files — never guess paths
35
+ 3. Load symbols and line ranges rather than whole files where possible
36
+ 4. Record active files in .critic-memory/RUN_STATE.md
37
+ 5. Find evidence → follow it to a second layer only when required
38
+ 6. Summarise confirmed findings before switching
39
+ 7. Discard the previous layer's file context
40
+ 8. Load the next layer → repeat until task complete
41
+ ```
42
+
43
+ ---
44
+
45
+ ## Layer dependency rules
46
+
47
+ Follow a dependency only when you have specific evidence from the primary layer.
48
+ State the evidence explicitly before loading the dependent layer.
49
+
50
+ | Primary layer | Evidence type | Then load |
51
+ |---|---|---|
52
+ | `api` | Service call found in route | → `backend` |
53
+ | `api` | DB query or ORM call found | → `database` |
54
+ | `api` | Auth decision point found | → `auth` |
55
+ | `backend` | Persistence call found | → `database` |
56
+ | `backend` | Cache read/write found | → `cache-queue` |
57
+ | `frontend` | API contract mismatch suspected | → `api-client` → `api` |
58
+ | `performance` | Slow query identified | → `database` |
59
+ | `performance` | Large bundle identified | → `frontend` |
60
+ | `security` | Injection vector in route | → `api` |
61
+ | `security` | Secret in config or env | → `infra` |
62
+ | `transactional` | Persistence concern | → `database` |
63
+ | `transactional` | Queue/retry concern | → `cache-queue` |
64
+ | `auth` | Permission enforced in route | → `api` |
65
+ | `auth` | Session stored in DB | → `database` |
66
+
67
+ Do not load `infra`, `testing`, or `architecture` unless the finding explicitly requires them.
68
+ Do not load more than two layers concurrently without justification in the run state.
@@ -0,0 +1,88 @@
1
+ # Transactional Domain Layer
2
+
3
+ Load when the project involves: orders, payments, reservations, bookings, subscriptions,
4
+ inventory management, cart/checkout, refunds, cancellations, or any state machine where
5
+ a write failure has real-world financial or resource consequences.
6
+
7
+ Universal layer — applies to e-commerce, SaaS billing, ticketing, booking, marketplaces,
8
+ financial tools, and any system where committed resources cannot simply be discarded.
9
+
10
+ ---
11
+
12
+ ## Chunks to load
13
+
14
+ Load only the chunks relevant to the current finding, not all at once.
15
+
16
+ | Chunk | What to include |
17
+ |-------|-----------------|
18
+ | Order / reservation service | Creation, confirmation, hold, expiry handlers |
19
+ | Payment client | Authorisation, capture, webhook handler, reconciliation job |
20
+ | Refund / cancellation flow | Cancel handler, refund trigger, partial refund logic |
21
+ | Inventory / capacity service | Availability query, decrement, lock, release, overbooking guard |
22
+ | State machine | Status definitions, transition guards, terminal states |
23
+ | Background jobs | Hold expiry, refund retry, reconciliation, notification dispatch |
24
+ | Focused tests | Tests for the above only — no unrelated files |
25
+
26
+ ---
27
+
28
+ ## Checks
29
+
30
+ ### Idempotency
31
+ - Is order/reservation creation idempotent on retry? What is the idempotency key?
32
+ - If the payment provider webhook fires twice, is the order confirmed once or twice?
33
+ - Is the cancel/refund endpoint safe to call more than once without double-refunding?
34
+ - Are background jobs safe to run concurrently on two worker processes?
35
+
36
+ ### Atomicity and race conditions
37
+ - Is inventory decrement and order creation in a single DB transaction?
38
+ - Can two concurrent requests claim the last unit of stock?
39
+ - Is there a DB-level lock (`SELECT FOR UPDATE`, unique constraint, optimistic version) — not just application-level logic?
40
+ - If a hold is created but payment fails, is the hold guaranteed to release regardless of how payment fails?
41
+
42
+ ### Payment flow
43
+ - Is authorisation separated from capture? At what point does capture fire?
44
+ - If capture fails after inventory is committed, what is the exact recovery path?
45
+ - Are payment provider webhooks verified by HMAC/signature before any state change?
46
+ - Is the refund amount recomputed server-side, or trusted from the incoming webhook or client request?
47
+ - Are partial captures handled correctly (group orders, multi-item baskets)?
48
+
49
+ ### State machine integrity
50
+ - List every possible status value. Are all terminal states explicitly defined?
51
+ - Are invalid transitions guarded? Can a `cancelled` order be `confirmed`?
52
+ - Is every transition logged with timestamp, actor identity, and reason?
53
+ - If a state write fails mid-transition, is there a compensating transaction or a recovery job?
54
+
55
+ ### Inventory and capacity
56
+ - Does availability check query the DB on every request, or is it cached?
57
+ - If cached: what is the TTL, what invalidates it, can a cache stampede oversell inventory?
58
+ - Is the overbooking guard at the DB level (constraint) or only application level?
59
+ - What happens to in-flight transactions during a DB failover or primary/replica lag?
60
+
61
+ ### Cancellation and refunds
62
+ - Are cancellation fee rules (time windows, penalties) enforced server-side only?
63
+ - Is the refund triggered synchronously, or queued? What happens if the queue is down?
64
+ - Is there a reconciliation job that detects queued refunds that never executed?
65
+ - Is there a time-lock preventing cancellation after a point of no return (e.g. after dispatch)?
66
+
67
+ ### Notifications and side effects
68
+ - Are emails, webhooks, and push notifications sent after the DB transaction commits — never before?
69
+ - If a notification send fails, does it roll back the transaction, or is it retried independently?
70
+ - Can duplicate notifications be sent on retry (duplicate email on order confirm)?
71
+
72
+ ---
73
+
74
+ ## Extra report sections when this layer is active
75
+
76
+ Append these sections after the standard Findings block:
77
+
78
+ ### Transactional Integrity Review
79
+ Atomicity, idempotency, and race condition findings with exact file:line references.
80
+
81
+ ### Payment Flow Review
82
+ Authorisation, capture, webhook verification, and refund logic findings.
83
+
84
+ ### Inventory and Capacity Review
85
+ Availability query strategy, cache risk, overbooking exposure, estimated failure rate at peak load.
86
+
87
+ ### State Machine Review
88
+ State graph completeness, invalid transition risks, audit trail sufficiency.
@@ -0,0 +1,20 @@
1
+ # Decisions
2
+
3
+ <!-- One entry per confirmed and applied fix. Written by the AI in FIX or FULL mode. -->
4
+ <!-- Never store credentials, tokens, API keys, PII, passwords, or raw log data here. -->
5
+
6
+ ## Entry format
7
+
8
+ ```
9
+ ### YYYY-MM-DD — Short title
10
+
11
+ - **Decision:** What was changed and why.
12
+ - **Location:** path/to/file:line
13
+ - **Rationale:** Why this approach over alternatives.
14
+ - **Trade-offs:** What was accepted, deferred, or out of scope.
15
+ - **Verified by:** test name, lint output, type check, or manual step description.
16
+ ```
17
+
18
+ ---
19
+
20
+ <!-- AI writes entries below this line -->