prisma-zod-generator
Version:
Prisma 2+ generator to emit Zod schemas from your Prisma schema
274 lines (211 loc) β’ 11.3 kB
Markdown
<div align="center">
<h1>Prisma Zod Generator</h1>
<p><strong>Unify Prisma validation, policy guardrails, and developer workflows in a single generator.</strong></p>
<p>
<a href="https://omar-dulaimi.github.io/prisma-zod-generator/pricing"><strong>π Get PZG Pro β Purchase on GitHub</strong></a> |
<a href="https://omar-dulaimi.github.io/prisma-zod-generator/"><strong>π Documentation</strong></a> |
<a href="https://omar-dulaimi.github.io/prisma-zod-generator/docs/features/guard"><strong>π‘οΈ Drift Guard</strong></a>
</p>
<p>
<a href="https://www.npmjs.com/package/prisma-zod-generator"><img alt="npm version" src="https://img.shields.io/npm/v/prisma-zod-generator.svg?color=16C464&label=npm"></a>
<a href="https://www.npmjs.com/package/prisma-zod-generator"><img alt="downloads" src="https://img.shields.io/npm/dw/prisma-zod-generator.svg?color=8B5CF6&label=downloads"></a>
<a href="https://github.com/omar-dulaimi/prisma-zod-generator/actions"><img alt="CI" src="https://img.shields.io/github/actions/workflow/status/omar-dulaimi/prisma-zod-generator/ci.yml?branch=master&label=CI"></a>
<a href="https://github.com/omar-dulaimi/prisma-zod-generator/blob/master/LICENSE"><img alt="MIT" src="https://img.shields.io/badge/license-MIT-0a0a0a.svg"></a>
<img alt="TypeScript" src="https://img.shields.io/badge/types-TypeScript%20>=5.4%20(rec%205.9)-3178c6.svg">
<img alt="Module formats" src="https://img.shields.io/badge/modules-ESM%20%2B%20CJS-444.svg">
<a href="https://omar-dulaimi.github.io/prisma-zod-generator/"><img alt="Docs" src="https://img.shields.io/badge/docs-website-0ea5e9.svg"></a>
<img alt="Node.js" src="https://img.shields.io/badge/node-%3E%3D20.19.0%20(rec%2022.x)-339933?logo=node.js&logoColor=white">
</p>
<sub>
Prisma β Zod generator for end-to-end workflows.<br/>
π generate validation Β· π gate policies Β· π ship docs Β· βοΈ automate server actions
</sub>
</div>
---
> Docs: https://omar-dulaimi.github.io/prisma-zod-generator/
## π All Features (Core + Pro)
<div align="center">
<img src="https://img.shields.io/badge/π―_Core_Features_(Free)-27AE60?style=for-the-badge&color=27AE60&logoColor=white" alt="Core Features" />
<img src="https://img.shields.io/badge/π_Pro_Features_(Paid)-9B59B6?style=for-the-badge&color=9B59B6&logoColor=white" alt="Pro Features" />
</div>
<br />
<details open>
<summary>
<h3>π <strong>Complete Feature Overview</strong></h3>
</summary>
<div align="center">
<p><sub>Green = Free (MIT) β’ Purple/Gold = Pro (Paid)</sub></p>
</div>
<br />
<!-- diagram:diagram-01-23b43096d1 -->
<p align="center">
<img src="docs/assets/diagrams/diagram-01-23b43096d1.svg" alt="Prisma Zod Generator feature map (Core vs Pro tiers)" width="960" />
</p>
<details data-mermaid-source>
<summary>View Mermaid source</summary>
```mermaid
graph TB
classDef coreRoot fill:#1e8449,stroke:#0b5345,stroke-width:4px,color:#fff;
classDef coreCategory fill:#27ae60,stroke:#145a32,stroke-width:3px,color:#fff;
classDef coreItem fill:#58d68d,stroke:#196f3d,color:#0b3d1f;
classDef proRoot fill:#f39c12,stroke:#7d6608,stroke-width:4px,color:#fff;
classDef proCategory fill:#9b59b6,stroke:#512e5f,stroke-width:3px,color:#fff;
classDef proItem fill:#bb8fce,stroke:#5b2c6f,color:#2e0f3a;
subgraph "π― CORE FEATURES (Free Forever)"
PZG[Prisma Zod Generator]
PZG --> GEN[Schema Generation]
PZG --> CUSTOM[Customization]
PZG --> SAFETY[Type Safety]
PZG --> PERF[Performance]
GEN --> GEN1["β‘ Minimal Mode"]
GEN --> GEN2["π Full Mode"]
GEN --> GEN3["ποΈ Custom Mode"]
GEN --> GEN4["π¦ Schema Variants"]
GEN --> GEN5["π’ Decimal Handling"]
GEN --> GEN6["π
DateTime Support"]
CUSTOM --> CUST1["π¨ Naming Patterns"]
CUSTOM --> CUST2["π File Organization"]
CUSTOM --> CUST3["π― Selective Generation"]
CUSTOM --> CUST4["π§ Config Options"]
CUSTOM --> CUST5["π§° Multi-Provider Helpers"]
SAFETY --> SAFE1["β
Zod v4 Formats"]
SAFETY --> SAFE2["π‘οΈ Strict Mode"]
SAFETY --> SAFE3["π Type Checking"]
SAFETY --> SAFE4["π Validation Suites"]
PERF --> PERF1["β‘ Fast Output"]
PERF --> PERF2["π¦ Tree Shaking"]
PERF --> PERF3["π― Selective Imports"]
PERF --> PERF4["π Granular Emit Control"]
end
subgraph "π PRO FEATURES (Paid Plans)"
PRO[PZG Pro]
PRO --> SEC[Security & Governance]
PRO --> DEV[Developer Experience]
PRO --> PLAT[Platform & Scale]
SEC --> SEC1["π‘οΈ Policies & Redaction"]
SEC --> SEC2["π¨ Drift Guard"]
SEC --> SEC3["π PostgreSQL RLS"]
SEC --> SEC4["π§ͺ Contract Testing"]
SEC1 --> SEC1A["Role-Based Policies"]
SEC1 --> SEC1B["Conditional Access"]
SEC1 --> SEC1C["PII Redaction"]
SEC2 --> SEC2A["CI Integration"]
SEC2 --> SEC2B["Breaking Change Alerts"]
SEC2 --> SEC2C["Auto-Block Enforcement"]
DEV --> DEV1["β‘ Server Actions Pack"]
DEV --> DEV2["π Form UX Pack"]
DEV --> DEV3["π API Docs Pack"]
DEV --> DEV4["π Data Factories"]
DEV1 --> DEV1A["Next.js Actions"]
DEV1 --> DEV1B["Type-Safe Handlers"]
DEV1 --> DEV1C["Error Recovery"]
PLAT --> PLAT1["π¦ SDK Publisher"]
PLAT --> PLAT2["π’ Multi-Tenant Kit"]
PLAT --> PLAT3["π Performance Pack"]
PLAT3 --> PLAT3A["Streaming Validation"]
PLAT3 --> PLAT3B["Chunked Processing"]
PLAT3 --> PLAT3C["Memory Efficient Pipelines"]
end
class PZG coreRoot;
class GEN,CUSTOM,SAFETY,PERF coreCategory;
class GEN1,GEN2,GEN3,GEN4,GEN5,GEN6,CUST1,CUST2,CUST3,CUST4,CUST5,SAFE1,SAFE2,SAFE3,SAFE4,PERF1,PERF2,PERF3,PERF4 coreItem;
class PRO proRoot;
class SEC,DEV,PLAT proCategory;
class SEC1,SEC2,SEC3,SEC4,SEC1A,SEC1B,SEC1C,SEC2A,SEC2B,SEC2C,DEV1,DEV2,DEV3,DEV4,DEV1A,DEV1B,DEV1C,PLAT1,PLAT2,PLAT3,PLAT3A,PLAT3B,PLAT3C proItem;
```
</details>
<!-- /diagram:diagram-01-23b43096d1 -->
### π― Core Features (MIT License - Free Forever)
**Schema Generation**
- β‘ Minimal Mode - Essential CRUD only
- π Full Mode - Complete ecosystem
- ποΈ Custom Mode - Granular control
- π¦ Schema Variants - Input, result, pure models
- π’ Decimal Handling - BigInt & Decimal support
- π
DateTime Support - ISO formats & Zod v4
**Customization**
- π¨ Naming Patterns - Custom schema names
- π Organization - File structure control
- π― Selective Generation - Filter what gets generated
- π§ Config Options - Extensive configuration
- π§° Multi-Provider Helpers - Ready-made presets for each datasource
**Type Safety**
- β
Zod v4 Formats - ISO string methods (`.iso.date()`, `.iso.datetime()`, etc.)
- π‘οΈ Strict Mode - Enforce type correctness
- π Type Checking - Full TypeScript integration
- π Validation - Runtime type validation
**Performance**
- β‘ Fast Output - Optimized generation
- π¦ Tree Shaking - Remove unused code
- π― Selective Imports - Import only what you need
- π Granular Emit Control - Precise directory + preset outputs
---
### π Pro Features (Paid Plans)
**Security & Governance**
- π‘οΈ **Policies & Redaction** (Professional+) - Role-based policies, conditional access, PII protection
- π¨ **Drift Guard** (Professional+) - Breaking change detection, CI integration
- π **PostgreSQL RLS** (Professional+) - Row-level security, tenant isolation
- π§ͺ **Contract Testing** (Business+) - Pact.js integration, consumer-driven contracts
**Developer Experience**
- β‘ **Server Actions Pack** (Starter+) - Next.js typed server actions
- π **Form UX Pack** (Starter+) - React Hook Form + UI library integration
- π **API Docs Pack** (Business+) - OpenAPI v3, Swagger UI generation
- π **Data Factories** (Business+) - Test data generation
**Platform & Scale**
- π¦ **SDK Publisher** (Professional+) - Generate typed client SDKs
- π’ **Multi-Tenant Kit** (Enterprise) - Tenant isolation, context management
- π **Performance Pack** (Professional+) - Streaming validation, chunked processing, memory efficient
<div align="center">
<p>
<a href="https://omar-dulaimi.github.io/prisma-zod-generator/pricing"><strong>View Pricing & Plans</strong></a> |
<a href="https://omar-dulaimi.github.io/prisma-zod-generator/docs"><strong>Full Documentation</strong></a>
</p>
</div>
</details>
<br />
---
## π Quick Start
> βοΈ Tip: Star the repo to keep track of new generators, recipes, and fixes.
```bash
# Install
npm install -D prisma-zod-generator
# Add to schema.prisma
generator zod {
provider = "prisma-zod-generator"
}
# Generate
npx prisma generate
```
## π§ Config IntelliSense
Point your config file at the published JSON Schema to get autocomplete, hover docs, and validation errors in any JSON-aware editor:
```json title="prisma/config.json"
{
"$schema": "../node_modules/prisma-zod-generator/lib/config/schema.json",
"mode": "full"
}
```
Use a relative path that matches your repo layout (for example `./node_modules/...`). See the [JSON Schema IntelliSense guide](https://omar-dulaimi.github.io/prisma-zod-generator/docs/config/schema-json) for monorepo examples, CI validation scripts, and tips on shipping the schema with custom tooling.
## π‘ Usage Examples
- See the [full documentation](https://omar-dulaimi.github.io/prisma-zod-generator/) for detailed guides, upgrade notes, and feature walkthroughs.
- Browse `recipes/` for copy-paste presets, CI snippets, and integration templates that match your stack.
- Share `llms.txt` with AI copilots for an on-ramp to the architecture, commands, and conventions.
## β€οΈ Sponsor Development
If Prisma Zod Generator saves you time or catches bugs before production, consider sponsoring to fund maintenance and new feature work.
- On GitHub Sponsors, switch to the **One-time** tab (second tab) to see the PZG plan tiers. Pick the
yearly tiers labeled **PZG Starter**, **PZG Professional**, **PZG Business**, or **PZG Enterprise** to
unlock the corresponding Pro licensesβmonthly βsupportβ tiers (e.g., *Pro (Individual)*) in the
Monthly tab do not include PZG Pro.
<p align="center">
<img src="website/static/img/tiers.png" alt="GitHub Sponsors One-time tab showing PZG yearly tiers" width="320" />
<br />
<sub>Open the One-time tab to see the Prisma Zod Generator Starter, Professional, and Business tiers.</sub>
</p>
- Become a sponsor: https://github.com/sponsors/omar-dulaimi
## π€ Contributing
PRs are welcome! Keep diffs focused, open an issue before large refactors, and lean on the test suites for expected behavior and coverage.
## πΌοΈ Updating Diagrams
When you edit Mermaid blocks in this README, run `pnpm render:diagrams` afterwards. The script refreshes the SVG fallbacks in `docs/assets/diagrams/` so diagrams render correctly on npm and GitHub Mobile.
## π License
MIT Β© [Omar Dulaimi](https://github.com/omar-dulaimi)
**Core features**: MIT licensed, free forever
**Pro features**: Commercial license, see [pricing](https://omar-dulaimi.github.io/prisma-zod-generator/pricing)