# qeqqe/vencord architecture

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

- Interactive diagram: https://gitdiagram.com/qeqqe/vencord
- Repository: https://github.com/qeqqe/vencord

## Overview

##### Project type and purpose
- Vencord is a client-side modification framework for Discord. It targets two runtime environments:
- Browser (as an extension or userscript)
- Desktop (via an Electron-style wrapper that patches the official Discord client)
- Its purpose is to inject a plugin system, UI enhancements, settings sync, and custom theming into Discord without altering Discord’s server-side code.

##### File structure
- Top-level directories:
- browser/ – content scripts, background scripts, manifest files for the web extension/userscript
- src/main/ – the desktop “main process” code (patcher, updater, IPC handlers, theme loader)
- src/preload.ts – code injected into the Discord renderer process in desktop builds
- src/webpack/ & scripts/build/ – bundling and patch application pipelines for both browser and desktop
- src/api, src/components, src/plugins – the runtime API surface, React UI components, and built-in plugins
- shared/ & utils/ – cross-context helpers (IPC event definitions, settings storage, debounce, lazy loading, etc.)
- scripts/ – build, test, packaging, version checks, installer generator
- Configuration files: package.json, pnpm-workspace.yaml, tsconfig.json, webpack config, build scripts, patch files under patches/

##### README for additional insights
- Vencord provides:
- An installer GUI for desktop
- 100+ built-in plugins and a plugin API for third-party authors
- Settings synchronization across devices
- A CSS theme editor
- A privacy-focused patcher that blocks telemetry/crash reporting
- Underlying stack: TypeScript, React (TSX), PNPM, Webpack, Electron-like IPC

a. Main components
- Build Pipeline
– scripts/build & webpack → generate browser extension bundle and desktop patch + preload script
– patches/ applied to Discord’s JavaScript assets
- Desktop Runtime (Electron style)
– Main Process (src/main)
· Patcher module loads Discord’s code, applies patches, spawns renderer
· Updater (HTTP/Git), settings store, theme loader
· IPC Main endpoints for renderer
– Preload Script (src/preload.ts)
· Exposes IPC Renderer API, plugin loader entrypoint, settings sync hooks
– Renderer Process (Discord UI + injected Vencord code)
· React components (src/components, src/api) render settings UI, plugin UI, etc.
· Plugin Loader scans src/plugins and user-installed plugins, injects their code
· Settings Store (shared/SettingsStore.ts) persists to local storage or cloud
- Browser Runtime
– Extension Background Script (browser/background.js)
– Content Script (browser/content.js) injects Vencord loader into discord.com pages
– GMPolyfill & userscript stubs to unify APIs with desktop preload
- External Services
– Plugin repository API (vencord.dev/plugins) for plugin metadata
– Settings sync server (optional cloud)
– Update distribution endpoints

b. Relationships and interactions
- Build Pipeline → produces Desktop Bundle & Browser Extension
- Desktop Main Process ↔ Preload Script via internal module imports
- Preload Script ↔ Renderer via IPC channels defined in shared/IpcEvents.ts
- Renderer ↔ Plugins (dynamic require + React render injection)
- Renderer ↔ Settings Sync Server (via HTTP)
- Browser Background → Content Script → injected loader → Renderer

c. Architectural patterns and principles
- Modular plugin architecture: each plugin folder under src/plugins is a self-contained module following a common API
- IPC boundary between untrusted renderer (Discord UI) and trusted main logic (patching, file access, updater)
- Build-time patch application: patches/ directory holds source patches for 3rd-party libraries (ESLint, etc.)
- Single-page overlay injections: Vencord UI is injected atop Discord’s SPA shell

d. Key technologies and frameworks
- TypeScript + TSX (React)
- Webpack bundling with custom patchWebpack logic
- PNPM workspaces (packages/vencord-types)
- Electron-style IPC (src/shared/IpcEvents.ts)
- Browser extension manifests (manifest.json, userscript.meta.js)
- Local storage & cloud sync (shared/SettingsStore.ts)

## Diagram (Mermaid)

```mermaid
graph TD
  subgraph "Build Pipeline"
    BS["scripts/build"]:::build
    WP["src/webpack"]:::build
    PT["patches/"]:::build
  end
  BS -->|builds| MainEntry
  WP -->|bundles| MainEntry
  PT -->|applies| MainEntry
  BS -->|builds| BG
  WP -->|bundles| BG
  PT -->|applies| BG

  subgraph "Desktop Runtime"
    subgraph "Main Process"
      MainEntry["Main Entry (src/main/index.ts)"]:::desktopMain
      Patcher["Patcher Module"]:::desktopMain
      Updater["Updater Modules"]:::desktopMain
      IPCMain["IPC Handlers"]:::desktopMain
      SettingsMain["Settings Store (Main)"]:::shared
      ThemeLoader["Theme Loader"]:::desktopMain
    end
    MainEntry --> Patcher
    MainEntry --> Updater
    MainEntry --> IPCMain
    MainEntry --> SettingsMain
    MainEntry --> ThemeLoader

    Preload["Preload Script"]:::preload
    Patcher --> Preload
    Preload --> IPCMain

    subgraph "Renderer Process"
      Renderer["Renderer Process"]:::renderer
      IPCEvents["IPC Events Definitions"]:::shared
      SettingsRenderer["Settings Store (Renderer)"]:::shared
      API["Plugin API Surface"]:::renderer
      Components["React UI Components"]:::renderer
      Plugins["Built-in Plugins"]:::renderer
      Utils["Utilities"]:::shared
    end

    Preload -->|"exposes"| IPCEvents
    IPCEvents --> Renderer
    Renderer --> API
    Renderer --> Components
    Renderer --> Plugins
    Renderer --> SettingsRenderer
    Renderer --> Utils
    Renderer -->|sync| SyncServer
    Renderer -->|fetch plugins| PluginRepo
  end

  subgraph "Browser Runtime"
    BG["Background Script"]:::browser
    CS["Content Script"]:::browser
    Manifests["Extension Manifests"]:::browser
    GM["GMPolyfill & Userscript Stub"]:::browser
    InjectedLoader["Injected Loader"]:::browser
    RendererBrowser["Discord Renderer"]:::renderer
  end
  BG --> CS
  CS --> InjectedLoader
  InjectedLoader --> RendererBrowser
  RendererBrowser --> API
  RendererBrowser --> Plugins
  RendererBrowser --> SettingsRenderer

  subgraph "External Services"
    PluginRepo["Plugin Repository API"]:::external
    SyncServer["Settings Sync Server"]:::external
    UpdateServer["Update Distribution"]:::external
  end

  click BS "https://github.com/qeqqe/vencord/tree/main/scripts/build"
  click WP "https://github.com/qeqqe/vencord/blob/main/src/webpack/webpack.ts"
  click PT "https://github.com/qeqqe/vencord/tree/main/patches/"
  click BG "https://github.com/qeqqe/vencord/blob/main/browser/background.js"
  click CS "https://github.com/qeqqe/vencord/blob/main/browser/content.js"
  click Manifests "https://github.com/qeqqe/vencord/blob/main/browser/manifest.json"
  click GM "https://github.com/qeqqe/vencord/blob/main/browser/GMPolyfill.js"
  click MainEntry "https://github.com/qeqqe/vencord/blob/main/src/main/index.ts"
  click Patcher "https://github.com/qeqqe/vencord/blob/main/src/main/patcher.ts"
  click Updater "https://github.com/qeqqe/vencord/blob/main/src/main/updater/index.ts"
  click IPCMain "https://github.com/qeqqe/vencord/blob/main/src/main/ipcMain.ts"
  click SettingsMain "https://github.com/qeqqe/vencord/blob/main/src/main/settings.ts"
  click ThemeLoader "https://github.com/qeqqe/vencord/blob/main/src/main/themes/index.ts"
  click Preload "https://github.com/qeqqe/vencord/blob/main/src/preload.ts"
  click IPCEvents "https://github.com/qeqqe/vencord/blob/main/src/shared/IpcEvents.ts"
  click SettingsRenderer "https://github.com/qeqqe/vencord/blob/main/src/shared/SettingsStore.ts"
  click API "https://github.com/qeqqe/vencord/blob/main/src/api/index.ts"
  click Components "https://github.com/qeqqe/vencord/tree/main/src/components/VencordSettings"
  click Plugins "https://github.com/qeqqe/vencord/tree/main/src/plugins/_core"
  click Utils "https://github.com/qeqqe/vencord/blob/main/src/utils/settingsSync.ts"

  classDef build fill:#f9f,stroke:#333,stroke-width:1px
  classDef desktopMain fill:#bbf,stroke:#333,stroke-width:1px
  classDef preload fill:#bfb,stroke:#333,stroke-width:1px
  classDef renderer fill:#fbf,stroke:#333,stroke-width:1px
  classDef browser fill:#ffb,stroke:#333,stroke-width:1px
  classDef shared fill:#ffd,stroke:#333,stroke-width:1px
  classDef external fill:#fdd,stroke:#333,stroke-width:1px
```
