# f/agentlytics architecture

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

- Interactive diagram: https://gitdiagram.com/f/agentlytics
- Repository: https://github.com/f/agentlytics

## Overview

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`](https://github.com/f/agentlytics/blob/master/editors/index.js) (Adapter scan), [`ui/src/App.jsx`](https://github.com/f/agentlytics/blob/master/ui/src/App.jsx) (App shell), [`server.js`](https://github.com/f/agentlytics/blob/master/server.js) (API server), [`index.js`](https://github.com/f/agentlytics/blob/master/index.js) (Bootstrap)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Local core"]
  node_index_js["Bootstrap<br/>node entrypoint<br/>[index.js]"]
  node_cache_js[("Cache DB<br/>sqlite cache<br/>[cache.js]")]
  node_server_js["API server<br/>read-only api<br/>[server.js]"]
end

subgraph group_editors["Editor adapters"]
  node_editors_index_js["Adapter scan<br/>scan pipeline<br/>[index.js]"]
  node_editors_base_js["Adapter contract<br/>adapter base<br/>[base.js]"]
  node_editors_cursor_js["Cursor<br/>editor adapter<br/>[cursor.js]"]
  node_editors_claude_js["Claude Code<br/>editor adapter<br/>[claude.js]"]
  node_editors_vscode_js["VS Code<br/>editor adapter<br/>[vscode.js]"]
  node_editors_windsurf_js["Windsurf<br/>editor adapter<br/>[windsurf.js]"]
end

subgraph group_ui["Web UI"]
  node_ui_main_jsx["UI entry<br/>spa bootstrap<br/>[main.jsx]"]
  node_ui_app_jsx["App shell<br/>spa shell<br/>[App.jsx]"]
  node_ui_api_js["API client<br/>frontend client<br/>[api.js]"]
  node_ui_live_jsx["Live hooks<br/>live updates<br/>[useLive.jsx]"]
  node_ui_dashboard_jsx["Dashboard<br/>analytics page<br/>[Dashboard.jsx]"]
  node_ui_cost_jsx["Cost analysis<br/>analytics page<br/>[CostAnalysis.jsx]"]
  node_ui_relay_jsx["Relay dashboard<br/>collaboration page<br/>[RelayDashboard.jsx]"]
end

subgraph group_relay["Relay & MCP"]
  node_relay_server_js[("Relay server<br/>shared storage api<br/>[relay-server.js]")]
  node_relay_client_js["Relay client<br/>sync client<br/>[relay-client.js]"]
  node_mcp_server_js["MCP tools<br/>agent tool server<br/>[mcp-server.js]"]
end

subgraph group_ops["Scan & pricing"]
  node_pricing_js["Pricing<br/>cost model<br/>[pricing.js]"]
  node_mod_ts["Deno scan<br/>zero-dep scanner<br/>[mod.ts]"]
end

node_index_js -->|"scan"| node_editors_index_js
node_index_js -->|"persist"| node_cache_js
node_index_js -->|"serve"| node_server_js
node_editors_index_js -->|"implements"| node_editors_base_js
node_editors_index_js -->|"loads"| node_editors_cursor_js
node_editors_index_js -->|"loads"| node_editors_claude_js
node_editors_index_js -->|"loads"| node_editors_vscode_js
node_editors_index_js -->|"loads"| node_editors_windsurf_js
node_editors_index_js -->|"normalize"| node_cache_js
node_server_js -->|"read"| node_cache_js
node_server_js -->|"enrich"| node_pricing_js
node_server_js -->|"api"| node_ui_api_js
node_ui_main_jsx -->|"mount"| node_ui_app_jsx
node_ui_app_jsx -->|"route"| node_ui_dashboard_jsx
node_ui_app_jsx -->|"route"| node_ui_cost_jsx
node_ui_app_jsx -->|"route"| node_ui_relay_jsx
node_ui_app_jsx -->|"query"| node_ui_api_js
node_ui_live_jsx -->|"refetch"| node_ui_api_js
node_relay_client_js -->|"sync"| node_relay_server_js
node_mcp_server_js -->|"tools"| node_relay_server_js
node_mod_ts -.->|"scan"| node_editors_base_js
node_mod_ts -.->|"scan"| node_editors_cursor_js
node_mod_ts -.->|"scan"| node_editors_claude_js

click node_index_js "https://github.com/f/agentlytics/blob/master/index.js"
click node_cache_js "https://github.com/f/agentlytics/blob/master/cache.js"
click node_server_js "https://github.com/f/agentlytics/blob/master/server.js"
click node_editors_index_js "https://github.com/f/agentlytics/blob/master/editors/index.js"
click node_editors_base_js "https://github.com/f/agentlytics/blob/master/editors/base.js"
click node_editors_cursor_js "https://github.com/f/agentlytics/blob/master/editors/cursor.js"
click node_editors_claude_js "https://github.com/f/agentlytics/blob/master/editors/claude.js"
click node_editors_vscode_js "https://github.com/f/agentlytics/blob/master/editors/vscode.js"
click node_editors_windsurf_js "https://github.com/f/agentlytics/blob/master/editors/windsurf.js"
click node_pricing_js "https://github.com/f/agentlytics/blob/master/pricing.js"
click node_mod_ts "https://github.com/f/agentlytics/blob/master/mod.ts"
click node_relay_server_js "https://github.com/f/agentlytics/blob/master/relay-server.js"
click node_relay_client_js "https://github.com/f/agentlytics/blob/master/relay-client.js"
click node_mcp_server_js "https://github.com/f/agentlytics/blob/master/mcp-server.js"
click node_ui_main_jsx "https://github.com/f/agentlytics/blob/master/ui/src/main.jsx"
click node_ui_app_jsx "https://github.com/f/agentlytics/blob/master/ui/src/App.jsx"
click node_ui_api_js "https://github.com/f/agentlytics/blob/master/ui/src/lib/api.js"
click node_ui_live_jsx "https://github.com/f/agentlytics/blob/master/ui/src/hooks/useLive.jsx"
click node_ui_dashboard_jsx "https://github.com/f/agentlytics/blob/master/ui/src/pages/Dashboard.jsx"
click node_ui_cost_jsx "https://github.com/f/agentlytics/blob/master/ui/src/pages/CostAnalysis.jsx"
click node_ui_relay_jsx "https://github.com/f/agentlytics/blob/master/ui/src/pages/RelayDashboard.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_index_js,node_cache_js,node_server_js toneBlue
class node_editors_index_js,node_editors_base_js,node_editors_cursor_js,node_editors_claude_js,node_editors_vscode_js,node_editors_windsurf_js toneAmber
class node_ui_main_jsx,node_ui_app_jsx,node_ui_api_js,node_ui_live_jsx,node_ui_dashboard_jsx,node_ui_cost_jsx,node_ui_relay_jsx toneMint
class node_relay_server_js,node_relay_client_js,node_mcp_server_js toneRose
class node_pricing_js,node_mod_ts toneIndigo
```

## Components

### Local core

Ingestion, normalization, cache, and read-only API serving

- [Bootstrap](https://github.com/f/agentlytics/blob/master/index.js): node entrypoint · Main Node command that coordinates collection and server startup · `index.js`
- [Cache DB](https://github.com/f/agentlytics/blob/master/cache.js): sqlite cache · Local SQLite system-of-record for normalized session data · `cache.js`
- [API server](https://github.com/f/agentlytics/blob/master/server.js): read-only api · Serves overview, analytics, drill-down, and live refetch endpoints · `server.js`

### Editor adapters

Vendor-specific ingestion adapters and aggregate scan pipeline

- [Adapter scan](https://github.com/f/agentlytics/blob/master/editors/index.js): scan pipeline · Aggregates editor adapters into a shared session model · `editors/index.js`
- [Adapter contract](https://github.com/f/agentlytics/blob/master/editors/base.js): adapter base · Common adapter interface and shared ingestion behavior · `editors/base.js`
- [Cursor](https://github.com/f/agentlytics/blob/master/editors/cursor.js): editor adapter · Adapter for Cursor session and storage formats · `editors/cursor.js`
- [Claude Code](https://github.com/f/agentlytics/blob/master/editors/claude.js): editor adapter · Adapter for Claude Code session ingestion · `editors/claude.js`
- [VS Code](https://github.com/f/agentlytics/blob/master/editors/vscode.js): editor adapter · Adapter for VS Code session sources · `editors/vscode.js`
- [Windsurf](https://github.com/f/agentlytics/blob/master/editors/windsurf.js): editor adapter · Adapter for Windsurf session sources · `editors/windsurf.js`

### Web UI

React/Vite dashboard and browser client

- [UI entry](https://github.com/f/agentlytics/blob/master/ui/src/main.jsx): spa bootstrap · Vite/React application entrypoint · `ui/src/main.jsx`
- [App shell](https://github.com/f/agentlytics/blob/master/ui/src/App.jsx): spa shell · Top-level route and layout composition for the dashboard · `ui/src/App.jsx`
- [API client](https://github.com/f/agentlytics/blob/master/ui/src/lib/api.js): frontend client · Thin browser client for local backend endpoints · `ui/src/lib/api.js`
- [Live hooks](https://github.com/f/agentlytics/blob/master/ui/src/hooks/useLive.jsx): live updates · Browser-side live/refetch subscription logic · `ui/src/hooks/useLive.jsx`
- [Dashboard](https://github.com/f/agentlytics/blob/master/ui/src/pages/Dashboard.jsx): analytics page · Primary dashboard view for overview metrics · `ui/src/pages/Dashboard.jsx`
- [Cost analysis](https://github.com/f/agentlytics/blob/master/ui/src/pages/CostAnalysis.jsx): analytics page · Spending and model-cost visualization page · `ui/src/pages/CostAnalysis.jsx`
- [Relay dashboard](https://github.com/f/agentlytics/blob/master/ui/src/pages/RelayDashboard.jsx): collaboration page · 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](https://github.com/f/agentlytics/blob/master/relay-server.js): shared storage api · Stores synced project/session data in a separate relay database · `relay-server.js`
- [Relay client](https://github.com/f/agentlytics/blob/master/relay-client.js): sync client · Pushes selected local data to the relay service · `relay-client.js`
- [MCP tools](https://github.com/f/agentlytics/blob/master/mcp-server.js): agent tool server · Exposes relay data to AI clients through MCP · `mcp-server.js`

### Scan & pricing

Lightweight scan mode and pricing data

- [Pricing](https://github.com/f/agentlytics/blob/master/pricing.js): cost model · Token and model pricing table used for spend analytics · `pricing.js`
- [Deno scan](https://github.com/f/agentlytics/blob/master/mod.ts): zero-dep scanner · Lightweight scan-only path that prints results without local storage · `mod.ts`

## Connections

- 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
