# ngantrandev/todo-list-api architecture

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

- Interactive diagram: https://gitdiagram.com/ngantrandev/todo-list-api
- Repository: https://github.com/ngantrandev/todo-list-api

## Overview

##### Main components
- API Server: Mark the central entry point as src/index.ts where the Express server is initialized.
- Configurations: Include a configuration layer (src/configs) that sets up the database (db.config.ts), environment variables (env.config.ts), logger (logger.config.ts), Redis (redis.config.ts), and scheduling (schedule.config.ts).
- Routes & Controllers: Show the separation between the routes (src/routes) and controllers (src/controllers) that handle user requests for authentication (auth.controllers.ts), task management (task.controllers.ts), and user routes.
- Middlewares: Represent the middleware components (src/middlewares) like logger middleware and request verification.
- Services: Indicate the core business logic services (src/services), with dependency.service.ts managing task dependencies and circular dependency detection logic.
- Data Layer: Illustrate interaction with the MySQL database (as in documents/db/tododb.sql and other SQL scripts) and how it is used by the application.
- Redis Cache: Show the connection to Redis from the Redis configuration; use it for caching or possibly session management.
- Docker & Deployment: Include elements showing Docker (Dockerfile, docker-compose.yaml) as well as environment configurations (example.env).

##### Detail the relationships and interactions
- From controllers, show calls to the services layer where business logic (like circular dependency detection) is encapsulated.
- Middleware chain layered between incoming requests and the controller logic.
- Clearly denote the configuration layer that underpins database connection details, caching configuration, and environment variables.

##### Architectural patterns or design principles
- Separation of concerns: Illustrate how routes, controllers, services, and configuration are isolated in different directories.
- Modular design: Each module (routes, controllers, services) is independent, making the API maintainable and scalable.
- Dependency management: Highlight the dedicated service for detecting circular dependencies in task graphs.

##### Relevant technologies and frameworks
- MySQL (as indicated in the README and SQL files), Redis, and Nodemailer with their associated configurations.
- That TypeScript is used (via tsconfig.json, use of .ts files) and that the project is bundled with Webpack (webpack.config.js).

##### Final Advice
- Be as detailed as possible. Even though the project is relatively straightforward, ensure that every component (from server initialization in src/index.ts to the configuration files in src/configs) is captured.
- Do not shy away from including smaller components like middlewares and utility functions if they logically impact data flow.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Top Level: Client and Entry Point
    Client["API Client"]:::client
    APIServer["Express API Server"]:::api

    Client -->|"sends request"| APIServer

    %% Subgraph: Configurations
    subgraph "Configurations"
        DBConfig["Database Configuration"]:::config
        EnvConfig["Environment Variables"]:::config
        LoggerConfig["Logger Configuration"]:::config
        RedisConfig["Redis Configuration"]:::config
        ScheduleConfig["Scheduling Configuration"]:::config
    end
    %% Configurations feed into API Server
    DBConfig --- APIServer
    EnvConfig --- APIServer
    LoggerConfig --- APIServer
    RedisConfig --- APIServer
    ScheduleConfig --- APIServer

    %% Subgraph: Middlewares
    subgraph "Middlewares"
        LoggerMiddleware["Logger Middleware"]:::middleware
        VerifyMiddleware["Request Verification Middleware"]:::middleware
    end
    %% API Server uses middlewares
    APIServer -->|"triggers"| LoggerMiddleware
    APIServer -->|"triggers"| VerifyMiddleware

    %% Subgraph: Routes & Controllers
    subgraph "Routes & Controllers"
        APIRoutes["API Routes"]:::routes
        AuthRoutes["Authentication Routes"]:::routes
        AuthController["Authentication Controller"]:::routes
        TaskRoutes["Task Routes"]:::routes
        TaskController["Task Controller"]:::routes
        UserRoutes["User Routes"]:::routes
    end
    %% Middlewares pass requests to routes
    LoggerMiddleware -->|"forwards"| APIRoutes
    VerifyMiddleware -->|"forwards"| AuthRoutes
    VerifyMiddleware -->|"forwards"| TaskRoutes
    VerifyMiddleware -->|"forwards"| UserRoutes
    
    %% Routes connect to Controllers
    AuthRoutes -->|"delegates"| AuthController
    TaskRoutes -->|"delegates"| TaskController

    %% Subgraph: Services
    subgraph "Services"
        DependencyService["Dependency Service"]:::service
    end
    %% Controllers call services for business logic
    AuthController -->|"calls"| DependencyService
    TaskController -->|"calls"| DependencyService

    %% Subgraph: Data & External Services
    subgraph "Data & External"
        MySQLDB["MySQL Database"]:::db
        SQLScripts["MySQL Additional Scripts"]:::db
        RedisCache["Redis Cache"]:::db
        EmailService["Email Notification Service"]:::external
    end
    %% Dependency Service interfaces with Data Layer
    DependencyService <-->|"queries"| MySQLDB
    DependencyService <-->|"caches"| RedisCache

    %% Subgraph: Scheduled Jobs
    subgraph "Scheduled Jobs"
        NotificationScheduler["Notification Scheduler"]:::scheduled
    end
    %% Scheduled job triggers email notifications
    NotificationScheduler -->|"sends"| EmailService

    %% Connections from Routes to Services
    APIRoutes -->|"routes to business logic"| DependencyService

    %% Subgraph: Docker & Deployment
    subgraph "Docker & Deployment"
        Dockerfile["Dockerfile"]:::docker
        DockerCompose["docker-compose.yaml"]:::docker
        EnvExample["Environment Example"]:::docker
    end
    %% Docker deployment wraps API Server
    Dockerfile --> APIServer
    DockerCompose --> APIServer
    EnvExample --> APIServer

    %% Subgraph: Bundling & TypeScript Configuration
    subgraph "Bundling & TS"
        WebpackConfig["Webpack Config"]:::bundling
        TSConfig["TypeScript Config"]:::bundling
    end
    %% Build tools feed into API Server
    WebpackConfig --> APIServer
    TSConfig --> APIServer

    %% Click Events
    click APIServer "https://github.com/ngantrandev/todo-list-api/blob/main/src/index.ts"
    click DBConfig "https://github.com/ngantrandev/todo-list-api/blob/main/src/configs/db.config.ts"
    click EnvConfig "https://github.com/ngantrandev/todo-list-api/blob/main/src/configs/env.config.ts"
    click LoggerConfig "https://github.com/ngantrandev/todo-list-api/blob/main/src/configs/logger.config.ts"
    click RedisConfig "https://github.com/ngantrandev/todo-list-api/blob/main/src/configs/redis.config.ts"
    click ScheduleConfig "https://github.com/ngantrandev/todo-list-api/blob/main/src/configs/schedule.config.ts"
    click APIRoutes "https://github.com/ngantrandev/todo-list-api/blob/main/src/routes/api.routes.ts"
    click AuthRoutes "https://github.com/ngantrandev/todo-list-api/blob/main/src/routes/auth.routes.ts"
    click AuthController "https://github.com/ngantrandev/todo-list-api/blob/main/src/controllers/auth.controllers.ts"
    click TaskRoutes "https://github.com/ngantrandev/todo-list-api/blob/main/src/routes/task.routes.ts"
    click TaskController "https://github.com/ngantrandev/todo-list-api/blob/main/src/controllers/task.controllers.ts"
    click UserRoutes "https://github.com/ngantrandev/todo-list-api/blob/main/src/routes/user.routes.ts"
    click LoggerMiddleware "https://github.com/ngantrandev/todo-list-api/blob/main/src/middlewares/logger.middleware.ts"
    click VerifyMiddleware "https://github.com/ngantrandev/todo-list-api/blob/main/src/middlewares/verify.middleware.ts"
    click DependencyService "https://github.com/ngantrandev/todo-list-api/blob/main/src/services/dependency.service.ts"
    click MySQLDB "https://github.com/ngantrandev/todo-list-api/blob/main/documents/db/tododb.sql"
    click SQLScripts "https://github.com/ngantrandev/todo-list-api/tree/main/documents/db/v1"
    click Dockerfile "https://github.com/ngantrandev/todo-list-api/tree/main/Dockerfile"
    click DockerCompose "https://github.com/ngantrandev/todo-list-api/blob/main/docker-compose.yaml"
    click EnvExample "https://github.com/ngantrandev/todo-list-api/blob/main/example.env"
    click WebpackConfig "https://github.com/ngantrandev/todo-list-api/blob/main/webpack.config.js"
    click TSConfig "https://github.com/ngantrandev/todo-list-api/blob/main/tsconfig.json"
    click NotificationScheduler "https://github.com/ngantrandev/todo-list-api/blob/main/src/configs/schedule.config.ts"

    %% Styles
    classDef client fill:#add8e6,stroke:#000,stroke-width:2px;
    classDef api fill:#FFD700,stroke:#000,stroke-width:2px;
    classDef config fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef middleware fill:#87CEEB,stroke:#000,stroke-width:2px;
    classDef routes fill:#FFA07A,stroke:#000,stroke-width:2px;
    classDef service fill:#D8BFD8,stroke:#000,stroke-width:2px;
    classDef db fill:#F08080,stroke:#000,stroke-width:2px;
    classDef external fill:#FFB6C1,stroke:#000,stroke-width:2px;
    classDef scheduled fill:#FFE4B5,stroke:#000,stroke-width:2px;
    classDef docker fill:#E6E6FA,stroke:#000,stroke-width:2px;
    classDef bundling fill:#98FB98,stroke:#000,stroke-width:2px;
```
