# tanphat0226/trello_api architecture

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

- Interactive diagram: https://gitdiagram.com/tanphat0226/trello_api
- Repository: https://github.com/tanphat0226/trello_api

## Overview

##### Project type and purpose
- This is the backend of a Trello-style task management application built with the MERN stack.
- It exposes RESTful endpoints (v1 and v2), real-time invitation notifications over WebSockets, handles authentication/authorization, file uploads, email invitations, and CRUD operations on boards, columns, cards, invitations, and users.

##### File structure
- Top-level configs (.babelrc, .eslintrc, .env.example, jsconfig.json, package.json) set up transpilation, linting, environment variables, path aliases.
- src/server.js: application entry point, loads middleware, routes, error handlers, sockets.
- src/routes/v1 & v2: versioned HTTP API layer.
- src/controllers → src/services → src/models: implements an MVC-style layered architecture.
- src/middlewares: authentication, error handling, file-upload (Multer).
- src/providers: external integrations (JWT, Brevo for transactional emails, Cloudinary for media storage).
- src/sockets: real-time invitation socket logic (Socket.io).
- src/config: CORS, environment, MongoDB connection.
- src/utils & src/validations: error definitions, input validation, constants, helper functions.

##### Extract architectural insights from README
- The project is designed to teach REST API best practices.
- Uses Express.js, MongoDB (via Mongoose), real-time via Socket.io, file uploads, email sending.

##### Elements
- Rectangles for internal modules (Routes, Controllers, Services, Models)
- Clouds or hexagons for external services
- Lightning bolt or zigzag for real-time/WebSocket traffic
- Labels for protocols (HTTPS, WSS) and data formats (JSON).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client
    Client["Client (React or any Frontend)"]:::client

    %% Real-time Layer
    Client -->|WSS: invite events| SocketIO["Socket.io\n(Invitation Socket)"]:::realtime
    subgraph "Real-time Layer"
        SocketIO
    end

    %% API Server
    Client -->|HTTPS: REST API v1/v2| APIServer["API Gateway / Express Server"]:::server
    subgraph "API Server"
        direction TB
        Configs["Configuration Modules"]:::config
        Middlewares["Middleware Pipeline"]:::middleware
        RoutesV1["v1 Routes"]:::routes
        RoutesV2["v2 Routes"]:::routes
        Controllers["Controllers"]:::controllers
        Services["Services"]:::services
        Models["Models"]:::models
        Providers["Providers"]:::providers
        Utils["Utilities & Helpers"]:::utils
        Validations["Input Validations"]:::validations

        APIServer --> Configs
        APIServer --> Middlewares
        APIServer --> RoutesV1
        APIServer --> RoutesV2
        RoutesV1 --> Controllers
        RoutesV2 --> Controllers
        Controllers --> Services
        Services --> Models
        Services --> Providers
        Controllers --> Utils
        Controllers --> Validations
    end

    %% Database
    APIServer -->|MongoDB CRUD| MongoDB["MongoDB Atlas\n(Cylinder)"]:::db

    %% External Services
    APIServer -->|Upload/Download| Cloudinary["Cloudinary\n(Media Storage)"]:::external
    APIServer -->|Send Emails| Brevo["Brevo\n(Email Provider)"]:::external
    APIServer -->|JWT Issuing/Verification| JWT["JWT Provider"]:::external

    %% Socket emits to Controllers for persistence or business logic
    SocketIO --> Controllers

    %% Click Events
    click APIServer "https://github.com/tanphat0226/trello_api/blob/master/src/server.js"
    click Configs "https://github.com/tanphat0226/trello_api/tree/master/src/config"
    click Configs "https://github.com/tanphat0226/trello_api/blob/master/src/config/cors.js"
    click Configs "https://github.com/tanphat0226/trello_api/blob/master/src/config/environment.js"
    click Configs "https://github.com/tanphat0226/trello_api/blob/master/src/config/mongodb.js"
    click RoutesV1 "https://github.com/tanphat0226/trello_api/blob/master/src/routes/v1/index.js"
    click RoutesV1 "https://github.com/tanphat0226/trello_api/blob/master/src/routes/v1/boardRoute.js"
    click RoutesV1 "https://github.com/tanphat0226/trello_api/blob/master/src/routes/v1/cardRoute.js"
    click RoutesV1 "https://github.com/tanphat0226/trello_api/blob/master/src/routes/v1/columnRoute.js"
    click RoutesV1 "https://github.com/tanphat0226/trello_api/blob/master/src/routes/v1/invitationRoute.js"
    click RoutesV1 "https://github.com/tanphat0226/trello_api/blob/master/src/routes/v1/userRoute.js"
    click RoutesV2 "https://github.com/tanphat0226/trello_api/blob/master/src/routes/v2/index.js"
    click Middlewares "https://github.com/tanphat0226/trello_api/blob/master/src/middlewares/authMiddlewares.js"
    click Middlewares "https://github.com/tanphat0226/trello_api/blob/master/src/middlewares/errorHandlingMiddleware.js"
    click Middlewares "https://github.com/tanphat0226/trello_api/blob/master/src/middlewares/multerUploadMiddlewares.js"
    click Controllers "https://github.com/tanphat0226/trello_api/blob/master/src/controllers/boardController.js"
    click Controllers "https://github.com/tanphat0226/trello_api/blob/master/src/controllers/columnController.js"
    click Controllers "https://github.com/tanphat0226/trello_api/blob/master/src/controllers/cardController.js"
    click Controllers "https://github.com/tanphat0226/trello_api/blob/master/src/controllers/invitationController.js"
    click Controllers "https://github.com/tanphat0226/trello_api/blob/master/src/controllers/userController.js"
    click Services "https://github.com/tanphat0226/trello_api/blob/master/src/services/boardService.js"
    click Services "https://github.com/tanphat0226/trello_api/blob/master/src/services/columnService.js"
    click Services "https://github.com/tanphat0226/trello_api/blob/master/src/services/cardService.js"
    click Services "https://github.com/tanphat0226/trello_api/blob/master/src/services/invitationService.js"
    click Services "https://github.com/tanphat0226/trello_api/blob/master/src/services/userService.js"
    click Models "https://github.com/tanphat0226/trello_api/blob/master/src/models/boardModel.js"
    click Models "https://github.com/tanphat0226/trello_api/blob/master/src/models/columnModel.js"
    click Models "https://github.com/tanphat0226/trello_api/blob/master/src/models/cardModel.js"
    click Models "https://github.com/tanphat0226/trello_api/blob/master/src/models/invitationModel.js"
    click Models "https://github.com/tanphat0226/trello_api/blob/master/src/models/userModel.js"
    click SocketIO "https://github.com/tanphat0226/trello_api/blob/master/src/sockets/inviteUserToBoardSocket.js"
    click Providers "https://github.com/tanphat0226/trello_api/blob/master/src/providers/JwtProvider.js"
    click Providers "https://github.com/tanphat0226/trello_api/blob/master/src/providers/BrevoProvider.js"
    click Providers "https://github.com/tanphat0226/trello_api/blob/master/src/providers/CloudinaryProvider.js"
    click Utils "https://github.com/tanphat0226/trello_api/blob/master/src/utils/ApiError.js"
    click Utils "https://github.com/tanphat0226/trello_api/blob/master/src/utils/constants.js"
    click Utils "https://github.com/tanphat0226/trello_api/blob/master/src/utils/algorithms.js"
    click Utils "https://github.com/tanphat0226/trello_api/blob/master/src/utils/formatters.js"
    click Utils "https://github.com/tanphat0226/trello_api/blob/master/src/utils/sorts.js"
    click Utils "https://github.com/tanphat0226/trello_api/blob/master/src/utils/validators.js"
    click Validations "https://github.com/tanphat0226/trello_api/blob/master/src/validations/boardValidation.js"
    click Validations "https://github.com/tanphat0226/trello_api/blob/master/src/validations/columnValidation.js"
    click Validations "https://github.com/tanphat0226/trello_api/blob/master/src/validations/cardValidation.js"
    click Validations "https://github.com/tanphat0226/trello_api/blob/master/src/validations/invitationValidation.js"
    click Validations "https://github.com/tanphat0226/trello_api/blob/master/src/validations/userValidation.js"

    %% Styles
    classDef client fill:#f9f,stroke:#333,stroke-width:2px
    classDef server fill:#bbf,stroke:#333,stroke-width:2px
    classDef config fill:#dfd,stroke:#333,stroke-width:1px
    classDef middleware fill:#ffd,stroke:#333,stroke-width:1px
    classDef routes fill:#fbf,stroke:#333,stroke-width:1px
    classDef controllers fill:#bfb,stroke:#333,stroke-width:1px
    classDef services fill:#ffb,stroke:#333,stroke-width:1px
    classDef models fill:#fbb,stroke:#333,stroke-width:1px
    classDef providers fill:#ddf,stroke:#333,stroke-width:1px
    classDef utils fill:#eee,stroke:#333,stroke-width:1px
    classDef validations fill:#eed,stroke:#333,stroke-width:1px
    classDef db fill:#ccf,stroke:#333,stroke-width:2px
    classDef external fill:#ffc,stroke:#333,stroke-width:2px
    classDef realtime fill:#fcf,stroke:#333,stroke-width:2px
```
