# huagoufdog/fdoginstantmessaging architecture

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

- Interactive diagram: https://gitdiagram.com/huagoufdog/fdoginstantmessaging
- Repository: https://github.com/huagoufdog/fdoginstantmessaging

## Overview

- A desktop client (FdogClient) built with Qt (using C++ and the Qt framework) that handles login, friend management, chat interfaces, and various UI components.
- A desktop/server component (FdogServer) also built with Qt, which manages connections, message routing, and other backend processing for the desktop client.
- A web front-end (FdogWeb) implemented with Java (using a Maven project) that handles account registration, web-based interactions, and possibly other web services (all deployed via Tomcat).
Additionally, there is a database schema file (FdogSql/fdogsql.sql) along with user SQL management code (usersql.cpp/h present in both client and server), indicating the use of MySQL as the backend database.

##### Main Components
a. Desktop Client (FdogClient):
– Qt-based event handling and UI management.
– Modules that communicate with the server (e.g., addfriend, chat, verify).
b. Desktop Server (FdogServer):
– Message routing and event handling.
– Database interaction via shared user SQL classes.
– Handling client connection states and dispatching messages.
c. Web Application (FdogWeb):
– Java-based backend (Maven project) handling account registration and authentication.
– Frontend components (HTML, CSS, JavaScript) for web UI.
– Integration with MySQL via JDBC (as indicated by the MySQL connector jar).
d. Database (FdogSql):
– MySQL database storing user information, chat history, and friend relationships.
– Serves as the central data store for both desktop and web applications.
e. External Services:
– Tencent Cloud SMS service for sending verification codes.
– Potential integration with third-party notification services.

##### Relationships and Interactions
– Desktop Client sends login requests, chat messages, and friend management commands to the Desktop Server.
– Desktop Server handles these requests and interacts with the MySQL database (using Usersql classes) to retrieve or update persistent data.
– Web Application serves account registration and account management functions, communicating with the same or a parallel MySQL database.
– Both client and web components may use external services (e.g., Tencent Cloud SMS) to verify phone numbers or send alerts.

##### Architectural Patterns and Design Principles
– Separation of concerns: clear division between the UI layer (client and web UI), business logic (server, Java backend), and persistent data layer (MySQL).
– Client-server communication: indicate network sockets/HTTP API endpoints connecting the client and server.
– Modular design: note the “friend management”, “chat”, “login”, and “tray widget” components on the client side separately.
– Singleton patterns are used in managing some shared resources (e.g., optimization in Usersql class as mentioned in the README).

##### Relevant Technologies, Frameworks, or Libraries
– Qt5.10 for the desktop client and server.
– C++ for client/server code with Qt Designer files (e.g., .ui, .h, .cpp files).
– Java Maven project for the web application, with Tomcat deployment and use of MySQL Connector/J.
– HTML/CSS/JavaScript assets in the web project.
– MySQL for database management.
– External APIs (Tencent Cloud for SMS).

## Diagram (Mermaid)

```mermaid
flowchart TD

    subgraph "Desktop Client (Qt)"
        FC_Main["Main UI (FdogClient)"]:::client
        FC_Login["Login Module"]:::client
        FC_Chat["Chat Module"]:::client
        FC_AddFriend["Add Friend Module"]:::client
        FC_AgreeFriend["Friend Agreement Module"]:::client
        FC_Tray["Tray Icon & Menu"]:::client
        FC_Verify["Verify Module"]:::client
        FC_GlobalObserver["Global Observer"]:::client
        FC_Query["Query Module"]:::client
        FC_Setting["Setting Color Module"]:::client
        FC_SQL["Client SQL Handler"]:::client
    end

    subgraph "Desktop Server (Qt)"
        FS_Main["Main Server UI/Backend"]:::server
        FS_SQL["Server SQL Handler"]:::server
        FS_Config["Project Config & Build"]:::server
    end

    subgraph "Web Application (Java/Tomcat)"
        FW_Backend["Java Backend"]:::web
        FW_Auth["Auth Code Module"]:::web
        FW_Rand["Additional Module (Rand)"]:::web
        FW_Filter["Filter Module"]:::web
        FW_UI["Web UI & Static Assets"]:::web
        FW_Config["Web Config & Libraries"]:::web
    end

    DB["MySQL Database"]:::database

    ES["External SMS Service (Tencent Cloud)"]:::external

    %% Interactions between components
    FC_Main -->|"sends commands"| FS_Main
    FC_Login -->|"login request"| FS_Main
    FC_Chat -->|"chat message"| FS_Main
    FC_AddFriend -->|"friend add request"| FS_Main
    FC_AgreeFriend -->|"friend confirmation"| FS_Main
    FC_Verify ---|"triggers verification"| ES

    FS_Main -->|"message routing & DB ops"| DB
    FS_SQL --- DB

    FW_Backend -->|"DB operations via JDBC"| DB
    FW_Auth ---|"SMS verification"| ES

    %% Click Events for FdogClient
    click FC_Main "https://github.com/huagoufdog/fdoginstantmessaging/blob/main/FdogClient/mainwindow.cpp"
    click FC_Login "https://github.com/huagoufdog/fdoginstantmessaging/blob/main/FdogClient/login.cpp"
    click FC_Chat "https://github.com/huagoufdog/fdoginstantmessaging/blob/main/FdogClient/chat.cpp"
    click FC_AddFriend "https://github.com/huagoufdog/fdoginstantmessaging/blob/main/FdogClient/addfriend.cpp"
    click FC_AgreeFriend "https://github.com/huagoufdog/fdoginstantmessaging/blob/main/FdogClient/agreefriend.cpp"
    click FC_SQL "https://github.com/huagoufdog/fdoginstantmessaging/blob/main/FdogClient/usersql.cpp"
    click FC_Tray "https://github.com/huagoufdog/fdoginstantmessaging/blob/main/FdogClient/trayiconmenu.cpp"
    click FC_Verify "https://github.com/huagoufdog/fdoginstantmessaging/blob/main/FdogClient/verify.cpp"
    click FC_GlobalObserver "https://github.com/huagoufdog/fdoginstantmessaging/blob/main/FdogClient/globalobserver.cpp"
    click FC_Query "https://github.com/huagoufdog/fdoginstantmessaging/blob/main/FdogClient/query.cpp"
    click FC_Setting "https://github.com/huagoufdog/fdoginstantmessaging/blob/main/FdogClient/settingcolor.cpp"

    %% Click Events for FdogServer
    click FS_Main "https://github.com/huagoufdog/fdoginstantmessaging/blob/main/FdogServer/mainwindow.cpp"
    click FS_SQL "https://github.com/huagoufdog/fdoginstantmessaging/blob/main/FdogServer/usersql.cpp"
    click FS_Config "https://github.com/huagoufdog/fdoginstantmessaging/blob/main/FdogServer/untitled2.pro"

    %% Click Events for FdogWeb
    click FW_Backend "https://github.com/huagoufdog/fdoginstantmessaging/blob/main/FdogWeb/FdogMaven/src/main/java/com/fdog/FdogMaven.java"
    click FW_Auth "https://github.com/huagoufdog/fdoginstantmessaging/blob/main/FdogWeb/FdogMaven/src/main/java/com/fdog/AuthCode.java"
    click FW_Rand "https://github.com/huagoufdog/fdoginstantmessaging/blob/main/FdogWeb/FdogMaven/src/main/java/com/fdogrand/Rand.java"
    click FW_Filter "https://github.com/huagoufdog/fdoginstantmessaging/blob/main/FdogWeb/FdogMaven/src/main/java/com/filter/Filter.java"
    click FW_UI "https://github.com/huagoufdog/fdoginstantmessaging/tree/main/FdogWeb/FdogMaven/src/main/webapp"
    click FW_Config "https://github.com/huagoufdog/fdoginstantmessaging/blob/main/FdogWeb/FdogMaven/src/main/webapp/WEB-INF/web.xml"

    %% Click Event for Database Schema
    click DB "https://github.com/huagoufdog/fdoginstantmessaging/blob/main/FdogSql/fdogsql.sql"

    %% Styling
    classDef client fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef server fill:#FAD7A0,stroke:#D35400,stroke-width:2px;
    classDef web fill:#D2B4DE,stroke:#6C3483,stroke-width:2px;
    classDef database fill:#ABEBC6,stroke:#196F3D,stroke-width:2px;
    classDef external fill:#F5B7B1,stroke:#C0392B,stroke-width:2px;
```
