# agentseal/codeburn architecture

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

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

## Overview

1. **What this repository is**
   - CodeBurn is a Node.js 20+ TypeScript CLI that reads local AI coding tool data from disk and turns it into cost/usage analytics.
   - It is not an API server or wrapper around the tools; it is a read-only offline analyzer.

2. **Core data flow**
   - The app starts from the CLI, selects a command and provider scope, discovers session files/databases on the local machine, parses them into a common internal event model, enriches them with pricing and currency, classifies activity, then renders one of several outputs: TUI dashboard, status line, export file, or menu bar plugin.

3. **Provider boundary**
   - The main architectural seam is the provider system in `src/providers/`.
   - Each provider adapts one AI tool’s storage format into a shared interface: session discovery, parsing, tool normalization, and display names.
   - Supported providers are Claude Code, Codex, Cursor, OpenCode, and Pi; Cursor and OpenCode are lazily loaded because they need SQLite support.

4. **Parsing and normalization layer**
   - `src/parser.ts` orchestrates reading session data, deduping messages, filtering by date range, and merging provider-specific records into a unified view.
   - This is where provider differences are hidden from the rest of the app, so downstream code works with one normalized event stream.
   - The parser also applies provider-specific deduplication strategies because each tool records sessions differently.

5. **Cost and model enrichment**
   - `src/models.ts` calculates costs using LiteLLM pricing data and handles token categories like input, output, cache read/write, and search-related costs.
   - `src/currency.ts` converts USD pricing into the selected ISO currency and fetches exchange rates from Frankfurter, with local caching.
   - `src/config.ts` stores the user’s currency preference under `~/.config/codeburn/`, while price/rate caches live under `~/.cache/codeburn/`.

6. **Activity classification**
   - `src/classifier.ts` maps each turn into one of 13 task categories using deterministic rules over tool usage patterns and user text keywords.
   - This subsystem feeds the “one-shot” success analysis and the breakdown panels, so it is central to the product’s interpretation layer.
   - The classifier depends on normalized tool names coming from providers, especially where tools differ across vendors.

7. **Output surfaces**
   - `src/dashboard.tsx` is the interactive terminal UI built with Ink/React for terminal rendering.
   - `src/format.ts` provides compact text formatting for status output.
   - `src/export.ts` generates CSV/JSON exports across multiple time windows.
   - `src/menubar.ts` generates a SwiftBar/xbar plugin for macOS menu bar display.

8. **Storage and caching boundaries**
   - The app is intentionally read-only against source data, but it does maintain its own caches.
   - `src/cursor-cache.ts` stores parsed Cursor results in a file cache and invalidates them when the underlying database changes.
   - `src/sqlite.ts` is a lazy adapter around `better-sqlite3`, keeping SQLite-specific work isolated to providers that need it.

9. **Command-line and runtime structure**
   - `src/cli.ts` is the Commander.js entry point and routes commands such as report, today, month, status, export, currency, and menubar install/uninstall.
   - The CLI is the orchestration layer; it does not do parsing or rendering itself, it delegates to the domain modules above.
   - Tests cover the command surface, provider registry, exports, dashboard behavior, and provider parsers.

10. **Provider registry and extensibility**
   - `src/providers/index.ts` and `src/providers/types.ts` define the plugin contract and registry behavior.
   - This is the primary extension boundary: adding a new AI tool generally means implementing one provider module without changing the rest of the system.
   - The README’s “single file provider” claim is reflected in this architecture.

11. **Platform-specific data access**
   - The repo mixes JSONL file ingestion and SQLite database reads depending on provider.
   - Claude, Codex, and Pi are file-based; Cursor and OpenCode require database access; Cursor additionally relies on extracted language/code block data rather than per-tool logs.
   - This affects both data discovery paths and the shape of the displayed breakdowns.

12. **External dependencies that materially affect architecture**
   - LiteLLM pricing data drives all cost calculations, and Frankfurter drives currency conversion.
   - `better-sqlite3` is an optional dependency that only becomes relevant for SQLite-backed providers.
   - SwiftBar/xbar is the only external UI integration outside the terminal.

13. **How to diagram it**
   - A useful architecture diagram would show: local AI tool data sources on disk on the left, provider adapters in the middle, a shared parse/classify/pricing core above them, and four output channels on the right: TUI dashboard, CLI/status text, export files, and SwiftBar menu bar plugin.

Main entry points: [`src/parser.ts`](https://github.com/agentseal/codeburn/blob/main/src/parser.ts) (Parser), [`src/cli.ts`](https://github.com/agentseal/codeburn/blob/main/src/cli.ts) (CLI), [`src/providers/index.ts`](https://github.com/agentseal/codeburn/blob/main/src/providers/index.ts) (Provider registry), [`src/models.ts`](https://github.com/agentseal/codeburn/blob/main/src/models.ts) (Cost model)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["CLI runtime"]
  node_src_cli["CLI<br/>entrypoint<br/>[cli.ts]"]
end

subgraph group_providers["Provider layer"]
  node_src_provider_index["Provider registry<br/>[index.ts]"]
  node_src_provider_types["Provider types<br/>contract<br/>[types.ts]"]
  node_src_provider_claude["Claude<br/>file provider<br/>[claude.ts]"]
  node_src_provider_codex["Codex<br/>file provider<br/>[codex.ts]"]
  node_src_provider_copilot["Copilot<br/>file provider<br/>[copilot.ts]"]
  node_src_provider_cursor["Cursor<br/>sqlite provider<br/>[cursor.ts]"]
  node_src_provider_opencode["OpenCode<br/>sqlite provider<br/>[opencode.ts]"]
  node_src_provider_pi["Pi<br/>file provider<br/>[pi.ts]"]
end

subgraph group_core["Analysis core"]
  node_src_parser["Parser<br/>normalizer<br/>[parser.ts]"]
  node_src_classifier["Classifier<br/>activity model<br/>[classifier.ts]"]
  node_src_models["Cost model<br/>pricing<br/>[models.ts]"]
  node_src_currency["Currency<br/>exchange<br/>[currency.ts]"]
  node_src_config["Config<br/>preferences<br/>[config.ts]"]
  node_src_cursor_cache[("Cursor cache<br/>[cursor-cache.ts]")]
  node_src_sqlite["SQLite adapter<br/>lazy adapter<br/>[sqlite.ts]"]
end

subgraph group_outputs["Outputs"]
  node_src_dashboard["Dashboard<br/>tui<br/>[dashboard.tsx]"]
  node_src_format["Status text<br/>formatter<br/>[format.ts]"]
  node_src_export["Export<br/>[export.ts]"]
  node_src_menubar["Menubar<br/>plugin<br/>[menubar.ts]"]
end

node_src_cli -->|"select provider"| node_src_provider_index
node_src_cli -->|"run analysis"| node_src_parser
node_src_cli -->|"classify"| node_src_classifier
node_src_cli -->|"open tui"| node_src_dashboard
node_src_cli -->|"status output"| node_src_format
node_src_cli -->|"export data"| node_src_export
node_src_cli -->|"build plugin"| node_src_menubar
node_src_cli -->|"set currency"| node_src_currency
node_src_provider_index -->|"implements"| node_src_provider_types
node_src_provider_index -->|"loads"| node_src_provider_claude
node_src_provider_index -->|"loads"| node_src_provider_codex
node_src_provider_index -->|"loads"| node_src_provider_copilot
node_src_provider_index -->|"loads"| node_src_provider_cursor
node_src_provider_index -->|"loads"| node_src_provider_opencode
node_src_provider_index -->|"loads"| node_src_provider_pi
node_src_parser -->|"uses contract"| node_src_provider_types
node_src_parser -->|"reads"| node_src_provider_claude
node_src_parser -->|"reads"| node_src_provider_codex
node_src_parser -->|"reads"| node_src_provider_copilot
node_src_parser -->|"reads"| node_src_provider_cursor
node_src_parser -->|"reads"| node_src_provider_opencode
node_src_parser -->|"reads"| node_src_provider_pi
node_src_parser -->|"feeds turns"| node_src_classifier
node_src_parser -->|"feeds usage"| node_src_models
node_src_models -->|"convert currency"| node_src_currency
node_src_currency -->|"reads prefs"| node_src_config
node_src_provider_cursor -->|"cache parsed data"| node_src_cursor_cache
node_src_provider_cursor -->|"query db"| node_src_sqlite
node_src_provider_opencode -->|"query db"| node_src_sqlite
node_src_dashboard -->|"breakdowns"| node_src_classifier
node_src_dashboard -->|"cost views"| node_src_models
node_src_format -->|"summarize"| node_src_models
node_src_export -->|"consume data"| node_src_parser
node_src_export -->|"include costs"| node_src_models
node_src_menubar -->|"reuse text"| node_src_format

click node_src_cli "https://github.com/agentseal/codeburn/blob/main/src/cli.ts"
click node_src_provider_index "https://github.com/agentseal/codeburn/blob/main/src/providers/index.ts"
click node_src_provider_types "https://github.com/agentseal/codeburn/blob/main/src/providers/types.ts"
click node_src_provider_claude "https://github.com/agentseal/codeburn/blob/main/src/providers/claude.ts"
click node_src_provider_codex "https://github.com/agentseal/codeburn/blob/main/src/providers/codex.ts"
click node_src_provider_copilot "https://github.com/agentseal/codeburn/blob/main/src/providers/copilot.ts"
click node_src_provider_cursor "https://github.com/agentseal/codeburn/blob/main/src/providers/cursor.ts"
click node_src_provider_opencode "https://github.com/agentseal/codeburn/blob/main/src/providers/opencode.ts"
click node_src_provider_pi "https://github.com/agentseal/codeburn/blob/main/src/providers/pi.ts"
click node_src_parser "https://github.com/agentseal/codeburn/blob/main/src/parser.ts"
click node_src_classifier "https://github.com/agentseal/codeburn/blob/main/src/classifier.ts"
click node_src_models "https://github.com/agentseal/codeburn/blob/main/src/models.ts"
click node_src_currency "https://github.com/agentseal/codeburn/blob/main/src/currency.ts"
click node_src_config "https://github.com/agentseal/codeburn/blob/main/src/config.ts"
click node_src_dashboard "https://github.com/agentseal/codeburn/blob/main/src/dashboard.tsx"
click node_src_format "https://github.com/agentseal/codeburn/blob/main/src/format.ts"
click node_src_export "https://github.com/agentseal/codeburn/blob/main/src/export.ts"
click node_src_menubar "https://github.com/agentseal/codeburn/blob/main/src/menubar.ts"
click node_src_cursor_cache "https://github.com/agentseal/codeburn/blob/main/src/cursor-cache.ts"
click node_src_sqlite "https://github.com/agentseal/codeburn/blob/main/src/sqlite.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_src_cli toneBlue
class node_src_provider_index,node_src_provider_types,node_src_provider_claude,node_src_provider_codex,node_src_provider_copilot,node_src_provider_cursor,node_src_provider_opencode,node_src_provider_pi toneAmber
class node_src_parser,node_src_classifier,node_src_models,node_src_currency,node_src_config,node_src_cursor_cache,node_src_sqlite toneMint
class node_src_dashboard,node_src_format,node_src_export,node_src_menubar toneRose
```

## Components

### CLI runtime

Command entrypoints and orchestration

- [CLI](https://github.com/agentseal/codeburn/blob/main/src/cli.ts): entrypoint · Commander.js entrypoint that routes commands and orchestrates the app · `src/cli.ts`

### Provider layer

Adapters for each AI tool storage format

- [Provider registry](https://github.com/agentseal/codeburn/blob/main/src/providers/index.ts): registry · Selects and loads provider implementations · `src/providers/index.ts`
- [Provider types](https://github.com/agentseal/codeburn/blob/main/src/providers/types.ts): contract · Shared provider interface and extension boundary · `src/providers/types.ts`
- [Claude](https://github.com/agentseal/codeburn/blob/main/src/providers/claude.ts): file provider · Reads Claude Code session data from local files · `src/providers/claude.ts`
- [Codex](https://github.com/agentseal/codeburn/blob/main/src/providers/codex.ts): file provider · Reads Codex session data from local files · `src/providers/codex.ts`
- [Copilot](https://github.com/agentseal/codeburn/blob/main/src/providers/copilot.ts): file provider · Reads Copilot session data from local files · `src/providers/copilot.ts`
- [Cursor](https://github.com/agentseal/codeburn/blob/main/src/providers/cursor.ts): sqlite provider · Loads Cursor data through SQLite-backed discovery and caching · `src/providers/cursor.ts`
- [OpenCode](https://github.com/agentseal/codeburn/blob/main/src/providers/opencode.ts): sqlite provider · Loads OpenCode data from SQLite-backed storage · `src/providers/opencode.ts`
- [Pi](https://github.com/agentseal/codeburn/blob/main/src/providers/pi.ts): file provider · Reads Pi session data from local files · `src/providers/pi.ts`

### Analysis core

Parsing, normalization, pricing, classification, and config

- [Parser](https://github.com/agentseal/codeburn/blob/main/src/parser.ts): normalizer · Discovers sessions, dedupes messages, merges provider records, and filters by date range · `src/parser.ts`
- [Classifier](https://github.com/agentseal/codeburn/blob/main/src/classifier.ts): activity model · Maps turns into task categories using tool patterns and user text · `src/classifier.ts`
- [Cost model](https://github.com/agentseal/codeburn/blob/main/src/models.ts): pricing · Calculates token costs from pricing data and model metadata · `src/models.ts`
- [Currency](https://github.com/agentseal/codeburn/blob/main/src/currency.ts): exchange · Converts USD pricing into the selected currency and fetches exchange rates · `src/currency.ts`
- [Config](https://github.com/agentseal/codeburn/blob/main/src/config.ts): preferences · Stores user currency preferences and cache locations · `src/config.ts`
- [Cursor cache](https://github.com/agentseal/codeburn/blob/main/src/cursor-cache.ts): cache · Caches parsed Cursor results and invalidates on database changes · `src/cursor-cache.ts`
- [SQLite adapter](https://github.com/agentseal/codeburn/blob/main/src/sqlite.ts): lazy adapter · Isolates better-sqlite3 access for SQLite-backed providers · `src/sqlite.ts`

### Outputs

Terminal, export, and menu bar renderers

- [Dashboard](https://github.com/agentseal/codeburn/blob/main/src/dashboard.tsx): tui · Interactive terminal dashboard built with Ink/React · `src/dashboard.tsx`
- [Status text](https://github.com/agentseal/codeburn/blob/main/src/format.ts): formatter · Produces compact text output for status surfaces · `src/format.ts`
- [Export](https://github.com/agentseal/codeburn/blob/main/src/export.ts): exporter · Generates CSV and JSON exports across time windows · `src/export.ts`
- [Menubar](https://github.com/agentseal/codeburn/blob/main/src/menubar.ts): plugin · Builds a SwiftBar/xbar macOS menu bar plugin · `src/menubar.ts`

## Connections

- CLI → Provider registry: select provider · CLI resolves provider scope through the registry
- CLI → Parser: run analysis · CLI delegates parsing and normalization to the core parser
- CLI → Classifier: classify · Command flows require activity classification
- CLI → Dashboard: open tui · Interactive report command renders the terminal dashboard
- CLI → Status text: status output · Status commands use compact text formatting
- CLI → Export: export data · Export commands produce files from normalized data
- CLI → Menubar: build plugin · Menubar commands generate the macOS plugin
- CLI → Currency: set currency · Currency commands update preferences used by pricing
- Provider registry → Provider types: implements · Registry is defined by the shared provider contract
- Provider registry → Claude: loads · Registry exposes Claude support
- Provider registry → Codex: loads · Registry exposes Codex support
- Provider registry → Copilot: loads · Registry exposes Copilot support
- Provider registry → Cursor: loads · Registry exposes Cursor support
- Provider registry → OpenCode: loads · Registry exposes OpenCode support
- Provider registry → Pi: loads · Registry exposes Pi support
- Parser → Provider types: uses contract · Parser works against the normalized provider interface
- Parser → Claude: reads · Parses Claude session data
- Parser → Codex: reads · Parses Codex session data
- Parser → Copilot: reads · Parses Copilot session data
- Parser → Cursor: reads · Parses Cursor session data
- Parser → OpenCode: reads · Parses OpenCode session data
- Parser → Pi: reads · Parses Pi session data
- Parser → Classifier: feeds turns · Normalized turns are classified into task categories
- Parser → Cost model: feeds usage · Parsed usage data is priced into costs
- Cost model → Currency: convert currency · Cost calculations are converted from USD to the selected currency
- Currency → Config: reads prefs · Currency selection comes from stored configuration
- Cursor → Cursor cache: cache parsed data · Cursor provider persists parsed results in a local cache
- Cursor → SQLite adapter: query db · Cursor provider uses the lazy SQLite adapter
- OpenCode → SQLite adapter: query db · OpenCode provider uses the lazy SQLite adapter
- Dashboard → Classifier: breakdowns · Dashboard presents classified activity and one-shot analysis
- Dashboard → Cost model: cost views · Dashboard shows cost and token summaries
- Status text → Cost model: summarize · Status text is derived from cost and usage totals
- Export → Parser: consume data · Exports are generated from normalized session data
- Export → Cost model: include costs · Exports include priced usage summaries
- Menubar → Status text: reuse text · Menu bar output reuses compact formatting rules
