How sukrutan/ide_time_tracker works
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: background.js Background · manifest.json Manifest · content.js Content Script · popup.html Popup
Components 17
JVM backend
Desktop tracker and local server
- IDE Tracker · Watches the active window and accumulates coding time
src/main/java/com/idetracker/IDETracker.java - Tracking Server · Reads saved time data and serves it over localhost
src/main/java/com/idetracker/TrackingServer.java - Window Check · Detects the foreground app and whether it is an IDE
- Coding Timer · Converts IDE focus into earned coding time
- /time-data · Local API consumed by the extension
Chrome extension
Manifest V3 enforcement and UI
- Manifest · Declares the extension surface and permissions
src/main/java/com/browser-extension/manifest.json - Background · Polls the server and maintains browsing budget
src/main/java/com/browser-extension/background.js - Content Script · Replaces blocked pages with the limit-reached experience
src/main/java/com/browser-extension/content.js - Popup · Shows earned, used, and remaining time
src/main/java/com/browser-extension/popup.html - Popup Logic · Handles popup interactions and reset controls
src/main/java/com/browser-extension/popup.js - Rulesets · Static blocking rules for entertainment sites
src/main/java/com/browser-extension/rules.json - Generated Rules · Indexed declarative net request output
src/main/java/com/browser-extension/_metadata/generated_indexed_rulesets/_ruleset1 - Blocked Sites · Hard-coded domains subject to blocking
- Budget Engine · Converts earned coding time into allowable browsing time
Extension dashboard
Standalone React frontend inside the extension tree
- Dashboard · Auxiliary Vite frontend for richer extension controls
src/main/java/com/browser-extension/dashboard/src/App.jsx - Dashboard Entry · Bootstraps the dashboard React app
src/main/java/com/browser-extension/dashboard/src/main.jsx
Local state
Machine-local persistence boundary
- Time JSON · Persisted usage state written on the local machine
Connections 18
- 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