# havanduc20194510/ailatrieuphu-1 architecture

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

- Interactive diagram: https://gitdiagram.com/havanduc20194510/ailatrieuphu-1
- Repository: https://github.com/havanduc20194510/ailatrieuphu-1

## Overview

##### Project type and purpose
- This is a full‐stack, networked quiz game (“Ai là triệu phú”) composed of
a Qt/QML‐based client (UI + local logic) and a C server that persists data in MySQL.
- Users can register/login, play solo or PvP, and the client connects over TCP to the server.

##### File structure
- Top‐level:
- client/ — Qt 5.12 QML frontend + C++ “backend” logic, assets (audio, fonts, sprites)
- server/ — C socket server, config, database.sql
- client:
- qml/ — all UI pages and popups (LoginPage, GameScreen, etc.)
- src/ & headers/ — C++ and C source files (BackEnd.cpp/h handle network protocols, Utils for helpers)
- assets/ — audio clips and graphics for the game
- server:
- server.c/h — main accept loop, request handling, game logic, user/score queries
- config — server settings (port, DB credentials)
- database.sql — table schemas for accounts, questions, game history

##### README for additional insights
- Technologies:
- Client: C/C++, Qt 5.12, QML, OpenGL library
- Server: C, POSIX sockets, libmysqlclient-dev, MySQL Server
- Execution flow:
- Start MySQL + import database.sql
- Launch server with port → accepts TCP clients
- Launch client with server IP + port → renders QML UI, interacts with server

##### Detail without over‐segmentation
- Major modules (UI, logic, networking)
- Config file and Makefile as annotations or footnotes

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Application
    subgraph "Client Application"
        direction TB
        Entry["Client Entry (main.cpp)"]:::client
        QMLUI["QML UI Layer"]:::client
        Logic["Client Logic Layer"]:::client
        Network["Network Layer (QTcpSocket)"]:::client
        Assets["Assets (Audio, Fonts, Sprites)"]:::client
        BuildClient["Build Files (client.pro, Makefile)"]:::client
    end

    %% Server Application
    subgraph "Server Application"
        direction TB
        Listener["Listener & Connection Manager"]:::server
        Dispatcher["Request Dispatcher & Game Logic"]:::server
        DataAccess["Data Access Layer (libmysqlclient)"]:::server
        Config["Config (port, DB credentials)"]:::server
        BuildServer["Build File (Makefile)"]:::server
    end

    %% Database
    MySQL["MySQL Database"]:::db

    %% External Dependencies
    subgraph "External Dependencies"
        direction TB
        Qt["Qt Framework"]:::ext
        OpenGL["OpenGL Library"]:::ext
        MySQLClientLib["MySQL Client Libs"]:::ext
    end

    %% Flow: Client
    Entry -->|"initializes"| QMLUI
    Entry -->|"initializes"| Logic
    QMLUI -->|"user actions"| Logic
    Logic -->|"serialize request"| Network

    %% Network to Server
    Network -->|"TCP request"| Listener
    Listener -->|"forward request"| Dispatcher
    Dispatcher -->|"DB query"| DataAccess
    DataAccess -->|"SQL over TCP"| MySQL

    %% Response flow
    MySQL -->|"result"| DataAccess
    DataAccess -->|"response"| Dispatcher
    Dispatcher -->|"send response"| Listener
    Listener -->|"TCP response"| Network
    Network -->|"deserialize"| Logic
    Logic -->|"update UI"| QMLUI

    %% Client build and assets
    Entry --> Assets
    Entry --> BuildClient

    %% Server config and build
    Listener --> Config
    Listener --> BuildServer

    %% Dependencies usage
    QMLUI --> Qt
    Network --> Qt
    Network --> OpenGL
    DataAccess --> MySQLClientLib

    %% Click Events
    click QMLUI "https://github.com/havanduc20194510/ailatrieuphu-1/tree/main/client/qml/"
    click Logic "https://github.com/havanduc20194510/ailatrieuphu-1/blob/main/client/src/BackEnd.cpp"
    click Logic "https://github.com/havanduc20194510/ailatrieuphu-1/blob/main/client/headers/BackEnd.h"
    click Logic "https://github.com/havanduc20194510/ailatrieuphu-1/blob/main/client/src/Utils.c"
    click Logic "https://github.com/havanduc20194510/ailatrieuphu-1/blob/main/client/headers/Utils.h"
    click Entry "https://github.com/havanduc20194510/ailatrieuphu-1/blob/main/client/src/main.cpp"
    click BuildClient "https://github.com/havanduc20194510/ailatrieuphu-1/blob/main/client/client.pro"
    click BuildClient "https://github.com/havanduc20194510/ailatrieuphu-1/tree/main/client/Makefile"
    click Assets "https://github.com/havanduc20194510/ailatrieuphu-1/tree/main/client/assets/"
    click Listener "https://github.com/havanduc20194510/ailatrieuphu-1/blob/main/server/server.c"
    click Listener "https://github.com/havanduc20194510/ailatrieuphu-1/blob/main/server/server.h"
    click BuildServer "https://github.com/havanduc20194510/ailatrieuphu-1/tree/main/server/Makefile"
    click Config "https://github.com/havanduc20194510/ailatrieuphu-1/tree/main/server/config"
    click MySQL "https://github.com/havanduc20194510/ailatrieuphu-1/blob/main/server/database.sql"

    %% Styles
    classDef client fill:#D6E4FF,stroke:#5B8FF9,color:#000;
    classDef server fill:#D9F7BE,stroke:#52C41A,color:#000;
    classDef db fill:#FFE7BA,stroke:#FA8C16,color:#000;
    classDef ext fill:#F4F5F7,stroke:#8C8C8C,color:#000;
```
