How aiko-chan-ai/discordbotclient works
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.