{
  "markdown": "# prisma-zod-consistency\n\n> Static + live-DB linter for Prisma schemas, Zod schemas, and your TypeScript code — finds drift before prod does.\n\n```text\n$ npx prisma-zod-consistency\ninfo: live-DB rules skipped (pass --db to enable): R07, R08, R09, R09b, R09c, R09d\n\n[R01] (2)\n  error src/zod/links.ts:4\n    Field `shortLink` is `@db.VarChar(400)` in Prisma; `LinkSchema` has no `.max()` to enforce that limit.\n    → Add `.max(400)` to `shortLink`.\n  error src/zod/users.ts:4\n    Field `email` is `@db.VarChar(255)` in Prisma; `UserSchema` has no `.max()` to enforce that limit.\n    → Add `.max(255)` to `email`.\n\n[R02] (1)\n  warn prisma/schema.prisma:20\n    Relation Link.user is missing explicit onDelete.\n    → Add `onDelete: <action>` to the @relation arguments.\n\n[R03] (1)\n  error src/zod/users.ts:5\n    Enum `role` does not match Prisma enum `Role` — missing in Zod: ADMIN, USER; extra in Zod: admin, user.\n    → Sync values: Prisma enum `Role` is { ADMIN, USER }.\n\n[R04] (1)\n  error src/zod/users.ts:6\n    Field `bio` is optional in Prisma (`String?`) but `UserSchema` requires a non-null, non-undefined value.\n    → Add `.nullable()` (for DB reads) or `.optional()` (to allow omitted keys).\n\n4 errors, 1 warning, 0 info\n```\n\n## Quick start\n\n```bash\nnpx prisma-zod-consistency\n```\n\nThat's it. Without flags it runs the static checks against `prisma/schema.prisma` and `src/**/*.ts`.\n\nIn a monorepo, point it at the schema and your TS sources:\n\n```jsonc\n// .prismazodrc.json\n{\n  \"schemaPath\": \"packages/db/prisma/schema.prisma\",\n  \"include\": [\"apps/**/*.ts\", \"packages/**/*.ts\"]\n}\n```\n\n## Use as a Claude Code skill\n\nAvailable in the official [Claude Code Plugin Directory](https://claude.com/plugins). Install from inside Claude Code:\n\n```\n/plugin marketplace add rshelekhov/prisma-zod-consistency\n/plugin install prisma-zod-consistency\n```\n\nThen in any Prisma + Zod project say \"check Prisma/Zod consistency\" (or `проверь согласованность`) — the skill auto-engages, runs the CLI under the hood, and returns a contextual report with suggested fixes. Adds the R06 missing-index review and R10/R11 pattern checks that the CLI intentionally doesn't ship.\n\n## What it catches\n\nReal drift cases from open-source TypeScript repos.\n\n**R01 — `@db.VarChar(N)` with no `.max()` in Zod.** A 401-char string passes Zod, then your DB rejects it with a truncation error and the API returns 500 instead of 400. *Found in `dub`:*\n\n```prisma\nmodel Link { shortLink String @unique @db.VarChar(400) }\n```\n```ts\n// apps/web/lib/zod/schemas/links.ts\nshortLink: z.string()  // no .max(400)\n```\n\n**R03 — Zod enum drift from Prisma.** Common case: lowercase Zod values, uppercase Prisma values. The two are silently incompatible until something refactors. *Found in `documenso`:*\n\n```prisma\nenum Role { ADMIN  USER }\n```\n```ts\nrole: z.enum([\"admin\", \"user\"])  // case mismatch\n```\n\n**R09c — FK action drift between Prisma and the live DB.** Prisma says `onUpdate: NoAction`, but the actual database has `ON UPDATE CASCADE` from a hand-written migration that never got back-ported. `prisma migrate diff` doesn't surface this; running with `--db` does. *Found in `formbricks`, `Membership.organization`.*\n\n[Full rule catalog →](packages/checks/README.md) covers R01-R05 (static), R07-R09d (live DB on Postgres + MySQL + SQLite).\n\n## CI integration\n\n```yaml\n- name: Prisma+Zod consistency\n  run: |\n    pnpm exec prisma-zod-consistency --output sarif > pzc.sarif\n- name: Upload SARIF\n  if: always()\n  uses: github/codeql-action/upload-sarif@v3\n  with: { sarif_file: pzc.sarif }\n```\n\nFindings appear in the **Security** tab of the repo and as inline annotations on PRs. Exit code 1 if any `error`-severity finding, exit 2 on misconfig (missing schema, no Zod files matched). See [`packages/cli/README.md`](packages/cli/README.md) for the full flag reference, suppression comments, `--db` configuration, and the auto-fix subcommand.\n\n## CLI + skill — two surfaces, one source of truth\n\nThe same rule definitions in `packages/checks` ship as:\n\n- **CLI** ([`prisma-zod-consistency` on npm](https://www.npmjs.com/package/prisma-zod-consistency)) — deterministic, low-noise, designed to gate CI.\n- **Claude Code skill** ([Plugin Directory](https://claude.com/plugins)) — adds context-aware analysis: reads service-layer code, suggests fixes, runs the R06 missing-index review.\n- **Codex agent** (`packages/skill-codex/AGENTS.md`) — same playbook for the Codex CLI.\n\n## Status\n\n11 rules implemented across the static and live-DB families. Pre-1.0; semver respected from 0.7.0 onward. Recent changes: see [CHANGELOG.md](packages/cli/CHANGELOG.md).\n\n## License\n\nMIT\n",
  "bytes": 4633,
  "sha": "6fc0be47c5c3325cf8c747fb68f7152ea1a90744795678e4ea469c54a7751161",
  "repo_slug": "rshelekhov/prisma-zod-consistency",
  "fonte": "repo",
  "truncated": false,
  "api": "https://agentalog.com/api/listings/plg_rshelekhov_prisma_zod_consistency_prisma_e9225e01/readme"
}