# macchiitaka/tasks-api-express architecture

> Architecture diagram of the GitHub repository macchiitaka/tasks-api-express, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/macchiitaka/tasks-api-express
- Repository: https://github.com/macchiitaka/tasks-api-express

## Overview

##### Project Type and Purpose
- The project is a full-stack back-end API that offers task management functionalities via a REST API.
- It uses Express as the web framework, TypeScript for type safety, and Prisma as an ORM connecting to a PostgreSQL database.
- The architecture is inspired by Clean Architecture, which separates application concerns into distinct layers (Domain, Application, Infrastructure, and Interfaces).

##### Analyzing the File Structure – Key Directories
- src/application:
- Contains use cases (e.g., create-task, get-task, list-tasks, remove-task, replace-task) and repository interfaces that abstract how the domain accesses data.
- src/domain:
- Contains domain models (e.g., task-model.ts) which represent the core business entities.
- src/infrastructure:
- Contains controllers, handlers, the router, and the server setup. This layer acts as the delivery mechanism for HTTP requests.
- src/interfaces:
- Provides adapters for external systems:
- Controllers testing and implementation.
- Database adapter using Prisma (prisma.ts).
- Repository implementations bridging the domain with the database.
- Serializers to format the data for outgoing API responses.
- prisma:
- Consists of the schema and migration files that define the database structure and transformation history.
- Other configuration and tooling files (e.g., .eslintrc.js, prettier config, GitHub workflows) help in building, testing, linting, and deploying the project.

##### Main Components
a. External Clients & HTTP Requests:
- External API consumers making HTTP requests.
b. API Layer (Express Server):
- Entry point (server.ts) that initializes the Express app, applies middleware (e.g., Helmet, CORS), and sets up the routing.
- Router (router.ts) that forwards specific task-related endpoints to the corresponding controllers.
c. Controllers & Handlers:
- Handlers (in infrastructure/handlers) responsible for executing task-related operations.
d. Application Layer:
- Use Cases (e.g., create-task, get-task) that encapsulate the business logic.
- Repository Interfaces to abstract data access, thus decoupling the application logic from persistence concerns.
e. Domain Layer:
- Domain models (e.g., task-model.ts) representing the fundamental business entities.
- That these models are independent of external frameworks.
f. Data Persistence Layer:
- Adapters using Prisma (prisma/schema.prisma, prisma/migrations) to interact with a PostgreSQL database.
- Repository implementations (e.g., task-repository.ts) placed in interfaces connect the domain to the database through Prisma.
g. External Services and Tools:
- Deployment tools (e.g., Heroku as depicted by Procfile).
- Utility tools such as GitHub workflows for CI/CD, linters, and formatters, though these are not directly part of the runtime flow, they ensure code quality and smooth deployment.

##### Relationships and Interactions
- From the server/router, show how requests are forwarded to controllers/handlers.
- Controllers then invoke use cases from the application layer, which in turn leverage domain models to execute business logic.
- The application layer interacts with repository interfaces; these interfaces are implemented by adapter classes in the interfaces directory.
- Flow from these repository implementations to the persistence layer (Prisma & PostgreSQL).
- Optionally, include feedback flow for error handling and logging by referencing utility modules (from src/utils).

##### Architectural Patterns and Design Principles
- Use of Clean Architecture: the system is structured so that the domain and application layers are independent of external details.
- Use dependency inversion to show that higher-level modules (use cases) do not depend on lower-level modules (database implementations) directly.
- Clearly separate concerns between layers to facilitate testing and future scalability.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A("External API Consumer"):::external

    subgraph "API Layer (Express Server)"
        B("Express Server"):::api
        C("Router"):::api
    end

    subgraph "Controllers & Handlers"
        D("Controllers (Infrastructure)"):::controller
        E("Tasks Controller (Interfaces)"):::controller
        F("Tasks Handlers"):::controller
    end

    subgraph "Application Layer (Use Cases & Repository Interfaces)"
        G("Use Case: Create Task"):::app
        H("Use Case: Get Task"):::app
        I("Use Case: List Tasks"):::app
        J("Use Case: Remove Task"):::app
        K("Use Case: Replace Task"):::app
        L("Task Repository Interface"):::app
    end

    subgraph "Domain Layer (Models)"
        M("Task Model"):::domain
    end

    subgraph "Data Persistence Layer (Prisma & Repositories)"
        N("Task Repository Implementation"):::persistence
        O("Database Adapter (Prisma)"):::persistence
        P("Prisma Schema"):::persistence
        Q("Migrations"):::persistence
    end

    subgraph "External Services and Tools"
        R("Deployment (Procfile)"):::externalTools
        S("GitHub Workflows"):::externalTools
        T("Error Utility"):::externalTools
        U("Type Utility"):::externalTools
    end

    A -->|"sends request to"| B
    B -->|"initializes"| C
    C -->|"routes to"| D
    C -->|"routes to"| E
    D -->|"delegates to"| F
    E -->|"delegates to"| F
    F -->|"invokes"| G
    F -->|"invokes"| H
    F -->|"invokes"| I
    F -->|"invokes"| J
    F -->|"invokes"| K
    G -->|"uses"| M
    H -->|"uses"| M
    I -->|"uses"| M
    J -->|"uses"| M
    K -->|"uses"| M
    G -->|"calls"| L
    H -->|"calls"| L
    I -->|"calls"| L
    J -->|"calls"| L
    K -->|"calls"| L
    L -->|"implemented by"| N
    N -->|"uses"| O
    O -->|"manages"| P
    O -->|"manages"| Q

    classDef external fill:#f9e79f,stroke:#333,stroke-width:2px;
    classDef api fill:#aed6f1,stroke:#333,stroke-width:2px;
    classDef controller fill:#abebc6,stroke:#333,stroke-width:2px;
    classDef app fill:#f5b7b1,stroke:#333,stroke-width:2px;
    classDef domain fill:#d7bde2,stroke:#333,stroke-width:2px;
    classDef persistence fill:#f9e79f,stroke:#333,stroke-width:2px;
    classDef externalTools fill:#d6eaf8,stroke:#333,stroke-width:2px;

    click B "https://github.com/macchiitaka/tasks-api-express/blob/main/src/infrastructure/server.ts"
    click C "https://github.com/macchiitaka/tasks-api-express/blob/main/src/infrastructure/router.ts"
    click D "https://github.com/macchiitaka/tasks-api-express/blob/main/src/infrastructure/controllers.ts"
    click E "https://github.com/macchiitaka/tasks-api-express/blob/main/src/interfaces/controllers/tasks-controller.ts"
    click F "https://github.com/macchiitaka/tasks-api-express/blob/main/src/infrastructure/handlers/tasks-handlers.ts"
    click G "https://github.com/macchiitaka/tasks-api-express/blob/main/src/application/usecases/create-task.ts"
    click H "https://github.com/macchiitaka/tasks-api-express/blob/main/src/application/usecases/get-task.ts"
    click I "https://github.com/macchiitaka/tasks-api-express/blob/main/src/application/usecases/list-tasks.ts"
    click J "https://github.com/macchiitaka/tasks-api-express/blob/main/src/application/usecases/remove-task.ts"
    click K "https://github.com/macchiitaka/tasks-api-express/blob/main/src/application/usecases/replace-task.ts"
    click L "https://github.com/macchiitaka/tasks-api-express/blob/main/src/application/repository-interface/task-repository-interface.ts"
    click M "https://github.com/macchiitaka/tasks-api-express/blob/main/src/domain/models/task-model.ts"
    click N "https://github.com/macchiitaka/tasks-api-express/blob/main/src/interfaces/repositories/task-repository.ts"
    click O "https://github.com/macchiitaka/tasks-api-express/blob/main/src/interfaces/database/prisma.ts"
    click P "https://github.com/macchiitaka/tasks-api-express/blob/main/prisma/schema.prisma"
    click Q "https://github.com/macchiitaka/tasks-api-express/tree/main/prisma/migrations/"
    click R "https://github.com/macchiitaka/tasks-api-express/tree/main/Procfile"
    click S "https://github.com/macchiitaka/tasks-api-express/tree/main/.github/workflows/"
    click T "https://github.com/macchiitaka/tasks-api-express/blob/main/src/utils/error.ts"
    click U "https://github.com/macchiitaka/tasks-api-express/blob/main/src/utils/type.ts"
```
