# sukrutan/ide_time_tracker architecture

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

- Interactive diagram: https://gitdiagram.com/sukrutan/ide_time_tracker
- Repository: https://github.com/sukrutan/ide_time_tracker

## Overview

1. **Repository shape**
   - This is a **three-part system** split across two runtimes: a **Java/JVM backend** and a **Chrome extension**.
   - The Java side produces two runnable JARs: an **IDE activity tracker** and a **local HTTP server**.
   - The browser side is a **Manifest V3 extension** with background, content, and popup scripts, plus a small React-based dashboard under `browser-extension/dashboard`.

2. **Core responsibility split**
   - **`com/idetracker/IDETracker.java`** is the data producer: it watches the active desktop window, decides whether the user is in an IDE, and accumulates coding time.
   - **`com/idetracker/TrackingServer.java`** is the data exposer: it reads the persisted tracking file and serves the current balance over HTTP.
   - **`com/browser-extension/*`** is the enforcement and UI layer: it consumes the server’s data, tracks browsing time, and blocks entertainment sites when the budget is exhausted.

3. **Primary data flow**
   - The tracker writes local usage state to a **JSON file on disk** in the user home directory.
   - The server reads that file and exposes it at **`GET /time-data`** on localhost.
   - The extension polls that endpoint, converts earned coding time into allowable browsing time, and uses that to decide whether to allow or block a page.

4. **Persistence boundary**
   - The local JSON file is the main persistence boundary for the whole system.
   - There is no database or cloud backend in this repo; the state lives on the machine running the tracker.
   - This means the browser extension is effectively stateless except for its local counters and periodic fetches.

5. **Java tracker subsystem**
   - The tracker is a desktop process, not a browser or web app.
   - It relies on OS-level active-window/process inspection to detect IDEs; the README notes **JNA** for window detection and **xdotool** on Linux.
   - The important architectural point is that this component converts **foreground IDE activity** into a simple time counter, rather than monitoring source control, editor events, or keyboard input.

6. **Java server subsystem**
   - The server is a lightweight local REST API, likely intended only for the browser extension and local inspection.
   - It has a single documented endpoint: **`/time-data`**.
   - Its role is read-only: it does not track time itself, it only transforms the tracker’s saved state into response data.

7. **Browser extension enforcement path**
   - **`background.js`** acts as the extension’s central coordinator: it fetches server data, maintains the current browsing budget, and decides when a domain is blocked.
   - **`content.js`** handles page-level behavior on blocked sites, typically replacing or overlaying the page with the “earn more time” experience.
   - **`popup.js` / `popup.html`** provide the user-facing balance view and reset controls.

8. **Blocking mechanism**
   - Blocking is based on a **site list** defined in the extension code, not on dynamic categorization or an external service.
   - The repo includes **`rules.json`** and `_metadata/generated_indexed_rulesets`, which suggests use of **Manifest V3 declarative net request rules** alongside script-based enforcement.
   - The architecture therefore combines **network/request-level blocking** with **content-script page replacement**, which is why both background and content scripts matter.

9. **UI surface area**
   - The main interaction point is the **extension popup**, which shows earned, used, and remaining time.
   - The `dashboard/` folder under the extension contains a separate **Vite + React + Tailwind** frontend, likely for a richer control panel or settings UI.
   - That dashboard is distinct from the popup and is built as a frontend asset, not part of the Java runtime.

10. **Configuration and coupling**
   - The tracker and extension are loosely coupled through two shared constants: the **server URL/port** and the **blocked-site list**.
   - The ratio between coding time and browsing time is defined in the Java tracker, while the extension only consumes the resulting budget.
   - This means changing policy usually requires edits on **both sides** of the system: tracker for earned time, extension for blocked domains and polling.

11. **Runtime and deployment model**
   - The system is designed to run **locally on the same machine**:
     - one process watches the desktop,
     - one process serves localhost API data,
     - one browser extension enforces browsing limits.
   - The README’s startup instructions show that all three pieces must be running together for the loop to work.
   - There is no central orchestration service; each part is independently launched.

12. **Build and packaging boundary**
   - Maven is the main Java build path in the repo, producing the runnable artifacts under `target/`.
   - The browser extension source lives inside the same repository tree, but it is logically a separate deliverable loaded into Chrome via “Load unpacked.”
   - The presence of `dependency-reduced-pom.xml` and built JARs in `target/` indicates the Java artifacts are packaged independently of the extension.

13. **What an architecture diagram should emphasize**
   - Show a **desktop tracker** feeding a **local JSON file**.
   - Show a **local HTTP server** reading that file and serving a **REST endpoint**.
   - Show the **Chrome extension** polling the server, maintaining a time budget, and enforcing blocked sites through **background/content scripts**.
   - Treat the React dashboard as an auxiliary UI subsystem unless you are diagramming all extension assets.

Main entry points: [`src/main/java/com/browser-extension/background.js`](https://github.com/sukrutan/ide_time_tracker/blob/main/src/main/java/com/browser-extension/background.js) (Background), [`src/main/java/com/browser-extension/manifest.json`](https://github.com/sukrutan/ide_time_tracker/blob/main/src/main/java/com/browser-extension/manifest.json) (Manifest), [`src/main/java/com/browser-extension/content.js`](https://github.com/sukrutan/ide_time_tracker/blob/main/src/main/java/com/browser-extension/content.js) (Content Script), [`src/main/java/com/browser-extension/popup.html`](https://github.com/sukrutan/ide_time_tracker/blob/main/src/main/java/com/browser-extension/popup.html) (Popup)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_backend["JVM backend"]
  node_ide_tracker["IDE Tracker<br/>desktop tracker<br/>[IDETracker.java]"]
  node_tracking_server["Tracking Server<br/>local api"]
  node_activity_detection(("Window Check<br/>os inspection"))
  node_coding_timer(("Coding Timer<br/>time counter"))
  node_local_rest{{"/time-data<br/>http endpoint"}}
end

subgraph group_extension["Chrome extension"]
  node_mv3_manifest["Manifest<br/>mv3 config<br/>[manifest.json]"]
  node_bg_script["Background<br/>extension coordinator<br/>[background.js]"]
  node_content_script["Content Script<br/>page enforcer<br/>[content.js]"]
  node_popup_ui["Popup<br/>extension ui<br/>[popup.html]"]
  node_popup_logic["Popup Logic<br/>ui controller<br/>[popup.js]"]
  node_rulesets["Rulesets<br/>dnr rules<br/>[rules.json]"]
  node_generated_rules["Generated Rules<br/>mv3 artifacts"]
  node_site_policy["Blocked Sites<br/>site list"]
  node_budget_engine(("Budget Engine<br/>time policy"))
end

subgraph group_dashboard["Extension dashboard"]
  node_dashboard_app["Dashboard<br/>react app<br/>[App.jsx]"]
  node_dashboard_entry["Dashboard Entry<br/>frontend entry<br/>[main.jsx]"]
end

subgraph group_storage["Local state"]
  node_tracking_file["Time JSON<br/>state file"]
end

node_activity_detection -->|"feeds focus"| node_ide_tracker
node_ide_tracker -->|"accumulates"| node_coding_timer
node_coding_timer -->|"persists"| node_tracking_file
node_tracking_file -->|"reads"| node_tracking_server
node_tracking_server -->|"serves"| node_local_rest
node_mv3_manifest -->|"loads"| node_bg_script
node_mv3_manifest -->|"loads"| node_content_script
node_mv3_manifest -->|"opens"| node_popup_ui
node_bg_script -->|"polls"| node_local_rest
node_bg_script -->|"updates"| node_budget_engine
node_budget_engine -->|"checks"| node_site_policy
node_site_policy -->|"compiles to"| node_rulesets
node_rulesets -->|"materializes"| node_generated_rules
node_bg_script -->|"signals block"| node_content_script
node_content_script -->|"redirects to"| node_popup_ui
node_popup_ui -->|"uses"| node_popup_logic
node_dashboard_entry -->|"boots"| node_dashboard_app
node_bg_script -.->|"shares state"| node_dashboard_app

click node_ide_tracker "https://github.com/sukrutan/ide_time_tracker/blob/main/src/main/java/com/idetracker/IDETracker.java"
click node_tracking_server "https://github.com/sukrutan/ide_time_tracker/blob/main/src/main/java/com/idetracker/TrackingServer.java"
click node_mv3_manifest "https://github.com/sukrutan/ide_time_tracker/blob/main/src/main/java/com/browser-extension/manifest.json"
click node_bg_script "https://github.com/sukrutan/ide_time_tracker/blob/main/src/main/java/com/browser-extension/background.js"
click node_content_script "https://github.com/sukrutan/ide_time_tracker/blob/main/src/main/java/com/browser-extension/content.js"
click node_popup_ui "https://github.com/sukrutan/ide_time_tracker/blob/main/src/main/java/com/browser-extension/popup.html"
click node_popup_logic "https://github.com/sukrutan/ide_time_tracker/blob/main/src/main/java/com/browser-extension/popup.js"
click node_rulesets "https://github.com/sukrutan/ide_time_tracker/blob/main/src/main/java/com/browser-extension/rules.json"
click node_generated_rules "https://github.com/sukrutan/ide_time_tracker/tree/main/src/main/java/com/browser-extension/_metadata/generated_indexed_rulesets/_ruleset1"
click node_dashboard_app "https://github.com/sukrutan/ide_time_tracker/blob/main/src/main/java/com/browser-extension/dashboard/src/App.jsx"
click node_dashboard_entry "https://github.com/sukrutan/ide_time_tracker/blob/main/src/main/java/com/browser-extension/dashboard/src/main.jsx"

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_ide_tracker,node_tracking_server,node_activity_detection,node_coding_timer,node_local_rest toneBlue
class node_mv3_manifest,node_bg_script,node_content_script,node_popup_ui,node_popup_logic,node_rulesets,node_generated_rules,node_site_policy,node_budget_engine toneAmber
class node_dashboard_app,node_dashboard_entry toneMint
class node_tracking_file toneRose
```

## Components

### JVM backend

Desktop tracker and local server

- [IDE Tracker](https://github.com/sukrutan/ide_time_tracker/blob/main/src/main/java/com/idetracker/IDETracker.java): desktop tracker · Watches the active window and accumulates coding time · `src/main/java/com/idetracker/IDETracker.java`
- [Tracking Server](https://github.com/sukrutan/ide_time_tracker/blob/main/src/main/java/com/idetracker/TrackingServer.java): local api · Reads saved time data and serves it over localhost · `src/main/java/com/idetracker/TrackingServer.java`
- **Window Check**: os inspection · Detects the foreground app and whether it is an IDE
- **Coding Timer**: time counter · Converts IDE focus into earned coding time
- **/time-data**: http endpoint · Local API consumed by the extension

### Chrome extension

Manifest V3 enforcement and UI

- [Manifest](https://github.com/sukrutan/ide_time_tracker/blob/main/src/main/java/com/browser-extension/manifest.json): mv3 config · Declares the extension surface and permissions · `src/main/java/com/browser-extension/manifest.json`
- [Background](https://github.com/sukrutan/ide_time_tracker/blob/main/src/main/java/com/browser-extension/background.js): extension coordinator · Polls the server and maintains browsing budget · `src/main/java/com/browser-extension/background.js`
- [Content Script](https://github.com/sukrutan/ide_time_tracker/blob/main/src/main/java/com/browser-extension/content.js): page enforcer · Replaces blocked pages with the limit-reached experience · `src/main/java/com/browser-extension/content.js`
- [Popup](https://github.com/sukrutan/ide_time_tracker/blob/main/src/main/java/com/browser-extension/popup.html): extension ui · Shows earned, used, and remaining time · `src/main/java/com/browser-extension/popup.html`
- [Popup Logic](https://github.com/sukrutan/ide_time_tracker/blob/main/src/main/java/com/browser-extension/popup.js): ui controller · Handles popup interactions and reset controls · `src/main/java/com/browser-extension/popup.js`
- [Rulesets](https://github.com/sukrutan/ide_time_tracker/blob/main/src/main/java/com/browser-extension/rules.json): dnr rules · Static blocking rules for entertainment sites · `src/main/java/com/browser-extension/rules.json`
- [Generated Rules](https://github.com/sukrutan/ide_time_tracker/tree/main/src/main/java/com/browser-extension/_metadata/generated_indexed_rulesets/_ruleset1): mv3 artifacts · Indexed declarative net request output · `src/main/java/com/browser-extension/_metadata/generated_indexed_rulesets/_ruleset1`
- **Blocked Sites**: site list · Hard-coded domains subject to blocking
- **Budget Engine**: time policy · Converts earned coding time into allowable browsing time

### Extension dashboard

Standalone React frontend inside the extension tree

- [Dashboard](https://github.com/sukrutan/ide_time_tracker/blob/main/src/main/java/com/browser-extension/dashboard/src/App.jsx): react app · Auxiliary Vite frontend for richer extension controls · `src/main/java/com/browser-extension/dashboard/src/App.jsx`
- [Dashboard Entry](https://github.com/sukrutan/ide_time_tracker/blob/main/src/main/java/com/browser-extension/dashboard/src/main.jsx): frontend entry · Bootstraps the dashboard React app · `src/main/java/com/browser-extension/dashboard/src/main.jsx`

### Local state

Machine-local persistence boundary

- **Time JSON**: state file · Persisted usage state written on the local machine

## Connections

- Window Check → IDE Tracker: feeds focus · Foreground IDE detection drives tracking decisions
- IDE Tracker → Coding Timer: accumulates · Updates earned coding time while an IDE is active
- Coding Timer → Time JSON: persists · Stores the current local usage state on disk
- Time JSON → Tracking Server: reads · Server loads the saved state from the local file
- Tracking Server → /time-data: serves · Exposes the current balance through the local HTTP endpoint
- Manifest → Background: loads · Manifest registers the background coordinator
- Manifest → Content Script: loads · Manifest registers page-level enforcement
- Manifest → Popup: opens · Manifest wires the browser action popup
- Background → /time-data: polls · Background script fetches earned time from the local server
- Background → Budget Engine: updates · Uses server data to maintain the browsing budget
- Budget Engine → Blocked Sites: checks · Policy determines whether a domain is allowed
- Blocked Sites → Rulesets: compiles to · Static site list is reflected in declarative rules
- Rulesets → Generated Rules: materializes · Generated MV3 ruleset is loaded by Chrome
- Background → Content Script: signals block · Background logic triggers page replacement for blocked sites
- Content Script → Popup: redirects to · Blocked pages point users toward the time balance UI
- Popup → Popup Logic: uses · Popup markup is driven by popup behavior
- Dashboard Entry → Dashboard: boots · Entry module renders the React dashboard
- Background → Dashboard: shares state · Dashboard and popup reflect the same extension budget model
