# kee-rti/prod architecture

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

- Interactive diagram: https://gitdiagram.com/kee-rti/prod
- Repository: https://github.com/kee-rti/prod

## Overview

Prod is a browser extension that tracks browsing activity, classifies focus locally, explains the classification, and summarizes focused versus distracted time. Its principal runtime path runs from page telemetry through the background service worker and XGBoost inference to an on-page status overlay; the popup reads locally stored session data for its dashboard. The repository also includes the documented synthetic-data training and model-export workflow. Source excerpts do not show every message-handler or model-loading detail, so the graph omits uncertain connections.

Main entry points: [`extension/model`](https://github.com/kee-rti/prod/tree/main/extension/model) (Model assets), [`extension/background.js`](https://github.com/kee-rti/prod/blob/main/extension/background.js) (Background hub), [`synthetic_data.csv`](https://github.com/kee-rti/prod/blob/main/synthetic_data.csv) (Synthetic dataset), [`extension/content.js`](https://github.com/kee-rti/prod/blob/main/extension/content.js) (Page tracker)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_browser["Extension runtime"]
  node_content["Page tracker<br/>[content.js]"]
  node_background["Background hub<br/>[background.js]"]
  node_telemetry["Tab telemetry<br/>[background.js]"]
  node_inference["Focus inference<br/>[inference.js]"]
  node_compiled["Compiled XGBoost<br/>[xgb_compiled.js]"]
  node_overlay["Status overlay<br/>[content.js]"]
  node_popup["Time dashboard<br/>[popup.js]"]
end

subgraph group_ml["Model pipeline"]
  node_train_data["Scenario data<br/>[generate_data.py]"]
  node_dataset["Synthetic dataset<br/>[synthetic_data.csv]"]
  node_baseline["Baseline training<br/>[train_model.py]"]
  node_xgb_train["XGBoost training<br/>[train_xgb.py]"]
  node_evaluation["Model evaluation<br/>[evaluate_model.py]"]
  node_threshold["Threshold tuning<br/>[threshold_sweep.py]"]
  node_compiler["Tree compiler<br/>[compile_xgb_js.py]"]
  node_model_assets["Model assets"]
end

subgraph group_data["Local state"]
  node_store[("Extension storage")]
end

node_user(("Browser user"))
node_page(("Web page"))

node_user -->|"browses"| node_page
node_page -->|"provides activity"| node_content
node_content -->|"sends heartbeat"| node_background
node_background -->|"tracks tab switches"| node_telemetry
node_background -->|"predicts focus"| node_inference
node_inference -->|"uses predictor"| node_compiled
node_background -.->|"returns status"| node_overlay
node_content -->|"updates display"| node_overlay
node_background -->|"writes session"| node_store
node_telemetry -->|"persists telemetry"| node_store
node_popup -->|"reads session data"| node_store
node_user -->|"opens dashboard"| node_popup
node_train_data -->|"generates samples"| node_dataset
node_dataset -->|"trains from"| node_xgb_train
node_dataset -->|"trains from"| node_baseline
node_dataset -->|"evaluates on"| node_evaluation
node_xgb_train -->|"exports model"| node_model_assets
node_model_assets -->|"loads model"| node_threshold
node_threshold -->|"exports trees"| node_model_assets
node_model_assets -->|"loads trees"| node_compiler
node_compiler -->|"writes predictor"| node_compiled
node_baseline -->|"exports weights"| node_model_assets
node_inference -->|"loads model assets"| node_model_assets

click node_content "https://github.com/kee-rti/prod/blob/main/extension/content.js"
click node_background "https://github.com/kee-rti/prod/blob/main/extension/background.js"
click node_telemetry "https://github.com/kee-rti/prod/blob/main/extension/background.js"
click node_inference "https://github.com/kee-rti/prod/blob/main/extension/lib/inference.js"
click node_compiled "https://github.com/kee-rti/prod/blob/main/extension/lib/xgb_compiled.js"
click node_overlay "https://github.com/kee-rti/prod/blob/main/extension/content.js"
click node_popup "https://github.com/kee-rti/prod/blob/main/extension/popup/popup.js"
click node_train_data "https://github.com/kee-rti/prod/blob/main/ml_lab/generate_data.py"
click node_dataset "https://github.com/kee-rti/prod/blob/main/synthetic_data.csv"
click node_baseline "https://github.com/kee-rti/prod/blob/main/ml_lab/train_model.py"
click node_xgb_train "https://github.com/kee-rti/prod/blob/main/ml_lab/train_xgb.py"
click node_evaluation "https://github.com/kee-rti/prod/blob/main/ml_lab/evaluate_model.py"
click node_threshold "https://github.com/kee-rti/prod/blob/main/ml_lab/threshold_sweep.py"
click node_compiler "https://github.com/kee-rti/prod/blob/main/ml_lab/compile_xgb_js.py"
click node_model_assets "https://github.com/kee-rti/prod/tree/main/extension/model"

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_background,node_telemetry,node_inference,node_compiled,node_overlay,node_popup,node_user toneBlue
class node_train_data,node_dataset,node_baseline,node_xgb_train,node_evaluation,node_threshold,node_compiler,node_model_assets toneAmber
class node_store toneMint
class node_page toneIndigo
```

## Components

### Extension runtime

- [Page tracker](https://github.com/kee-rti/prod/blob/main/extension/content.js): `extension/content.js`
- [Background hub](https://github.com/kee-rti/prod/blob/main/extension/background.js): `extension/background.js`
- [Tab telemetry](https://github.com/kee-rti/prod/blob/main/extension/background.js): `extension/background.js`
- [Focus inference](https://github.com/kee-rti/prod/blob/main/extension/lib/inference.js): `extension/lib/inference.js`
- [Compiled XGBoost](https://github.com/kee-rti/prod/blob/main/extension/lib/xgb_compiled.js): `extension/lib/xgb_compiled.js`
- [Status overlay](https://github.com/kee-rti/prod/blob/main/extension/content.js): `extension/content.js`
- [Time dashboard](https://github.com/kee-rti/prod/blob/main/extension/popup/popup.js): `extension/popup/popup.js`

### Model pipeline

- [Scenario data](https://github.com/kee-rti/prod/blob/main/ml_lab/generate_data.py): `ml_lab/generate_data.py`
- [Synthetic dataset](https://github.com/kee-rti/prod/blob/main/synthetic_data.csv): `synthetic_data.csv`
- [Baseline training](https://github.com/kee-rti/prod/blob/main/ml_lab/train_model.py): `ml_lab/train_model.py`
- [XGBoost training](https://github.com/kee-rti/prod/blob/main/ml_lab/train_xgb.py): `ml_lab/train_xgb.py`
- [Model evaluation](https://github.com/kee-rti/prod/blob/main/ml_lab/evaluate_model.py): `ml_lab/evaluate_model.py`
- [Threshold tuning](https://github.com/kee-rti/prod/blob/main/ml_lab/threshold_sweep.py): `ml_lab/threshold_sweep.py`
- [Tree compiler](https://github.com/kee-rti/prod/blob/main/ml_lab/compile_xgb_js.py): `ml_lab/compile_xgb_js.py`
- [Model assets](https://github.com/kee-rti/prod/tree/main/extension/model): `extension/model`

### Local state

- **Extension storage**

### Other components

- **Browser user**
- **Web page**

## Connections

- Browser user → Web page: browses (evidence: `README.md`)
- Web page → Page tracker: provides activity (evidence: `extension/content.js`)
- Page tracker → Background hub: sends heartbeat (evidence: `extension/content.js`)
- Background hub → Tab telemetry: tracks tab switches (evidence: `extension/background.js`)
- Background hub → Focus inference: predicts focus (evidence: `extension/background.js`)
- Focus inference → Compiled XGBoost: uses predictor (evidence: `extension/lib/inference.js`)
- Background hub → Status overlay: returns status
- Page tracker → Status overlay: updates display (evidence: `extension/content.js`)
- Background hub → Extension storage: writes session (evidence: `extension/background.js`)
- Tab telemetry → Extension storage: persists telemetry (evidence: `extension/background.js`)
- Time dashboard → Extension storage: reads session data (evidence: `extension/popup/popup.js`)
- Browser user → Time dashboard: opens dashboard (evidence: `README.md`)
- Scenario data → Synthetic dataset: generates samples (evidence: `ml_lab/generate_data.py`)
- Synthetic dataset → XGBoost training: trains from (evidence: `ml_lab/train_xgb.py`)
- Synthetic dataset → Baseline training: trains from (evidence: `ml_lab/train_model.py`)
- Synthetic dataset → Model evaluation: evaluates on (evidence: `ml_lab/evaluate_model.py`)
- XGBoost training → Model assets: exports model (evidence: `ml_lab/train_xgb.py`)
- Model assets → Threshold tuning: loads model (evidence: `ml_lab/threshold_sweep.py`)
- Threshold tuning → Model assets: exports trees (evidence: `ml_lab/threshold_sweep.py`)
- Model assets → Tree compiler: loads trees (evidence: `ml_lab/compile_xgb_js.py`)
- Tree compiler → Compiled XGBoost: writes predictor (evidence: `ml_lab/compile_xgb_js.py`)
- Baseline training → Model assets: exports weights (evidence: `ml_lab/train_model.py`)
- Focus inference → Model assets: loads model assets (evidence: `extension/lib/inference.js`)
