# rocketchat/rocket.chat.electron architecture

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

- Interactive diagram: https://gitdiagram.com/rocketchat/rocket.chat.electron
- Repository: https://github.com/rocketchat/rocket.chat.electron

## Overview

##### Project type and purpose
- This is an Electron-based desktop client for the Rocket.Chat chat platform.

##### File structure
- Top-level:
- build, dist and configuration files for packaging (electron-builder.json, rollup.config.mjs, build/, workspaces/).
- src/ contains all application code, organized by feature and by Electron layer.
- src/main.ts, src/rootWindow.ts, src/preload.ts are the three Rollup entry points:
- main.ts runs in the Electron Main process and orchestrates windows, IPC, native APIs, auto-update, store.
- rootWindow.ts powers the Renderer (React) UI of the main window.
- preload.ts is injected into webviews to expose a safe subset of Node/Electron APIs to Rocket.Chat’s web client.
- src/app holds Redux-style “actions”, “reducers”, “selectors”, and persistence logic driving application state in the main process.
- Feature modules: deepLinks, documentViewer, downloads, i18n, jitsi, navigation, notifications, outlookCalendar, screenSharing, servers, spellChecking, updates, userPresence, videoCallWindow. Each module typically has:
- main.ts (in Main process),
- preload.ts or preload/ (exposed APIs),
- renderer.tsx or ipc.ts (Renderer or WebView code),
- actions.ts, common.ts, reducers.ts or specs.

##### README for additional insights
- Confirms the three-entry build pipeline (main, rootWindow, preload).
- Emphasizes TypeScript, Rollup bundler, Jest for tests, electron-builder for packaging.
- Mentions how configuration (servers.json, overridden-settings.json) is loaded at runtime.

##### Elements
- Gray clouds for external services

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Layer 1: OS and Electron Runtime
    OS["Host OS (Windows/macOS/Linux)"]:::external
    ElectronRuntime["Electron Runtime"]:::process
    OS --> ElectronRuntime

    %% Layer 2: Main Process
    subgraph "Electron Main Process" 
        direction TB
        MainEntry["Main Entry Point\nsrc/main.ts"]:::process
        AppLogic["Redux App Logic\nsrc/app"]:::modules
        AppReducers["Reducers & Selectors\nsrc/app/reducers\nsrc/app/selectors.ts"]:::modules
        Store["Redux Store & IPC Settings\nsrc/store"]:::store
        IPCMain["IPC Channel Manager (Main)\nsrc/ipc/main.ts\nsrc/ipc/channels.ts"]:::modules
        Features["Feature Modules"]:::modules
    end
    ElectronRuntime --> MainEntry
    MainEntry --> AppLogic
    MainEntry --> Store
    MainEntry --> IPCMain
    MainEntry --> Features
    AppLogic --> AppReducers
    Store --> IPCMain

    subgraph "Feature Modules (Main)" 
        direction TB
        DL["Deep Links\nsrc/deepLinks/main.ts"]:::modules
        DV["Document Viewer\nsrc/documentViewer/ipc.ts"]:::modules
        DLn["Downloads\nsrc/downloads/main.ts"]:::modules
        I18nM["i18n\nsrc/i18n/main.ts"]:::modules
        JitsiM["Jitsi\nsrc/jitsi/main.ts"]:::modules
        Nav["Navigation\nsrc/navigation/main.ts"]:::modules
        NotifM["Notifications\nsrc/notifications/main.ts"]:::modules
        OutlookM["Outlook Calendar\nsrc/outlookCalendar/getOutlookEvents.ts"]:::modules
        ScreenM["Screen Sharing\nsrc/screenSharing/main.ts"]:::modules
        ServersM["Servers\nsrc/servers/main.ts"]:::modules
        SpellM["Spell Checking\nsrc/spellChecking/main.ts"]:::modules
        UpdatesM["Updates\nsrc/updates/main.ts"]:::modules
        PresenceM["User Presence\nsrc/userPresence/main.ts"]:::modules
        VideoWinM["Video Call Window\nsrc/videoCallWindow/videoCallWindow.tsx"]:::modules
    end
    Features --> DL & DV & DLn & I18nM & JitsiM & Nav & NotifM & OutlookM & ScreenM & ServersM & SpellM & UpdatesM & PresenceM & VideoWinM

    %% Layer 3: Renderer Process
    subgraph "Renderer Process (Root Window)" 
        direction TB
        RootEntry["Renderer Entry Point\nsrc/rootWindow.ts"]:::process
        UI["UI Layer (React)\nsrc/ui"]:::modules
        UIReducers["UI Reducers & Selectors\nsrc/ui/reducers\nsrc/ui/selectors.ts"]:::modules
        IPCR["IPC Helper (Renderer)\nsrc/ipc/renderer.ts"]:::modules
    end
    ElectronRuntime --> RootEntry
    RootEntry --> UI
    UI --> UIReducers
    RootEntry --> IPCR
    IPCR --> IPCMain

    %% Layer 4: WebView and Preload
    subgraph "WebView Preload Scripts" 
        direction TB
        PreloadGlobal["Global Preload\nsrc/preload.ts"]:::process
        ModulePreload["Module Preloads\nsrc/jitsi/preload.ts\nsrc/notifications/preload.ts\nsrc/outlookCalendar/preload.ts\nsrc/screenSharing/preload.ts\nsrc/servers/preload/**\nsrc/userPresence/preload.ts\nsrc/videoCallWindow/preload/**"]:::modules
    end
    RootEntry --> PreloadGlobal
    RootEntry --> ModulePreload
    PreloadGlobal -->|"ContextBridge APIs"| WebView["Rocket.Chat WebView"]:::process
    WebView -->|"HTTPS"| RocketChatServer["Rocket.Chat Server"]:::external

    %% External Services
    JitsiSrv["Jitsi Server"]:::external
    OutlookAPI["Outlook Calendar API"]:::external
    UpdateSrv["Auto-Update Servers"]:::external
    RocketChatServer & JitsiSrv & OutlookAPI & UpdateSrv -->|"Network Requests"| MainEntry

    %% Click Events
    click MainEntry "https://github.com/rocketchat/rocket.chat.electron/blob/master/src/main.ts"
    click AppLogic "https://github.com/rocketchat/rocket.chat.electron/tree/master/src/app"
    click AppReducers "https://github.com/rocketchat/rocket.chat.electron/tree/master/src/app/reducers"
    click AppReducers "https://github.com/rocketchat/rocket.chat.electron/blob/master/src/app/selectors.ts"
    click Store "https://github.com/rocketchat/rocket.chat.electron/tree/master/src/store"
    click IPCMain "https://github.com/rocketchat/rocket.chat.electron/blob/master/src/ipc/main.ts"
    click IPCMain "https://github.com/rocketchat/rocket.chat.electron/blob/master/src/ipc/channels.ts"
    click RootEntry "https://github.com/rocketchat/rocket.chat.electron/blob/master/src/rootWindow.ts"
    click IPCR "https://github.com/rocketchat/rocket.chat.electron/blob/master/src/ipc/renderer.ts"
    click PreloadGlobal "https://github.com/rocketchat/rocket.chat.electron/blob/master/src/preload.ts"
    click UI "https://github.com/rocketchat/rocket.chat.electron/tree/master/src/ui"
    click UI "https://github.com/rocketchat/rocket.chat.electron/tree/master/src/ui/components"
    click UI "https://github.com/rocketchat/rocket.chat.electron/tree/master/src/ui/main"
    click UI "https://github.com/rocketchat/rocket.chat.electron/tree/master/src/ui/preload"
    click UIReducers "https://github.com/rocketchat/rocket.chat.electron/tree/master/src/ui/reducers"
    click UIReducers "https://github.com/rocketchat/rocket.chat.electron/blob/master/src/ui/selectors.ts"

    %% Styles
    classDef process fill:#D6EAF8,stroke:#1B4F72,stroke-width:1px
    classDef modules fill:#ABEBC6,stroke:#145A32,stroke-width:1px
    classDef store fill:#F9E79F,stroke:#7D6608,stroke-width:1px
    classDef external fill:#E5E8E8,stroke:#566573,stroke-width:1px
```
