API Endpoints Overview
Relevant source files
The following files were used as context for generating this wiki page:
The Ever Teams platform operates on a client-server architecture where frontend applications (web, mobile, desktop) communicate with a backend API provided by the Ever Gauzy platform. This document provides an overview of the client-side services and patterns used to manage these API interactions.
The core of the API communication layer is a standardized APIService class that abstracts HTTP requests, handles authentication, and provides a structured way to define endpoints for different application features like Projects, Tasks, and Teams. This ensures consistency, maintainability, and a clear separation of concerns between the UI and data-fetching logic.
Architecture Overview
The frontend applications do not call the API directly. Instead, they use a service layer that encapsulates all HTTP communication. This layer is built around a base APIService which uses axios for making requests. Specific services, such as ProjectService or TaskService, extend this base class to implement feature-specific endpoints.
The diagram below illustrates the high-level data flow from a UI component to the backend API.
API Configuration
The backend API endpoint is not hardcoded. It is configured via environment variables, allowing the frontend to connect to different backend instances (e.g., local development, demo, production).
| Environment Variable | Purpose | Example Value |
|---|---|---|
GAUZY_API_SERVER_URL | Server-side API URL for the Next.js backend. | https://api.ever.team |
NEXT_PUBLIC_GAUZY_API_SERVER_URL | Client-side API URL, exposed to the browser. | https://api.ever.team |
These variables are defined in Docker configuration files, such as docker-compose.yml.
Sources: docker-compose.yml:71-72, docker-compose.demo.yml:5-6, docker-compose.build.yml:5-6
Web Client API Service
The web application's API layer is centered around the APIService base class, which provides a robust foundation for all HTTP requests.
Sources: apps/web/core/services/client/api.service.ts
APIService Base Class
This abstract class standardizes API communication. Any feature-specific service (e.g., ProjectService) extends APIService to inherit its core functionality.
This diagram shows the key properties and methods of the APIService class.
Sources: apps/web/core/services/client/api.service.ts:37-418
Key responsibilities of APIService:
- Axios Instance Management: Creates and configures a shared
axiosinstance. - Request Interceptors: Automatically attaches the
Authorization(Bearer Token) andtenant-idheaders to every outgoing request. - Response Interceptors: Handles global responses, most notably intercepting
401 Unauthorizederrors to trigger a re-authentication flow. It also logs successful and failed responses. - CRUD Methods: Provides standardized methods for
GET,POST,PUT,PATCH, andDELETErequests. - Request Cancellation: Manages request cancellation via
AbortControllerto prevent unnecessary network traffic. - Error Handling: Wraps
axioserrors into a customApiErrorServicefor consistent error management.
Request and Response Flow
The interceptors are crucial for centralizing authentication and error handling logic.
The following sequence diagram shows a typical API call flow:
This diagram illustrates how an API call from a feature service is processed through the APIService and its interceptors.
Sources: apps/web/core/services/client/api.service.ts:159-183, apps/web/core/services/client/api.service.ts:134-157
Unauthorized (401) Error Handling
If the API returns a 401 Unauthorized status, the response interceptor triggers the handleUnauthorized function. This function is responsible for redirecting the user to the login page or attempting a token refresh, providing a centralized mechanism for managing expired sessions.
Sources: apps/web/core/services/client/api.service.ts:152-154, apps/web/core/services/client/api.service.ts:185-212, apps/web/core/services/client/axios.ts:30-37
Specific Service Implementations
Feature-specific services extend APIService to define concrete endpoints. This promotes code organization and reusability.
Example: ProjectService
This service manages all API calls related to projects.
// packages/services/src/projects/project.service.ts
export class ProjectService extends APIService {
constructor(baseURL: string = EVER_TEAMS_API_BASE_URL) {
super(baseURL);
}
async fetchProjects(params?: Record<string, any>) {
// ...
const response = await this.get('/api/projects/', { params });
// ...
}
async createProject(data: any) {
// ...
const response = await this.post<any>('/api/projects/', data);
// ...
}
// ... other methods
}
Sources: packages/services/src/projects/project.service.ts:1-73
Example: TaskService
Similarly, this service handles task-related API calls.
// packages/services/src/task/task.service.ts
export class TaskService extends APIService {
constructor(baseURL: string = EVER_TEAMS_API_BASE_URL) {
super(baseURL);
}
async fetchTasks(params?: Record<string, any>) {
// ...
const response = await this.get<any>('/api/tasks/', { params });
// ...
}
async createTask(data: any) {
// ...
const response = await this.post<any>('/api/tasks/', data);
// ...
}
// ... other methods
}
Sources: packages/services/src/task/task.service.ts:1-73
Mobile Client API Service
The mobile application uses a similar, but distinct, API service class. It leverages apisauce, a wrapper around axios, to simplify API requests.
Sources: apps/mobile/app/services/api/api.ts
Api Class
The mobile Api class encapsulates API configuration and request logic.
Key features:
- Configuration: Initializes with a base URL from
Config.API_URL. - Authentication: Asynchronously loads the auth token and adds it to headers for protected routes.
- Common Methods: Provides
commonGetApi,commonPostApi, andcommonPutApiwrappers that handle response validation and error mapping. - Route Definitions: Centralizes all API route paths in a
routesgetter for easy management.
Mobile API Routes
The routes getter provides a clear mapping of actions to endpoint paths.
| Action | Endpoint Path |
|---|---|
loginUser | auth/login |
registerUser | auth/register |
authenticatedUser | auth/authenticated |
userProfile | user/me |
createWorkspace | tenant |
createOrganization | organization |
startTimer | timesheet/timer/start |
stopTimer | timesheet/timer/stop |
createTeam | organization-team |
Sources: apps/mobile/app/services/api/api.ts:145-156
Data Validation
To ensure data integrity and type safety, the web application uses Zod for runtime validation of API responses. Schemas are defined for various data models (e.g., roleSchema, tagSchema). A validateApiResponse utility function is used to parse and validate incoming data against these schemas, throwing a ValidationError if the data does not match the expected structure. This prevents malformed data from propagating through the application.
Sources: apps/web/core/types/schemas/README.md
Summary
The API endpoint architecture in Ever Teams is designed for scalability and maintainability. By using a base APIService class, the system centralizes common logic like authentication, logging, and error handling. Feature-specific services extend this base class, creating a clean, organized, and decoupled service layer. Both web and mobile clients follow this service-oriented pattern, with configurations managed through environment variables to support different deployment environments.