A CLI that keeps your Zod schemas in sync with your Prisma models. It generates modular, type-safe validation files automatically, ensuring your database and application logic stay aligned.
Support the Project
To keep this library maintained and evolving, your contribution would be greatly appreciated! It helps keep me motivated to continue collaborating and improving this framework for everyone.
-
Node.js >= 22.0.0 -
Yarn >= 1.x
# Global install (once)
npm install -g prazod # or pnpm add -g prazod# Run without installing (npx)
npx prazod schema.prisma output.ts --modularPrazod also supports generating a Prisma schema from existing Zod schemas. This is useful when you want to prototype with Zod first or migrate an existing Zod-based project to Prisma.
# Generate Prisma schema from Zod file
prazod reverse ./src/zod-schemas.ts ./prisma/schema.prisma- Models: Zod objects are converted to Prisma models.
- Enums: Zod enums are converted to Prisma enums.
- Attributes:
@id: Inferred fromidfield or.cuid()/.uuid()validations.@default: Inferred from.default()values.@updatedAt: Inferred fromupdatedAtfield name.@unique: Inferred from.describe("@unique").@relation: Parsed from.describe()(e.g.,.describe("@relation(fields: [userId], references: [id])")).@map: Parsed from.describe()(e.g.,.describe('@map("column_name")')).- Native Types: Parsed from
.describe()(e.g.,.describe("@db.Text")).
- Model Attributes:
@@index: Parsed from model documentation.@@id: Parsed from model documentation (for composite IDs).@@unique: Parsed from model documentation (for composite unique constraints).@@fulltext: Parsed from model documentation (for full-text search indexes).@@map: Parsed from model documentation.
- Types:
z.string()->Stringz.number()->Float(orIntif.int()is used)z.boolean()->Booleanz.date()->DateTimez.enum()->Enumz.lazy(() => Model)->Model(for relations)
- Database Provider: Defaults to
postgresql. You may need to adjust thedatasourceblock manually.
# Local dev dependency (recommended for projects)
pm install --save-dev prazod # or pnpm add -D prazodAdd the script to your package.json:
{
"scripts": {
"generate:zod": "prazod prisma/schema.prisma src/zod-schemas --modular"
}
}prazod examples/ecommerce.prisma output.tsGenerate organized folder structure with separate files:
prazod examples/ecommerce.prisma output-dir --modularCheck out the examples/ directory for sample Prisma schemas:
examples/ecommerce.prisma- Comprehensive e-commerce schemaexamples/test-features.prisma- Feature test schema (default functions, ignore attributes)
For local development:
pnpm build && node dist/index.js examples/ecommerce.prisma examples/ecommerce-zod --modularAll Prisma scalar types are fully supported:
String,Int,BigInt,Float,DecimalBoolean,DateTime,Json,Bytes
autoincrement()- Auto-incrementing integersnow()- Current timestampuuid()- UUID v4 generationcuid()- Collision-resistant IDauto()- MongoDB ObjectId (auto-generated)sequence()- CockroachDB sequences with optionsulid()- Lexicographically sortable IDsnanoid()- Nano IDs with custom lengthdbgenerated()- Database-level default expressions
@id- Primary key@unique- Unique constraint@default- Default value@updatedAt- Automatic update timestamp@relation- Define relationships@map- Column name mapping@ignore- Exclude from Zod schema (field will be omitted)
@@id- Composite primary key@@unique- Composite unique constraint@@index- Database index@@map- Table name mapping@@ignore- Exclude model from Zod schemas (file will not be generated)
- One-to-one, one-to-many, and many-to-many relationships
- Self-relations and bi-directional relations
- Relation actions:
Cascade,Restrict,NoAction,SetNull
Full enum support with proper Zod enum generation
We welcome contributions! Please read our Contributing Guide and Code of Conduct before submitting pull requests.
Quick start:
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature - Commit your changes:
git commit -am 'Add some feature' - Push to the branch:
git push origin my-new-feature - Submit a pull request
- Chris Michael (Project Leader, and Developer)
This is just a personal project created for study / demonstration purpose and to simplify my working life, it may or may not be a good fit for your project(s).
Please β this repository if you like it or this project helped you!
Feel free to open issues or submit pull-requests to help me improving my work.
Chris M. Perez
Copyright Β©2025 prazod.