How f/agentlytics works
1. This repo is a local-first analytics platform for AI coding sessions. Its main job is to ingest conversation/session data from multiple editors, normalize it, cache it locally, and expose it through a dashboard and APIs. The architecture is split into three execution modes: full local dashboard, relay/collaboration, and a lightweight Deno scan.
2. Editor ingestion is adapter-based. The editors/ directory contains one adapter per supported editor/agent (Cursor, Windsurf, Claude Code, VS Code, Copilot, Zed, Codex, Gemini, etc.). editors/index.js and editors/base.js appear to define the common adapter interface and the aggregate scan pipeline. The adapters are the boundary where vendor-specific storage formats, RPC calls, and live-process reads are translated into a shared session model.
3. Normalization and persistence happen in a local SQLite cache. cache.js is the central data layer, and the README says normalized data lands in ~/.agentlytics/cache.db. This cache is the system-of-record for the dashboard and API, which keeps the UI read-only and avoids re-reading editor sources on every request.
4. The main CLI/bootstrap entrypoint orchestrates collection and serving. index.js and server.js likely handle the Node-based “one command” experience: scan editor sources, populate cache, then start the local web server. The README’s --collect mode suggests the collection step can run independently from the server.
5. The REST API is the server-to-UI boundary. server.js exposes read-only endpoints such as overview stats, daily activity, dashboard stats, chats, projects, deep analytics, tool calls, and an SSE refetch stream. This is the contract consumed by the frontend, and it keeps all expensive aggregation logic server-side rather than in the browser.
6. The frontend is a separate React/Vite SPA under ui/. It has its own package, build pipeline, and app shell (ui/src/main.jsx, ui/src/App.jsx). The pages map directly to product areas: Dashboard, Sessions, Projects, Cost Analysis, Deep Analysis, Compare, Subscriptions, Relay, SQL viewer, and settings. Shared components in ui/src/components/ handle analytics visuals, chat rendering, timelines, heatmaps, modals, and sidebar session inspection.
7. The UI reads from the backend through a thin client layer. ui/src/lib/api.js and hooks like ui/src/hooks/useLive.jsx suggest the browser talks only to the local server, not directly to editor data. This keeps the browser as a presentation layer and allows live updates, filters, and drill-downs to remain centralized.
8. Pricing is a separate data domain. pricing.js, pricing.json, and sync-pricing.js indicate token cost estimation is derived from a maintained pricing table rather than computed ad hoc in the UI. That pricing feed drives the Costs page and per-model/per-editor spend analytics.
9. Relay is a second backend for multi-user sharing. relay-server.js and relay-client.js implement a separate path from the single-user dashboard. Join clients periodically push selected project/session data to POST /relay/sync, and the relay stores it in its own SQLite database (~/.agentlytics/relay.db).
10. Relay also exposes collaboration APIs and an MCP boundary. mcp-server.js turns relay data into AI-agent-accessible tools like listing users, searching sessions, and fetching session details. That means the relay is not just a web server; it is also an integration point for external AI clients via MCP.
11. There is a lightweight Deno path that bypasses storage entirely. mod.ts is the sandboxed, zero-dependency scanner described in the README. It reads editor data directly and prints CLI/JSON output without writing files or starting the dashboard, which makes it a separate operational mode from the SQLite-backed app.
12. Supporting assets are split from the runtime app. docs/ appears to host the public documentation site, share-image.js likely generates social/share cards, and misc/ contains branding assets. These are auxiliary rather than core runtime subsystems, but they support distribution and sharing.
13. The main architecture boundary is “local data collection vs. presentation vs. collaboration.” Editor adapters feed the cache; the server turns cache data into APIs; the React UI renders analytics; relay/MCP add networked sharing on top; Deno provides a minimal scan-only alternative. That separation is the key diagram to draw accurately.
Main entry points: editors/index.js Adapter scan · App.jsx App shell · server.js API server · index.js Bootstrap
Components 21
Local core
Ingestion, normalization, cache, and read-only API serving
- Bootstrap · Main Node command that coordinates collection and server startup
index.js - Cache DB · Local SQLite system-of-record for normalized session data
cache.js - API server · Serves overview, analytics, drill-down, and live refetch endpoints
server.js
Editor adapters
Vendor-specific ingestion adapters and aggregate scan pipeline
- Adapter scan · Aggregates editor adapters into a shared session model
editors/index.js - Adapter contract · Common adapter interface and shared ingestion behavior
editors/base.js - Cursor · Adapter for Cursor session and storage formats
editors/cursor.js - Claude Code · Adapter for Claude Code session ingestion
editors/claude.js - VS Code · Adapter for VS Code session sources
editors/vscode.js - Windsurf · Adapter for Windsurf session sources
editors/windsurf.js
Web UI
React/Vite dashboard and browser client
- UI entry · Vite/React application entrypoint
ui/src/main.jsx - App shell · Top-level route and layout composition for the dashboard
ui/src/App.jsx - API client · Thin browser client for local backend endpoints
ui/src/lib/api.js - Live hooks · Browser-side live/refetch subscription logic
ui/src/hooks/useLive.jsx - Dashboard · Primary dashboard view for overview metrics
ui/src/pages/Dashboard.jsx - Cost analysis · Spending and model-cost visualization page
ui/src/pages/CostAnalysis.jsx - Relay dashboard · UI for shared relay data and multi-user visibility
ui/src/pages/RelayDashboard.jsx
Relay & MCP
Collaboration sync, shared storage, and agent tools
- Relay server · Stores synced project/session data in a separate relay database
relay-server.js - Relay client · Pushes selected local data to the relay service
relay-client.js - MCP tools · Exposes relay data to AI clients through MCP
mcp-server.js
Connections 23
- Bootstrap → Adapter scan: scan · Bootstraps collection by scanning editor sources
- Bootstrap → Cache DB: persist · Writes normalized sessions into the local cache
- Bootstrap → API server: serve · Starts the local API server after collection
- Adapter scan → Adapter contract: implements · Uses the shared adapter contract
- Adapter scan → Cursor: loads · Runs the Cursor adapter during aggregate scan
- Adapter scan → Claude Code: loads · Runs the Claude Code adapter during aggregate scan
- Adapter scan → VS Code: loads · Runs the VS Code adapter during aggregate scan
- Adapter scan → Windsurf: loads · Runs the Windsurf adapter during aggregate scan
- Adapter scan → Cache DB: normalize · Converts adapter output into cached session records
- API server → Cache DB: read · Serves read-only analytics from the cache database
- API server → Pricing: enrich · Uses pricing data for cost endpoints and analysis
- API server → API client: api · Exposes the browser-facing REST boundary
- UI entry → App shell: mount · Bootstraps the React application shell
- App shell → Dashboard: route · Renders the main dashboard experience
- App shell → Cost analysis: route · Renders cost analytics
- App shell → Relay dashboard: route · Renders relay and collaboration views
- App shell → API client: query · Fetches analytics data through the local API client
- Live hooks → API client: refetch · Handles live updates and refresh cycles from the backend
- Relay client → Relay server: sync · Pushes selected project/session data to the relay backend
- MCP tools → Relay server: tools · Reads relay data to serve MCP operations
- Deno scan → Adapter contract: scan · Uses the lightweight editor scanning path
- Deno scan → Cursor: scan · Reads editor data directly in zero-dependency mode
- Deno scan → Claude Code: scan · Reads editor data directly in zero-dependency mode