# ranjithrajv/opencode-usage-quota-tracker architecture

> Architecture diagram of the GitHub repository ranjithrajv/opencode-usage-quota-tracker, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ranjithrajv/opencode-usage-quota-tracker
- Repository: https://github.com/ranjithrajv/opencode-usage-quota-tracker

## Overview

This OpenCode plugin renders live usage and workspace quota in the TUI sidebar footer. Its workflow gathers credentials and session/provider state, fetches shared plan quota, then selects and renders a provider view; users can switch views through a picker or command, with the choice persisted. The main behavior is concentrated in tui.tsx; source excerpts show its polling, caching, session scans, and rendering, while README statements support the documented view-selection and integration capabilities.

Main entry points: [`tui.tsx`](https://github.com/ranjithrajv/opencode-usage-quota-tracker/blob/main/tui.tsx) (TUI plugin setup), [`src/index.ts`](https://github.com/ranjithrajv/opencode-usage-quota-tracker/blob/main/src/index.ts) (Server plugin entry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_integration["Host integration"]
  node_server_plugin["Server plugin entry<br/>[index.ts]"]
  node_tui_plugin["TUI plugin setup<br/>[tui.tsx]"]
end

subgraph group_collection["Usage collection"]
  node_auth_store[("OpenCode auth store")]
  node_session_data[("Session messages")]
  node_quota_api["Workspace usage API"]
  node_usage_fetch["Quota fetcher<br/>[tui.tsx]"]
  node_usage_cache[("Quota cache<br/>[tui.tsx]")]
  node_session_scan["Session usage scan<br/>[tui.tsx]"]
  node_provider_usage["Provider usage totals<br/>[tui.tsx]"]
end

subgraph group_footer["Footer experience"]
  node_provider_registry["Provider views<br/>[tui.tsx]"]
  node_connected_providers["Connected providers<br/>[tui.tsx]"]
  node_view_picker["View picker command<br/>[tui.tsx]"]
  node_view_preference[("Saved view choice<br/>[tui.tsx]")]
  node_view_selection["Automatic view selection<br/>[tui.tsx]"]
  node_row_builder["Usage row builder<br/>[tui.tsx]"]
  node_footer_renderer["Footer renderer<br/>[tui.tsx]"]
end

node_opencode(("OpenCode host"))
node_sidebar_footer["Sidebar footer"]

node_opencode -->|"loads plugin"| node_server_plugin
node_opencode -->|"loads TUI"| node_tui_plugin
node_tui_plugin -->|"reads credentials"| node_auth_store
node_tui_plugin -->|"reads messages"| node_session_data
node_tui_plugin -->|"starts polling"| node_usage_fetch
node_usage_fetch -->|"fetches quota"| node_quota_api
node_usage_fetch -->|"updates cache"| node_usage_cache
node_tui_plugin -->|"creates store"| node_usage_cache
node_tui_plugin -->|"checks integrations"| node_connected_providers
node_tui_plugin -->|"scans sessions"| node_session_scan
node_session_scan -->|"reads history"| node_session_data
node_session_scan -->|"derives totals"| node_provider_usage
node_tui_plugin -->|"registers command"| node_view_picker
node_view_picker -->|"persists choice"| node_view_preference
node_tui_plugin -->|"selects view"| node_view_selection
node_connected_providers -->|"limits choices"| node_view_selection
node_view_preference -->|"provides fallback"| node_view_selection
node_view_selection -->|"chooses provider"| node_provider_registry
node_provider_registry -->|"builds rows"| node_row_builder
node_row_builder -->|"supplies rows"| node_footer_renderer
node_usage_cache -->|"supplies quota"| node_row_builder
node_provider_usage -->|"supplies totals"| node_row_builder
node_footer_renderer -->|"renders footer"| node_sidebar_footer

click node_server_plugin "https://github.com/ranjithrajv/opencode-usage-quota-tracker/blob/main/src/index.ts"
click node_tui_plugin "https://github.com/ranjithrajv/opencode-usage-quota-tracker/blob/main/tui.tsx"
click node_usage_fetch "https://github.com/ranjithrajv/opencode-usage-quota-tracker/blob/main/tui.tsx"
click node_usage_cache "https://github.com/ranjithrajv/opencode-usage-quota-tracker/blob/main/tui.tsx"
click node_session_scan "https://github.com/ranjithrajv/opencode-usage-quota-tracker/blob/main/tui.tsx"
click node_provider_usage "https://github.com/ranjithrajv/opencode-usage-quota-tracker/blob/main/tui.tsx"
click node_provider_registry "https://github.com/ranjithrajv/opencode-usage-quota-tracker/blob/main/tui.tsx"
click node_connected_providers "https://github.com/ranjithrajv/opencode-usage-quota-tracker/blob/main/tui.tsx"
click node_view_picker "https://github.com/ranjithrajv/opencode-usage-quota-tracker/blob/main/tui.tsx"
click node_view_preference "https://github.com/ranjithrajv/opencode-usage-quota-tracker/blob/main/tui.tsx"
click node_view_selection "https://github.com/ranjithrajv/opencode-usage-quota-tracker/blob/main/tui.tsx"
click node_row_builder "https://github.com/ranjithrajv/opencode-usage-quota-tracker/blob/main/tui.tsx"
click node_footer_renderer "https://github.com/ranjithrajv/opencode-usage-quota-tracker/blob/main/tui.tsx"

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_server_plugin,node_tui_plugin toneBlue
class node_auth_store,node_session_data,node_quota_api,node_usage_fetch,node_usage_cache,node_session_scan,node_provider_usage toneAmber
class node_provider_registry,node_connected_providers,node_view_picker,node_view_preference,node_view_selection,node_row_builder,node_footer_renderer toneMint
class node_opencode,node_sidebar_footer toneIndigo
```

## Components

### Host integration

- [Server plugin entry](https://github.com/ranjithrajv/opencode-usage-quota-tracker/blob/main/src/index.ts): `src/index.ts`
- [TUI plugin setup](https://github.com/ranjithrajv/opencode-usage-quota-tracker/blob/main/tui.tsx): `tui.tsx`

### Usage collection

- **OpenCode auth store**
- **Session messages**
- **Workspace usage API**
- [Quota fetcher](https://github.com/ranjithrajv/opencode-usage-quota-tracker/blob/main/tui.tsx): `tui.tsx`
- [Quota cache](https://github.com/ranjithrajv/opencode-usage-quota-tracker/blob/main/tui.tsx): `tui.tsx`
- [Session usage scan](https://github.com/ranjithrajv/opencode-usage-quota-tracker/blob/main/tui.tsx): `tui.tsx`
- [Provider usage totals](https://github.com/ranjithrajv/opencode-usage-quota-tracker/blob/main/tui.tsx): `tui.tsx`

### Footer experience

- [Provider views](https://github.com/ranjithrajv/opencode-usage-quota-tracker/blob/main/tui.tsx): `tui.tsx`
- [Connected providers](https://github.com/ranjithrajv/opencode-usage-quota-tracker/blob/main/tui.tsx): `tui.tsx`
- [View picker command](https://github.com/ranjithrajv/opencode-usage-quota-tracker/blob/main/tui.tsx): `tui.tsx`
- [Saved view choice](https://github.com/ranjithrajv/opencode-usage-quota-tracker/blob/main/tui.tsx): `tui.tsx`
- [Automatic view selection](https://github.com/ranjithrajv/opencode-usage-quota-tracker/blob/main/tui.tsx): `tui.tsx`
- [Usage row builder](https://github.com/ranjithrajv/opencode-usage-quota-tracker/blob/main/tui.tsx): `tui.tsx`
- [Footer renderer](https://github.com/ranjithrajv/opencode-usage-quota-tracker/blob/main/tui.tsx): `tui.tsx`

### Other components

- **OpenCode host**
- **Sidebar footer**

## Connections

- OpenCode host → Server plugin entry: loads plugin (evidence: `README.md`)
- OpenCode host → TUI plugin setup: loads TUI (evidence: `README.md`)
- TUI plugin setup → OpenCode auth store: reads credentials (evidence: `tui.tsx`)
- TUI plugin setup → Session messages: reads messages (evidence: `tui.tsx`)
- TUI plugin setup → Quota fetcher: starts polling (evidence: `tui.tsx`)
- Quota fetcher → Workspace usage API: fetches quota (evidence: `README.md`)
- Quota fetcher → Quota cache: updates cache (evidence: `tui.tsx`)
- TUI plugin setup → Quota cache: creates store (evidence: `tui.tsx`)
- TUI plugin setup → Connected providers: checks integrations (evidence: `tui.tsx`)
- TUI plugin setup → Session usage scan: scans sessions (evidence: `tui.tsx`)
- Session usage scan → Session messages: reads history (evidence: `tui.tsx`)
- Session usage scan → Provider usage totals: derives totals (evidence: `tui.tsx`)
- TUI plugin setup → View picker command: registers command (evidence: `tui.tsx`)
- View picker command → Saved view choice: persists choice (evidence: `README.md`)
- TUI plugin setup → Automatic view selection: selects view (evidence: `README.md`)
- Connected providers → Automatic view selection: limits choices (evidence: `README.md`)
- Saved view choice → Automatic view selection: provides fallback (evidence: `README.md`)
- Automatic view selection → Provider views: chooses provider (evidence: `README.md`)
- Provider views → Usage row builder: builds rows (evidence: `README.md`)
- Usage row builder → Footer renderer: supplies rows (evidence: `tui.tsx`)
- Quota cache → Usage row builder: supplies quota (evidence: `tui.tsx`)
- Provider usage totals → Usage row builder: supplies totals (evidence: `tui.tsx`)
- Footer renderer → Sidebar footer: renders footer (evidence: `README.md`)
