Keep schemas next to routes
Zod schemas live alongside their API route handlers. This keeps the accepted input close to the endpoint that enforces it.CreateOrganizationBody and UpdateOrganizationBody are inferred
from these schemas. Typed frontend API services can use the same input types
without defining a second contract.
Share validation with forms
When the same rules apply to a frontend form, the form can use the routeβs Zod schema as well. This keeps client feedback and backend enforcement aligned without making the frontend the source of truth. The backend always parses the request again. Client-side validation improves the experience, but it does not replace validation at the API boundary.Validate before other operations
A typical route parses the request before calling its repository:validateQuery. When Zod throws a
validation error, withErrorHandler converts it into the standard API
validation response.
See Request handling and API format for
the error-handling and response details.