The packages/schemas
folder
The packages/schemas
folder serves as the single source of truth for TypeScript Types, and Validation objects.
Purpose
The schemas package provides a unified approach to data validation and type safety throughout the application. By centralizing schema definitions, we ensure consistency and reduce duplication across different parts of the codebase. The schemas defined in this packages are meant to be imported and used in the rest of the monorepo.
In a nutshell, this is the place to:
- Define all business object schemas using Zod
- Export TypeScript types inferred from the Zod schemas
- Provide schemas for use across the entire monorepo
Zod (opens in a new tab) is a TypeScript-first schema declaration and validation library, allowing you to not only have compile-time type safety, but also runtime validations of any complexity. It integrates perfectly with tRPC, to make sure that the data you receive from the client on the backend is exactly what you expect it to be.
Usage
Schemas defined in this package are used for:
- Validating forms on the frontend
- Validating tRPC route endpoints on the backend and frontend
- Ensuring data integrity in DynamoDB by validating objects against Zod schemas
- Providing TypeScript types for compile-time checks across the codebase
For your convenience, Blitzship already provides some schema definitions that you can use as a reference.