# aiko-chan-ai/discordbotclient architecture

> Architecture diagram of the GitHub repository aiko-chan-ai/discordbotclient, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aiko-chan-ai/discordbotclient
- Repository: https://github.com/aiko-chan-ai/discordbotclient

## Overview

##### Project Type and Purpose
- This is a full-stack **Electron** desktop application that wraps Discord’s web client for bot accounts.
- It consists of:
– A **Node.js** backend (local proxy/API server & data layer)
– A **Renderer** (Discord’s frontend assets in an Electron BrowserWindow)
– An embedded **browser-extension** (Vencord)
– A **protobuf** library for typed data (discord-protos)

##### Main Components
A. Electron Main Process (AppCore)
– **APIServer** (Express-style HTTP/HTTPS server)
– **Proxy** (intercepts and rewrites WebRequests)
– **Database** module (file-based stores for DirectMessages, UserSettings, etc.)
– **IPCEvent** & **ElectronPreload** (bridges Main ↔ Renderer)
B. Renderer Process (DiscordCore + VencordExtension)
– **DiscordCore/index.html** + static assets (official Discord web UI)
– **VencordExtension** (content script, injected modifications)
– **AppAssets** (JS helpers: Intents, Bitfields, SystemMessages…)
C. External Services
– **Discord Public API / CDN** (real endpoints for messages, guilds, assets)
– **discord-protos** (protobuf definitions, TS/JS codegen)
D. Build & Tooling
– **scripts/** (fetch latest build, generate protos, copy assets)
– **tsup**, **npm** scripts, **tsconfig.json**

##### Relationships & Data Flows
1. **User** interacts with the **Renderer** (UI in BrowserWindow).
2. The **Renderer** issues HTTP(S) requests to **localhost** (AppCore’s APIServer) instead of `discord.com`.
3. **APIServer** processes requests via its **routes/** (mimicking Discord’s API), optionally reading/writing from the **Database**.
4. For endpoints it doesn’t override, the **Proxy** forwards requests to the real **Discord Public API/CDN** and returns responses.
5. The **Electron Main** and **Renderer** exchange events via **IPC** (e.g., for token storage, UI notifications).
6. **discord-protos** is used by AppCore and the Renderer (via AppAssets) to marshal/unmarshal structured data.

##### Architectural Patterns & Principles
- **Micro-frontend + micro-backend**: Renderer is pure web UI; backend is a local API server.
- **Proxy Pattern**: intercept and route network calls.
- **Adapter/Wrapper**: routes mimic Discord’s HTTP API but add bot-specific logic.
- **IPC/Event Bus**: decouple UI from native operations.
- **Code Generation**: protobuf definitions → type-safe code.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Presentation Layer"
        direction TB
        UI["DiscordCore Web UI"]:::frontend
        Vencord["VencordExtension (Injected)"]:::extension
        Assets["AppAssets Helpers"]:::frontend
    end

    subgraph "Application Layer"
        direction TB
        Main["Electron Main Process"]:::backend
        Preload["Electron Preload"]:::backend
        IPC["IPCEvent Bridge"]:::backend
        subgraph "AppCore"
            direction TB
            APIServer["APIServer"]:::backend
            Proxy["Proxy"]:::backend
            Database["Database Module"]:::database
        end
    end

    subgraph "Data & External"
        direction TB
        DiscordAPI["Discord Public API/CDN"]:::external
        Protos["discord-protos Library"]:::proto
    end

    UI -->|"HTTP(s) API calls"| APIServer
    APIServer -->|"reads/writes"| Database
    APIServer -->|"forwards HTTP(s)"| DiscordAPI
    Proxy -->|"intercepts & forwards"| DiscordAPI
    Preload -->|"injects scripts"| UI
    IPC <-->|"IPC"| UI
    APIServer -->|"uses"| Protos
    UI -->|"uses"| Protos

    click Main "https://github.com/aiko-chan-ai/discordbotclient/blob/electron-v3/AppCore/index.js"
    click APIServer "https://github.com/aiko-chan-ai/discordbotclient/blob/electron-v3/AppCore/APIServer.js"
    click Proxy "https://github.com/aiko-chan-ai/discordbotclient/blob/electron-v3/AppCore/Proxy.js"
    click Database "https://github.com/aiko-chan-ai/discordbotclient/blob/electron-v3/AppCore/database/index.js"
    click Preload "https://github.com/aiko-chan-ai/discordbotclient/blob/electron-v3/AppCore/ElectronPreload.js"
    click IPC "https://github.com/aiko-chan-ai/discordbotclient/blob/electron-v3/AppCore/IPCEvent.js"
    click UI "https://github.com/aiko-chan-ai/discordbotclient/blob/electron-v3/DiscordCore/index.html"
    click Vencord "https://github.com/aiko-chan-ai/discordbotclient/blob/electron-v3/VencordExtension/content.js"
    click Assets "https://github.com/aiko-chan-ai/discordbotclient/tree/electron-v3/AppAssets/"
    click Protos "https://github.com/aiko-chan-ai/discordbotclient/tree/electron-v3/discord-protos/src/discord_protos/"

    classDef frontend fill:#DDEEFF,stroke:#99BBFF;
    classDef backend fill:#FFEECC,stroke:#FFCC99;
    classDef database fill:#EEFFEE,stroke:#99CC99;
    classDef external fill:#F0F0F0,stroke:#CCCCCC;
    classDef extension fill:#FFEEDD,stroke:#FFCCBB;
    classDef proto fill:#E8E8FF,stroke:#BBBBDD;
```
