# sathyaseelan2006/titletruth architecture

> Architecture diagram of the GitHub repository sathyaseelan2006/titletruth, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sathyaseelan2006/titletruth
- Repository: https://github.com/sathyaseelan2006/titletruth

## Overview

TitleTruth is a browser extension that scores YouTube videos for clickbait and displays an explanation badge in the feed. The main workflow extracts video metadata, batches visible videos, requests Gemini analysis through the background worker, caches results, and renders badges and tooltips. The README documents support for multiple YouTube layouts, model failover, and RAM plus IndexedDB caching. The popup manages the API key, enablement, testing, and cache clearing. Some implementation details are unsampled; arrows rely on the excerpts or README where indicated.

Main entry points: [`src/background/background.ts`](https://github.com/sathyaseelan2006/titletruth/blob/main/src/background/background.ts) (Background Worker), [`src/popup/popup.ts`](https://github.com/sathyaseelan2006/titletruth/blob/main/src/popup/popup.ts) (Settings Popup), [`src/utils/gemini.ts`](https://github.com/sathyaseelan2006/titletruth/blob/main/src/utils/gemini.ts) (Gemini Analysis), [`src/utils/storage.ts`](https://github.com/sathyaseelan2006/titletruth/blob/main/src/utils/storage.ts) (Cache Operations)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_feed["YouTube Feed"]
  node_extract["Video Extraction<br/>[content.ts]"]
  node_batch["Viewport Batching<br/>[content.ts]"]
  node_overlay["Badge and Tooltip<br/>[content.ts]"]
end

subgraph group_analysis["Analysis"]
  node_worker["Background Worker<br/>[background.ts]"]
  node_gemini["Gemini Analysis<br/>[gemini.ts]"]
end

subgraph group_persistence["Caching"]
  node_cache["Cache Operations<br/>[storage.ts]"]
  node_idb[("IndexedDB Cache")]
  node_ram[("RAM Cache<br/>[background.ts]")]
end

subgraph group_controls["Extension Controls"]
  node_popup["Settings Popup<br/>[popup.ts]"]
  node_localsettings[("Browser Local Storage")]
end

node_youtube(("YouTube Feed"))
node_user(("Extension User"))
node_google{{"Google Gemini API"}}

node_youtube -->|"provides cards"| node_extract
node_extract -->|"queues metadata"| node_batch
node_batch -->|"sends batch"| node_worker
node_worker -->|"requests scoring"| node_gemini
node_gemini -->|"calls API"| node_google
node_gemini -->|"returns scores"| node_worker
node_worker -->|"returns results"| node_overlay
node_worker -->|"reads and writes"| node_ram
node_worker -->|"reads and writes"| node_cache
node_cache -->|"persists results"| node_idb
node_user -->|"configures detector"| node_popup
node_popup -->|"reads and saves"| node_localsettings
node_localsettings -->|"notifies changes"| node_worker
node_popup -->|"tests API key"| node_worker
node_popup -->|"clears cache"| node_cache

click node_extract "https://github.com/sathyaseelan2006/titletruth/blob/main/src/content/content.ts"
click node_batch "https://github.com/sathyaseelan2006/titletruth/blob/main/src/content/content.ts"
click node_overlay "https://github.com/sathyaseelan2006/titletruth/blob/main/src/content/content.ts"
click node_worker "https://github.com/sathyaseelan2006/titletruth/blob/main/src/background/background.ts"
click node_gemini "https://github.com/sathyaseelan2006/titletruth/blob/main/src/utils/gemini.ts"
click node_cache "https://github.com/sathyaseelan2006/titletruth/blob/main/src/utils/storage.ts"
click node_ram "https://github.com/sathyaseelan2006/titletruth/blob/main/src/background/background.ts"
click node_popup "https://github.com/sathyaseelan2006/titletruth/blob/main/src/popup/popup.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_extract,node_batch,node_overlay,node_user toneBlue
class node_worker,node_gemini toneAmber
class node_cache,node_idb,node_ram,node_google toneMint
class node_popup,node_localsettings toneRose
class node_youtube toneIndigo
```

## Components

### YouTube Feed

- [Video Extraction](https://github.com/sathyaseelan2006/titletruth/blob/main/src/content/content.ts): `src/content/content.ts`
- [Viewport Batching](https://github.com/sathyaseelan2006/titletruth/blob/main/src/content/content.ts): `src/content/content.ts`
- [Badge and Tooltip](https://github.com/sathyaseelan2006/titletruth/blob/main/src/content/content.ts): `src/content/content.ts`

### Analysis

- [Background Worker](https://github.com/sathyaseelan2006/titletruth/blob/main/src/background/background.ts): `src/background/background.ts`
- [Gemini Analysis](https://github.com/sathyaseelan2006/titletruth/blob/main/src/utils/gemini.ts): `src/utils/gemini.ts`

### Caching

- [Cache Operations](https://github.com/sathyaseelan2006/titletruth/blob/main/src/utils/storage.ts): `src/utils/storage.ts`
- **IndexedDB Cache**
- [RAM Cache](https://github.com/sathyaseelan2006/titletruth/blob/main/src/background/background.ts): `src/background/background.ts`

### Extension Controls

- [Settings Popup](https://github.com/sathyaseelan2006/titletruth/blob/main/src/popup/popup.ts): `src/popup/popup.ts`
- **Browser Local Storage**

### Other components

- **YouTube Feed**
- **Extension User**
- **Google Gemini API**

## Connections

- YouTube Feed → Video Extraction: provides cards (evidence: `README.md`)
- Video Extraction → Viewport Batching: queues metadata (evidence: `README.md`)
- Viewport Batching → Background Worker: sends batch (evidence: `src/content/content.ts`)
- Background Worker → Gemini Analysis: requests scoring (evidence: `src/background/background.ts`)
- Gemini Analysis → Google Gemini API: calls API (evidence: `src/utils/gemini.ts`)
- Gemini Analysis → Background Worker: returns scores (evidence: `src/background/background.ts`)
- Background Worker → Badge and Tooltip: returns results (evidence: `README.md`)
- Background Worker → RAM Cache: reads and writes (evidence: `src/background/background.ts`)
- Background Worker → Cache Operations: reads and writes (evidence: `src/background/background.ts`)
- Cache Operations → IndexedDB Cache: persists results (evidence: `src/utils/storage.ts`)
- Extension User → Settings Popup: configures detector (evidence: `README.md`)
- Settings Popup → Browser Local Storage: reads and saves (evidence: `src/popup/popup.ts`)
- Browser Local Storage → Background Worker: notifies changes (evidence: `src/background/background.ts`)
- Settings Popup → Background Worker: tests API key (evidence: `src/popup/popup.ts`)
- Settings Popup → Cache Operations: clears cache (evidence: `src/popup/popup.ts`)
