# esh83/chat-application architecture

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

- Interactive diagram: https://gitdiagram.com/esh83/chat-application
- Repository: https://github.com/esh83/chat-application

## Overview

##### Main Components
- UI Layer: Represented by several .ui files (like chatpage.ui, setupmain.ui, addchat.ui) corresponding to different pages (chat page, setup page, etc.). This layer is managed by Qt’s widget system.
- Business Logic / Controllers: C++ source files (e.g., chatpage.cpp, addchat.cpp, setupmain.cpp, requesthandler.cpp) that implement the interactions between the UI and the backend services.
- Data Access and Local Persistence: The application uses SQLite for local data storage. Files like queries.cpp/queries.h suggest interaction with database layers.
- Network Communication Module: The requesthandler.cpp and associated classes (workerchat.cpp, workerlist.cpp, workerother.cpp) handle HTTP requests to interact with the remote server.
- Configuration: The config.h and iutgram.pro files establish build settings and project-level configurations.
- Installer: The installer directory holds the executable (iutgramInstaller.exe) to distribute the application.

##### Relationships & Interactions
- The UI components (setup page, chat page, add chat page) receive user input and trigger actions/commands.
- These UI elements are connected to controller classes (the cpp files with similar base names) that coordinate business logic.
- The controllers interact with the local SQLite database via the functions defined in queries.* files to save and retrieve chat data.
- The same controllers or specialized worker classes (workerchat, workerlist, workerother) are responsible for sending and receiving HTTP requests to/from a remote server for online functionality.
- The configuration files and project settings (like config.h and the Qt project file) are used to initialize the application and define dependencies.

##### Architectural Patterns
- MVC (or a variant thereof): Even though less formalized, the separation between UI (view), business logic (controller) and data querying (model) suggests an MVC-like architecture.
- Asynchronous/Worker Pattern: Worker classes (e.g., workerchat, workerlist) indicate that background processing or asynchronous tasks are handled separately, which is important for keeping the UI responsive.
- Modular Design: Separating out UI, network communication, and data access components supports maintenance and extensibility.

##### Specific Technologies & Libraries
- Qt Widgets for UI development.
- SQLite for local storage.
- C++ language and the associated build (qmake, as indicated by the .pro file) for compiling the application.
- HTTP libraries (most likely integrated within the Qt framework) for network requests.

##### Granularity
- Do not oversimplify—break the system into as many detailed components as possible.
- Mention that the installer is a separate deployment aspect, not part of the runtime architecture but essential for the packaged delivery of the application.

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "UI Layer"
        ChatPageUI["Chat Page UI"]:::ui
        SetupPageUI["Setup Page UI"]:::ui
        AddChatUI["Add Chat UI"]:::ui
    end

    subgraph "Business Logic / Controllers"
        ChatPageController["Chat Page Controller"]:::businesslogic
        SetupPageController["Setup Page Controller"]:::businesslogic
        AddChatController["Add Chat Controller"]:::businesslogic
        RequestHandler["General Request Handling"]:::businesslogic
    end

    subgraph "Data Access & Persistence"
        DatabaseQueries["Database Queries Module"]:::data
        LocalSQLiteConfig["Local SQLite Configuration"]:::data
    end

    subgraph "Network Communication"
        WorkerChat["Worker for Chat Operations"]:::network
        WorkerList["Worker for List Operations"]:::network
        WorkerOther["Worker for Other Network Tasks"]:::network
        ExternalRemoteServer["External Remote Server"]:::external
    end

    subgraph "Configuration"
        BuildSettings["Project Build Settings"]:::config
        AdditionalConfig["Additional Settings"]:::config
    end

    subgraph "Installer"
        InstallerExec["Installer Executable"]:::installer
    end

    %% UI triggers Controllers
    ChatPageUI --> ChatPageController
    SetupPageUI --> SetupPageController
    AddChatUI --> AddChatController

    %% Controllers triggering General Request Handling
    ChatPageController --> RequestHandler
    SetupPageController --> RequestHandler
    AddChatController --> RequestHandler

    %% Controllers interacting with Database Queries
    ChatPageController -->|"reads/writes"| DatabaseQueries
    SetupPageController -->|"reads/writes"| DatabaseQueries
    AddChatController -->|"reads/writes"| DatabaseQueries

    %% Controllers using Local SQLite Configuration
    ChatPageController --> LocalSQLiteConfig
    SetupPageController --> LocalSQLiteConfig
    AddChatController --> LocalSQLiteConfig

    %% Request Handler communicating with Worker modules
    RequestHandler --> WorkerChat
    RequestHandler --> WorkerList
    RequestHandler --> WorkerOther

    %% Network Workers contacting the External Remote Server
    WorkerChat --> ExternalRemoteServer
    WorkerList --> ExternalRemoteServer
    WorkerOther --> ExternalRemoteServer

    %% Configuration providing initialization inputs
    BuildSettings --> ChatPageController
    BuildSettings --> SetupPageController
    BuildSettings --> AddChatController
    BuildSettings --> RequestHandler

    AdditionalConfig --> ChatPageController
    AdditionalConfig --> SetupPageController
    AdditionalConfig --> AddChatController
    AdditionalConfig --> RequestHandler

    %% Installer as deployment aspect (optional connection)
    InstallerExec --- ExternalRemoteServer

    %% Click Events for UI Layer
    click ChatPageUI "https://github.com/esh83/chat-application/blob/main/src/chatpage.ui"
    click SetupPageUI "https://github.com/esh83/chat-application/blob/main/src/setupmain.ui"
    click AddChatUI "https://github.com/esh83/chat-application/blob/main/src/addchat.ui"

    %% Click Events for Business Logic / Controllers
    click ChatPageController "https://github.com/esh83/chat-application/blob/main/src/chatpage.cpp"
    click ChatPageController "https://github.com/esh83/chat-application/blob/main/src/chatpage.h"
    click SetupPageController "https://github.com/esh83/chat-application/blob/main/src/setupmain.cpp"
    click SetupPageController "https://github.com/esh83/chat-application/blob/main/src/setupmain.h"
    click AddChatController "https://github.com/esh83/chat-application/blob/main/src/addchat.cpp"
    click AddChatController "https://github.com/esh83/chat-application/blob/main/src/addchat.h"
    click RequestHandler "https://github.com/esh83/chat-application/blob/main/src/requesthandler.cpp"
    click RequestHandler "https://github.com/esh83/chat-application/blob/main/src/requesthandler.h"

    %% Click Events for Data Access & Persistence
    click DatabaseQueries "https://github.com/esh83/chat-application/blob/main/src/queries.cpp"
    click DatabaseQueries "https://github.com/esh83/chat-application/blob/main/src/queries.h"
    click LocalSQLiteConfig "https://github.com/esh83/chat-application/blob/main/src/config.h"

    %% Click Events for Network Communication
    click WorkerChat "https://github.com/esh83/chat-application/blob/main/src/workerchat.cpp"
    click WorkerChat "https://github.com/esh83/chat-application/blob/main/src/workerchat.h"
    click WorkerList "https://github.com/esh83/chat-application/blob/main/src/workerlist.cpp"
    click WorkerList "https://github.com/esh83/chat-application/blob/main/src/workerlist.h"
    click WorkerOther "https://github.com/esh83/chat-application/blob/main/src/workerother.cpp"
    click WorkerOther "https://github.com/esh83/chat-application/blob/main/src/workerother.h"

    %% Click Events for Configuration
    click BuildSettings "https://github.com/esh83/chat-application/blob/main/src/iutgram.pro"
    click AdditionalConfig "https://github.com/esh83/chat-application/blob/main/src/config.h"

    %% Click Event for Installer
    click InstallerExec "https://github.com/esh83/chat-application/blob/main/installer/iutgramInstaller.exe"

    %% Style Definitions
    classDef ui fill:#ACE7EF,stroke:#333,stroke-width:2px;
    classDef businesslogic fill:#C4E1C1,stroke:#333,stroke-width:2px;
    classDef data fill:#FFD59A,stroke:#333,stroke-width:2px;
    classDef network fill:#D8B4FF,stroke:#333,stroke-width:2px;
    classDef external fill:#E1BEE7,stroke:#333,stroke-width:2px;
    classDef config fill:#FFF59D,stroke:#333,stroke-width:2px;
    classDef installer fill:#FFC1E3,stroke:#333,stroke-width:2px;
```
