# ntth7419/gmail-controller architecture

> Architecture diagram of the GitHub repository ntth7419/gmail-controller, 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/ntth7419/gmail-controller
- Repository: https://github.com/ntth7419/gmail-controller

## Overview

##### Project Overview
- The project follows a client–server architecture aimed at controlling or interfacing with Gmail functionality. The “controller” aspect, combined with the presence of Gmail API code (in the gmailapi folder) and OAuth2 implementation, suggests that the client interacts with Gmail (likely for authentication and related operations) while also sending commands.
- On the server side, files such as keylogger.cpp and webcam.cpp indicate that the server might monitor or capture system-level activity based on commands received from the client.

##### Top-Level Structure Identification
- There are two main source components: “source/client” and “source/server”. Additionally, there is a “release” folder (with client config files like client_secret.json and cacert.pem) that indicates packaged assets for the client.
- Both client and server use Makefiles, meaning the build processes are separated and maintained independently.
- The “client” side integrates several external libraries:
- FTXUI for terminal-based user interfaces.
- The Gmail API code (including OAuth2 and base64 modules) to handle Gmail authentication and API interactions.
- Curl libraries and JSON (nlohmann) for network communication and data serialization.
- The “server” side contains modules for processing commands (server_cmd), managing socket communications, keylogging, and webcam functionality.

##### Main Components
a. Client Application:
- User Interface: Built using FTXUI, handling terminal input/output.
- Gmail API Module: Consists of OAuth2, base64, and gmail-api submodules that manage authentication and interaction with Gmail.
- Command Module: Processes user commands (client_cmd and process_cmd) and relays instructions.
- Socket Communication: Client_socket for network communication with the server.
- Third-party libraries: Curl (for network protocols) and JSON (for configuration or data interchange).

b. Server Application:
- Socket Communication: Server_socket for receiving commands from the client.
- Command Processing: Server_cmd and services manipulation to handle incoming requests.
- Monitoring/Interfacing Modules: Keylogger and Webcam modules indicate additional functionality triggered by commands.
- Overall, the server likely parses commands and drives system-level actions.

c. External Dependencies:
- Gmail/Google Authentication: Managed on the client using OAuth2 (with client_secret.json and certificates provided in release).
- Networking Libraries: Curl and possible TLS/SSL libraries (as gathered from the lib/curl folder).
- JSON library: nlohmann for handling data exchange in a structured format.

##### Relationships and Data Flow
- Data Flow from Client to Server: The client captures user commands through its UI and processes them through the command module, then sends these commands via a socket layer to the server.
- Server Processing: On receiving a command, the server’s command processing module determines the appropriate action (e.g., start keylogging, capture webcam images).
- Gmail API Interaction: The client uses the Gmail API module to authenticate the user via OAuth2 and may interact with Gmail services as part of its control flow. This module relies on libraries like curl and JSON for communication and data handling.
- External connectivity (if any): OAuth2 data exchanges and possibly notifications or status reporting via Gmail services are external to the local client–server model.

##### Architectural Patterns and Principles
- Separation of Concerns: Distinct separation between UI, network communication, and business logic on the client side.
- Modular Design: Both the client and server have their own submodules (commands, sockets, and specific functionality like keylogger/webcam).
- Reusability of Third-Party Libraries: Integration of established libraries (FTXUI for UI, Curl for HTTP/communications, nlohmann JSON) suggests reliance on proven components for common tasks.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Client Application
    subgraph "Client Application"
        UI("Client UI (FTXUI)"):::client
        Gmail("Gmail API Module"):::client
        Cmd("Client Command Module"):::client
        CSock("Client Socket Communication"):::client
        subgraph "Third-Party Libraries"
            Curl("Curl Library"):::lib
            JSON("JSON Library"):::lib
        end
    end

    %% Server Application
    subgraph "Server Application"
        SSock("Server Socket Communication"):::server
        SCmd("Server Command Processing Module"):::server
        Key("Keylogger Module"):::server
        Webcam("Webcam Module"):::server
        ServManip("Server Services Manipulation Module"):::server
    end

    %% Data Flow Connections (vertical orientation)
    UI -->|"inputs"| Cmd
    UI -->|"OAuth2Auth"| Gmail
    Gmail -->|"uses"| Curl
    Gmail -->|"uses"| JSON
    Cmd -->|"sends"| CSock
    CSock -->|"transmits"| SSock
    SSock -->|"forwards"| SCmd
    SCmd -->|"triggers"| Key
    SCmd -->|"triggers"| Webcam
    SCmd -->|"triggers"| ServManip

    %% Click Events for Client Application
    click UI "https://github.com/ntth7419/gmail-controller/tree/main/source/client/lib/FTXUI"
    click Gmail "https://github.com/ntth7419/gmail-controller/tree/main/source/client/gmailapi"
    click Cmd "https://github.com/ntth7419/gmail-controller/blob/main/source/client/client_cmd.cpp"
    click Cmd "https://github.com/ntth7419/gmail-controller/blob/main/source/client/process_cmd.cpp"
    click CSock "https://github.com/ntth7419/gmail-controller/blob/main/source/client/client_socket.cpp"
    click CSock "https://github.com/ntth7419/gmail-controller/blob/main/source/client/client_socket.h"
    click Curl "https://github.com/ntth7419/gmail-controller/blob/main/source/client/lib/curl_8.11"
    click JSON "https://github.com/ntth7419/gmail-controller/tree/main/source/client/lib/json"

    %% Click Events for Server Application
    click SSock "https://github.com/ntth7419/gmail-controller/blob/main/source/server/server_socket.cpp"
    click SSock "https://github.com/ntth7419/gmail-controller/blob/main/source/server/server_socket.h"
    click SCmd "https://github.com/ntth7419/gmail-controller/blob/main/source/server/server_cmd.cpp"
    click SCmd "https://github.com/ntth7419/gmail-controller/blob/main/source/server/server_cmd.h"
    click Key "https://github.com/ntth7419/gmail-controller/blob/main/source/server/keylogger.cpp"
    click Key "https://github.com/ntth7419/gmail-controller/blob/main/source/server/keylogger.h"
    click Webcam "https://github.com/ntth7419/gmail-controller/blob/main/source/server/webcam.cpp"
    click Webcam "https://github.com/ntth7419/gmail-controller/blob/main/source/server/webcam.h"
    click ServManip "https://github.com/ntth7419/gmail-controller/blob/main/source/server/services_manip.cpp"

    %% Styles
    classDef client fill:#B0E0E6,stroke:#000,stroke-width:2px;
    classDef server fill:#98FB98,stroke:#000,stroke-width:2px;
    classDef lib fill:#FFD700,stroke:#000,stroke-width:2px;
```
