How benlorantfy/nestjs-zod works
Project type and purpose
• This is a library monorepo (using pnpm workspaces) containing:
• packages/nestjs-zod: the core NestJS–Zod integration
• packages/z: the extended Zod helper package
• packages/example: a sample NestJS application demonstrating usage
• Its purpose is to publish validation and serialization tools (with OpenAPI support) for NestJS applications.
File structure
• Top-level:
• pnpm-workspace.yaml + pnpm-lock.yaml (workspace management)
• .github/workflows (CI/CD pipelines for test/build, release, PR labeling)
• MIGRATION.md, LICENSE, README.md, package.json (root scripts and docs)
• packages/nestjs-zod: source code (pipes, guards, DTO creation, OpenAPI patch), tests, rollup config, jest config
• packages/z: extended Zod schemas, error-mapping, frontend helpers, build/test configs
• packages/example: a NestJS app (controllers, modules, filters), tsconfigs, e2e tests
README for architecture insights
• Core features (DTO creation, validation pipe, guard, OpenAPI conversion) indicate these components interact at runtime within a NestJS application.
• Example app shows how modules and controllers integrate with the library.
Main components
A. Developer workstation / Local Environment
• pnpm Workspace
• IDE (TypeScript, NestJS, Zod code)
B. Monorepo Structure
• Core Library (nestjs-zod)
– Zod DTO generator
– ZodValidationPipe
– ZodGuard
– OpenAPI patch & zodToOpenAPI
– ZodSerializerInterceptor
• Extended Z package (@nest-zod/z)
– dateString, password, json, from schema utilities
– error mapping, frontend helpers
• Example Application (packages/example)
– NestJS modules, controllers, filters (uses core library)
C. External Dependencies
• Zod (peer dependency)
• @nestjs/core, @nestjs/common, @nestjs/swagger
• NPM Registry
D. CI/CD
• GitHub Actions workflows
– test-and-build
– release
– pr-labeler
• Rollup (bundling)
• Jest (unit/integration tests)
E. Publish & Consumption
• npm publish of core and Z packages
• Developers consuming via npm install nestjs-zod zod @nest-zod/z
Relationships and data flow
• Developer → (code changes) → monorepo
• Monorepo → (pnpm install, build scripts) → compiled artifacts
• CI workflows → (run tests + build) → validate & publish
• Example app → (imports) → core library + Z package → at runtime
• Core library → (calls into) → Zod for schema parsing & validation
• Core library → (patches) → @nestjs/swagger to generate OpenAPI
• Z package → (provides) → custom Zod schemas & frontend utilities
Architectural patterns and principles
• Monorepo with workspaces: shared tooling, versioning, cross-package dependencies
• Library–consumer: clear separation between library code (reusable components) and example usage
• Plug-in style: NestJS pipes, guards, interceptors registered via dependency injection
• Build/Test/Release pipeline: reproducible builds, automated publishing
Final checklist
• Clear component names, roles, and interactions