# gustavofringgg/todolist-backend architecture

> Architecture diagram of the GitHub repository gustavofringgg/todolist-backend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/gustavofringgg/todolist-backend
- Repository: https://github.com/gustavofringgg/todolist-backend

## Overview

##### Main Components

A. API Layer
- Entry Point (app.js)
- Route Handlers (/routes)
- Controllers Layer (/controllers)
- Authentication/Authorization Layer (/utils)

B. Data Layer
- Models Layer (/model)
- Database Connection Layer (/connections)
- Sequelize ORM

C. Supporting Infrastructure
- Error Handling System
- Success Response Handler
- JWT Authentication System
- Swagger Documentation

**[Client Applications] → [API Gateway Layer]**
- ↑                    ↓
- [Auth Layer]──┘
- ↓
- [Controllers Layer (Business Logic)]
- ↓
- [Data Access Layer (Models)]
- ↓
- [Database Connection Layer (Sequelize)]
- ↓
- [Database (SQL Database)]

##### Component Details

a. API Gateway Layer (Blue)
- Routes: /todo and /users
- Swagger documentation integration
- To error handling middleware

b. Authentication Layer (Yellow)
- JWT Token handling (JwtToken.js)
- Token verification (TokenCheck.js)
- To protected routes

c. Controllers Layer (Green)
- TodoController
- UserController
- Connection to error handling (handleErrorAsync.js)
- Success response handling (handleSuccess.js)

d. Data Layer (Purple)
- Todo Model
- User Model
- Sequelize connection
- Model associations

##### Important Flows to Highlight

- Authentication Flow:
Request → TokenCheck → Controller → Response

- CRUD Operations Flow:
Request → Route → Controller → Model → Database

##### Technical Details

- Node.js/Express.js as the main framework
- Sequelize ORM for database operations
- JWT for authentication
- Swagger for API documentation

##### Specific Implementation Notes

- Error handling flows with red lines
- Middleware chain in the request processing pipeline

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        CL[Client Applications]
    end

    subgraph API_Gateway
        EN["Entry Point"]:::entry
        RT["Route Handlers"]:::routes
        SW["Swagger Documentation"]:::swagger
    end

    subgraph Auth_Layer
        JT["JWT Token Handler"]:::auth
        TC["Token Checker"]:::auth
    end

    subgraph Controllers
        TDC["Todo Controller"]:::controller
        USC["User Controller"]:::controller
        EH["Error Handler"]:::error
        SH["Success Handler"]:::success
    end

    subgraph Data_Layer
        subgraph Models
            TM["Todo Model"]:::model
            UM["User Model"]:::model
            NTM["New Todo Model"]:::model
            NUM["New User Model"]:::model
        end
        
        subgraph DB_Connection
            SQ["Sequelize Connection"]:::db
            DBS["Database Sync"]:::db
        end
    end

    subgraph Database
        SQL[(SQL Database)]
    end

    %% Connections
    CL --> EN
    EN --> RT
    RT --> TDC & USC
    RT -.-> SW
    
    TDC & USC --> JT
    JT --> TC
    TC --> TDC & USC
    
    TDC & USC --> EH
    TDC & USC --> SH
    
    TDC --> TM & NTM
    USC --> UM & NUM
    
    TM & UM & NTM & NUM --> SQ
    SQ --> DBS
    DBS --> SQL

    %% Click Events
    click EN "https://github.com/GustavoFringgg/todolist-backend/blob/main/app.js"
    click RT "https://github.com/GustavoFringgg/todolist-backend/tree/main/routes"
    click SW "https://github.com/GustavoFringgg/todolist-backend/blob/main/swagger.js"
    click JT "https://github.com/GustavoFringgg/todolist-backend/blob/main/utils/JwtToken.js"
    click TC "https://github.com/GustavoFringgg/todolist-backend/blob/main/utils/TokenCheck.js"
    click TDC "https://github.com/GustavoFringgg/todolist-backend/blob/main/controllers/todoControllers.js"
    click USC "https://github.com/GustavoFringgg/todolist-backend/blob/main/controllers/userControllers.js"
    click EH "https://github.com/GustavoFringgg/todolist-backend/blob/main/utils/handleErrorAsync.js"
    click SH "https://github.com/GustavoFringgg/todolist-backend/blob/main/utils/handleSuccess.js"
    click TM "https://github.com/GustavoFringgg/todolist-backend/blob/main/model/todomodel.js"
    click UM "https://github.com/GustavoFringgg/todolist-backend/blob/main/model/usermodel.js"
    click NTM "https://github.com/GustavoFringgg/todolist-backend/blob/main/model/new_todomodel.js"
    click NUM "https://github.com/GustavoFringgg/todolist-backend/blob/main/model/new_usermodel.js"
    click SQ "https://github.com/GustavoFringgg/todolist-backend/blob/main/connections/sequelize.js"
    click DBS "https://github.com/GustavoFringgg/todolist-backend/blob/main/sync.js"

    %% Styles
    classDef entry fill:#2196F3,stroke:#1565C0,color:white
    classDef routes fill:#42A5F5,stroke:#1565C0,color:white
    classDef swagger fill:#90CAF9,stroke:#1565C0,color:white
    classDef auth fill:#FFC107,stroke:#FFA000,color:black
    classDef controller fill:#4CAF50,stroke:#388E3C,color:white
    classDef error fill:#f44336,stroke:#d32f2f,color:white
    classDef success fill:#8BC34A,stroke:#689F38,color:white
    classDef model fill:#9C27B0,stroke:#7B1FA2,color:white
    classDef db fill:#7E57C2,stroke:#5E35B1,color:white

    %% Legend
    subgraph Legend
        L1[API Gateway]:::entry
        L2[Auth Components]:::auth
        L3[Controllers]:::controller
        L4[Error Handling]:::error
        L5[Success Handling]:::success
        L6[Data Models]:::model
        L7[Database]:::db
    end
```
