# luongxuannhat/e_learning_be architecture

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

- Interactive diagram: https://gitdiagram.com/luongxuannhat/e_learning_be
- Repository: https://github.com/luongxuannhat/e_learning_be

## Overview

##### Main components
- Entry Points & Servers:
- server.js – the main HTTP server handling API requests.
- socketServer.js – a dedicated server for real-time functionalities (chat, notifications, etc.).
- Controllers:
- A wide range of controllers (e.g., attendanceController.js, classController.js, blogController.js, etc.) managing business logic for various domain features.
- Routes:
- Routing files (e.g., chatMessageRoutes.js, classRoutes.js, etc.) which map HTTP requests to the appropriate controller actions.
- Models:
- Domain models (e.g., User.js, Course.js, Enrollment.js, etc.) that represent data entities. Their interactions (and possible ORM setup) are defined in models/index.js.
- Data Transfer Objects (DTO):
- Files under the DTO directory (like ClassDTO.js, UserDTO.js, etc.) that help mediate data between layers.
- Database Configuration & Migrations:
- The config folder (with config.json, db.js, mongo.js) sets up connections to SQL and/or NoSQL databases.
- Migrations (e.g., create-users migration) indicate a structured approach to evolving the database schema.
- Documentation:
- Swagger documentation (swagger/swagger.js) is available to describe API endpoints.

##### Understanding the Relationships and Interactions
- Requests flow into the server.js (or through socketServer.js for real-time interactions).
- HTTP routes are defined in the routes folder and are directed to specific controllers.
- Controllers process the requests by leveraging Models (data structures and ORM).
- Data is then transferred via DTOs to ensure consistent data structures between layers.
- The configuration files and migrations ensure that database connectivity and schema changes are managed centrally.
- External tools (for example, Swagger) help document these APIs for other developers or external integrations.

##### Architectural Patterns & Design Principles
- Layered Architecture: Clearly distinguish between routes, controllers, models, and DTOs.
- MVC-Inspired Approach: While the separation is not strictly Model-View-Controller (since it is backend-only), the routes (controllers) and models mimic this separation.
- Real-time Communication: The presence of a dedicated socket server (socketServer.js) suggests the use of web sockets for live interactions like chatting.
- Database Abstraction: Use of configuration files and migration scripts indicates best practices in managing schema evolution and multi-database support.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Clients["Clients"]:::client

    subgraph "API Entry Points"
        HTTPServer["HTTP Server – server.js"]:::entry
        RealTimeServer["Real-Time Server – socketServer.js"]:::entry
    end

    Routes["API Routing – routes"]:::route
    Controllers["Controllers"]:::controller
    ModelsORM["Models & ORM"]:::model
    DTO["Data Transfer Objects (DTO)"]:::dto
    DatabaseConfig["Database Layer"]:::db
    APIDoc["API Documentation – Swagger"]:::doc

    Clients --> HTTPServer
    Clients --> RealTimeServer
    Clients --> APIDoc
    HTTPServer --> Routes
    Routes --> Controllers
    RealTimeServer --> Controllers
    Controllers --> ModelsORM
    Controllers --> DTO
    ModelsORM --> DatabaseConfig

    subgraph "Legend: Color Codes"
        L1["Clients - #f9c2ff"]:::client
        L2["Entry Points - #b0e0e6"]:::entry
        L3["Routes - #e6e6fa"]:::route
        L4["Controllers - #90ee90"]:::controller
        L5["Models/ORM - #ffdead"]:::model
        L6["DTO - #ffe4e1"]:::dto
        L7["Database - #fafad2"]:::db
        L8["Documentation - #d3d3d3"]:::doc
    end

    click HTTPServer "https://github.com/luongxuannhat/e_learning_be/blob/main/server.js"
    click RealTimeServer "https://github.com/luongxuannhat/e_learning_be/blob/main/socketServer.js"
    click Routes "https://github.com/luongxuannhat/e_learning_be/tree/main/routes/"
    click Controllers "https://github.com/luongxuannhat/e_learning_be/tree/main/controllers/"
    click ModelsORM "https://github.com/luongxuannhat/e_learning_be/tree/main/models/"
    click DTO "https://github.com/luongxuannhat/e_learning_be/tree/main/DTO/"
    click DatabaseConfig "https://github.com/luongxuannhat/e_learning_be/tree/main/config/"
    click APIDoc "https://github.com/luongxuannhat/e_learning_be/blob/main/swagger/swagger.js"

    classDef client fill:#f9c2ff,stroke:#333,stroke-width:2px;
    classDef entry fill:#b0e0e6,stroke:#333,stroke-width:2px;
    classDef route fill:#e6e6fa,stroke:#333,stroke-width:2px;
    classDef controller fill:#90ee90,stroke:#333,stroke-width:2px;
    classDef model fill:#ffdead,stroke:#333,stroke-width:2px;
    classDef dto fill:#ffe4e1,stroke:#333,stroke-width:2px;
    classDef db fill:#fafad2,stroke:#333,stroke-width:2px;
    classDef doc fill:#d3d3d3,stroke:#333,stroke-width:2px;
```
