# luc-ribeiro/task-manager architecture

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

- Interactive diagram: https://gitdiagram.com/luc-ribeiro/task-manager
- Repository: https://github.com/luc-ribeiro/task-manager

## Overview

##### Main Components
- Frontend: Represents the User Interface, built with HTML, CSS, JavaScript (with Bootstrap for responsiveness), and supports communication with the backend via the Fetch API.
- Backend: A RESTful API built with Node.js, Express, and TypeScript. Its structure is organized into several layers:
- Controllers: Handle HTTP requests and responses (located in backend/src/controllers). Specifically, components for task creation, deletion, update, and retrieval.
- Routes: Define the endpoints (e.g., backend/src/routes/task-routes.ts).
- Middleware: Contains error handling and other middleware functionalities (backend/src/middleware).
- Validators: Enforces business rules and sanitizes input data (backend/src/validators).
- Repositories: Handle data persistence and database interactions (backend/src/repositories).
- Database: The application uses MySQL, with configuration and connection handled in backend/db/database.ts.
- External and Supporting Services:
- Documentation: Swagger is used for API documentation (backend/config/swagger.ts).
- Containerization: Docker is used (see Dockerfile, docker-compose.yml) for both backend (and possibly database via docker-compose).

##### Relationships and Interactions Between Components
- Data Flow:
- The frontend sends HTTP requests (using JavaScript’s Fetch API) to the backend API endpoints.
- The backend receives these requests through its routes, passes them to the controllers, and uses middleware for error handling and validations.
- Controller logic utilizes repository functions for database operations (create, read, update, delete tasks).
- Results are returned to the frontend, displaying task data and statuses.
- Inter-component Communication:
- Within the backend, illustrate the flow from routes → controllers → repositories → MySQL database.
- A separate annotation for Docker, showing how containerized components (backend server and MySQL) interact, with external access points (e.g., host ports).

##### Architectural Patterns and Design Principles
- MVC (or a similar separation of concerns):
- Controllers encapsulate business logic,
- Separately organized middleware for cross-cutting concerns,
- Validators enforce data integrity.
- Layered Architecture: Clear separation between presentation (frontend), application logic (backend controllers/routes/middleware), and data persistence (repositories and database).
- Containerization: The Docker and docker-compose components indicate that the application is designed for isolated and consistent deployment environments.

##### Relevant Technologies
- Frontend: HTML5, CSS3, JavaScript (ES6+), Bootstrap 5.
- Backend: Node.js with Express, TypeScript.
- Database: MySQL.
- Documentation: Swagger.
- Testing Tools: Jest (as seen with configuration in backend/jest.config.js) for unit testing controllers and routes.
- Containerization: Docker and Docker Compose.

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Frontend Subgraph
    subgraph "Frontend"
        FE_Index("index.html"):::frontend
        FE_App("app.js"):::frontend
        FE_Styles("styles.css"):::frontend
        FE_UI("Frontend UI (Fetch API)"):::frontend
        FE_Index --> FE_UI
        FE_App --> FE_UI
        FE_Styles --> FE_UI
    end

    %% Docker Container Subgraph (enclosing Backend and Database)
    subgraph "Docker Container"
        subgraph "Backend"
            APP("App (app.ts)"):::backend
            Server("Server (server.ts)"):::backend
            Routes("Routes (API Endpoints)"):::backend
            Middleware("Middleware (Error Handling)"):::backend
            Validators("Task Validator"):::backend
            Controllers("Task Controllers"):::backend
            Repositories("Task Repository"):::backend
            Swagger("Swagger API Docs"):::backend
            Jest("Jest (Unit Testing)"):::backend

            APP --> Server
            Server -->|"HTTP"| Routes
            Routes --> Middleware
            Middleware --> Validators
            Validators --> Controllers
            Controllers --> Repositories
            Repositories --> Database
            Server --> Swagger
            Controllers -.-> Jest
        end
        Database("MySQL Database"):::database
    end

    %% Docker Setup Nodes (External to Docker Container)
    Dockerfile("Dockerfile"):::docker
    DockerCompose("Docker Compose"):::docker

    %% Data Flow from Frontend to Backend
    FE_UI -->|"HTTP Request"| Server

    %% Docker components linking
    Dockerfile -->|"builds"| Server
    Dockerfile -->|"builds"| Database
    DockerCompose -->|"orchestrates"| Server
    DockerCompose -->|"orchestrates"| Database

    %% Styling Classes
    classDef frontend fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef backend fill:#A9DFBF,stroke:#196F3D,stroke-width:2px;
    classDef database fill:#F9E79F,stroke:#B7950B,stroke-width:2px,stroke-dasharray: 5 5;
    classDef docker fill:#F5B7B1,stroke:#943126,stroke-width:2px,stroke-dasharray: 5 5;

    %% Click Events
    click FE_Index "https://github.com/luc-ribeiro/task-manager/blob/main/frontend/index.html"
    click FE_App "https://github.com/luc-ribeiro/task-manager/blob/main/frontend/js/app.js"
    click FE_Styles "https://github.com/luc-ribeiro/task-manager/blob/main/frontend/css/styles.css"
    click APP "https://github.com/luc-ribeiro/task-manager/blob/main/backend/src/app.ts"
    click Server "https://github.com/luc-ribeiro/task-manager/blob/main/backend/src/server.ts"
    click Routes "https://github.com/luc-ribeiro/task-manager/blob/main/backend/src/routes/task-routes.ts"
    click Middleware "https://github.com/luc-ribeiro/task-manager/tree/main/backend/src/middleware/errors/"
    click Validators "https://github.com/luc-ribeiro/task-manager/blob/main/backend/src/validators/task-validator.ts"
    click Controllers "https://github.com/luc-ribeiro/task-manager/tree/main/backend/src/controllers/tasks/"
    click Repositories "https://github.com/luc-ribeiro/task-manager/blob/main/backend/src/repositories/task.ts"
    click Database "https://github.com/luc-ribeiro/task-manager/blob/main/backend/db/database.ts"
    click Swagger "https://github.com/luc-ribeiro/task-manager/blob/main/backend/config/swagger.ts"
    click Dockerfile "https://github.com/luc-ribeiro/task-manager/tree/main/backend/Dockerfile"
    click DockerCompose "https://github.com/luc-ribeiro/task-manager/blob/main/backend/docker-compose.yml"
    click Jest "https://github.com/luc-ribeiro/task-manager/blob/main/backend/jest.config.js"
```
