# hoanghai0810/gvdqg architecture

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

- Interactive diagram: https://gitdiagram.com/hoanghai0810/gvdqg
- Repository: https://github.com/hoanghai0810/gvdqg

## Overview

##### Project Type & Purpose
- This is a full-stack, three-tier web application (“Client-Server-Database”) for managing a national football championship (GVDQG).
- Frontend: HTML/CSS/JavaScript (Bootstrap, EJS templates) served by Express.
- Backend: Node.js + Express.js + Sequelize ORM.
- Database: MySQL.

##### File Structure Analysis
- src/
- config/: DB connection (connectDB.js), view engine setup (ViewEngine.js), environment config (config.json, .env).
- controllers/: request handlers (homeController.js).
- route/web.js: defines HTTP endpoints and ties them to controllers.
- services/: business logic and generic CRUD (CRUDService.js).
- models/: Sequelize models representing tables (user, team, player, match, statistics, allcode). index.js initializes associations.
- migrations/ & seeders/: database schema migrations & initial data.
- views/: EJS templates for pages (login, dashboard for Admin/Manager, CRUD pages).
- public/: static assets (CSS, JS, images, widgets).
- insert/: custom scripts to bulk-insert domain entities (players, teams, coaches, matches, parameters).
- sever.js (entry point): wires up Express, middleware, routing, DB sync, view engine.

##### Key Architectural Patterns
- Three-Tier Separation:
- Presentation Layer (Client via EJS + static files)
- Application Layer (Express controllers, services)
- Data Layer (Sequelize ORM + MySQL)
- MVC flavor: Models (Sequelize), Views (EJS), Controllers (Express handlers).
- Modular routing and service-oriented design: controllers delegate to services which interact with models.

##### Main Components & Interactions
A. Client Tier
- Web Browser: issues HTTP/HTTPS requests to server.
- Static Assets: CSS, JS, images under /public served by Express static middleware.
- EJS Views: rendered server-side and sent as HTML.

B. Server Tier
- Express.js HTTP Server (sever.js)
- Middleware: bodyParser, static file serving, session/auth (if any).
- Router (src/route/web.js): maps URL paths to controller methods.
- Controllers: handle requests, validate input, call services, render views or return JSON.
- Services (CRUDService.js, domain-specific logic): encapsulate business rules (team registration, scheduling algorithm, result updating, report generation).
- ORM Layer: Sequelize models and associations (src/models) map to database tables.
- Migrations & Seeders: define and evolve DB schema and populate reference data.

C. Database Tier
- MySQL: persistent storage for users, teams, players, matches, statistics, configuration parameters.
- Access via Sequelize (connectDB.js).

D. External / Optional Services
- (None explicitly in codebase; could include email or notification in the future.)

##### Detailed Elements
- Tier boundaries and module groupings.
- Tech stack annotations (e.g., “Node.js vX”, “Express.js”, “Sequelize ORM”, “MySQL 8”).
- Notes on configuration files (.env, config.json) feeding into DB and view-engine setup.
- Distinction between dynamic page rendering (EJS) and client-side static assets.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Tier
    subgraph "Client Tier"
        direction TB
        Browser["Web Browser"]:::client
        StaticAssets["Static Assets<br/>(CSS, JS, Images)"]:::client
        EJSViews["EJS View Templates"]:::client
    end

    %% Server Tier
    subgraph "Server Tier"
        direction TB

        subgraph "Config & Middleware"
            direction TB
            DBConn["DB Connection<br/>(connectDB.js)"]:::config
            ViewEngine["View Engine Setup<br/>(ViewEngine.js)"]:::config
            EnvConfig["Env & ORM Config<br/>(config.json, .env)"]:::config
        end

        subgraph "Routing & Controllers"
            direction TB
            Router["Express Router<br/>(web.js)"]:::server
            Controller["Home & Dashboard Controller<br/>(homeController.js)"]:::server
        end

        subgraph "Services / Business Logic"
            direction TB
            CRUDService["CRUD Service<br/>(CRUDService.js)"]:::server
            SchedulingService["Scheduling & Reporting"]:::server
        end

        subgraph "ORM & Data Access"
            direction TB
            ModelsIndex["Model Associations Init<br/>(index.js)"]:::server
            SequelizeModels["Sequelize Models<br/>(user, team, player...)"]:::server
        end

        subgraph "Migrations & Seeders"
            direction TB
            Migrations["Schema Migrations"]:::server
            Seeders["Data Seeders"]:::server
        end

        subgraph "Data Population Tools"
            direction TB
            InsertScripts["Custom Insert Scripts"]:::server
        end
    end

    %% Database Tier
    subgraph "Database Tier"
        direction TB
        MySQL["MySQL 8"]:::database
    end

    %% Connections
    Browser -->|HTTP GET/POST| Router
    Browser -->|Fetch| StaticAssets
    Router -->|route matching| Controller
    Controller -->|renders| EJSViews
    Controller -->|calls| CRUDService
    Controller -->|calls| SchedulingService
    CRUDService -->|queries| SequelizeModels
    SchedulingService -->|queries| SequelizeModels
    SequelizeModels -->|associations init| ModelsIndex
    SequelizeModels -->|SQL commands| MySQL
    Migrations -->|apply schema| MySQL
    Seeders -->|populate data| MySQL
    InsertScripts -->|bulk insert| SequelizeModels

    DBConn -->|configures| SequelizeModels
    EnvConfig -->|feeds| DBConn
    ViewEngine -->|registers| EJSViews
    DBConn -->|connects| MySQL

    %% Click Events
    click DBConn "https://github.com/hoanghai0810/gvdqg/blob/master/src/config/connectDB.js"
    click ViewEngine "https://github.com/hoanghai0810/gvdqg/blob/master/src/config/ViewEngine.js"
    click EnvConfig "https://github.com/hoanghai0810/gvdqg/blob/master/src/config/config.json"
    click Router "https://github.com/hoanghai0810/gvdqg/blob/master/src/route/web.js"
    click Controller "https://github.com/hoanghai0810/gvdqg/blob/master/src/controllers/homeController.js"
    click CRUDService "https://github.com/hoanghai0810/gvdqg/blob/master/src/sevices/CRUDSevice.js"
    click ModelsIndex "https://github.com/hoanghai0810/gvdqg/blob/master/src/models/index.js"
    click SequelizeModels "https://github.com/hoanghai0810/gvdqg/blob/master/src/models/user.js"
    click Migrations "https://github.com/hoanghai0810/gvdqg/blob/master/src/migrations/migration-create-*.js"
    click Seeders "https://github.com/hoanghai0810/gvdqg/blob/master/src/seeders/seeder-users.js"
    click InsertScripts "https://github.com/hoanghai0810/gvdqg/blob/master/src/insert/insertCauThu.js"

    %% Styles
    classDef client fill:#E0F7FA,stroke:#0288D1,color:#000
    classDef server fill:#E8F5E9,stroke:#388E3C,color:#000
    classDef database fill:#FFF3E0,stroke:#F57C00,color:#000
    classDef config fill:#E3F2FD,stroke:#1976D2,color:#000
```
