# saarthakkj/detoxify-x architecture

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

- Interactive diagram: https://gitdiagram.com/saarthakkj/detoxify-x
- Repository: https://github.com/saarthakkj/detoxify-x

## Overview

##### Main Components
- Chrome Extension Shell: This includes all the UI components and background infrastructure needed by a Chrome extension.
- Popup Module: The user interface (popup.html, popup.css, popup.js) where users input their API key and content preferences.
- Content Script: The file (contentScript.js) that gets injected into Twitter/X pages to monitor and potentially modify the DOM based on filtering results.
- Background Script: Managed by background.js, this script handles persistent tasks and acts as a mediator for processes or event listeners within the extension.
- Core Logic/Utility Functions: Files like index.js and utils.js that contain the core logic tying together UI inputs, tweet processing, and communication with external APIs.
- Build/Bundle Process: The webpack.config.mjs and dist directory show that the project uses Webpack to bundle or compile code for production.
- External API Integration: The extension uses the Nebius AI Studio API for AI analysis, which is critical for filtering content in real time.

##### Relationships and Interactions
- The Popup Module collects user configurations (API key and filtering preferences) and stores them using Chrome’s secure storage (as mentioned in the README).
- The Content Script is injected into Twitter/X pages and continuously monitors page content, capturing tweets (both text and images) as they load.
- The Content Script communicates with the Background Script (using Chrome messaging) to offload heavier processing or API calls.
- The Background Script, utilizing the core logic (index.js, utils.js), processes the tweets by interfacing with the Nebius AI Studio API for real-time content analysis.
- The processed results (i.e., which tweets to filter out or highlight) are sent back to the Content Script to perform the actual DOM manipulation—filtering out or modifying the Twitter feed in accordance with user preferences.
- The Build Process (Webpack) ensures the code is bundled correctly for the Chrome runtime. The dist folder contains the final bundled JavaScript used within the extension.

##### Architectural Patterns and Design Principles
- Modular Design: Different functionalities (UI, content processing, background tasks) are encapsulated in separate JavaScript modules.
- Event-Driven Communication: The use of Chrome messaging for communication among components (especially between the Content Script and Background Script) represents an event-driven architecture.
- Separation of Concerns: The distinct division between presentation (popup), background processing (background.js), and page-level interaction (contentScript.js) follows separation of concerns, keeping each part focused on a single responsibility.
- Client-Side Privacy: Emphasize that all processing happens within the user’s browser with secure storage of sensitive API keys, ensuring privacy.

- Event-driven nature of communications (e.g., Chrome messaging channels) and clearly mark out where real-time data processing occurs.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Main container
    Extension("Detoxify Extension"):::extension

    %% Chrome Extension Shell
    Shell("Chrome Extension Shell"):::shell

    %% Popup Module Subgraph
    subgraph "Popup Module"
        PHTML("popup.html"):::popup
        PCSS("popup.css"):::popup
        PJS("popup.js"):::popup
    end

    %% Content Script
    Content("Content Script"):::content

    %% Background Service Subgraph
    subgraph "Background Service"
        BG("background.js"):::background
        IDX("index.js"):::background
        UTILS("utils.js"):::background
    end

    %% Build/Bundle Process Subgraph
    subgraph "Build/Bundle Process"
        WP("webpack.config.mjs"):::build
        DIST("dist"):::build
    end

    %% External API
    API("Nebius AI Studio API"):::api

    %% Relationships
    Shell -->|"defines extension structure"| Extension
    PHTML --- PCSS
    PCSS --- PJS
    Shell -->|"provides UI container"| PHTML
    Shell -->|"injects scripts"| Content
    Shell -->|"registers"| BG
    Extension -->|"bundles via"| WP
    Extension -->|"bundles into"| DIST

    %% Data flow arrows
    PHTML -->|"sends userConfig"| BG
    Content -->|"sends tweetData"| BG
    BG -->|"returns filterData"| Content
    BG -->|"calls"| API
    API -->|"responds"| BG

    %% Styles
    classDef shell fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef popup fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef content fill:#FFFF99,stroke:#000,stroke-width:1px;
    classDef background fill:#F08080,stroke:#000,stroke-width:1px;
    classDef build fill:#D3D3D3,stroke:#000,stroke-width:1px;
    classDef api fill:#FFB6C1,stroke:#000,stroke-width:1px;
    classDef extension fill:#E6E6FA,stroke:#000,stroke-width:1px;

    %% Click Events
    click Shell "https://github.com/saarthakkj/detoxify-x/blob/master/extension/manifest.json"
    click PHTML "https://github.com/saarthakkj/detoxify-x/blob/master/extension/popup.html"
    click PCSS "https://github.com/saarthakkj/detoxify-x/blob/master/extension/popup.css"
    click PJS "https://github.com/saarthakkj/detoxify-x/blob/master/extension/popup.js"
    click Content "https://github.com/saarthakkj/detoxify-x/blob/master/extension/contentScript.js"
    click BG "https://github.com/saarthakkj/detoxify-x/blob/master/extension/background.js"
    click IDX "https://github.com/saarthakkj/detoxify-x/blob/master/extension/index.js"
    click UTILS "https://github.com/saarthakkj/detoxify-x/blob/master/extension/utils.js"
    click WP "https://github.com/saarthakkj/detoxify-x/blob/master/extension/webpack.config.mjs"
    click DIST "https://github.com/saarthakkj/detoxify-x/tree/master/extension/dist"
```
