I am working on a project using a pnpm monorepo setup. My backend is built with Hono, Drizzle ORM, and Zod for validation. I am using the drizzle-zod package to generate Zod schemas from my database tables.
For example, I’m generating a schema like this on the backend:
import { createSelectSchema } from 'drizzle-zod';
import { users } from './db/schema';
export const UserSchema = createSelectSchema(users);
I want to reuse this UserSchema in my frontend for form validation using @hookform/resolvers. What is the best way to share this schema between my backend and frontend within the pnpm monorepo?
Also I’m generating my types from openapi using orval, so I have a nice typesafe TanStack Query.
I have tried creating a validation package, but there are very few good tutorial doing that, and my case is a little different since, I want to include my server app as “dependency” for my package.
I considered using NX but I think it is overkill for my setup.
4