Type System Overview
The template centralizes its TypeScript type definitions in template/lib/types/. This directory contains interfaces, type aliases, Zod validation schemas, and request/response DTOs used across repositories, services, and API routes.
Source directory: template/lib/types/
Directory Listing
| File | Purpose |
|---|---|
item.ts | Item data model, create/update/review requests, list options, status types |
user.ts | Authentication user data, create/update requests, Zod validation schemas, list options |
role.ts | Role data model, create/update requests, list options, role-with-count type |
tag.ts | Tag data model, create/update requests, paginated list response |
category.ts | Category data model with count, create/update requests, validation constants, list options |
comment.ts | Comment data structures |
vote.ts | Vote data structures |
client.ts | Client profile types |
client-item.ts | Client-facing item types |
profile.ts | User profile types |
survey.ts | Survey data structures |
location.ts | Location/geography types |
sponsor-ad.ts | Sponsor and advertisement types |
twenty-crm-config.types.ts | Twenty CRM integration configuration types |
twenty-crm-entities.types.ts | Twenty CRM entity model types |
twenty-crm-errors.types.ts | Twenty CRM error handling types |
twenty-crm-sync.types.ts | Twenty CRM synchronization types |
Core Domain Types
Item Types (item.ts)
The item type system is the most extensive, covering the full lifecycle of a directory listing.
Key types:
ItemData-- the primary item data model with fields forid,name,slug,description,source_url,status,category,tags,collections,submitted_by,submitted_at,deleted_at, and moreCreateItemRequest-- DTO for item creation; requiresid,name,slug,description,source_urlUpdateItemRequest-- partial DTO for item updates; all fields optionalReviewRequest-- containsstatus('approved'or'rejected') and optionalreview_notesItemListOptions-- filtering and pagination options:status,categories,tags,submittedBy,search,includeDeleted,sortBy,sortOrder
User Types (user.ts)
Authentication-level user types with Zod validation schemas.
Key types:
AuthUserData-- represents an authenticated user record (id, email, created_at, etc.)CreateUserRequest-- email and password for user creationUpdateUserRequest-- partial update fieldsUserListOptions-- pagination and filtering optionsAuthUserListResponse-- paginated response withusers,total,page,limit,totalPagesuserValidationSchema-- Zod schema for full user creation validationupdateUserValidationSchema-- Zod schema for partial user update validation
Role Types (role.ts)
Role data types for the RBAC system.
Key types:
RoleData-- role record withid,name,description,permissions,isDefault,status, timestampsCreateRoleRequest-- fields needed to create a new roleUpdateRoleRequest-- partial role updateRoleListOptions-- filtering options includingstatus, search, and paginationRoleWithCount-- extendsRoleDatawithuserCountfor admin display
Tag Types (tag.ts)
Tag data types for the labeling/tagging system.
Key types:
TagData-- tag record withid,name, and optional metadataCreateTagRequest-- requiresidandnameUpdateTagRequest-- partial tag updateTagListResponse-- paginated tag list withtags,total,page,limit,totalPages
Category Types (category.ts)
Category data types for the organizational taxonomy.
Key types:
CategoryData-- category record withid,name,description, and metadataCategoryWithCount-- extendsCategoryDatawith an item countCreateCategoryRequest-- requiresid,name, optionaldescriptionUpdateCategoryRequest-- partial category update (requiresid)CategoryListOptions-- filtering, sorting, and pagination optionsCATEGORY_VALIDATION-- constants for field length validation (name min/max, description max, ID constraints)
Integration Types
Twenty CRM Types
Four files define the type system for the Twenty CRM integration:
| File | Contents |
|---|---|
twenty-crm-config.types.ts | Configuration types for CRM connection settings |
twenty-crm-entities.types.ts | Entity models mapping to CRM objects |
twenty-crm-errors.types.ts | Error types for CRM API error handling |
twenty-crm-sync.types.ts | Synchronization state and operation types |
Type Pattern Conventions
Request/Response DTOs
The codebase follows a consistent pattern for data transfer objects:
Create[Entity]Request-- contains all required fields for creationUpdate[Entity]Request-- partial type where most fields are optional; typically requiresid[Entity]ListOptions-- filtering, sorting, and pagination parameters[Entity]ListResponse-- paginated response withitems,total,page,limit,totalPages
Validation Schemas
Zod schemas are co-located with their corresponding types:
// In user.ts
export const userValidationSchema = z.object({
email: z.string().email(),
password: z.string().min(8),
// ...
});
Repositories use .parse() or .pick() on these schemas before executing mutations.
Validation Constants
For Git-backed entities (categories, collections), validation constants are exported as plain objects:
export const CATEGORY_VALIDATION = {
NAME_MIN_LENGTH: 2,
NAME_MAX_LENGTH: 100,
// ...
};
These are referenced in repository validation methods.
Type Relationships
ItemData
├── references CategoryData (via category field)
├── references TagData (via tags field)
├── references Collection (via collections field)
└── referenced by ClientDashboardRepository
AuthUserData
├── references RoleData (via role assignments)
└── referenced by UserRepository
RoleData
├── contains Permission[] (from permissions/definitions)
└── referenced by RoleRepository
CategoryData
└── referenced by items (category field)
TagData
└── referenced by items (tags field)
Usage Guidelines
- Always import types from
@/lib/types/rather than re-declaring them in components or API routes - Use request DTOs for API handler input validation, not the full data model
- Use Zod schemas where available (user types) for runtime validation
- Use validation constants (categories, collections) for consistent field constraints across frontend and backend
- Extend types locally only when you need component-specific derived types that do not belong in the shared layer
Related Files
| File | Relationship |
|---|---|
lib/repositories/*.ts | Consumers of these types for data access |
lib/services/*.ts | Business logic that transforms between these types |
lib/permissions/definitions.ts | Permission type definitions (separate from this directory) |
lib/guards/plan-features.guard.ts | Feature type definitions (in guards, not types directory) |
app/api/** | API routes that accept request DTOs and return response types |