Data Models and Schemas
Relevant source files
The following files were used as context for generating this wiki page:- apps/web/core/types/schemas/README.md
- apps/web/core/types/schemas/index.ts
- apps/web/core/types/schemas/task/task.schema.ts
- apps/web/core/types/schemas/team/organization-team.schema.ts
- apps/web/core/types/schemas/organization/employee.schema.ts
- apps/web/core/types/schemas/task/task-status.schema.ts
- apps/web/core/types/schemas/activities/activity.schema.ts
The Ever Teams platform employs a robust data validation system built upon the Zod library. This system is crucial for ensuring type safety and data integrity for all data flowing from the API to the Next.js web application. By defining strict schemas for every data entity, the application can perform runtime validation, catch data inconsistencies, and provide clear error messages when validation fails. This ensures that the frontend components and services operate on predictable and correctly structured data.
This documentation provides an overview of the schema architecture, details key data models, and outlines the best practices for using and extending the validation system. All schemas are centrally managed within the apps/web/core/types/schemas/ directory, providing a single source of truth for data structures across the application.
Sources: apps/web/core/types/schemas/README.md:1-10
Schema Validation System
The core of the data integrity strategy is a schema validation system that leverages Zod to enforce strict data structures for API responses.
Sources: apps/web/core/types/schemas/README.md:3-4
System Overview
The system provides several key benefits:
- Type Safety: Guarantees that API responses conform to the expected TypeScript types, preventing type-related bugs.
- Runtime Validation: Catches unexpected data structures, missing fields, or incorrect data types at the application's boundary (i.e., when data is received from the API).
- Centralized Definitions: All schemas are located in
apps/web/core/types/schemas/, with a centralindex.tsfile for easy importing. - Strictness: All schemas use
.strict()by default, which rejects any unrecognized properties in the data, preventing unexpected data from propagating through the application.
Sources: apps/web/core/types/schemas/README.md:6-10, apps/web/core/types/schemas/README.md:104-108, apps/web/core/types/schemas/index.ts
Validation Flow
The typical flow for validating an API response involves fetching data and passing it through a validation utility function. If validation succeeds, the function returns the typed data; otherwise, it throws a ValidationError.
The diagram below illustrates the API response validation process.
This diagram shows the conditional flow of data validation after an API call.
Sources: apps/web/core/types/schemas/README.md:18-26, apps/web/core/types/schemas/README.md:94-102
Validation Utilities
A set of helper functions standardizes how validation is performed.
| Function | Description |
|---|---|
zodParse(schema, data) | Parses data against a schema and throws an exception on failure. |
zodSafeParse(schema, data) | Parses data without throwing exceptions, returning a success/error object. |
validateApiResponse(schema, data) | A wrapper for zodParse specifically for single API responses. |
validatePaginationResponse(itemSchema, data) | Validates paginated API responses, applying a schema to each item. |
Sources: apps/web/core/types/schemas/README.md:59-63
Core Data Models
The application defines schemas for numerous business entities. These schemas are composed of base schemas and specific entity properties. Below are some of the key data models.
Task Schema (task.schema.ts)
The Task is a central entity in the platform. Its schema is complex, featuring self-references for parent-child relationships and associations with other entities like Employee, Tag, and OrganizationTeam.
Key properties of the taskSchema include:
id,title,description,number,prefix- Status-related fields:
status,priority,size,issueType - Date fields:
startDate,dueDate,resolvedAt - Estimation fields:
estimate,estimateHours,estimateMinutes - Relational IDs:
projectId,parentId,taskStatusId, etc. - Associations:
tags,members,teams - Self-References:
parent,rootEpic,children,linkedIssues
Sources: apps/web/core/types/schemas/task/task.schema.ts:40-70
The diagram below shows the structure of the Task schema, including its recursive relationships.
This class diagram illustrates the TTask type with its properties and relationships, highlighting the self-referencing fields parent, rootEpic, and children.
Sources: apps/web/core/types/schemas/task/task.schema.ts:24-36, apps/web/core/types/schemas/task/task.schema.ts:100-106
Organization Team Schema (organization-team.schema.ts)
The OrganizationTeam model represents a team within an organization. It connects members, projects, tasks, and other configuration entities.
Key properties include:
name,color,emoji,logomembers: An array ofOrganizationTeamEmployeeobjects.managers: A subset of members with manager roles.projects: An array of associatedOrganizationProjects.tasks: An array ofTasks assigned to the team.- Configuration entities:
statuses,priorities,sizes,labels,issueTypes,versions.
Sources: apps/web/core/types/schemas/team/organization-team.schema.ts:16-30, apps/web/core/types/schemas/team/organization-team.schema.ts:35-61
The following ER diagram shows the relationships between OrganizationTeam and other key entities.
This entity-relationship diagram shows how an ORGANIZATION_TEAM is connected to its members (EMPLOYEE), ORGANIZATION_PROJECTs, TASKs, and TAGs.
Sources: apps/web/core/types/schemas/team/organization-team.schema.ts:35-61, apps/web/core/types/schemas/organization/employee.schema.ts:10-14, apps/web/core/types/schemas/task/task.schema.ts:40-42
Employee Schema (employee.schema.ts)
The Employee schema defines the data structure for an employee within an organization. It links to a User account and contains employment-specific details.
| Field | Type | Description |
|---|---|---|
userId | string | The ID of the associated user account. |
startedWorkOn | Date (optional) | The date the employee started working. |
billRateValue | number (optional) | The employee's billing rate. |
billRateCurrency | ECurrencies (optional) | The currency for the billing rate. |
isTrackingEnabled | boolean (optional) | Flag to enable/disable time tracking for the employee. |
isManager | boolean (optional) | Flag indicating if the employee has a manager role. |
teams | OrganizationTeam[] (optional) | The teams the employee is a member of. |
user | User (optional) | The full user object associated with the employee. |
Sources: apps/web/core/types/schemas/organization/employee.schema.ts:10-14, apps/web/core/types/schemas/organization/employee.schema.ts:18-86
Task Status Schema (task-status.schema.ts)
The TaskStatus schema is used to define the different states a task can be in (e.g., "Open", "In Progress", "Done"). It includes visual properties and workflow metadata.
Key properties include:
name: The identifier for the status (e.g.,ETaskStatusName.OPEN).value: The human-readable display name.color: A hex color code for UI representation.isTodo,isInProgress,isDone: Booleans to categorize the status within a workflow.isSystem: A flag indicating if the status is a non-deletable system default.
Sources: apps/web/core/types/schemas/task/task-status.schema.ts:14-29
Usage and Best Practices
The README.md for schemas provides clear guidelines on how to integrate and use the validation system effectively.
Integrating Validation
The recommended approach is to use "validated services," which are wrappers around existing API services that automatically apply schema validation to responses.
// Before
import { roleService } from '@/core/services/client/api/roles/role.service';
// After
import { validatedRoleService as roleService } from '@/core/services/client/api/roles/role-validated.service';
Sources: apps/web/core/types/schemas/README.md:79-85
This pattern ensures that any data returned from roleService is guaranteed to match the defined Zod schema.
Error Handling
It is critical to handle validation errors gracefully. The system throws a custom ValidationError which contains detailed information about the validation failure.
try {
const data = validateApiResponse(schema, response);
return data;
} catch (error) {
if (error instanceof ValidationError) {
// Log detailed validation issues
console.error('Validation failed:', error.issues);
// Show user-friendly message
showErrorToast('Data validation failed. Please try again.');
}
throw error;
}
Sources: apps/web/core/types/schemas/README.md:94-102
Schema Naming Conventions
To maintain consistency, schemas and their inferred types should follow a standard naming convention.
| Type | Convention | Example |
|---|---|---|
| Zod Schema | {entity}Schema | userSchema |
| TypeScript Type | T{Entity} | TUser |
| Create Schema | {entity}CreateSchema | userCreateSchema |
| Update Schema | {entity}UpdateSchema | userUpdateSchema |
Sources: apps/web/core/types/schemas/README.md:128-133
Conclusion
The data modeling and schema validation architecture in Ever Teams is a foundational element for building a reliable and maintainable application. By using Zod to enforce strict data contracts at the API boundary, the system minimizes runtime errors, improves developer confidence, and ensures data integrity throughout the frontend. The centralized and extensible nature of the schema directory allows the platform to scale while maintaining high standards of type safety and data quality.