# sahilbakoru/on-device-ai-doc-analyser architecture

> Architecture diagram of the GitHub repository sahilbakoru/on-device-ai-doc-analyser, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sahilbakoru/on-device-ai-doc-analyser
- Repository: https://github.com/sahilbakoru/on-device-ai-doc-analyser

## Overview

##### Project type and purpose
- This is a single-page Chrome extension that performs offline analysis of CSV files. It reads uploaded CSVs, processes them through Chrome’s built-in Gemini Nano model and optional external Translate API, then renders summaries, insights, and graphs in a side panel.

##### File structure
- Top level:
- manifest.json         → Chrome extension manifest
- background.js         → background/service worker script
- rollup.config.mjs     → build configuration (bundler)
- package.json / lock   → dependencies and scripts
- images/               → UI assets
- Chrome_Extension_Project_Overview.md / README.md / License
- sidepanel/:
- index.html            → UI container for report
- index.js              → front-end logic (data ingest, rendering)
- index.css             → styling
- pdf-sample.pdf        → example asset
- Supporting files: Test_example.csv, privacy.txt

##### Readme insights
- Offline CSV analysis
- Uses Prompt API + Translate API + Gemini Nano built in
- Build with “npm run build” → dist folder loaded as unpacked extension

##### Detail
- Every architectural element (build, manifest, background, UI, model calls, external API)
- Intermediary message channels (chrome.runtime messaging)
- Asset folder only if it’s critical to resource loading

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Build & Deployment"
        RC["rollup.config.mjs"]:::build
        RC -->|"bundles to"| Dist["dist/"]:::build
    end

    subgraph "Extension Package"
        MN["manifest.json"]:::chrome
        BG["background.js"]:::chrome
        UIHTML["sidepanel/index.html"]:::ui
        IMG[(Images Folder)]:::data
        click MN "https://github.com/sahilbakoru/on-device-ai-doc-analyser/blob/main/manifest.json"
        click BG "https://github.com/sahilbakoru/on-device-ai-doc-analyser/blob/main/background.js"
        click UIHTML "https://github.com/sahilbakoru/on-device-ai-doc-analyser/blob/main/sidepanel/index.html"
        click IMG "https://github.com/sahilbakoru/on-device-ai-doc-analyser/tree/main/images/"
    end

    Dist -->|"loaded as unpacked"| MN
    MN -->|"defines entry for"| BG
    MN -->|"defines entry for"| UIHTML

    subgraph "Chrome Runtime" 
        CR["Chrome Runtime"]:::chrome
    end

    CR --> BG
    CR --> UIHTML

    subgraph "Sidepanel UI Components"
        JS["sidepanel/index.js"]:::ui
        CSS["sidepanel/index.css"]:::ui
        PDF[(Sample PDF)]:::data
        TestCSV[(Test CSV)]:::data
        DOC[(Docs & License)]:::data
        click JS "https://github.com/sahilbakoru/on-device-ai-doc-analyser/blob/main/sidepanel/index.js"
        click CSS "https://github.com/sahilbakoru/on-device-ai-doc-analyser/blob/main/sidepanel/index.css"
        click PDF "https://github.com/sahilbakoru/on-device-ai-doc-analyser/blob/main/sidepanel/pdf-sample.pdf"
        click TestCSV "https://github.com/sahilbakoru/on-device-ai-doc-analyser/blob/main/Test_example.csv"
        click DOC "https://github.com/sahilbakoru/on-device-ai-doc-analyser/blob/main/Chrome_Extension_Project_Overview.md"
    end

    UIHTML --> JS
    UIHTML --> CSS
    UIHTML --> PDF
    UIHTML --> IMG
    UIHTML --> TestCSV
    UIHTML --> DOC

    subgraph "Processing Modules"
        Parser["Local CSV Parser"]:::process
        Gemini["Gemini Nano Model"]:::process
        Translate(("External Translate API")):::cloud
        Chart["Charting Library"]:::process
    end

    JS -->|"upload CSV"| Parser
    Parser -->|"parsed data"| JS
    JS -->|"invoke chrome.prompt"| Gemini
    Gemini -->|"model output"| JS
    JS -->|"optional POST /translate"| Translate
    Translate -->|"translated output"| JS
    JS -->|"render charts"| Chart
    Chart -->|"visuals in UI"| UIHTML

    UIHTML -->|"chrome.runtime.sendMessage"| BG
    BG -->|"chrome.runtime.onMessage"| JS

    classDef chrome fill:#B3CDE3,stroke:#036; 
    classDef ui fill:#FBB4AE,stroke:#900;
    classDef process fill:#C7E9C0,stroke:#090;
    classDef build fill:#D9D9D9,stroke:#666;
    classDef data fill:#ECECEC,stroke:#888;
    classDef cloud fill:#DECBE4,stroke:#609;
    class RC,Dist build
    class MN,BG,CR chrome
    class UIHTML,JS,CSS ui
    class Parser,Gemini,Chart process
    class Translate cloud
    class PDF,IMG,TestCSV,DOC data
```
