# getagentseal/codeburn architecture

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

- Interactive diagram: https://gitdiagram.com/getagentseal/codeburn
- Repository: https://github.com/getagentseal/codeburn

## Overview

#### Purpose and entry points
CodeBurn is a local-first AI coding-usage analytics product. It reads provider session data from disk (plus optional Vercel reporting), prices and classifies usage, then exposes reports, optimization, controls, and native surfaces. The Node CLI is the core entry point at `src/main.ts` and command router at `src/cli.ts`; default execution opens the terminal dashboard in `src/dashboard.tsx`. Other primary entry points are local web (`src/web-dashboard.ts`), MCP stdio (`src/mcp/server.ts`), and Electron desktop (`app/electron/main.ts`).

#### Ingestion and provider boundary
Provider adapters isolate vendor-specific discovery and parsing into one-file integrations, registered centrally in `src/providers/index.ts` against shared contracts in `src/providers/types.ts`. Examples include `src/providers/claude.ts`, `src/providers/codex.ts`, and SQLite-oriented sources such as `src/providers/cursor.ts`. Adapters locate local files/databases, parse records into normalized session/call data, deduplicate provider artifacts, and preserve source-quality distinctions (actual versus estimated). This boundary is the main extension point for new tools.

#### Parse, cache, and normalized usage pipeline
The parser coordinates multi-provider scanning, filtering, incremental hydration, and worker execution through `src/parser.ts`, `src/parse-workers.ts`, and `src/parse-worker.ts`. Durable local caching and concurrent-refresh coordination live in `src/session-cache.ts` and `src/cache-refresh-lock.ts`; SQLite reads are abstracted by `src/sqlite.ts`. Parsed calls flow into aggregation/pricing stages: `src/usage-aggregator.ts` computes totals and freshness, `src/day-aggregator.ts` produces time buckets, and `src/models.ts` / `src/model-breakdown.ts` form model views.

#### Pricing, classification, and analytical products
Shared pricing uses LiteLLM data with bundled fallbacks in `src/data/litellm-snapshot.json` and `src/data/pricing-fallback.json`, mediated by `src/models.ts` and `src/fetch-utils.ts`; currency conversion is handled by `src/currency.ts`. Deterministic task labeling and behavioral metrics originate in `src/classifier.ts` and `src/behavioral-weight.ts`. Analysis layers consume normalized sessions for model comparison (`src/compare.tsx`), waste detection and recommendations (`src/optimize.ts`), git-correlated delivery yield (`src/yield.ts`), and context inspection (`src/context-tree.ts`).

#### Outputs and local control plane
CLI reports, TUI panels, JSON/CSV export, and status views are generated from the same pipeline (`src/dashboard.tsx`, `src/overview.ts`, `src/export.ts`). The localhost web dashboard is served by `src/serve.ts` / `src/web-dashboard.ts`; its separate React prototype/client resides in `dash/src/App.tsx`. MCP exposes local usage and savings tools, with project-name redaction at `src/mcp/redact.ts`. Guard installs fail-open Claude hooks (`src/guard/cli.ts`, `src/guard/hooks.ts`). Optimize changes are transactional: backup/journal/apply/undo live under `src/act/`.

#### Desktop and ambient clients
Electron packages a cross-platform React desktop UI: main-process CLI/IPC bridge at `app/electron/main.ts`, secure preload at `app/electron/preload.ts`, renderer root at `app/renderer/App.tsx`. Native macOS menubar is a Swift/SwiftUI client that invokes/consumes CLI data via `mac/Sources/CodeBurnMenubar/Data/DataClient.swift`, renders via `mac/Sources/CodeBurnMenubar/CodeBurnApp.swift`, and stores credentials in Keychain-oriented code. Windows/Linux tray is Tauri/Rust plus React (`windows/src-tauri/src/lib.rs`, `windows/src/App.tsx`). GNOME uses a JavaScript extension (`gnome/extension.js`).

#### Networking, privacy, and delivery
Default operation is local disk and localhost only. Pricing refresh contacts LiteLLM; currency contacts Frankfurter. Optional device sharing uses LAN discovery/pairing and sanitized transport in `src/sharing/`, while preview team sync uses OIDC, consent, credential storage, OTLP encoding, and remote push under `src/sync/`. Releases build npm/CLI plus Snap, installers, Store, and native menubar artifacts via workflows such as `.github/workflows/ci.yml`, `.github/workflows/build-snap.yml`, and `.github/workflows/build-windows-installer.yml`.

Main entry points: [`src/usage-aggregator.ts`](https://github.com/getagentseal/codeburn/blob/main/src/usage-aggregator.ts) (Usage aggregation), [`src/main.ts`](https://github.com/getagentseal/codeburn/blob/main/src/main.ts) (Node CLI), [`src/optimize.ts`](https://github.com/getagentseal/codeburn/blob/main/src/optimize.ts) (Analysis products), [`src/parser.ts`](https://github.com/getagentseal/codeburn/blob/main/src/parser.ts) (Parse coordinator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry Points"]
  node_cli["Node CLI<br/>entry point<br/>[main.ts]"]
end

subgraph group_pipeline["Local Usage Pipeline"]
  node_providers{{"Provider registry<br/>adapter boundary<br/>[index.ts]"}}
  node_provider_contracts["Provider contracts<br/>shared types<br/>[types.ts]"]
  node_provider_sources["Local provider adapters<br/>integrations<br/>[claude.ts]"]
  node_parser["Parse coordinator<br/>pipeline orchestrator<br/>[parser.ts]"]
  node_parse_workers["Parse workers<br/>worker pipeline<br/>[parse-workers.ts]"]
  node_session_cache[("Session cache<br/>local durable cache<br/>[session-cache.ts]")]
  node_usage_aggregator["Usage aggregation<br/>normalized usage"]
end

subgraph group_analytics["Analytics &amp; Actions"]
  node_models["Models &amp; pricing<br/>pricing layer<br/>[models.ts]"]
  node_classifier["Task classification<br/>behavioral analytics<br/>[classifier.ts]"]
  node_analysis["Analysis products<br/>insights<br/>[optimize.ts]"]
  node_actions["Transactional optimize actions<br/>local mutation"]
end

subgraph group_surfaces["Local Surfaces"]
  node_dashboard["Terminal dashboard<br/>TUI report<br/>[dashboard.tsx]"]
  node_exports["Reports &amp; export<br/>CLI output<br/>[export.ts]"]
  node_web["Local web dashboard<br/>localhost server<br/>[web-dashboard.ts]"]
  node_mcp["MCP server<br/>stdio tools<br/>[server.ts]"]
  node_electron["Electron desktop<br/>desktop client<br/>[main.ts]"]
  node_native_clients["Ambient native clients<br/>menubar and tray clients<br/>[DataClient.swift]"]
  node_guard["Claude guard hooks<br/>local controls<br/>[cli.ts]"]
end

subgraph group_optional["Optional Networked Features"]
  node_sharing["LAN device sharing<br/>optional local network"]
  node_sync["Preview team sync<br/>optional remote sync"]
end

node_cli -->|"runs pipeline"| node_parser
node_cli -->|"default command"| node_dashboard
node_cli -->|"report commands"| node_exports
node_cli -->|"web command"| node_web
node_cli -->|"MCP command"| node_mcp
node_cli -->|"installs controls"| node_guard
node_providers -->|"implements"| node_provider_contracts
node_provider_sources -->|"registered by"| node_providers
node_providers -->|"discovers and parses"| node_parser
node_parser -->|"dispatches"| node_parse_workers
node_parser -->|"hydrates and caches"| node_session_cache
node_parse_workers -->|"normalized calls"| node_usage_aggregator
node_session_cache -->|"cached sessions"| node_usage_aggregator
node_usage_aggregator -->|"usage totals"| node_models
node_usage_aggregator -->|"session behavior"| node_classifier
node_models -->|"priced model views"| node_analysis
node_classifier -->|"task metrics"| node_analysis
node_analysis -->|"recommended changes"| node_actions
node_usage_aggregator -->|"local reports"| node_dashboard
node_analysis -->|"insights"| node_dashboard
node_usage_aggregator -->|"export data"| node_exports
node_analysis -->|"dashboard data"| node_web
node_usage_aggregator -->|"usage tools"| node_mcp
node_cli -->|"invoked through bridge"| node_electron
node_cli -->|"local data source"| node_native_clients
node_usage_aggregator -.->|"sanitized usage"| node_sharing
node_usage_aggregator -.->|"consented telemetry"| node_sync

click node_cli "https://github.com/getagentseal/codeburn/blob/main/src/main.ts"
click node_providers "https://github.com/getagentseal/codeburn/blob/main/src/providers/index.ts"
click node_provider_contracts "https://github.com/getagentseal/codeburn/blob/main/src/providers/types.ts"
click node_provider_sources "https://github.com/getagentseal/codeburn/blob/main/src/providers/claude.ts"
click node_parser "https://github.com/getagentseal/codeburn/blob/main/src/parser.ts"
click node_parse_workers "https://github.com/getagentseal/codeburn/blob/main/src/parse-workers.ts"
click node_session_cache "https://github.com/getagentseal/codeburn/blob/main/src/session-cache.ts"
click node_usage_aggregator "https://github.com/getagentseal/codeburn/blob/main/src/usage-aggregator.ts"
click node_models "https://github.com/getagentseal/codeburn/blob/main/src/models.ts"
click node_classifier "https://github.com/getagentseal/codeburn/blob/main/src/classifier.ts"
click node_analysis "https://github.com/getagentseal/codeburn/blob/main/src/optimize.ts"
click node_dashboard "https://github.com/getagentseal/codeburn/blob/main/src/dashboard.tsx"
click node_exports "https://github.com/getagentseal/codeburn/blob/main/src/export.ts"
click node_web "https://github.com/getagentseal/codeburn/blob/main/src/web-dashboard.ts"
click node_mcp "https://github.com/getagentseal/codeburn/blob/main/src/mcp/server.ts"
click node_electron "https://github.com/getagentseal/codeburn/blob/main/app/electron/main.ts"
click node_native_clients "https://github.com/getagentseal/codeburn/blob/main/mac/Sources/CodeBurnMenubar/Data/DataClient.swift"
click node_guard "https://github.com/getagentseal/codeburn/blob/main/src/guard/cli.ts"

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_cli toneBlue
class node_providers,node_provider_contracts,node_provider_sources,node_parser,node_parse_workers,node_session_cache,node_usage_aggregator toneAmber
class node_models,node_classifier,node_analysis,node_actions toneMint
class node_dashboard,node_exports,node_web,node_mcp,node_electron,node_native_clients,node_guard toneRose
class node_sharing,node_sync toneIndigo
```

## Components

### Entry Points

- [Node CLI](https://github.com/getagentseal/codeburn/blob/main/src/main.ts): entry point · Core command entry point and router. · `src/main.ts`

### Local Usage Pipeline

- [Provider registry](https://github.com/getagentseal/codeburn/blob/main/src/providers/index.ts): adapter boundary · Registers normalized local-data adapters. · `src/providers/index.ts`
- [Provider contracts](https://github.com/getagentseal/codeburn/blob/main/src/providers/types.ts): shared types · `src/providers/types.ts`
- [Local provider adapters](https://github.com/getagentseal/codeburn/blob/main/src/providers/claude.ts): integrations · Claude, Codex, Cursor, and other disk/database readers. · `src/providers/claude.ts`
- [Parse coordinator](https://github.com/getagentseal/codeburn/blob/main/src/parser.ts): pipeline orchestrator · Scans, filters, hydrates, and dispatches parsing work. · `src/parser.ts`
- [Parse workers](https://github.com/getagentseal/codeburn/blob/main/src/parse-workers.ts): worker pipeline · Concurrent provider parsing. · `src/parse-workers.ts`
- [Session cache](https://github.com/getagentseal/codeburn/blob/main/src/session-cache.ts): local durable cache · Caches parsed sessions and coordinates refreshes. · `src/session-cache.ts`
- [Usage aggregation](https://github.com/getagentseal/codeburn/blob/main/src/usage-aggregator.ts): normalized usage · Computes totals and freshness from parsed calls. · `src/usage-aggregator.ts`

### Analytics & Actions

- [Models & pricing](https://github.com/getagentseal/codeburn/blob/main/src/models.ts): pricing layer · Builds model views using LiteLLM and fallback pricing. · `src/models.ts`
- [Task classification](https://github.com/getagentseal/codeburn/blob/main/src/classifier.ts): behavioral analytics · Deterministic labels and behavioral metrics. · `src/classifier.ts`
- [Analysis products](https://github.com/getagentseal/codeburn/blob/main/src/optimize.ts): insights · Comparison, optimization, yield, and context analysis. · `src/optimize.ts`
- **Transactional optimize actions**: local mutation · Backup, journal, apply, and undo optimized changes.

### Local Surfaces

- [Terminal dashboard](https://github.com/getagentseal/codeburn/blob/main/src/dashboard.tsx): TUI report · Default CLI surface. · `src/dashboard.tsx`
- [Reports & export](https://github.com/getagentseal/codeburn/blob/main/src/export.ts): CLI output · Overview, JSON/CSV export, and status views. · `src/export.ts`
- [Local web dashboard](https://github.com/getagentseal/codeburn/blob/main/src/web-dashboard.ts): localhost server · Serves the local browser dashboard. · `src/web-dashboard.ts`
- [MCP server](https://github.com/getagentseal/codeburn/blob/main/src/mcp/server.ts): stdio tools · Exposes local usage and savings with redaction. · `src/mcp/server.ts`
- [Electron desktop](https://github.com/getagentseal/codeburn/blob/main/app/electron/main.ts): desktop client · CLI/IPC bridge for the React desktop UI. · `app/electron/main.ts`
- [Ambient native clients](https://github.com/getagentseal/codeburn/blob/main/mac/Sources/CodeBurnMenubar/Data/DataClient.swift): menubar and tray clients · macOS menubar, Tauri tray, and GNOME extension consume local data. · `mac/Sources/CodeBurnMenubar/Data/DataClient.swift`
- [Claude guard hooks](https://github.com/getagentseal/codeburn/blob/main/src/guard/cli.ts): local controls · Fail-open hook installation and enforcement. · `src/guard/cli.ts`

### Optional Networked Features

- **LAN device sharing**: optional local network · Discovery, pairing, and sanitized transport.
- **Preview team sync**: optional remote sync · Consent-gated OIDC telemetry encoding and remote push.

## Connections

- Node CLI → Parse coordinator: runs pipeline
- Node CLI → Terminal dashboard: default command
- Node CLI → Reports & export: report commands
- Node CLI → Local web dashboard: web command
- Node CLI → MCP server: MCP command
- Node CLI → Claude guard hooks: installs controls
- Provider registry → Provider contracts: implements
- Local provider adapters → Provider registry: registered by
- Provider registry → Parse coordinator: discovers and parses
- Parse coordinator → Parse workers: dispatches
- Parse coordinator → Session cache: hydrates and caches
- Parse workers → Usage aggregation: normalized calls
- Session cache → Usage aggregation: cached sessions
- Usage aggregation → Models & pricing: usage totals
- Usage aggregation → Task classification: session behavior
- Models & pricing → Analysis products: priced model views
- Task classification → Analysis products: task metrics
- Analysis products → Transactional optimize actions: recommended changes
- Usage aggregation → Terminal dashboard: local reports
- Analysis products → Terminal dashboard: insights
- Usage aggregation → Reports & export: export data
- Analysis products → Local web dashboard: dashboard data
- Usage aggregation → MCP server: usage tools
- Node CLI → Electron desktop: invoked through bridge
- Node CLI → Ambient native clients: local data source
- Usage aggregation → LAN device sharing: sanitized usage
- Usage aggregation → Preview team sync: consented telemetry
