# opencost/opencost-ui architecture

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

- Interactive diagram: https://gitdiagram.com/opencost/opencost-ui
- Repository: https://github.com/opencost/opencost-ui

## Overview

OpenCost UI presents Kubernetes and cloud cost information, with allocation analysis as a representative user workflow: request allocation data, retrieve it from the OpenCost API, then summarize and visualize costs. The tree also exposes newer dashboard/report workflows and legacy allocation, cloud-cost, and external-cost views, plus settings. The excerpts directly verify allocation fetching and selected chart/helper relationships; other feature ownership is identifiable from route/component paths, but their internal calls were not sampled, so those links are omitted rather than inferred.

Main entry points: [`app/root.tsx`](https://github.com/opencost/opencost-ui/blob/main/app/root.tsx) (App shell), [`app/routes/legacy/allocation.tsx`](https://github.com/opencost/opencost-ui/blob/main/app/routes/legacy/allocation.tsx) (Allocation route), [`app/services/allocation.ts`](https://github.com/opencost/opencost-ui/blob/main/app/services/allocation.ts) (Allocation service), [`app/components/external-services-chart-widget.tsx`](https://github.com/opencost/opencost-ui/blob/main/app/components/external-services-chart-widget.tsx) (External services chart)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Application Shell"]
  node_shell["App shell<br/>[root.tsx]"]
  node_legacy_nav["Legacy navigation<br/>[Page.jsx]"]
  node_settings["Settings<br/>[settings.tsx]"]
end

subgraph group_allocation["Allocation Analysis"]
  node_alloc_route["Allocation route<br/>[allocation.tsx]"]
  node_alloc_service["Allocation service<br/>[allocation.ts]"]
  node_api_client["API client<br/>[api-client.ts]"]
  node_allocation_charts["Allocation charts<br/>[index.jsx]"]
  node_allocation_chart_views["Range and summary charts<br/>[RangeChart.jsx]"]
  node_legacy_util["Cost utilities<br/>[legacy-util.ts]"]
end

subgraph group_costs["Cost Views"]
  node_cloud_route["Cloud cost route<br/>[cloud.tsx]"]
  node_cloud_details["Cloud cost details"]
  node_cloud_service["Cloud cost service<br/>[cloud-cost.ts]"]
  node_external_route["External costs route<br/>[external-costs.tsx]"]
  node_external_chart["External services chart"]
  node_external_service["External costs service<br/>[external-costs.ts]"]
end

subgraph group_dashboards["Dashboards And Reports"]
  node_dashboard_routes["Dashboard routes<br/>[dashboard-list.tsx]"]
  node_dashboard_builder["Dashboard builder"]
  node_dashboard_view["Dashboard view<br/>[dashboard-view.tsx]"]
  node_report_routes["Report routes<br/>[report-builder.tsx]"]
  node_report_query["Report query<br/>[report-query.ts]"]
  node_report_results["Report results"]
end

node_user(("Cost analyst"))
node_opencost_api{{"OpenCost API"}}

node_user -->|"opens UI"| node_shell
node_shell -.->|"routes to"| node_alloc_route
node_shell -.->|"routes to"| node_dashboard_routes
node_shell -.->|"routes to"| node_report_routes
node_alloc_route -.->|"requests data"| node_alloc_service
node_alloc_service -->|"calls"| node_api_client
node_alloc_service -->|"fetches allocations"| node_opencost_api
node_alloc_route -.->|"renders"| node_allocation_charts
node_allocation_charts -->|"selects chart"| node_allocation_chart_views
node_allocation_chart_views -->|"formats costs"| node_legacy_util
node_cloud_route -.->|"shows details"| node_cloud_details
node_cloud_details -->|"fetches totals"| node_cloud_service
node_external_route -.->|"renders"| node_external_chart
node_external_chart -->|"fetches costs"| node_external_service
node_external_chart -->|"formats currency"| node_legacy_util
node_dashboard_routes -.->|"builds dashboards"| node_dashboard_builder
node_dashboard_routes -.->|"displays dashboards"| node_dashboard_view
node_report_routes -.->|"queries reports"| node_report_query
node_report_routes -.->|"shows results"| node_report_results

click node_shell "https://github.com/opencost/opencost-ui/blob/main/app/root.tsx"
click node_legacy_nav "https://github.com/opencost/opencost-ui/blob/main/app/components/legacy/Page.jsx"
click node_settings "https://github.com/opencost/opencost-ui/blob/main/app/routes/settings.tsx"
click node_alloc_route "https://github.com/opencost/opencost-ui/blob/main/app/routes/legacy/allocation.tsx"
click node_alloc_service "https://github.com/opencost/opencost-ui/blob/main/app/services/allocation.ts"
click node_api_client "https://github.com/opencost/opencost-ui/blob/main/app/services/api-client.ts"
click node_allocation_charts "https://github.com/opencost/opencost-ui/blob/main/app/components/legacy/AllocationChart/index.jsx"
click node_allocation_chart_views "https://github.com/opencost/opencost-ui/blob/main/app/components/legacy/AllocationChart/RangeChart.jsx"
click node_legacy_util "https://github.com/opencost/opencost-ui/blob/main/app/lib/legacy-util.ts"
click node_cloud_route "https://github.com/opencost/opencost-ui/blob/main/app/routes/legacy/cloud.tsx"
click node_cloud_details "https://github.com/opencost/opencost-ui/blob/main/app/components/legacy/cloudCost/cloudCostDetails.jsx"
click node_cloud_service "https://github.com/opencost/opencost-ui/blob/main/app/services/cloud-cost.ts"
click node_external_route "https://github.com/opencost/opencost-ui/blob/main/app/routes/legacy/external-costs.tsx"
click node_external_chart "https://github.com/opencost/opencost-ui/blob/main/app/components/external-services-chart-widget.tsx"
click node_external_service "https://github.com/opencost/opencost-ui/blob/main/app/services/external-costs.ts"
click node_dashboard_routes "https://github.com/opencost/opencost-ui/blob/main/app/routes/dashboard-list.tsx"
click node_dashboard_builder "https://github.com/opencost/opencost-ui/blob/main/app/components/dashboard-builder.tsx"
click node_dashboard_view "https://github.com/opencost/opencost-ui/blob/main/app/components/dashboard-view.tsx"
click node_report_routes "https://github.com/opencost/opencost-ui/blob/main/app/routes/report-builder.tsx"
click node_report_query "https://github.com/opencost/opencost-ui/blob/main/app/services/report-query.ts"
click node_report_results "https://github.com/opencost/opencost-ui/blob/main/app/components/report-results-view.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_shell,node_legacy_nav,node_settings toneBlue
class node_alloc_route,node_alloc_service,node_api_client,node_allocation_charts,node_allocation_chart_views,node_legacy_util toneAmber
class node_cloud_route,node_cloud_details,node_cloud_service,node_external_route,node_external_chart,node_external_service,node_opencost_api toneMint
class node_dashboard_routes,node_dashboard_builder,node_dashboard_view,node_report_routes,node_report_query,node_report_results toneRose
class node_user toneIndigo
```

## Components

### Application Shell

- [App shell](https://github.com/opencost/opencost-ui/blob/main/app/root.tsx): `app/root.tsx`
- [Legacy navigation](https://github.com/opencost/opencost-ui/blob/main/app/components/legacy/Page.jsx): `app/components/legacy/Page.jsx`
- [Settings](https://github.com/opencost/opencost-ui/blob/main/app/routes/settings.tsx): `app/routes/settings.tsx`

### Allocation Analysis

- [Allocation route](https://github.com/opencost/opencost-ui/blob/main/app/routes/legacy/allocation.tsx): `app/routes/legacy/allocation.tsx`
- [Allocation service](https://github.com/opencost/opencost-ui/blob/main/app/services/allocation.ts): `app/services/allocation.ts`
- [API client](https://github.com/opencost/opencost-ui/blob/main/app/services/api-client.ts): `app/services/api-client.ts`
- [Allocation charts](https://github.com/opencost/opencost-ui/blob/main/app/components/legacy/AllocationChart/index.jsx): `app/components/legacy/AllocationChart/index.jsx`
- [Range and summary charts](https://github.com/opencost/opencost-ui/blob/main/app/components/legacy/AllocationChart/RangeChart.jsx): `app/components/legacy/AllocationChart/RangeChart.jsx`
- [Cost utilities](https://github.com/opencost/opencost-ui/blob/main/app/lib/legacy-util.ts): `app/lib/legacy-util.ts`

### Cost Views

- [Cloud cost route](https://github.com/opencost/opencost-ui/blob/main/app/routes/legacy/cloud.tsx): `app/routes/legacy/cloud.tsx`
- [Cloud cost details](https://github.com/opencost/opencost-ui/blob/main/app/components/legacy/cloudCost/cloudCostDetails.jsx): `app/components/legacy/cloudCost/cloudCostDetails.jsx`
- [Cloud cost service](https://github.com/opencost/opencost-ui/blob/main/app/services/cloud-cost.ts): `app/services/cloud-cost.ts`
- [External costs route](https://github.com/opencost/opencost-ui/blob/main/app/routes/legacy/external-costs.tsx): `app/routes/legacy/external-costs.tsx`
- [External services chart](https://github.com/opencost/opencost-ui/blob/main/app/components/external-services-chart-widget.tsx): `app/components/external-services-chart-widget.tsx`
- [External costs service](https://github.com/opencost/opencost-ui/blob/main/app/services/external-costs.ts): `app/services/external-costs.ts`

### Dashboards And Reports

- [Dashboard routes](https://github.com/opencost/opencost-ui/blob/main/app/routes/dashboard-list.tsx): `app/routes/dashboard-list.tsx`
- [Dashboard builder](https://github.com/opencost/opencost-ui/blob/main/app/components/dashboard-builder.tsx): `app/components/dashboard-builder.tsx`
- [Dashboard view](https://github.com/opencost/opencost-ui/blob/main/app/components/dashboard-view.tsx): `app/components/dashboard-view.tsx`
- [Report routes](https://github.com/opencost/opencost-ui/blob/main/app/routes/report-builder.tsx): `app/routes/report-builder.tsx`
- [Report query](https://github.com/opencost/opencost-ui/blob/main/app/services/report-query.ts): `app/services/report-query.ts`
- [Report results](https://github.com/opencost/opencost-ui/blob/main/app/components/report-results-view.tsx): `app/components/report-results-view.tsx`

### Other components

- **Cost analyst**
- **OpenCost API**

## Connections

- Cost analyst → App shell: opens UI (evidence: `README.md`)
- App shell → Allocation route: routes to
- App shell → Dashboard routes: routes to
- App shell → Report routes: routes to
- Allocation route → Allocation service: requests data
- Allocation service → API client: calls (evidence: `app/services/allocation.ts`)
- Allocation service → OpenCost API: fetches allocations (evidence: `app/services/allocation.ts`)
- Allocation route → Allocation charts: renders
- Allocation charts → Range and summary charts: selects chart (evidence: `app/components/legacy/AllocationChart/index.jsx`)
- Range and summary charts → Cost utilities: formats costs (evidence: `app/components/legacy/AllocationChart/RangeChart.jsx`)
- Cloud cost route → Cloud cost details: shows details
- Cloud cost details → Cloud cost service: fetches totals (evidence: `app/components/legacy/cloudCost/cloudCostDetails.jsx`)
- External costs route → External services chart: renders
- External services chart → External costs service: fetches costs (evidence: `app/components/external-services-chart-widget.tsx`)
- External services chart → Cost utilities: formats currency (evidence: `app/components/external-services-chart-widget.tsx`)
- Dashboard routes → Dashboard builder: builds dashboards
- Dashboard routes → Dashboard view: displays dashboards
- Report routes → Report query: queries reports
- Report routes → Report results: shows results
