# vinz3210/chatguessr architecture

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

- Interactive diagram: https://gitdiagram.com/vinz3210/chatguessr
- Repository: https://github.com/vinz3210/chatguessr

## Overview

##### Project Type & Purpose
- This is a desktop game application (ChatGuessr) that has been extended with additional game modes, settings, and customizability. It is built on top of the official ChatGuessr version and supports integrations like Twitch commands and additional external resources.
- Its architecture shows a mix of Electron-style main/renderer separation, with an authentication module and a rich UI composed partly of Vue components.

##### Analyzing the File Structure
- Look at top-level files (package.json, forge.config.ts) and configuration files (tsconfig*, vite.*.config.ts) which indicate that the project uses Electron with Vite as the bundler.
- The top-level directories such as:
- src/auth: Contains HTML, TypeScript, and CSS files for an authentication flow (with its own preload).
- src/main: Contains core game logic (Game.ts, GameHandler.ts, MainWindow.ts) and supporting utilities. This represents the Electron main process.
- src/preload: Contains code intended to securely expose APIs to the renderer process.
- src/renderer: Contains the frontend code (including Vue components, assets, custom styles, mods, and shaders) that will render the game UI.
- Additional directories like build, public, and .github/workflows underscore that there’s packaging/deployment automation, asset management, and version control practices to support continuous integration and deployment.

a. Main Components
- Electron Main Process:
- src/main – core game logic (Game.ts, GameHandler.ts, window management)
- Build configuration (forge.config.ts) and main process bundling (vite.main.config.ts)
- Authentication Module:
- src/auth – containing the authentication window (AuthWindow.ts), its HTML, styling and preload script (auth_preload.ts)
- Renderer Process:
- Preload APIs via src/preload (chatguessrApi.ts, preload.ts, etc.) allowing safe communication between the main and renderer processes.
- Utility/Library Layer:
- src/main/lib and src/main/utils – containing game state, helper functions, and JSON data (flags, streak codes, etc.)
- External Services/Integrations:
- Twitch integration (e.g., useTwitchJS.ts)
- Supabase integration (e.g., useSupabase.ts)
- Support for custom flags loaded from user directories which hint at file I/O and configuration.

b. Relationships & Interactions
- The Main Process manages critical game logic and window creation. It triggers and communicates with:
- The Auth Window (for authentication) in src/auth.
- The Main Window, which loads the Renderer process.
- Preload scripts (located in src/preload) act as a secure intermediary, exposing game-related APIs to the Renderer process.
- The Renderer process (UI layer) interacts with both the user and the main process, consuming exposed APIs; it is structured using Vue components and supports plugins/mods for extended visuals (like shader effects or game mode modifications).
- Utility libraries (in src/main/lib and utils) provide supporting data and functionality, used across the system.

c. Architectural Patterns / Design Principles
- Electron’s multi-process architecture is clearly delineated: a main process managing windows and core logic vs. a renderer process handling the UI.
- Use of preload scripts for secure API bridging.
- Modular design for game modes and customizations (e.g., mods folder, extenssr plugin support) enables extensibility.
- Clear separation of concerns: authentication, gameplay logic, UI presentation, and external service integration are maintained in distinct folders.

d. Relevant Technologies, Frameworks, and Libraries
- Electron (or a related framework like Electron Forge) to handle desktop app packaging.
- Vite for bundling both main and renderer processes (vite.main.config.ts and vite.renderer.config.ts).
- Vue.js for frontend components (.vue files in src/renderer/components).
- TypeScript as the primary development language.
- Integration libraries including TwitchJS, Supabase, and support for shaders in WebGL (as indicated by .glsl files in mods/extenssr/shaders).

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Electron Main Process"
        MP("Main Process: src/main"):::main
        UtilLib1("Core Libraries: src/main/lib"):::util
        UtilLib2("Helper Utilities: src/main/utils"):::util
    end

    subgraph "Authentication Module"
        Auth("Auth Module: src/auth"):::auth
    end

    subgraph "Preload API Bridge"
        Preload("Preload Bridge: src/preload"):::preload
    end

    subgraph "Renderer/UI Process"
        Renderer("Renderer: src/renderer"):::renderer
    end

    subgraph "External Service Integrations"
        Twitch("Twitch Integration"):::external
        Supabase("Supabase Integration"):::external
    end

    %% Relationships
    MP -->|"Initializes"| Auth
    MP -->|"Loads Window"| Renderer
    MP -->|"Sets up"| Preload
    Preload -->|"Exposes APIs"| Renderer

    UtilLib1 -->|"Provides Data"| MP
    UtilLib2 -->|"Provides Helpers"| MP
    UtilLib1 -->|"Supports"| Renderer
    UtilLib2 -->|"Supports"| Renderer

    UtilLib2 -->|"Uses"| Twitch
    UtilLib2 -->|"Uses"| Supabase
    Renderer -->|"Receives Twitch Cmds"| Twitch
    Renderer -->|"Sends Data"| Supabase

    %% Click Events
    click MP "https://github.com/vinz3210/chatguessr/tree/master/src/main"
    click Auth "https://github.com/vinz3210/chatguessr/tree/master/src/auth"
    click Preload "https://github.com/vinz3210/chatguessr/tree/master/src/preload"
    click Renderer "https://github.com/vinz3210/chatguessr/tree/master/src/renderer"
    click UtilLib1 "https://github.com/vinz3210/chatguessr/tree/master/src/main/lib"
    click UtilLib2 "https://github.com/vinz3210/chatguessr/tree/master/src/main/utils"
    click Twitch "https://github.com/vinz3210/chatguessr/blob/master/src/main/utils/useTwitchJS.ts"
    click Supabase "https://github.com/vinz3210/chatguessr/blob/master/src/main/utils/useSupabase.ts"

    %% Styles
    classDef main fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef auth fill:#FFC0CB,stroke:#333,stroke-width:2px;
    classDef preload fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef renderer fill:#FFFFE0,stroke:#333,stroke-width:2px;
    classDef util fill:#D3D3D3,stroke:#333,stroke-width:2px;
    classDef external fill:#FFA07A,stroke:#333,stroke-width:2px;
```
