# eduardr02/faster-chatgpt architecture

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

- Interactive diagram: https://gitdiagram.com/eduardr02/faster-chatgpt
- Repository: https://github.com/eduardr02/faster-chatgpt

## Overview

##### Project Type and Purpose
- The project is a Chrome extension that wraps various language model APIs (OpenAI, Anthropic, Gemini, etc.) to provide “1 click answers” across web pages.
- It offers multiple modes (chat, side panel, arena, and thinking modes) and includes support for both text and images along with chat history management.

##### File Structure
- Top-Level Files:
– manifest.json: The extension manifest defining permissions, scripts, and UI pages (popup, sidepanel).
– README.md, LICENSE, .gitignore, privacy_policy.md: Project documentation and legal info.
- src Directory:
– css, html: Styling and markup for various user interfaces like history, popup, settings, and sidepanel.
– js: Contains multiple JavaScript modules; examples include:
- background.js – the background script coordinating between different parts of the extension.
- content.js – a content script that interacts with web pages (e.g., reacting to text selections).
- popup.js, sidepanel.js, sidepanel_controller.js – handle popup and side panel interfaces.
- chat_core.js, chat_storage.js, chat_ui.js – manage chat logic, history, and UI rendering.
- state_manager.js, utils.js – common utility functions and state management.
- api_manager.js – handles API requests to external LLM services.
- Additional scripts for settings and renaming suggest modular features and extensibility.
– prompts: Text files containing default prompts for chat and other operations.

##### README for Additional Insights
- The README details key features such as fast responses via custom prompts, model switching, arena mode with voting, thinking mode, and chat history management.
- It explains how users interact with the extension (popup, side panel, text selection) along with a rough idea of the intended user flows.
- The instructions mention the need for API keys and the visibility of these keys in the browser, a potential security consideration.

##### Main Components
a. Browser UI Components (Frontend Elements):
- Popup UI: Represented by popup.html and popup.js; serves as the main interaction point for direct chat inputs and settings.
- Side Panel: Represented by sidepanel.html, sidepanel.js, and sidepanel_controller.js; appears when text is selected with CTRL and provides interactive responses.
- Additional UI Pages: History (history.html) and Settings (settings.html) for managing chat history and API keys.
- Content Injection: content.js interacts with web page elements to trigger the side panel.
b. Background Process:
- Background Script: background.js acts as a central hub, managing communication between UI components (popup, side panel, content script) and linking them to backend logic.
c. Core Business Logic:
- Chat Core & UI: chat_core.js and chat_ui.js handle the chat conversation logic and UI updates.
- Chat Storage: chat_storage.js maintains user conversation history.
- State & Utility Management: state_manager.js and utils.js manage dynamic states and shared utility functions.
d. API Communication:
- API Manager: api_manager.js encapsulates the calls to external language models, handling API communication and error management.
e. Prompts and Customization:
- Prompts Folder: Contains default prompt text files (chat_prompt.txt, prompt.txt) used in constructing and customizing API requests.
f. Additional Functionalities:
- Rename Manager and Settings: rename_manager.js and settings.js manage extension-specific configurations and dynamic model switching.

##### Relationships and Data Flow
– The Content Script (content.js) detects text selections and sends a message to the Background Script.
– The Background Script routes requests to the Popup UI or Side Panel UI based on the context.
– The API Manager (via api_manager.js) is invoked by these UI components (or via the background) to fetch responses from external API services.
– Chat Core (chat_core.js) manages conversation state and routing between the UI, storage (chat_storage.js), and API responses.
– Settings (settings.js) and rename_manager.js allow users to customize chat behavior and model selection.
- Use of Chrome message passing between content scripts, background scripts, and UI pages.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Different UI components (popup, side panel) are decoupled while still coordinated via the background script.
- Extensibility: Inclusion of separate prompt files and settings modules illustrate that the system is built for easy customization and future expansion.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI Components
    subgraph "Browser UI"
        popupUI["Popup UI (popup.html, popup.js)"]
        sidePanel["Side Panel (sidepanel.html, sidepanel.js, sidepanel_controller.js)"]
        historyPage["History Page (history.html, history.js)"]
        settingsPage["Settings Page (settings.html, settings.js)"]
        contentScript["Content Script (content.js)"]
    end

    %% Background Process
    subgraph "Background Process"
        backgroundScript["Background Script (background.js)"]
    end

    %% Business Logic
    subgraph "Business Logic"
        chatCoreUI["Chat Core & UI (chat_core.js, chat_ui.js)"]
        chatStorage["Chat Storage (chat_storage.js)"]
        stateUtil["State & Utility (state_manager.js, utils.js)"]
        renameManager["Rename Manager (rename_manager.js)"]
    end

    %% API Communication
    subgraph "API Communication"
        apiManager["API Manager (api_manager.js)"]
    end

    %% Prompts & Customization
    subgraph "Prompts & Customization"
        prompts["Prompts (prompts folder)"]
    end

    %% External Service
    llmServices(("LLM Services")) 

    %% Connections
    contentScript -->|"detects_text_selection"| backgroundScript
    popupUI -->|"message_passing"| backgroundScript
    sidePanel -->|"message_passing"| backgroundScript
    settingsPage -->|"settings_data"| backgroundScript

    backgroundScript -->|"routes_chat_messages"| chatCoreUI

    chatCoreUI -->|"stores_history"| chatStorage
    chatCoreUI -->|"calls_API"| apiManager
    chatCoreUI -->|"updates_state"| stateUtil

    settingsPage -->|"config_changes"| renameManager
    settingsPage -->|"state_updates"| stateUtil

    apiManager -->|"api_calls"| llmServices

    %% Click Events
    click popupUI "https://github.com/eduardr02/faster-chatgpt/blob/main/src/html/popup.html"
    click sidePanel "https://github.com/eduardr02/faster-chatgpt/blob/main/src/html/sidepanel.html"
    click historyPage "https://github.com/eduardr02/faster-chatgpt/blob/main/src/html/history.html"
    click settingsPage "https://github.com/eduardr02/faster-chatgpt/blob/main/src/html/settings.html"
    click contentScript "https://github.com/eduardr02/faster-chatgpt/blob/main/src/js/content.js"
    click backgroundScript "https://github.com/eduardr02/faster-chatgpt/blob/main/src/js/background.js"
    click chatCoreUI "https://github.com/eduardr02/faster-chatgpt/blob/main/src/js/chat_core.js"
    click chatStorage "https://github.com/eduardr02/faster-chatgpt/blob/main/src/js/chat_storage.js"
    click stateUtil "https://github.com/eduardr02/faster-chatgpt/blob/main/src/js/state_manager.js"
    click renameManager "https://github.com/eduardr02/faster-chatgpt/blob/main/src/js/rename_manager.js"
    click apiManager "https://github.com/eduardr02/faster-chatgpt/blob/main/src/js/api_manager.js"
    click prompts "https://github.com/eduardr02/faster-chatgpt/tree/main/src/prompts"

    %% Styles
    class popupUI,sidePanel,historyPage,settingsPage,contentScript ui
    class backgroundScript bkg
    class chatCoreUI,chatStorage,stateUtil,renameManager logic
    class apiManager api
    class prompts prompt
    class llmServices external

    %% Class Definitions for colors
    classDef ui fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef bkg fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef logic fill:#FFFFCC,stroke:#333,stroke-width:2px;
    classDef api fill:#FFDAB9,stroke:#333,stroke-width:2px;
    classDef prompt fill:#D8BFD8,stroke:#333,stroke-width:2px;
    classDef external fill:#F5F5F5,stroke:#333,stroke-width:2px;
```
