prazod
v1.1.0
Published
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.
Maintainers
Readme
Prazod
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.
Current Status
⚠️ This is a proof of concept (POC) - The library is currently in active development and should be used for experimental purposes. While functional, it may not be production-ready for all use cases.
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.
Prerequisites
- [x]
Node.js >= 22.0.0 - [x]
Yarn >= 1.x
📚 Documentation
:package: Installation
# Global install (once)
npm install -g prazod # or pnpm add -g prazod# Run without installing (npx)
npx prazod schema.prisma output.ts --modularReverse Generation (Zod -> Prisma)
Prazod 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.prismaSupported Features
- 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)
Limitations
- 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"
}
}:rocket: Usage
Single File Mode (Default)
prazod examples/ecommerce.prisma output.tsModular Mode
Generate organized folder structure with separate files:
prazod examples/ecommerce.prisma output-dir --modularExamples
Check 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 --modular:sparkles: Supported Prisma Features
Scalar Types
All Prisma scalar types are fully supported:
String,Int,BigInt,Float,DecimalBoolean,DateTime,Json,Bytes
Default Value Functions
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
Field Attributes
@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)
Model Attributes
@@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)
Relations
- One-to-one, one-to-many, and many-to-many relationships
- Self-relations and bi-directional relations
- Relation actions:
Cascade,Restrict,NoAction,SetNull
Enums
Full enum support with proper Zod enum generation
:handshake: Contributing
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
:busts_in_silhouette: Credits
- Chris Michael (Project Leader, and Developer)
:anger: Troubleshootings
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).
:heart: Show your support
Please :star: 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.
:robot: Author
Chris M. Perez
Copyright ©2025 prazod.
