# animalnots/betterchatgpt-plus architecture

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

- Interactive diagram: https://gitdiagram.com/animalnots/betterchatgpt-plus
- Repository: https://github.com/animalnots/betterchatgpt-plus

## Overview

##### Main Components
- Electron Desktop Wrapper: Located in the “electron” directory, this part is used to bundle the web app as a desktop application.
- API & Business Logic Layer: Found in src/api and src/utils, these components handle OpenAI ChatGPT API calls, Google API calls, model parsing, and chat-related logic.
- State Management: The project makes extensive use of Redux slices in the src/store directory. This layer manages chats, configuration, authentication, and other global states.
- Internationalization (i18n): The public/locales directory holds translation files for multiple languages, indicating that text and UI strings are made available in various locales.
- Build & Deployment Configurations: Dockerfile, docker-compose.yml, Vite config files, and GitHub Actions workflows indicate options for containerization as well as continuous deployment. These are also helpful to include for a comprehensive view of where and how the app is built and deployed.

##### Relationships and Interactions
- Frontend UI (React components) as the primary user interface layer.
- The Electron layer should wrap around the frontend; include a separate block or boundary labeled “Desktop App (Electron)” to indicate that it encapsulates the web UI and adds any desktop-specific functionalities.
- Use of i18n components by showing a connection from the UI to “Translation Files (public/locales)” to denote dynamic loading of locale data.

##### Architectural Patterns and Principles
- Modularity and Reusability: The file structure (with folders for components, hooks, tools, and utilities) indicates that different functionalities are encapsulated within reusable modules.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Desktop Application Layer
    subgraph "Desktop App (Electron)"
        direction TB
        ElectronWrapper["Electron Wrapper (Desktop)"]:::desktop
        FUI["Frontend UI"]:::frontend
        ElectronWrapper --> FUI
        subgraph "React Components"
            direction TB
            Chat["Chat Component (React)"]:::frontend
            Config["Config Menu (React)"]:::frontend
            Lang["Language Selector (React)"]:::frontend
        end
        FUI --> Chat
        FUI --> Config
        FUI --> Lang
    end

    %% State Management Layer
    subgraph "State Management"
        direction TB
        Redux["Redux Store"]:::state
        auth["Auth Slice"]:::state
        chatS["Chat Slice"]:::state
        configS["Config Slice"]:::state
        Redux --> auth
        Redux --> chatS
        Redux --> configS
    end

    %% API & Business Logic Layer
    subgraph "API & Business Logic Layer"
        direction TB
        subgraph "API Calls"
            direction TB
            apiTS["api.ts (API)"]:::api
            googleApi["google-api.ts (API)"]:::api
            helper["helper.ts"]:::api
        end
        subgraph "Utility Functions"
            direction TB
            utilApi["api.ts (Util)"]:::api
            utilChat["chat.ts"]:::api
            utilGoogle["google-api.ts (Util)"]:::api
        end
    end

    %% Internationalization
    subgraph "Internationalization"
        Translations["Translation Files"]:::i18n
    end

    %% Deployment / Build Pipeline
    subgraph "Deployment / Build Pipeline"
        direction TB
        dockerfile["Dockerfile"]:::deployment
        dockerCompose["docker-compose.yml"]:::deployment
        dockerIgnore[".dockerignore"]:::deployment
        ciDeploy["deploy.yml"]:::deployment
        ciPublish["publish.yml"]:::deployment
        viteConfig["vite.config.ts"]:::deployment
        tsconfig["tsconfig.json"]:::deployment
        postcss["postcss.config.cjs"]:::deployment
        tailwind["tailwind.config.cjs"]:::deployment
    end

    %% External APIs
    subgraph "External APIs"
        OpenAI["ChatGPT API"]:::external
        Google["Google API"]:::external
    end

    %% Connections between layers
    FUI -->|"dispatch"| Redux
    Redux -->|"state_update"| FUI
    FUI -->|"api_request"| apiTS
    apiTS -->|"send_request"| OpenAI
    googleApi -->|"sync_request"| Google
    apiTS -->|"response"| Redux
    utilChat -->|"process_data"| FUI
    FUI -->|"load_locale"| Translations
    viteConfig -->|"build_trigger"| FUI

    %% Class Definitions
    classDef frontend fill:#AED6F1,stroke:#1B4F72,color:#1B2631;
    classDef state fill:#ABEBC6,stroke:#1E8449,color:#145A32;
    classDef api fill:#F9E79F,stroke:#B7950B,color:#7D6608;
    classDef desktop fill:#F5CBA7,stroke:#9C640C,color:#512E5F;
    classDef i18n fill:#D2B4DE,stroke:#6C3483,color:#4A235A;
    classDef deployment fill:#FAD7A0,stroke:#D35400,color:#884EA0;
    classDef external fill:#C39BD3,stroke:#8E44AD,color:#512E5F;

    %% Click Events for Frontend UI Components
    click Chat "https://github.com/animalnots/betterchatgpt-plus/tree/main/src/components/Chat"
    click Config "https://github.com/animalnots/betterchatgpt-plus/tree/main/src/components/ConfigMenu"
    click Lang "https://github.com/animalnots/betterchatgpt-plus/tree/main/src/components/LanguageSelector"
    
    %% Click Event for Electron Desktop Wrapper
    click ElectronWrapper "https://github.com/animalnots/betterchatgpt-plus/blob/main/electron/index.cjs"

    %% Click Events for API Calls
    click apiTS "https://github.com/animalnots/betterchatgpt-plus/blob/main/src/api/api.ts"
    click googleApi "https://github.com/animalnots/betterchatgpt-plus/blob/main/src/api/google-api.ts"
    click helper "https://github.com/animalnots/betterchatgpt-plus/blob/main/src/api/helper.ts"

    %% Click Events for Utility Functions
    click utilApi "https://github.com/animalnots/betterchatgpt-plus/blob/main/src/utils/api.ts"
    click utilChat "https://github.com/animalnots/betterchatgpt-plus/blob/main/src/utils/chat.ts"
    click utilGoogle "https://github.com/animalnots/betterchatgpt-plus/blob/main/src/utils/google-api.ts"

    %% Click Events for State Management
    click auth "https://github.com/animalnots/betterchatgpt-plus/blob/main/src/store/auth-slice.ts"
    click chatS "https://github.com/animalnots/betterchatgpt-plus/blob/main/src/store/chat-slice.ts"
    click configS "https://github.com/animalnots/betterchatgpt-plus/blob/main/src/store/config-slice.ts"

    %% Click Event for Internationalization
    click Translations "https://github.com/animalnots/betterchatgpt-plus/tree/main/public/locales/en"

    %% Click Events for Build & Deployment Configurations
    click dockerfile "https://github.com/animalnots/betterchatgpt-plus/tree/main/Dockerfile"
    click dockerCompose "https://github.com/animalnots/betterchatgpt-plus/blob/main/docker-compose.yml"
    click dockerIgnore "https://github.com/animalnots/betterchatgpt-plus/blob/main/.dockerignore"
    click ciDeploy "https://github.com/animalnots/betterchatgpt-plus/blob/main/.github/workflows/deploy.yml"
    click ciPublish "https://github.com/animalnots/betterchatgpt-plus/blob/main/.github/workflows/publish.yml"
    click viteConfig "https://github.com/animalnots/betterchatgpt-plus/blob/main/vite.config.ts"
    click tsconfig "https://github.com/animalnots/betterchatgpt-plus/blob/main/tsconfig.json"
    click postcss "https://github.com/animalnots/betterchatgpt-plus/blob/main/postcss.config.cjs"
    click tailwind "https://github.com/animalnots/betterchatgpt-plus/blob/main/tailwind.config.cjs"
```
