# vuongnguyen333/trello-api architecture

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

- Interactive diagram: https://gitdiagram.com/vuongnguyen333/trello-api
- Repository: https://github.com/vuongnguyen333/trello-api

## Overview

##### Project type and purpose
- This is a Node.js back-end RESTful API (no frontend in this repo) for managing “boards,” “columns,” and “cards” (a Kanban‐style service).
- It uses Express, MongoDB, input validation, WebSockets, and versioned routes (v1, v2).

##### File structure
- Top‐level config:
- .env.example, src/config (cors, environment, mongodb)
- src/server.js (entry point)
- Routing & HTTP layer:
- src/routes/v1/*.js, src/routes/v2/index.js
- Controllers:
- src/controllers/*Controller.js
- Services (business logic):
- src/services/*Service.js
- Data layer:
- src/models/*.js (Mongoose schemas)
- Cross-cutting:
- src/middlewares/errorHandlingMiddleware.js
- src/utils/*.js (errors, formatters, validators, algorithms, constants)
- src/validations/*.js
- Real-time (WebSocket) support:
- src/sockets/exampleSocket.js
- Providers (external integrations):
- src/providers/exampleProvider.js

##### README
- (Empty in this case—structure itself implies MVC + service + socket architecture.)

##### Diagramming the architecture
a. Main components
1. Client(s): HTTP clients (web/mobile) and WebSocket clients
2. API Gateway / Express App
3. Route Modules (v1, v2)
4. Controllers
5. Validation & Middleware Layer
6. Services (business logic)
7. Data Layer (MongoDB via Mongoose models)
8. External Providers (exampleProvider)
9. Socket Server
10. Utilities (ApiError, formatters, etc.)

b. Relationships and data flow
- HTTP Request → Express App
- Passes through CORS + Environment middlewares
- Hits versioned Route Module
- Runs Validation → Controller → Service
- Service interacts with Mongoose Models → MongoDB
- Response bubbles back through Controller → Route → Express → Client
- Errors handled by errorHandlingMiddleware
- WebSocket connections managed by Socket Server → exampleSocket
- Services or Controllers may emit socket events on data changes
- Providers can be called by Services for external integration

c. Architectural patterns & design principles
- MVC‐style separation: Routes → Controllers → Services → Models
- Layered architecture (Validation & Middleware, Business, Data)
- Single responsibility per module
- Versioned API for backward compatibility
- Asynchronous event‐driven sockets for real-time updates

d. Key technologies & libraries
- Node.js + Express
- Mongoose + MongoDB
- Joi or custom validators (in src/validations)
- WebSocket library (socket.io or ws in exampleSocket)
- dotenv for environment vars
- ESLint, Babel for build

##### Final advice
- Be exhaustive in naming each layer and module group
- Real-time vs. RESTful flows distinctly
- Environment/configuration as a separate component

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Clients
    HTTPClient["HTTP Client"]:::externalClient
    WSClient["WebSocket Client"]:::externalClient

    %% Application Entry
    Express["Express App"]:::app

    %% Configuration
    subgraph "Configuration"
        CORS["CORS Config"]:::config
        ENV["Environment Config"]:::config
        MongoConfig["MongoDB Config"]:::config
    end

    %% Routing - v1
    subgraph "Routes v1"
        V1Index["v1/index.js"]:::routes
        BoardRoute["boardRoute.js"]:::routes
        ColumnRoute["columnRoute.js"]:::routes
        CardRoute["cardRoute.js"]:::routes
    end

    %% Routing - v2
    subgraph "Routes v2"
        V2Index["v2/index.js"]:::routes
    end

    %% Middleware & Validation
    subgraph "Middleware & Validation"
        ErrorMiddleware["errorHandlingMiddleware.js"]:::middleware
        BoardVal["boardValidation.js"]:::validations
        ColumnVal["columnValidation.js"]:::validations
        CardVal["cardValidation.js"]:::validations
    end

    %% Controllers
    subgraph "Controllers"
        BoardCtrl["BoardController"]:::controller
        ColumnCtrl["ColumnController"]:::controller
        CardCtrl["CardController"]:::controller
    end

    %% Services
    subgraph "Services"
        BoardSvc["BoardService"]:::service
        ColumnSvc["ColumnService"]:::service
        CardSvc["CardService"]:::service
    end

    %% Data Models
    subgraph "Data Models"
        BoardModel["Board Model"]:::model
        ColumnModel["Column Model"]:::model
        CardModel["Card Model"]:::model
    end

    %% Utilities
    subgraph "Utilities"
        ApiError["ApiError"]:::utils
        Alg["Algorithms"]:::utils
        Const["Constants"]:::utils
        Fmt["Formatters"]:::utils
        Sorts["Sort Helpers"]:::utils
        Vlds["Validators"]:::utils
    end

    %% External Providers
    ExampleProvider["ExampleProvider"]:::external

    %% Database
    DB["MongoDB"]:::db

    %% WebSocket
    SocketServer["Socket Server"]:::socket
    ExampleSocket["exampleSocket.js"]:::socket

    %% Flow - HTTP
    HTTPClient --> Express
    Express --> CORS
    Express --> ENV
    Express --> MongoConfig
    Express --> V1Index
    Express --> V2Index
    V1Index --> BoardRoute
    V1Index --> ColumnRoute
    V1Index --> CardRoute
    BoardRoute --> BoardVal
    ColumnRoute --> ColumnVal
    CardRoute --> CardVal
    BoardVal --> BoardCtrl
    ColumnVal --> ColumnCtrl
    CardVal --> CardCtrl
    BoardCtrl --> BoardSvc
    ColumnCtrl --> ColumnSvc
    CardCtrl --> CardSvc
    BoardSvc --> BoardModel
    ColumnSvc --> ColumnModel
    CardSvc --> CardModel
    BoardSvc --> ExampleProvider
    ColumnSvc --> ExampleProvider
    CardSvc --> ExampleProvider
    BoardSvc --> ApiError
    ColumnSvc --> ApiError
    CardSvc --> ApiError
    BoardSvc --> Alg
    BoardSvc --> Const
    BoardSvc --> Fmt
    BoardSvc --> Sorts
    BoardSvc --> Vlds
    ColumnSvc --> Alg
    ColumnSvc --> Const
    ColumnSvc --> Fmt
    ColumnSvc --> Sorts
    ColumnSvc --> Vlds
    CardSvc --> Alg
    CardSvc --> Const
    CardSvc --> Fmt
    CardSvc --> Sorts
    CardSvc --> Vlds
    BoardModel --> DB
    ColumnModel --> DB
    CardModel --> DB
    Express --> ErrorMiddleware
    ErrorMiddleware --> Express

    %% Flow - WebSocket
    WSClient --> SocketServer
    SocketServer --> ExampleSocket
    ExampleSocket --> BoardSvc
    ExampleSocket --> ColumnSvc
    ExampleSocket --> CardSvc

    %% Click Events
    click Express "https://github.com/vuongnguyen333/trello-api/blob/master/src/server.js"
    click CORS "https://github.com/vuongnguyen333/trello-api/blob/master/src/config/cors.js"
    click ENV "https://github.com/vuongnguyen333/trello-api/blob/master/src/config/environment.js"
    click MongoConfig "https://github.com/vuongnguyen333/trello-api/blob/master/src/config/mongodb.js"
    click V1Index "https://github.com/vuongnguyen333/trello-api/blob/master/src/routes/v1/index.js"
    click BoardRoute "https://github.com/vuongnguyen333/trello-api/blob/master/src/routes/v1/boardRoute.js"
    click ColumnRoute "https://github.com/vuongnguyen333/trello-api/blob/master/src/routes/v1/columnRoute.js"
    click CardRoute "https://github.com/vuongnguyen333/trello-api/blob/master/src/routes/v1/cardRoute.js"
    click V2Index "https://github.com/vuongnguyen333/trello-api/blob/master/src/routes/v2/index.js"
    click BoardCtrl "https://github.com/vuongnguyen333/trello-api/blob/master/src/controllers/boardController.js"
    click ColumnCtrl "https://github.com/vuongnguyen333/trello-api/blob/master/src/controllers/columnController.js"
    click CardCtrl "https://github.com/vuongnguyen333/trello-api/blob/master/src/controllers/cardController.js"
    click BoardSvc "https://github.com/vuongnguyen333/trello-api/blob/master/src/services/boardService.js"
    click ColumnSvc "https://github.com/vuongnguyen333/trello-api/blob/master/src/services/columnService.js"
    click CardSvc "https://github.com/vuongnguyen333/trello-api/blob/master/src/services/cardService.js"
    click BoardModel "https://github.com/vuongnguyen333/trello-api/blob/master/src/models/board.js"
    click ColumnModel "https://github.com/vuongnguyen333/trello-api/blob/master/src/models/column.js"
    click CardModel "https://github.com/vuongnguyen333/trello-api/blob/master/src/models/card.js"
    click ErrorMiddleware "https://github.com/vuongnguyen333/trello-api/blob/master/src/middlewares/errorHandlingMiddleware.js"
    click ExampleSocket "https://github.com/vuongnguyen333/trello-api/blob/master/src/sockets/exampleSocket.js"
    click ExampleProvider "https://github.com/vuongnguyen333/trello-api/blob/master/src/providers/exampleProvider.js"
    click ApiError "https://github.com/vuongnguyen333/trello-api/blob/master/src/utils/ApiError.js"
    click Alg "https://github.com/vuongnguyen333/trello-api/blob/master/src/utils/algorithms.js"
    click Const "https://github.com/vuongnguyen333/trello-api/blob/master/src/utils/constants.js"
    click Fmt "https://github.com/vuongnguyen333/trello-api/blob/master/src/utils/formatters.js"
    click Sorts "https://github.com/vuongnguyen333/trello-api/blob/master/src/utils/sorts.js"
    click Vlds "https://github.com/vuongnguyen333/trello-api/blob/master/src/utils/validators.js"
    click BoardVal "https://github.com/vuongnguyen333/trello-api/blob/master/src/validations/boardValidation.js"
    click ColumnVal "https://github.com/vuongnguyen333/trello-api/blob/master/src/validations/columnValidation.js"
    click CardVal "https://github.com/vuongnguyen333/trello-api/blob/master/src/validations/cardValidation.js"

    %% Styles
    classDef externalClient fill:#FFECB3,stroke:#FFB300;
    classDef app fill:#D0E6FF,stroke:#0066cc;
    classDef config fill:#E0F7FA,stroke:#006064;
    classDef routes fill:#BBDEFB,stroke:#0D47A1;
    classDef middleware fill:#F3E5F5,stroke:#6A1B9A;
    classDef validations fill:#E1BEE7,stroke:#4A148C;
    classDef controller fill:#C5CAE9,stroke:#303F9F;
    classDef service fill:#C8E6C9,stroke:#2E7D32;
    classDef model fill:#A5D6A7,stroke:#1B5E20;
    classDef db fill:#388E3C,stroke:#1B5E20;
    classDef external fill:#FFCC80,stroke:#EF6C00;
    classDef utils fill:#FFF59D,stroke:#F9A825;
    classDef socket fill:#FFE0B2,stroke:#FB8C00;
```
