# vencord/vesktop architecture

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

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

## Overview

##### Main components of the system
- Main Process (Electron Main): Represented by the contents in the src/main folder (files such as index.ts, mainWindow.ts, ipc.ts, etc.). This component handles application startup, window management, IPC initialization, auto-launch settings, and high-level application logic.
- Renderer Process: Located in the src/renderer folder and its subdirectories. This includes React components (as seen in .tsx files), styling (CSS files), patches, settings pages, and UI elements. This process renders the user interface and interacts with the main process via IPC.
- Preload Scripts: Present in the src/preload folder. These scripts expose specific APIs to the renderer process in a secure way (for instance, through IPC wrappers) while preserving security boundaries.
- Shared Modules: Found in the src/shared folder. They offer common utilities, settings definitions, and IPC event definitions that are used by both the main and renderer processes.
- Static Assets: The static directory contains HTML views (e.g., splash, about, first-launch) and CSS assets that may be used during initial launch or as fallback resources.

##### Relationships and interactions between these components
- The Main Process initializes the application and creates the windows that load the Renderer process. It manages IPC communications with renderer scripts and leverages preload scripts for secure context bridging.
- The Renderer consumes UI components and applies patches (modifications to Discord’s behavior, as seen in several patch files) while communicating with the Main Process over defined IPC channels.
- Preload scripts bridge the gap between the two processes, exposing a controlled API for renderer tasks.
- Shared modules provide abstraction layers and utility functions so both main and renderer can operate consistently.
- Build scripts coordinate the packaging process, transforming the source, injecting resources (like Vencord dependencies), and finally outputting builds in the dist/ folder.

##### Important architectural patterns and design principles
- Separation of concerns: The clear division between the main process, renderer, and preload layers is crucial for maintainability, security, and scalability—typical in Electron architectures.
- Modular design: Using a “src” folder with clear subdirectories for main, renderer, and shared indicates a modular structure. Plus, the patches subdirectory shows the application of hotfixes or runtime modifications.
- Build and Distribution Pipeline: Illustrate the build scripts, packaging instructions, and how the assets (like installers for Windows, .dmg for macOS, and Linux packages) tie into the production release cycle.

##### Relevant technologies/frameworks
- TypeScript: Observed from file extensions (.ts, .mts, .tsx) across main, renderer, and scripts.
- Electron: The architecture (with main, renderer, preload) strongly indicates the use of Electron.
- PNPM: Observed from package.json and pnpm-lock.yaml for dependency management.
- React (or similar UI framework): Inferred from .tsx file usage in the renderer components.
- Build tools: Custom scripts for packaging (build scripts, NSIS installer scripts, etc.) are essential for deployment across Windows, macOS, and Linux.

- A component for the Main Process including sub-components like window management, IPC commands, and utility modules found in src/main.
- A component for the Renderer Process highlighting UI components, settings, and patches, as well as its relationship to static assets.
- A component for the Preload Scripts that illustrate the secure bridging between the main and renderer processes.
- A separate Build Pipeline section showing the role of build scripts (in scripts/build), patch application (patches directory), and packaging instructions (pnpm commands).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Core Processes"
        MP["Main Process"]:::main
        RP["Renderer Process"]:::renderer
        PS["Preload Scripts"]:::preload
        SM["Shared Modules"]:::shared
    end

    subgraph "Build & Assets"
        BP["Build Pipeline"]:::build
        SA["Static Assets"]:::assets
    end

    RP -->|"IPCcalls"| PS
    PS -->|"IPCbridging"| MP
    MP -->|"UIupdate"| RP
    RP -->|"utilizes"| SM
    MP -->|"utilizes"| SM
    PS -->|"sharedAPIs"| SM
    BP -->|"builds"| MP
    BP -->|"builds"| RP
    BP -->|"packages"| SA
    SA -->|"feedsUI"| RP

    click MP "https://github.com/vencord/vesktop/tree/main/src/main"
    click RP "https://github.com/vencord/vesktop/tree/main/src/renderer"
    click PS "https://github.com/vencord/vesktop/tree/main/src/preload"
    click SM "https://github.com/vencord/vesktop/tree/main/src/shared"
    click BP "https://github.com/vencord/vesktop/tree/main/scripts/build"
    click SA "https://github.com/vencord/vesktop/tree/main/static"

    classDef main fill:#ffcccc,stroke:#000,stroke-width:2px;
    classDef renderer fill:#ccffcc,stroke:#000,stroke-width:2px;
    classDef preload fill:#ccccff,stroke:#000,stroke-width:2px;
    classDef shared fill:#ffffcc,stroke:#000,stroke-width:2px;
    classDef build fill:#cce5ff,stroke:#000,stroke-width:2px;
    classDef assets fill:#d5ffcc,stroke:#000,stroke-width:2px;
```
