System Architecture
Core Features
Data Management
Frontend Components
Extensibility
The following files were used as context for generating this wiki page:
The Framework Editor module provides an API for managing "Task Templates". These templates define recurring tasks with properties such as name, description, frequency, and responsible department. The module offers standard CRUD (Create, Read, Update, Delete) operations for these task templates, exposed via a RESTful API.
This module is built using the NestJS framework, adhering to its architectural patterns of controllers, services, and DTOs (Data Transfer Objects) to ensure a clear separation of concerns and maintainability. It integrates with an authentication system and uses database interactions for persistence.
The Framework Editor's Task Template component follows a typical NestJS modular architecture, consisting of a module, controller, and service. This structure facilitates organized code and clear responsibilities for handling API requests, business logic, and data persistence.
Sources: apps/api/src/framework-editor/task-template/task-template.module.ts:1-7, apps/api/src/framework-editor/task-template/task-template.controller.ts:20-22, apps/api/src/framework-editor/task-template/task-template.service.ts:1-4
The TaskTemplateModule is the entry point for this part of the Framework Editor. It imports the AuthModule for authentication capabilities and registers TaskTemplateController and TaskTemplateService. The TaskTemplateService is also exported, making it available for use by other modules if needed.
@Module({
imports: [AuthModule],
controllers: [TaskTemplateController],
providers: [TaskTemplateService],
exports: [TaskTemplateService],
})
export class TaskTemplateModule {}The TaskTemplateController handles incoming HTTP requests related to task templates. It defines the API endpoints, applies authentication guards (HybridAuthGuard), and uses DTOs for request body validation. It delegates business logic to the TaskTemplateService. All endpoints are secured and require an X-Organization-Id header.
The TaskTemplateService encapsulates the business logic for managing task templates. It interacts directly with the database via db.frameworkEditorTaskTemplate (presumably a Prisma client or similar ORM) to perform CRUD operations. It includes error handling and logging for database interactions and throws NotFoundException for non-existent resources.
The module defines specific Data Transfer Objects (DTOs) for creating and updating task templates, ensuring data integrity and clear API contracts.
This DTO defines the required fields for creating a new task template. All fields are mandatory and include validation rules.
export class CreateTaskTemplateDto {
name: string; // Task template name
description: string; // Detailed description
frequency: Frequency; // Frequency of the task (enum)
department: Departments; // Department responsible (enum)
}The Frequency and Departments enums are imported from @trycompai/db, indicating predefined categories for these fields.
The UpdateTaskTemplateDto is based on CreateTaskTemplateDto but uses PartialType from @nestjs/swagger. This makes all fields optional, allowing for partial updates of a task template.
import { PartialType } from '@nestjs/swagger';
import { CreateTaskTemplateDto } from './create-task-template.dto';
export class UpdateTaskTemplateDto extends PartialType(CreateTaskTemplateDto) {}The TaskTemplateController exposes a set of RESTful API endpoints for managing task templates. All endpoints are versioned under /v1/framework-editor/task-template and require authentication.
All endpoints in the TaskTemplateController are protected by HybridAuthGuard. This guard enforces authentication, which can be either session-based or API key-based. The X-Organization-Id header is required for session authentication and optional for API key authentication. The AuthContext decorator is used to inject authentication details (e.g., userId, userEmail, authType) into controller methods.
Sources: apps/api/src/framework-editor/task-template/task-template.controller.ts:14-19, apps/api/src/framework-editor/task-template/task-template.controller.ts:50-51
The module employs several validation mechanisms:
ValidateIdPipe: Ensures that the id parameter in the URL is valid before it reaches the service layer.ValidationPipe: Applied to the updateTaskTemplate endpoint, it validates the UpdateTaskTemplateDto request body against the rules defined in the DTO (e.g., @IsString, @IsEnum). It is configured to whitelist and forbidNonWhitelisted properties, ensuring only expected data is processed.
Sources: apps/api/src/framework-editor/task-template/task-template.controller.ts:12, apps/api/src/framework-editor/task-template/task-template.controller.ts:63-68The TaskTemplateService implements the core logic for interacting with the database. It uses a Logger for operational insights and robust error handling.
findAll()Retrieves all task templates from the database, ordered alphabetically by name. Logs the number of retrieved templates.
Sources: apps/api/src/framework-editor/task-template/task-template.service.ts:9-23
findById(id: string)Fetches a single task template by its unique id. If no template is found, it throws a NotFoundException.
Sources: apps/api/src/framework-editor/task-template/task-template.service.ts:25-47
updateById(id: string, updateDto: UpdateTaskTemplateDto)Updates an existing task template. It first calls findById to ensure the template exists. If found, it proceeds with the update operation using the provided updateDto.
Sources: apps/api/src/framework-editor/task-template/task-template.service.ts:49-69
deleteById(id: string)Deletes a task template by its id. Similar to updateById, it first verifies the template's existence using findById before performing the deletion. It returns a confirmation message and details of the deleted template.
Sources: apps/api/src/framework-editor/task-template/task-template.service.ts:71-96