Production & Architecture
Learn how to integrate Prisma Guard into your build pipelines and understand the compiler's architectural design.
Production & CI/CD Integration
Since the generated zod/ and validation mapping files are typically excluded from source control (i.e. git-ignored), you must compile them during your application build or deployment pipeline.
Package Scripts Configuration
Update the scripts object in your root package.json file:
{
"scripts": {
"prisma:guard": "npx prisma-guard --no-prettier --skip-gitignore",
"build": "npm run prisma:guard && next build"
}
}
Build Optimization Flags
When building schemas on CI/CD servers, leverage these production flags to optimize build times:
--no-prettier: Skips running Prettier formatting on the output files, saving compilation overhead in automated environments.--skip-gitignore: Skips scanning and writing updating checks to.gitignorefiles.--no-zod: If you only use Mode 1 (Runtime Protection Only) in production, you can skip Zod schema generation entirely, creating only light model mappings.
Architecture Design
Prisma Guard uses the following conventions and design patterns:
Kebab-Case Outputs
Generated schema file names are mapped using kebab-case naming. For example, a model named BillingAddress in schema.prisma will output to billing-address.ts.
Base Object Pattern
To prevent redundant code duplication in output files, Prisma Guard defines a private base Zod object inside the generated file:
CreateSchemabuilds fields directly from this base object.UpdateSchemaapplies.partial()onto the base definition.- If field overrides alter the shape between creation and updating, the engine intelligently constructs a tailored partial model map.
Prettier Support
By default, the generator reads your local project's Prettier configuration (.prettierrc, prettier.config.js, etc.) and formats all generated TypeScript source files, keeping your generated directories clean and standardized.