Shared Types Style Guide
All shared types in HoneyGrid must be derived from validators to ensure runtime type safety. There are two paths for type creation:
1. Database Schema Types
Section titled “1. Database Schema Types”For database entities, types flow from Drizzle schema to Zod validators to TypeScript types:
Drizzle Schema --> Zod Validator --> TypeScript TypeExample using Workspaces:
- Define Drizzle schema:
export const Workspaces = table('Workspaces', { id: text().primaryKey().notNull(), name: text().notNull(), // ... other fields})- Create Zod validators using drizzle-zod:
export const workspaceSelectValidator = createSelectSchema(Workspaces)export const workspaceInsertValidator = createInsertSchema(Workspaces).omit({ createdAt: true, id: true,})- Derive TypeScript types:
export type WorkspaceSelect = typeof Workspaces.$inferSelectexport type WorkspaceInsert = z.infer<typeof workspaceInsertValidator>2. Direct Validator Types
Section titled “2. Direct Validator Types”For non-database types, define Zod validators first then derive TypeScript types:
Zod Validator --> TypeScript TypeExample:
export const UserPreferencesValidator = z.object({ theme: z.enum(['light', 'dark']), notifications: z.boolean(),})
export type UserPreferences = z.infer<typeof UserPreferencesValidator>Best Practices
Section titled “Best Practices”- Always suffix validators with
Validator - Place related schemas, validators and types in the same directory
- Export both validators and types for runtime validation
- Use
.omit()and.extend()to customize validators when needed - Keep schema definitions as the source of truth
- Co-locate related types in feature-specific files
File Organization
Section titled “File Organization”honeygrid-types/├── schema/ # Drizzle schema definitions├── validators-and-types/ # Validators and derived types└── index.ts # Public exportsCommon Patterns
Section titled “Common Patterns”- Use
Selectsuffix for read operations - Use
Insertsuffix for create operations - Use
Updatesuffix for partial updates - Omit auto-generated fields from insert validators
- Define enums in schema when possible for DB constraints