# madhumithra-r/focuslens architecture

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

- Interactive diagram: https://gitdiagram.com/madhumithra-r/focuslens
- Repository: https://github.com/madhumithra-r/focuslens

## Overview

FocusLens is a local-first Chrome extension that monitors browsing behavior, calculates a rule-based distraction score, and offers a check-in when scrolling crosses its configured threshold. Its main workflow runs in the page content script: observe scrolling and active time, score behavior, then blur the page and present a learning-or-break prompt. The popup provides live metrics and controls; the background worker handles settings and persisted statistics. The sampled excerpts do not show all message types or the complete scoring and dismissal logic, so those links are documented where possible and otherwise omitted.

Main entry points: [`popup.js`](https://github.com/madhumithra-r/focuslens/blob/main/popup.js) (Dashboard controller), [`background.js`](https://github.com/madhumithra-r/focuslens/blob/main/background.js) (Background worker), [`content.js`](https://github.com/madhumithra-r/focuslens/blob/main/content.js) (Blur and check-in), [`popup.html`](https://github.com/madhumithra-r/focuslens/blob/main/popup.html) (Popup dashboard)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_page_monitoring["Page monitoring"]
  node_scroll_detection["Scroll detection<br/>[content.js]"]
  node_active_time["Active-time tracking<br/>[content.js]"]
  node_behavioral_scoring["Rule-based scoring<br/>[content.js]"]
end

subgraph group_intervention["Check-in intervention"]
  node_page_intervention["Blur and check-in<br/>[content.js]"]
end

subgraph group_dashboard["Popup dashboard"]
  node_popup_ui["Popup dashboard<br/>[popup.html]"]
  node_popup_controller["Dashboard controller<br/>[popup.js]"]
end

subgraph group_background["Background and storage"]
  node_background_worker["Background worker<br/>[background.js]"]
  node_local_storage[("Local statistics and settings<br/>[background.js]")]
  node_extension_badge["Extension badge"]
end

node_user(("User"))
node_web_page["Web page"]

node_user -->|"browses"| node_web_page
node_web_page -->|"emits scroll events"| node_scroll_detection
node_scroll_detection -->|"supplies scroll behavior"| node_behavioral_scoring
node_active_time -->|"supplies session duration"| node_behavioral_scoring
node_behavioral_scoring -->|"triggers check-in"| node_page_intervention
node_page_intervention -->|"blurs page"| node_web_page
node_page_intervention -->|"asks for check-in"| node_user
node_user -->|"chooses response"| node_page_intervention
node_user -->|"opens dashboard"| node_popup_ui
node_popup_ui -->|"loads controls"| node_popup_controller
node_popup_controller -->|"requests global stats"| node_background_worker
node_popup_controller -->|"updates settings"| node_background_worker
node_popup_controller -->|"resets statistics"| node_background_worker
node_popup_controller -->|"requests live metrics"| node_scroll_detection
node_popup_controller -->|"requests test prompt"| node_page_intervention
node_background_worker -->|"reads and writes"| node_local_storage
node_background_worker -->|"sets alert badge"| node_extension_badge
node_active_time -->|"sends focus heartbeat"| node_background_worker

click node_scroll_detection "https://github.com/madhumithra-r/focuslens/blob/main/content.js"
click node_active_time "https://github.com/madhumithra-r/focuslens/blob/main/content.js"
click node_behavioral_scoring "https://github.com/madhumithra-r/focuslens/blob/main/content.js"
click node_page_intervention "https://github.com/madhumithra-r/focuslens/blob/main/content.js"
click node_popup_ui "https://github.com/madhumithra-r/focuslens/blob/main/popup.html"
click node_popup_controller "https://github.com/madhumithra-r/focuslens/blob/main/popup.js"
click node_background_worker "https://github.com/madhumithra-r/focuslens/blob/main/background.js"
click node_local_storage "https://github.com/madhumithra-r/focuslens/blob/main/background.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_scroll_detection,node_active_time,node_behavioral_scoring,node_user toneBlue
class node_page_intervention toneAmber
class node_popup_ui,node_popup_controller toneMint
class node_background_worker,node_local_storage,node_extension_badge toneRose
class node_web_page toneIndigo
```

## Components

### Page monitoring

- [Scroll detection](https://github.com/madhumithra-r/focuslens/blob/main/content.js): `content.js`
- [Active-time tracking](https://github.com/madhumithra-r/focuslens/blob/main/content.js): `content.js`
- [Rule-based scoring](https://github.com/madhumithra-r/focuslens/blob/main/content.js): `content.js`

### Check-in intervention

- [Blur and check-in](https://github.com/madhumithra-r/focuslens/blob/main/content.js): `content.js`

### Popup dashboard

- [Popup dashboard](https://github.com/madhumithra-r/focuslens/blob/main/popup.html): `popup.html`
- [Dashboard controller](https://github.com/madhumithra-r/focuslens/blob/main/popup.js): `popup.js`

### Background and storage

- [Background worker](https://github.com/madhumithra-r/focuslens/blob/main/background.js): `background.js`
- [Local statistics and settings](https://github.com/madhumithra-r/focuslens/blob/main/background.js): `background.js`
- **Extension badge**

### Other components

- **User**
- **Web page**

## Connections

- User → Web page: browses (evidence: `README.md`)
- Web page → Scroll detection: emits scroll events (evidence: `content.js`)
- Scroll detection → Rule-based scoring: supplies scroll behavior (evidence: `README.md`)
- Active-time tracking → Rule-based scoring: supplies session duration (evidence: `README.md`)
- Rule-based scoring → Blur and check-in: triggers check-in (evidence: `README.md`)
- Blur and check-in → Web page: blurs page (evidence: `content.js`)
- Blur and check-in → User: asks for check-in (evidence: `README.md`)
- User → Blur and check-in: chooses response (evidence: `content.js`)
- User → Popup dashboard: opens dashboard (evidence: `README.md`)
- Popup dashboard → Dashboard controller: loads controls (evidence: `popup.js`)
- Dashboard controller → Background worker: requests global stats (evidence: `popup.js`)
- Dashboard controller → Background worker: updates settings (evidence: `popup.js`)
- Dashboard controller → Background worker: resets statistics (evidence: `popup.js`)
- Dashboard controller → Scroll detection: requests live metrics (evidence: `popup.js`)
- Dashboard controller → Blur and check-in: requests test prompt (evidence: `popup.js`)
- Background worker → Local statistics and settings: reads and writes (evidence: `background.js`)
- Background worker → Extension badge: sets alert badge (evidence: `background.js`)
- Active-time tracking → Background worker: sends focus heartbeat (evidence: `content.js`)
