# tantara/transformers.js-chrome architecture

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

- Interactive diagram: https://gitdiagram.com/tantara/transformers.js-chrome
- Repository: https://github.com/tantara/transformers.js-chrome

## Overview

##### Project Type and Purpose
- This is a browser‐based, full-stack Chrome extension built on Plasmo that runs LLMs (text-generation, speech-to-text, text-to-speech, multimodal LLM, reasoning) entirely in the client using Transformers.js and ONNX/WebAssembly.

##### File Structure Analysis
- Top-level artifacts
- src/ – contains three Plasmo extension contexts:
– background.ts (service worker)
– popup.tsx (popup UI)
– sidepanel.tsx (in-page side panel)
- genai/ – core inference pipelines and model registry (text-gen, TTS, STT, multimodal, stopping criteria)
- components/ – React UI components (chat, forms, audio recorder, Shadcn-styled primitives)
- lib/ – utility modules (audio helpers, blob fixes, formatters)
- hooks/ – custom React hooks (e.g., useMobile detection)
- static/ & output/ – static assets (audio, MathJax), compiled HTML outputs
- postinstall/, postbuild/ – build and install scripts
- Build & config files
- package.json, pnpm-lock.yaml, tsconfig.json, tailwind.config.js, postcss.config.js

##### README Insights
- Emphasizes Plasmo for extension scaffolding, Transformers.js for client LLM inference, ONNX runtime under the hood, caching via Local Storage, deployment via Chrome Web Store.
- UI scenarios: text summarization, code generation, image understanding, STT, TTS, reasoning.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Chrome Browser Environment"
        direction TB

        subgraph "Extension Contexts"
            direction TB
            BG["Background Service Worker"]:::ui
            POP["Popup UI"]:::ui
            SIDE["Side Panel UI"]:::ui
        end

        subgraph "GenAI Library"
            direction TB
            subgraph "Pipelines" 
                direction TB
                TG["Text Generation"]:::inference
                STT["Speech-to-Text"]:::inference
                TTS["Text-to-Speech"]:::inference
                MM["Multimodal LLM"]:::inference
            end
            SC["Stopping Criteria"]:::inference
            WS["Whisper Text Streamer"]:::inference
            DC["Default Config"]:::inference
            ML["Model List"]:::inference
            MR["Model Registry"]:::inference
        end

        subgraph "Utility Modules"
            direction TB
            AU["Audio Helpers"]:::inference
            BF["Blob Fixes"]:::inference
            FR["Formatters"]:::inference
            UT["Misc Utils"]:::inference
        end

        subgraph "React UI Components"
            direction TB
            CHAT["Chat & Forms"]:::ui
            AR["Audio Recorder"]:::ui
            CMF["ChangeModelForm"]:::ui
            GCF["GenerationConfigForm"]:::ui
            MRF["ModelRegistryForm"]:::ui
            UIKIT["Shadcn Primitives"]:::ui
        end

        subgraph "Hooks"
            direction TB
            UM["useMobile Hook"]:::ui
        end

        CS["Chrome Local Storage"]:::storage

        subgraph "External Services"
            direction TB
            HF["Hugging Face Models"]:::external
            SA["Static Assets"]:::external
        end
    end

    %% Data Flows
    POP -->|"user input"| TG
    POP -->|"user input"| STT
    POP -->|"user input"| MM
    SIDE -->|"user input"| TG
    SIDE -->|"user input"| STT
    SIDE -->|"user input"| MM

    TG -->|"cache lookup"| CS
    STT -->|"cache lookup"| CS
    TTS -->|"cache lookup"| CS
    MM -->|"cache lookup"| CS

    CS -->|"cache hit"| TG
    CS -->|"cache hit"| STT
    CS -->|"cache hit"| TTS
    CS -->|"cache hit"| MM

    TG -->|"model fetch"| HF
    STT -->|"model fetch"| HF
    TTS -->|"model fetch"| HF
    MM -->|"model fetch"| HF

    TG -->|"inference results"| POP
    TG -->|"inference results"| SIDE
    STT -->|"inference results"| POP
    STT -->|"inference results"| SIDE
    TTS -->|"inference results"| POP
    TTS -->|"inference results"| SIDE
    MM -->|"inference results"| POP
    MM -->|"inference results"| SIDE

    BG <-->|"message passing"| POP
    BG <-->|"message passing"| SIDE

    POP -->|"fetch assets"| SA
    SIDE -->|"fetch assets"| SA

    %% Click Events
    click BG "https://github.com/tantara/transformers.js-chrome/blob/main/src/background.ts"
    click POP "https://github.com/tantara/transformers.js-chrome/blob/main/src/popup.tsx"
    click SIDE "https://github.com/tantara/transformers.js-chrome/blob/main/src/sidepanel.tsx"
    click TG "https://github.com/tantara/transformers.js-chrome/blob/main/genai/pipeline/text-generation.ts"
    click STT "https://github.com/tantara/transformers.js-chrome/blob/main/genai/pipeline/speech-to-text.ts"
    click TTS "https://github.com/tantara/transformers.js-chrome/blob/main/genai/pipeline/text-to-speech.ts"
    click MM "https://github.com/tantara/transformers.js-chrome/blob/main/genai/pipeline/multimodal-llm.ts"
    click DC "https://github.com/tantara/transformers.js-chrome/blob/main/genai/default-config.ts"
    click ML "https://github.com/tantara/transformers.js-chrome/blob/main/genai/model-list.ts"
    click MR "https://github.com/tantara/transformers.js-chrome/blob/main/genai/model-registry.ts"
    click SC "https://github.com/tantara/transformers.js-chrome/blob/main/genai/stopping-criteria.ts"
    click WS "https://github.com/tantara/transformers.js-chrome/blob/main/genai/whisper-text-streamer.ts"
    click AU "https://github.com/tantara/transformers.js-chrome/blob/main/lib/AudioUtils.ts"
    click BF "https://github.com/tantara/transformers.js-chrome/blob/main/lib/BlobFix.ts"
    click FR "https://github.com/tantara/transformers.js-chrome/blob/main/lib/formatter.ts"
    click UT "https://github.com/tantara/transformers.js-chrome/blob/main/lib/utils.ts"
    click CHAT "https://github.com/tantara/transformers.js-chrome/blob/main/components/Chat.tsx"
    click AR "https://github.com/tantara/transformers.js-chrome/blob/main/components/AudioRecorder.tsx"
    click CMF "https://github.com/tantara/transformers.js-chrome/blob/main/components/ChangeModelForm.tsx"
    click GCF "https://github.com/tantara/transformers.js-chrome/blob/main/components/GenerationConfigForm.tsx"
    click MRF "https://github.com/tantara/transformers.js-chrome/blob/main/components/ModelRegistryForm.tsx"
    click UIKIT "https://github.com/tantara/transformers.js-chrome/tree/main/components/ui/"
    click UM "https://github.com/tantara/transformers.js-chrome/blob/main/hooks/use-mobile.tsx"
    click SA "https://github.com/tantara/transformers.js-chrome/tree/main/static/"
    click SA "https://github.com/tantara/transformers.js-chrome/tree/main/src/thirdparty/mathjax/"

    %% Styles
    classDef ui fill:#D0E8FF,stroke:#0868AC,color:#000
    classDef inference fill:#D5E8D4,stroke:#2E7D32,color:#000
    classDef storage fill:#FFE6CC,stroke:#E65100,color:#000
    classDef external fill:#E8E8E8,stroke:#616161,color:#000
```
