Code Review
Review code changes against Open Mercato architecture rules, security requirements, and quality standards.
Review Workflow
- Scope: Identify changed files. Classify by layer (entity, API route, validator, backend page, subscriber, worker, command, widget).
- Gather context: Read
AGENTS.md for module conventions. Check .ai/specs/ for active specs. Read .ai/lessons.md for known pitfalls.
- CI/CD verification gate (MANDATORY): Run the checks below. Every gate MUST pass. See CI/CD Gate section.
- Run checklist: Apply rules from
references/review-checklist.md. Flag violations with severity, file, and fix suggestion.
- Test coverage: Verify changed behavior is covered by tests. Flag missing coverage.
- Cross-module impact: If the change touches events, extensions, or widgets, verify consumers handle the contract correctly.
- Output: Produce the review report.
CI/CD Verification Gate (MANDATORY)
NEVER claim code is "ready to merge" without running these checks. If any step fails, it MUST be fixed before the review can pass.
| # |
Command |
What it checks |
If it fails |
| 1 |
yarn generate |
Module registries are up to date |
Run it — it generates missing files |
| 2 |
yarn typecheck |
TypeScript types are correct |
Fix type errors |
| 3 |
yarn test |
All unit tests pass |
Fix failing tests |
| 4 |
yarn build |
The app builds successfully |
Fix build errors |
Rules:
- Steps 2 and 3 can run in parallel.
- Every failure is a Critical finding — even if it appears unrelated to the current changes.
- The review output MUST include actual pass/fail results. Do not assume — run and report.
Output Format
# Code Review: {change description}
## Summary
{1-3 sentences: what the change does, overall assessment}
## CI/CD Verification
| Gate | Status | Notes |
|------|--------|-------|
| `yarn generate` | PASS/FAIL | |
| `yarn typecheck` | PASS/FAIL | |
| `yarn test` | PASS/FAIL | |
| `yarn build` | PASS/FAIL | |
## Findings
### Critical
{Security, data integrity, tenant isolation violations}
### High
{Architecture violations, missing required exports}
### Medium
{Convention violations, suboptimal patterns}
### Low
{Suggestions, minor improvements}
## Checklist
{From references/review-checklist.md — mark [x] passing, [ ] failing with explanation}
Omit empty severity sections.
Severity Classification
| Severity |
Criteria |
Action |
| Critical |
Security vulnerability, cross-tenant leak, data corruption, missing auth |
MUST fix before merge |
| High |
Architecture violation, missing required export, broken module contract |
MUST fix before merge |
| Medium |
Convention violation, suboptimal pattern, missing best practice |
Should fix |
| Low |
Style suggestion, minor improvement |
Nice to have |
Quick Rule Reference
Architecture
- NO direct ORM relationships between modules — use FK IDs, fetch separately
- Always filter by
organization_id for tenant-scoped entities
- Use DI (Awilix) to inject services — never
new directly
- NO direct module-to-module calls for side effects — use events
- Cross-module data: use extension entities +
data/extensions.ts
Security
- Validate all inputs with zod in
data/validators.ts
- Use
findWithDecryption instead of raw em.find/em.findOne
- Hash passwords with bcryptjs (cost >= 10) — never log credentials
- Every endpoint MUST declare auth guards (
requireAuth, requireRoles, requireFeatures)
Data Integrity
- Migration files and snapshots must match entity intent — prefer
yarn db:generate; scoped manual SQL is allowed only to avoid unrelated generated churn and must include .snapshot-open-mercato.json
- Validate migration scope — autogenerated doesn't mean correct
- Workers/subscribers MUST be idempotent
- Commands MUST be undoable — include before/after snapshots
Naming
- Modules: plural, snake_case (folders and
id)
- JS/TS identifiers: camelCase
- Database: snake_case, table names plural
- Standard columns:
id, created_at, updated_at, deleted_at, is_active, organization_id
UI & HTTP
- Forms:
CrudForm — never custom
- Tables:
DataTable — never manual markup
- Notifications:
flash() — never alert() or custom toast
- API calls:
apiCall/apiCallOrThrow — never raw fetch
- Dialogs:
Cmd/Ctrl+Enter (submit), Escape (cancel)
pageSize MUST be <= 100
Code Quality
- No
any types — use zod + z.infer
- No empty
catch blocks
- No one-letter variable names
- Boolean parsing: use
parseBooleanToken/parseBooleanWithDefault
- Don't add docstrings/comments to code you didn't change
Review Heuristics
- New files: Check if
yarn generate is needed. Verify auto-discovery paths.
- Entity changes: Check if migration and snapshot updates are needed. Look for missing tenant columns.
- Migration sanity: Inspect SQL content and
.snapshot-open-mercato.json. Reject unrelated schema churn.
- New API routes: Verify
openApi export, auth guards, zod validation, tenant filtering.
- Event emitters: Verify event is declared in
events.ts with as const.
- Commands: Verify undoable, before/after snapshots.
- UI changes: Verify
CrudForm/DataTable, flash(), keyboard shortcuts, loading/error states.
- Test coverage: Verify unit/integration tests cover new behavior.
Reference Materials
1---2name: code-review3description: Review code changes for architecture, security, conventions, and quality compliance. Use when reviewing pull requests, code changes, or auditing code quality.4---56# Code Review78Review code changes against Open Mercato architecture rules, security requirements, and quality standards.910## Review Workflow11121. **Scope**: Identify changed files. Classify by layer (entity, API route, validator, backend page, subscriber, worker, command, widget).132. **Gather context**: Read `AGENTS.md` for module conventions. Check `.ai/specs/` for active specs. Read `.ai/lessons.md` for known pitfalls.143. **CI/CD verification gate (MANDATORY)**: Run the checks below. Every gate MUST pass. See **CI/CD Gate** section.154. **Run checklist**: Apply rules from `references/review-checklist.md`. Flag violations with severity, file, and fix suggestion.165. **Test coverage**: Verify changed behavior is covered by tests. Flag missing coverage.176. **Cross-module impact**: If the change touches events, extensions, or widgets, verify consumers handle the contract correctly.187. **Output**: Produce the review report.1920## CI/CD Verification Gate (MANDATORY)2122**NEVER claim code is "ready to merge" without running these checks.** If any step fails, it MUST be fixed before the review can pass.2324| # | Command | What it checks | If it fails |25|---|---------|----------------|-------------|26| 1 | `yarn generate` | Module registries are up to date | Run it — it generates missing files |27| 2 | `yarn typecheck` | TypeScript types are correct | Fix type errors |28| 3 | `yarn test` | All unit tests pass | Fix failing tests |29| 4 | `yarn build` | The app builds successfully | Fix build errors |3031**Rules**:32- Steps 2 and 3 can run in parallel.33- Every failure is a **Critical** finding — even if it appears unrelated to the current changes.34- The review output MUST include actual pass/fail results. Do not assume — run and report.3536## Output Format3738```markdown39# Code Review: {change description}4041## Summary42{1-3 sentences: what the change does, overall assessment}4344## CI/CD Verification4546| Gate | Status | Notes |47|------|--------|-------|48| `yarn generate` | PASS/FAIL | |49| `yarn typecheck` | PASS/FAIL | |50| `yarn test` | PASS/FAIL | |51| `yarn build` | PASS/FAIL | |5253## Findings5455### Critical56{Security, data integrity, tenant isolation violations}5758### High59{Architecture violations, missing required exports}6061### Medium62{Convention violations, suboptimal patterns}6364### Low65{Suggestions, minor improvements}6667## Checklist68{From references/review-checklist.md — mark [x] passing, [ ] failing with explanation}69```7071Omit empty severity sections.7273## Severity Classification7475| Severity | Criteria | Action |76|----------|----------|--------|77| **Critical** | Security vulnerability, cross-tenant leak, data corruption, missing auth | MUST fix before merge |78| **High** | Architecture violation, missing required export, broken module contract | MUST fix before merge |79| **Medium** | Convention violation, suboptimal pattern, missing best practice | Should fix |80| **Low** | Style suggestion, minor improvement | Nice to have |8182## Quick Rule Reference8384### Architecture8586- **NO direct ORM relationships between modules** — use FK IDs, fetch separately87- **Always filter by `organization_id`** for tenant-scoped entities88- **Use DI (Awilix)** to inject services — never `new` directly89- **NO direct module-to-module calls** for side effects — use events90- **Cross-module data**: use extension entities + `data/extensions.ts`9192### Security9394- **Validate all inputs with zod** in `data/validators.ts`95- **Use `findWithDecryption`** instead of raw `em.find`/`em.findOne`96- **Hash passwords with bcryptjs (cost >= 10)** — never log credentials97- **Every endpoint MUST declare auth guards** (`requireAuth`, `requireRoles`, `requireFeatures`)9899### Data Integrity100101- **Migration files and snapshots must match entity intent** — prefer `yarn db:generate`; scoped manual SQL is allowed only to avoid unrelated generated churn and must include `.snapshot-open-mercato.json`102- **Validate migration scope** — autogenerated doesn't mean correct103- **Workers/subscribers MUST be idempotent**104- **Commands MUST be undoable** — include before/after snapshots105106### Naming107108- Modules: **plural, snake_case** (folders and `id`)109- JS/TS identifiers: **camelCase**110- Database: **snake_case**, table names plural111- Standard columns: `id`, `created_at`, `updated_at`, `deleted_at`, `is_active`, `organization_id`112113### UI & HTTP114115- Forms: `CrudForm` — never custom116- Tables: `DataTable` — never manual markup117- Notifications: `flash()` — never `alert()` or custom toast118- API calls: `apiCall`/`apiCallOrThrow` — never raw `fetch`119- Dialogs: `Cmd/Ctrl+Enter` (submit), `Escape` (cancel)120- `pageSize` MUST be <= 100121122### Code Quality123124- No `any` types — use zod + `z.infer`125- No empty `catch` blocks126- No one-letter variable names127- Boolean parsing: use `parseBooleanToken`/`parseBooleanWithDefault`128- Don't add docstrings/comments to code you didn't change129130## Review Heuristics1311321. **New files**: Check if `yarn generate` is needed. Verify auto-discovery paths.1332. **Entity changes**: Check if migration and snapshot updates are needed. Look for missing tenant columns.1343. **Migration sanity**: Inspect SQL content and `.snapshot-open-mercato.json`. Reject unrelated schema churn.1354. **New API routes**: Verify `openApi` export, auth guards, zod validation, tenant filtering.1365. **Event emitters**: Verify event is declared in `events.ts` with `as const`.1376. **Commands**: Verify undoable, before/after snapshots.1387. **UI changes**: Verify `CrudForm`/`DataTable`, `flash()`, keyboard shortcuts, loading/error states.1398. **Test coverage**: Verify unit/integration tests cover new behavior.140141## Reference Materials142143- [Review Checklist](references/review-checklist.md)144- [AGENTS.md](../../../AGENTS.md)