2.2 KiB
2.2 KiB
1. Package scaffolding
- 1.1 Create
packages/schema/package.jsonwith name@workspace/schema, private: true, and TypeScript build script - 1.2 Create
packages/schema/tsconfig.jsonextending the API's config pattern (nodenext, ES2023, strictNullChecks, declaration) - 1.3 Add
drizzle-orm,superstruct, and@types/nodeas dependencies in the new package - 1.4 Create
packages/schema/src/index.tsbarrel file re-exporting from sub-modules - 1.5 Add
@workspace/schemaas a workspace dependency inapps/api/package.json - 1.6 Add
@workspace/schemaas a workspace dependency inapps/web/package.json - 1.7 Verify
pnpm installresolves the workspace dependency andpnpm buildcompiles the package
2. Drizzle schema definitions
- 2.1 Create
packages/schema/src/drizzle/directory structure - 2.2 Define
pgEnumexports 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
InferSelectModelandInferInsertModeltypes derived from all Drizzle tables - 4.3 Export
Infertypes derived from all Superstruct schemas - 4.4 Re-export all types through the top-level
src/index.tsbarrel
5. Wire into monorepo
- 5.1 Verify Turborepo topological build order —
turbo.json^buildshould already handleschema→api/web - 5.2 Run
pnpm buildfrom root to confirm clean compilation - 5.3 Run
pnpm --filter=api testto confirm no regressions - 5.4 Run
pnpm check-typesto confirm type-checking passes across all workspaces