work-hub-server/openspec/changes/add-shared-schema-package/tasks.md
Nicolas HOARAU 9314e72f3e feat(schema): add shared schema package with Drizzle ORM and Valibot validation
Create @workspace/schema package with Project and Task table definitions, Drizzle relations, Valibot validation schemas (select/insert/update), and wire as workspace dependency in API and Web apps.
2026-06-04 12:46:51 +04:00

2.2 KiB

1. Package scaffolding

  • 1.1 Create packages/schema/package.json with name @workspace/schema, private: true, and TypeScript build script
  • 1.2 Create packages/schema/tsconfig.json extending the API's config pattern (nodenext, ES2023, strictNullChecks, declaration)
  • 1.3 Add drizzle-orm, superstruct, and @types/node as dependencies in the new package
  • 1.4 Create packages/schema/src/index.ts barrel file re-exporting from sub-modules
  • 1.5 Add @workspace/schema as a workspace dependency in apps/api/package.json
  • 1.6 Add @workspace/schema as a workspace dependency in apps/web/package.json
  • 1.7 Verify pnpm install resolves the workspace dependency and pnpm build compiles the package

2. Drizzle schema definitions

  • 2.1 Create packages/schema/src/drizzle/ directory structure
  • 2.2 Define pgEnum exports for any PostgreSQL enums needed
  • 2.3 Define initial Drizzle tables with pgTable, proper column types, constraints, and defaults
  • 2.4 Define relations() between tables for relational queries
  • 2.5 Export all table definitions, enums, and relations from the Drizzle sub-module barrel

3. Superstruct validation schemas

  • 3.1 Create packages/schema/src/validation/ directory structure
  • 3.2 Define Superstruct schemas for data shapes, with proper type constraints
  • 3.3 Support nested/optional/defaulted fields via Superstruct combinators
  • 3.4 Export all validation schemas from the validation sub-module barrel

4. Shared TypeScript types

  • 4.1 Create packages/schema/src/types/ directory structure
  • 4.2 Export InferSelectModel and InferInsertModel types derived from all Drizzle tables
  • 4.3 Export Infer types derived from all Superstruct schemas
  • 4.4 Re-export all types through the top-level src/index.ts barrel

5. Wire into monorepo

  • 5.1 Verify Turborepo topological build order — turbo.json ^build should already handle schemaapi/web
  • 5.2 Run pnpm build from root to confirm clean compilation
  • 5.3 Run pnpm --filter=api test to confirm no regressions
  • 5.4 Run pnpm check-types to confirm type-checking passes across all workspaces