---
title: "Framework Editor"
description: "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. T..."
last_updated: "2026-05-06T07:29:41.642573+00:00"
canonical_url: "https://www.doc0.dev/docs/49c89830-117b-4def-8edc-b5bcc50766e0/technical/section-8/framework-editor"
---

<details>
<summary>Relevant source files</summary>

The following files were used as context for generating this wiki page:

- [apps/api/src/framework-editor/task-template/dto/create-task-template.dto.ts](https://github.com/blade47/comp/blob/main/apps/api/src/framework-editor/task-template/dto/create-task-template.dto.ts)
- [apps/api/src/framework-editor/task-template/schemas/task-template-operations.ts](https://github.com/blade47/comp/blob/main/apps/api/src/framework-editor/task-template/schemas/task-template-operations.ts)
- [apps/api/src/framework-editor/task-template/dto/update-task-template.dto.ts](https://github.com/blade47/comp/blob/main/apps/api/src/framework-editor/task-template/dto/update-task-template.dto.ts)
- [apps/api/src/framework-editor/task-template/task-template.controller.ts](https://github.com/blade47/comp/blob/main/apps/api/src/framework-editor/task-template/task-template.controller.ts)
- [apps/api/src/framework-editor/task-template/task-template.service.ts](https://github.com/blade47/task-template/blob/main/apps/api/src/framework-editor/task-template/task-template.service.ts)
- [apps/api/src/framework-editor/task-template/task-template.module.ts](https://github.com/blade47/comp/blob/main/apps/api/src/framework-editor/task-template/task-template.module.ts)
</details>

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.

## Architecture Overview

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](https://github.com/blade47/comp/blob/main/apps/api/src/framework-editor/task-template/task-template.module.ts#L1-L7), [apps/api/src/framework-editor/task-template/task-template.controller.ts:20-22](https://github.com/blade47/comp/blob/main/apps/api/src/framework-editor/task-template/task-template.controller.ts#L20-L22), [apps/api/src/framework-editor/task-template/task-template.service.ts:1-4](https://github.com/blade47/comp/blob/main/apps/api/src/framework-editor/task-template/task-template.service.ts#L1-L4)

### TaskTemplateModule

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.

```typescript
@Module({
  imports: [AuthModule],
  controllers: [TaskTemplateController],
  providers: [TaskTemplateService],
  exports: [TaskTemplateService],
})
export class TaskTemplateModule {}
```
Sources: [apps/api/src/framework-editor/task-template/task-template.module.ts:1-7](https://github.com/blade47/comp/blob/main/apps/api/src/framework-editor/task-template/task-template.module.ts#L1-L7)

### TaskTemplateController

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.

```mermaid
sequenceDiagram
    participant Client
    participant Controller as TaskTemplateController
    participant Service as TaskTemplateService
    participant DB as Database

    Client->>Controller: PATCH /framework-editor/task-template/:id (UpdateTaskTemplateDto)
    activate Controller
    Controller->>Controller: Validate ID (ValidateIdPipe)
    Controller->>Controller: Validate Body (ValidationPipe)
    Controller->>Service: updateById(id, updateDto)
    activate Service
    Service->>Service: findById(id)
    activate Service
    Service->>DB: Query existing template
    deactivate Service
    alt Template not found
        Service-->>Controller: NotFoundException
        Controller-->>Client: 404 Not Found
    else Template found
        Service->>DB: Update template data
        DB-->>Service: Updated template
        Service-->>Controller: Updated template
    end
    deactivate Service
    Controller-->>Client: 200 OK (Updated template + AuthContext)
    deactivate Controller
```
Sources: [apps/api/src/framework-editor/task-template/task-template.controller.ts:1-87](https://github.com/blade47/comp/blob/main/apps/api/src/framework-editor/task-template/task-template.controller.ts#L1-L87)

### TaskTemplateService

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.

Sources: [apps/api/src/framework-editor/task-template/task-template.service.ts:6-96](https://github.com/blade47/comp/blob/main/apps/api/src/framework-editor/task-template/task-template.service.ts#L6-L96)

## Data Structures

The module defines specific Data Transfer Objects (DTOs) for creating and updating task templates, ensuring data integrity and clear API contracts.

### CreateTaskTemplateDto

This DTO defines the required fields for creating a new task template. All fields are mandatory and include validation rules.

```typescript
export class CreateTaskTemplateDto {
  name: string; // Task template name
  description: string; // Detailed description
  frequency: Frequency; // Frequency of the task (enum)
  department: Departments; // Department responsible (enum)
}
```

<Callout title="Enums" variant="info">
The `Frequency` and `Departments` enums are imported from `@trycompai/db`, indicating predefined categories for these fields.
</Callout>

| Field        | Type        | Description                                     | Validation                                | Example                   |
| :----------- | :---------- | :---------------------------------------------- | :---------------------------------------- | :------------------------ |
| `name`       | `string`    | Task template name                              | `@IsString()`, `@IsNotEmpty()`            | "Monthly Security Review" |
| `description`| `string`    | Detailed description of the task template       | `@IsString()`, `@IsNotEmpty()`            | "Review and update..."    |
| `frequency`  | `Frequency` | Frequency of the task (e.g., monthly, weekly)   | `@IsEnum(Frequency)`                      | `Frequency.monthly`       |
| `department` | `Departments` | Department responsible for the task (e.g., IT) | `@IsEnum(Departments)`                    | `Departments.it`          |
Sources: [apps/api/src/framework-editor/task-template/dto/create-task-template.dto.ts:1-30](https://github.com/blade47/comp/blob/main/apps/api/src/framework-editor/task-template/dto/create-task-template.dto.ts#L1-L30)

### UpdateTaskTemplateDto

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.

```typescript
import { PartialType } from '@nestjs/swagger';
import { CreateTaskTemplateDto } from './create-task-template.dto';

export class UpdateTaskTemplateDto extends PartialType(CreateTaskTemplateDto) {}
```
Sources: [apps/api/src/framework-editor/task-template/dto/update-task-template.dto.ts:1-4](https://github.com/blade47/comp/blob/main/apps/api/src/framework-editor/task-template/dto/update-task-template.dto.ts#L1-L4)



## API Endpoints

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.

| Method | Path                  | Description                                | Service Method Called | Request Body         |
| :----- | :-------------------- | :----------------------------------------- | :-------------------- | :------------------- |
| `GET`  | `/`                   | Retrieve all task templates                | `findAll()`           | N/A                  |
| `GET`  | `/:id`                | Retrieve a specific task template by ID    | `findById(id)`        | N/A                  |
| `PATCH`| `/:id`                | Update an existing task template by ID     | `updateById(id, dto)` | `UpdateTaskTemplateDto` |
| `DELETE`| `/:id`                | Delete a task template by ID               | `deleteById(id)`      | N/A                  |
Sources: [apps/api/src/framework-editor/task-template/task-template.controller.ts:31-87](https://github.com/blade47/comp/blob/main/apps/api/src/framework-editor/task-template/task-template.controller.ts#L31-L87), [apps/api/src/framework-editor/task-template/schemas/task-template-operations.ts:1-16](https://github.com/blade47/comp/blob/main/apps/api/src/framework-editor/task-template/schemas/task-template-operations.ts#L1-L16)

### Authentication and Authorization

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](https://github.com/blade47/comp/blob/main/apps/api/src/framework-editor/task-template/task-template.controller.ts#L14-L19), [apps/api/src/framework-editor/task-template/task-template.controller.ts:50-51](https://github.com/blade47/comp/blob/main/apps/api/src/framework-editor/task-template/task-template.controller.ts#L50-L51)

### Request Validation

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](https://github.com/blade47/comp/blob/main/apps/api/src/framework-editor/task-template/task-template.controller.ts#L12), [apps/api/src/framework-editor/task-template/task-template.controller.ts:63-68](https://github.com/blade47/comp/blob/main/apps/api/src/framework-editor/task-template/task-template.controller.ts#L63-L68)

## Service Logic Details

The `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](https://github.com/blade47/comp/blob/main/apps/api/src/framework-editor/task-template/task-template.service.ts#L9-L23)

### `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](https://github.com/blade47/comp/blob/main/apps/api/src/framework-editor/task-template/task-template.service.ts#L25-L47)

### `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](https://github.com/blade47/comp/blob/main/apps/api/src/framework-editor/task-template/task-template.service.ts#L49-L69)

### `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](https://github.com/blade47/comp/blob/main/apps/api/src/framework-editor/task-template/task-template.service.ts#L71-L96)

## Sitemap

See the full [sitemap](https://www.doc0.dev/docs/49c89830-117b-4def-8edc-b5bcc50766e0/llms.txt) for all pages in this wiki.
