Review Zod
Review Zod usage across contract boundaries (@repo/dtos-common, HTTP routes, SPA clients, queue/webhook payloads) for alignment with current official Zod v4 best practices - schema organization, typing, and parse performance. Your reply must be a plan of suggested changes: concise, actionable, structured - not only prose.
Invocation
Text after the slash command is additional scope/focus (e.g. "dtos-common only", "error formatting") - narrow the review accordingly.
Ground truth (mandatory)
Your pre-trained knowledge of Zod may be outdated (v3 → v4 changed APIs and error internals significantly). Do not draft suggestions from memory alone.
- Resolve "Zod" via the Context7 MCP (
resolve-library-id → query-docs) at v4: top-level APIs, .safeParse/.parse semantics, z.output/z.input inference, discriminated unions, registries/metadata features, error customization, tree-shaking/minification notes.
- For anything Context7 lacks, use Firecrawl search/scrape restricted to the official domain (
zod.dev) - v4 changelog/migration notes relevant to schemas in this repo.
- Version currency: catalog
zod in pnpm-workspace.yaml and installed version vs latest stable; flag any remaining v3-only APIs (e.g. old error-map patterns) in code.
- Cite the retrieved source next to every finding; label anything unverifiable as Unverified.
Scope artifacts
Analysis axes
- Single source of truth: every cross-boundary payload has exactly one owning schema in
dtos-common; no shadow re-declarations in apps; enums sourced from @repo/enums-common.
- Inference discipline: types derived via
z.infer/z.output (input vs output distinction respected); no hand-written duplicate TS types drifting from schemas.
- Boundary coverage: all Hono routes validate request/response payloads; webhook signatures verified before parsing; queue messages validated on consume.
- Schema quality: discriminated unions over boolean flags;
.strict()/.loose() choices deliberate; reusable primitives factored; no runtime-costly transforms on hot paths where a refine suffices.
- Errors: consistent error formatting for API responses (no internal details leaked); i18n/custom messages pattern coherent with current v4 APIs.
- Version currency: full v4 adoption (no compat shims); new capabilities worth adopting noted.
DX & AI-agentic workflow
Verify agent-friendliness: adding a contract is a documented procedure (schema folder → route → SPA service updated together per AGENTS.md); generated types flow through turbo run check-types so agents get fast feedback.
Steps
- Collect ground truth before reading code.
- Read dtos-common structure and trace one schema end-to-end (worker validation → SPA consumption).
- Walk each analysis axis; note findings or explicit one-line "no issues".
- Compose the plan grouped Critical / Improvements / Optional with what, where, why, and source citations.
Output format
- Critical - unvalidated boundary, schema/type drift, leaked internals in errors.
- Improvements - organization/inference alignment with v4 guidance.
- Optional - nice-to-haves; prefix pure polish with Nit:.
Read-only review: produce the plan only; implement nothing unless explicitly asked afterwards.
1---2name: review-zod3description: Zod review (v4 adoption across @repo/dtos-common boundaries, schema organization, parse strategies) against current official Zod best practices. USE WHEN: user runs /review-zod or explicitly asks for this review. DO NOT USE WHEN: reviewing app code, other dev dependencies, or implementing features.4---56# Review Zod78Review Zod usage across contract boundaries (`@repo/dtos-common`, HTTP routes, SPA clients, queue/webhook payloads) for alignment with current official Zod v4 best practices - schema organization, typing, and parse performance. Your reply must be a **plan of suggested changes**: concise, actionable, structured - not only prose.910## Invocation1112Text after the slash command is additional scope/focus (e.g. "dtos-common only", "error formatting") - narrow the review accordingly.1314## Ground truth (mandatory)1516Your pre-trained knowledge of Zod may be outdated (v3 → v4 changed APIs and error internals significantly). **Do not draft suggestions from memory alone.**17181. Resolve "Zod" via the **Context7 MCP** (`resolve-library-id` → `query-docs`) at v4: top-level APIs, `.safeParse`/`.parse` semantics, `z.output`/`z.input` inference, discriminated unions, registries/metadata features, error customization, tree-shaking/minification notes.192. For anything Context7 lacks, use **Firecrawl search/scrape restricted to the official domain** (`zod.dev`) - v4 changelog/migration notes relevant to schemas in this repo.203. Version currency: catalog `zod` in [pnpm-workspace.yaml](../../../pnpm-workspace.yaml) and installed version vs latest stable; flag any remaining v3-only APIs (e.g. old error-map patterns) in code.214. Cite the retrieved source next to every finding; label anything unverifiable as **Unverified**.2223## Scope artifacts2425- [packages/dtos-common/src/](../../../packages/dtos-common/src/) - `api/`, `rpc/`, `queue/`, `webhook/` schema folders26- Consumers: [apps/worker-api/src/routes/](../../../apps/worker-api/src/routes/) (validation middleware), front-app services decoding responses27- [.claude/rules/contracts/](../../../.claude/rules/contracts/) ↔ `.cursor/rules/contracts/` ownership conventions28- Tests asserting schema contracts under `packages/dtos-common` and app tests2930## Analysis axes3132- **Single source of truth**: every cross-boundary payload has exactly one owning schema in `dtos-common`; no shadow re-declarations in apps; enums sourced from `@repo/enums-common`.33- **Inference discipline**: types derived via `z.infer`/`z.output` (input vs output distinction respected); no hand-written duplicate TS types drifting from schemas.34- **Boundary coverage**: all Hono routes validate request/response payloads; webhook signatures verified before parsing; queue messages validated on consume.35- **Schema quality**: discriminated unions over boolean flags; `.strict()`/`.loose()` choices deliberate; reusable primitives factored; no runtime-costly transforms on hot paths where a refine suffices.36- **Errors**: consistent error formatting for API responses (no internal details leaked); i18n/custom messages pattern coherent with current v4 APIs.37- **Version currency**: full v4 adoption (no compat shims); new capabilities worth adopting noted.3839## DX & AI-agentic workflow4041Verify agent-friendliness: adding a contract is a documented procedure (schema folder → route → SPA service updated together per AGENTS.md); generated types flow through `turbo run check-types` so agents get fast feedback.4243## Steps44451. Collect ground truth before reading code.462. Read dtos-common structure and trace one schema end-to-end (worker validation → SPA consumption).473. Walk each analysis axis; note findings or explicit one-line "no issues".484. Compose the plan grouped Critical / Improvements / Optional with **what**, **where**, **why**, and source citations.4950## Output format51521. **Critical** - unvalidated boundary, schema/type drift, leaked internals in errors.532. **Improvements** - organization/inference alignment with v4 guidance.543. **Optional** - nice-to-haves; prefix pure polish with **Nit:**.5556Read-only review: produce the plan only; implement nothing unless explicitly asked afterwards.