# haiatami/to-do architecture

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

- Interactive diagram: https://gitdiagram.com/haiatami/to-do
- Repository: https://github.com/haiatami/to-do

## Overview

##### Project Type and Purpose
- This is a backend REST API for a To-Do list application built using Spring Boot. It handles task management (creation, update, deletion, listing), task dependencies, and notifications.
- It makes use of MySQL as the relational database for persisting task information and leverages Redis (optionally) for caching.
- It also provides Docker and Docker Compose configurations for containerized deployment that integrates the API, MySQL, and Redis.

##### File Structure
- The project follows a typical Maven structure with the main source code located in src/main/java and tests in src/test/java.
- The Java packages are organized by feature (e.g., controllers, dtos, entities, enums, repositorys, and services/impl), suggesting a layered (or hexagonal-like) architecture.
- Several configuration files exist: application.properties for Spring Boot configuration; Dockerfile and docker-compose.yml for containerized deployment.
- The main entry point is ToDoApplication.java, and REST controllers are organized under the “controllers” package which indicates REST endpoints mapping.
- Services (and their implementations) encapsulate business logic while repositories abstract the persistence logic.

##### Key Components
- API Gateway / REST Controllers: Representing the API endpoints (TaskController, NotificationController, TaskDependencyController) that receive and process HTTP requests.
- Data Access Layer: Repositories for Task and TaskDependencies that interact with the MySQL database.
- Data Storage: MySQL for persistent storage of tasks and dependency data.
- Cache Layer (optional): Redis, which is usually used for caching task information or other data as configured.
- External Interfaces:
- The clients (e.g., front-end client or mobile apps) that consume these REST APIs.
- Docker environment for container orchestration.

##### Relationships and Interactions
- A clear separation between the client layer and the internal layers.
- Service interactions with external resources such as MySQL and Redis.
- In the case of notifications, illustrate the use of EmailService (external email provider integration can also be depicted if required).

##### Architectural Patterns and Design Principles
- Layered Architecture: The division into controllers, services, and repositories enforces separation of concerns.
- RESTful API design: Clearly defined endpoints and HTTP operations.
- Dependency Injection: Managed by Spring Boot.
- Containerization: Use of Docker and Docker Compose to separate concerns in deployment by containerizing the API, database, and caching layer.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Client Layer
    subgraph "Client Layer"
        Client["Client / Consumer"]:::client
    end

    %% API Layer - REST Controllers
    subgraph "API Layer"
        TC["TaskController (REST)"]:::controllers
        NC["NotificationController (REST)"]:::controllers
        TDC["TaskDependencyController (REST)"]:::controllers
    end

    %% Service Layer
    subgraph "Service Layer"
        subgraph "Task Services"
            TSI["TaskService (Interface)"]:::services
            TSImpl["TaskServiceImpl (Impl)"]:::services
        end
        subgraph "Notification Services"
            NSI["NotificationService (Interface)"]:::services
            NSImpl["NotificationServiceImpl (Impl)"]:::services
            ESI["EmailService (Interface)"]:::services
            ESImpl["EmailServiceImpl (Impl)"]:::services
        end
        subgraph "Task Dependency Services"
            TDSI["TaskDependencyService (Interface)"]:::services
            TDSImpl["TaskDependencyServiceImpl (Impl)"]:::services
        end
    end

    %% Data Access Layer (Repositories)
    subgraph "Data Access Layer"
        TR["TaskRepository"]:::repos
        TDR["TaskDependenciesRepository"]:::repos
    end

    %% Data Storage & Cache
    subgraph "Data Storage & Cache"
        MySQL["MySQL Database"]:::storage
        Redis["Redis Cache"]:::storage
        APP["Spring Boot Config"]:::storage
    end

    %% Docker Environment (Containers)
    subgraph "Docker Environment"
        APICont["API Container"]:::deployment
        MySQLCont["MySQL Container"]:::deployment
        RedisCont["Redis Container"]:::deployment
    end

    %% Deployment Configurations
    subgraph "Deployment Config"
        DF["Dockerfile"]:::deployment
        DC["docker-compose.yml"]:::deployment
    end

    %%----------------------------------------
    %% Relationships and Flow

    %% Client to REST Controllers
    Client -->|"sendsRequest"| TC
    Client -->|"sendsRequest"| NC
    Client -->|"sendsRequest"| TDC

    %% REST Controllers to Services
    TC -->|"calls"| TSI
    NC -->|"calls"| NSI
    TDC -->|"calls"| TDSI

    %% Service interfaces to implementations
    TSI -->|"uses"| TSImpl
    NSI -->|"uses"| NSImpl
    TDSI -->|"uses"| TDSImpl

    %% NotificationService calls EmailService
    NSI ---|"calls"| ESI
    ESI -->|"uses"| ESImpl

    %% Services to Repositories
    TSI -->|"calls"| TR
    TDSI -->|"calls"| TDR

    %% Repositories to MySQL Database
    TR -->|"CRUD"| MySQL
    TDR -->|"CRUD"| MySQL

    %% Optional caching from TaskService
    TSI -->|"cache"| Redis

    %% Config node configures MySQL and Redis
    APP ---|"configures"| MySQL
    APP ---|"configures"| Redis

    %% Deployment Config to Docker Environment
    DF -->|"builds"| APICont
    DC -->|"orchestrates"| APICont
    DC -->|"orchestrates"| MySQLCont
    DC -->|"orchestrates"| RedisCont

    %% Containers hosting components
    APICont -->|"hosts"| TC
    MySQLCont -->|"hosts"| MySQL
    RedisCont -->|"hosts"| Redis

    %%----------------------------------------
    %% Styles
    classDef client fill:#e0e0e0,stroke:#333,stroke-width:2px;
    classDef controllers fill:#ffcccc,stroke:#333,stroke-width:2px;
    classDef services fill:#ccffcc,stroke:#333,stroke-width:2px;
    classDef repos fill:#ccccff,stroke:#333,stroke-width:2px;
    classDef storage fill:#ffffcc,stroke:#333,stroke-width:2px;
    classDef deployment fill:#ffebcc,stroke:#333,stroke-width:2px;

    %%----------------------------------------
    %% Click Events for REST Controllers
    click TC "https://github.com/haiatami/to-do/blob/main/src/main/java/com/hoanghai/todo/controllers/TaskController.java"
    click NC "https://github.com/haiatami/to-do/blob/main/src/main/java/com/hoanghai/todo/controllers/NotificationController.java"
    click TDC "https://github.com/haiatami/to-do/blob/main/src/main/java/com/hoanghai/todo/controllers/TaskDependencyController.java"

    %% Click Events for Task Service Layer
    click TSI "https://github.com/haiatami/to-do/blob/main/src/main/java/com/hoanghai/todo/services/TaskService.java"
    click TSImpl "https://github.com/haiatami/to-do/blob/main/src/main/java/com/hoanghai/todo/services/impl/TaskServiceImpl.java"

    %% Click Events for Notification Service Layer
    click NSI "https://github.com/haiatami/to-do/blob/main/src/main/java/com/hoanghai/todo/services/NotificationService.java"
    click NSImpl "https://github.com/haiatami/to-do/blob/main/src/main/java/com/hoanghai/todo/services/impl/NotificationServiceImpl.java"
    click ESI "https://github.com/haiatami/to-do/blob/main/src/main/java/com/hoanghai/todo/services/EmailService.java"
    click ESImpl "https://github.com/haiatami/to-do/blob/main/src/main/java/com/hoanghai/todo/services/impl/EmailServiceImpl.java"

    %% Click Events for Task Dependency Service Layer
    click TDSI "https://github.com/haiatami/to-do/blob/main/src/main/java/com/hoanghai/todo/services/TaskDependencyService.java"
    click TDSImpl "https://github.com/haiatami/to-do/blob/main/src/main/java/com/hoanghai/todo/services/impl/TaskDependencyServiceImpl.java"

    %% Click Events for Data Access Layer
    click TR "https://github.com/haiatami/to-do/blob/main/src/main/java/com/hoanghai/todo/repositorys/TaskRepository.java"
    click TDR "https://github.com/haiatami/to-do/blob/main/src/main/java/com/hoanghai/todo/repositorys/TaskDependenciesRepository.java"

    %% Click Event for Configuration
    click APP "https://github.com/haiatami/to-do/blob/main/src/main/resources/application.properties"

    %% Click Events for Deployment Configurations
    click DF "https://github.com/haiatami/to-do/tree/main/Dockerfile"
    click DC "https://github.com/haiatami/to-do/blob/main/docker-compose.yml"
```
