# bonaguidin/tc-analyzer architecture

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

- Interactive diagram: https://gitdiagram.com/bonaguidin/tc-analyzer
- Repository: https://github.com/bonaguidin/tc-analyzer

## Overview

T&C Analyzer is a Chrome extension that detects terms pages, extracts their text, asks an LLM to flag potentially harmful clauses, and presents a severity summary with detailed results. The main path runs from the page content script through the popup and analyzer to the model, then to the popup and optional detail tab. The background worker manages badges and session results. The README documents accordion expansion, search-page exclusions, truncation warnings, and the detailed clause breakdown. Edges are limited to relationships visible in the excerpts or explicitly described in the README.

Main entry points: [`tc-analyzer/popup/popup.js`](https://github.com/bonaguidin/tc-analyzer/blob/main/tc-analyzer/popup/popup.js) (Analysis popup), [`tc-analyzer/content.js`](https://github.com/bonaguidin/tc-analyzer/blob/main/tc-analyzer/content.js) (Detect & extract), [`tc-analyzer/lib/analyzer.js`](https://github.com/bonaguidin/tc-analyzer/blob/main/tc-analyzer/lib/analyzer.js) (Prompt & analyzer), [`tc-analyzer/background.js`](https://github.com/bonaguidin/tc-analyzer/blob/main/tc-analyzer/background.js) (Badge & session worker)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_page["Page Detection"]
  node_content["Detect &amp; extract<br/>[content.js]"]
end

subgraph group_analysis["Analysis Flow"]
  node_popup["Analysis popup<br/>[popup.js]"]
  node_analyzer["Prompt &amp; analyzer<br/>[analyzer.js]"]
end

subgraph group_results["Results &amp; State"]
  node_background["Badge &amp; session worker<br/>[background.js]"]
  node_session[("Session result store")]
  node_details["Detailed results view<br/>[results.js]"]
end

node_user(("Extension user"))
node_webpage["Terms page"]
node_model["OpenRouter model API"]

node_webpage -->|"scans content"| node_content
node_content -->|"reports detection"| node_background
node_user -->|"opens &amp; analyzes"| node_popup
node_popup -->|"requests extraction"| node_content
node_content -->|"returns extracted text"| node_popup
node_popup -->|"analyzes text"| node_analyzer
node_analyzer -->|"sends prompt"| node_model
node_model -->|"returns analysis"| node_analyzer
node_popup -->|"updates badge &amp; result"| node_background
node_background -->|"stores result"| node_session
node_popup -->|"caches result"| node_session
node_user -->|"opens full breakdown"| node_details
node_details -->|"reads result"| node_session

click node_content "https://github.com/bonaguidin/tc-analyzer/blob/main/tc-analyzer/content.js"
click node_popup "https://github.com/bonaguidin/tc-analyzer/blob/main/tc-analyzer/popup/popup.js"
click node_analyzer "https://github.com/bonaguidin/tc-analyzer/blob/main/tc-analyzer/lib/analyzer.js"
click node_background "https://github.com/bonaguidin/tc-analyzer/blob/main/tc-analyzer/background.js"
click node_details "https://github.com/bonaguidin/tc-analyzer/blob/main/tc-analyzer/results/results.js"

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_content,node_user toneBlue
class node_popup,node_analyzer toneAmber
class node_background,node_session,node_details,node_model toneMint
class node_webpage toneIndigo
```

## Components

### Page Detection

- [Detect & extract](https://github.com/bonaguidin/tc-analyzer/blob/main/tc-analyzer/content.js): `tc-analyzer/content.js`

### Analysis Flow

- [Analysis popup](https://github.com/bonaguidin/tc-analyzer/blob/main/tc-analyzer/popup/popup.js): `tc-analyzer/popup/popup.js`
- [Prompt & analyzer](https://github.com/bonaguidin/tc-analyzer/blob/main/tc-analyzer/lib/analyzer.js): `tc-analyzer/lib/analyzer.js`

### Results & State

- [Badge & session worker](https://github.com/bonaguidin/tc-analyzer/blob/main/tc-analyzer/background.js): `tc-analyzer/background.js`
- **Session result store**
- [Detailed results view](https://github.com/bonaguidin/tc-analyzer/blob/main/tc-analyzer/results/results.js): `tc-analyzer/results/results.js`

### Other components

- **Extension user**
- **Terms page**
- **OpenRouter model API**

## Connections

- Terms page → Detect & extract: scans content (evidence: `tc-analyzer/content.js`)
- Detect & extract → Badge & session worker: reports detection
- Extension user → Analysis popup: opens & analyzes
- Analysis popup → Detect & extract: requests extraction (evidence: `tc-analyzer/popup/popup.js`)
- Detect & extract → Analysis popup: returns extracted text (evidence: `tc-analyzer/content.js`)
- Analysis popup → Prompt & analyzer: analyzes text (evidence: `tc-analyzer/popup/popup.js`)
- Prompt & analyzer → OpenRouter model API: sends prompt (evidence: `tc-analyzer/lib/analyzer.js`)
- OpenRouter model API → Prompt & analyzer: returns analysis (evidence: `tc-analyzer/lib/analyzer.js`)
- Analysis popup → Badge & session worker: updates badge & result (evidence: `tc-analyzer/popup/popup.js`)
- Badge & session worker → Session result store: stores result (evidence: `tc-analyzer/background.js`)
- Analysis popup → Session result store: caches result (evidence: `tc-analyzer/popup/popup.js`)
- Extension user → Detailed results view: opens full breakdown
- Detailed results view → Session result store: reads result (evidence: `tc-analyzer/results/results.js`)
