# abhinavdatta/punarva architecture

> Architecture diagram of the GitHub repository abhinavdatta/punarva, 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/abhinavdatta/punarva
- Repository: https://github.com/abhinavdatta/punarva

## Overview

PUNARVA is a browser-based battery diagnostics and firmware-tooling prototype. The main workflow runs from a routed Battery Check screen through pre-checks and timed sampling to a stored test record, then to reports, charts, comparison, and CSV export; readings can come from demo sampling or validated device transports. Other documented branches cover history/import, device settings, interactive technology views, and firmware compilation/flashing. Some page and service relationships rely on the README or SOURCE INDEX; unsampled details are not inferred.

Main entry points: [`src/App.tsx`](https://github.com/abhinavdatta/punarva/blob/main/src/App.tsx) (Route shell), [`src/state/testEngine.ts`](https://github.com/abhinavdatta/punarva/blob/main/src/state/testEngine.ts) (Test engine), [`src/components/results/ResultsReport.tsx`](https://github.com/abhinavdatta/punarva/blob/main/src/components/results/ResultsReport.tsx) (Report and comparison), [`src/state/deviceStore.ts`](https://github.com/abhinavdatta/punarva/blob/main/src/state/deviceStore.ts) (Device connection)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workflow["Diagnostics workflow"]
  node_battery_check["Battery Check"]
  node_test_engine["Test engine<br/>[testEngine.ts]"]
  node_test_store["Test state<br/>[testStore.ts]"]
  node_demo_sampler["Demo sampler<br/>[sampler.ts]"]
  node_charts["Time-series charts"]
end

subgraph group_device["Device and firmware"]
  node_device_store["Device connection<br/>[deviceStore.ts]"]
  node_validation["Reading validation<br/>[validation.ts]"]
  node_serial["Web Serial<br/>[transports.ts]"]
  node_websocket["WebSocket bridge"]
  node_flash_page["Firmware flashing<br/>[FlashPage.tsx]"]
  node_flash_store["Flash state<br/>[flashStore.ts]"]
  node_flasher["ESP32 flasher<br/>[flasher.ts]"]
  node_compile["Firmware compiler client<br/>[firmwareCompile.ts]"]
end

subgraph group_records["Reports and history"]
  node_history_page["Test history<br/>[HistoryPage.tsx]"]
  node_history_store["History state<br/>[historyStore.ts]"]
  node_results_page["Test report route<br/>[ResultsPage.tsx]"]
  node_results_report["Report and comparison<br/>[ResultsReport.tsx]"]
  node_csv_export["CSV export<br/>[exportCsv.ts]"]
  node_csv_import["CSV import<br/>[importCsv.ts]"]
end

subgraph group_product["Product experience"]
  node_app["Route shell<br/>[App.tsx]"]
  node_overview["Overview dashboard<br/>[OverviewPage.tsx]"]
  node_technology["Technology view<br/>[TechnologyPage.tsx]"]
  node_settings["Settings<br/>[SettingsPage.tsx]"]
  node_scene["3D product scene"]
end

subgraph group_shared["Shared state and services"]
  node_storage[("Safe storage<br/>[safeStorage.ts]")]
  node_calibration["Calibration service<br/>[calibration.ts]"]
  node_calibration_store["Calibration state"]
end

node_user(("User"))
node_browser(("Browser device APIs"))
node_compile_bridge(("Local compile bridge"))

node_user -->|"opens"| node_app
node_app -->|"routes to"| node_battery_check
node_app -->|"routes to"| node_results_page
node_app -->|"routes to"| node_history_page
node_app -->|"routes to"| node_flash_page
node_app -->|"routes to"| node_overview
node_app -->|"routes to"| node_technology
node_app -->|"routes to"| node_settings
node_battery_check -->|"starts test"| node_test_engine
node_battery_check -->|"reads state"| node_test_store
node_test_engine -->|"updates phases"| node_test_store
node_test_engine -->|"samples demo"| node_demo_sampler
node_test_engine -->|"reads readings"| node_device_store
node_test_engine -->|"adds record"| node_history_store
node_device_store -->|"validates payloads"| node_validation
node_device_store -->|"connects transport"| node_serial
node_device_store -->|"connects transport"| node_websocket
node_serial -.->|"uses serial API"| node_browser
node_websocket -.->|"opens socket"| node_browser
node_flash_page -->|"controls flashing"| node_flash_store
node_flash_page -->|"compiles source"| node_compile
node_flash_store -.->|"runs flasher"| node_flasher
node_compile -.->|"requests compile"| node_compile_bridge
node_history_page -.->|"shows records"| node_history_store
node_history_page -.->|"imports CSV"| node_csv_import
node_history_page -.->|"exports CSV"| node_csv_export
node_history_store -.->|"persists records"| node_storage
node_results_page -.->|"renders report"| node_results_report
node_results_report -->|"exports samples"| node_csv_export
node_results_report -->|"compares baseline"| node_calibration
node_results_report -->|"reads reference"| node_calibration_store
node_results_report -->|"renders response charts"| node_charts
node_calibration_store -->|"uses comparison logic"| node_calibration
node_calibration_store -.->|"persists settings"| node_storage
node_history_store -->|"uses storage"| node_storage
node_overview -.->|"shows visualization"| node_scene
node_overview -.->|"shows live charts"| node_charts
node_settings -->|"configures connection"| node_device_store
node_settings -->|"configures calibration"| node_calibration_store

click node_app "https://github.com/abhinavdatta/punarva/blob/main/src/App.tsx"
click node_battery_check "https://github.com/abhinavdatta/punarva/blob/main/src/pages/BatteryCheckPage.tsx"
click node_test_engine "https://github.com/abhinavdatta/punarva/blob/main/src/state/testEngine.ts"
click node_test_store "https://github.com/abhinavdatta/punarva/blob/main/src/state/testStore.ts"
click node_demo_sampler "https://github.com/abhinavdatta/punarva/blob/main/src/services/demo/sampler.ts"
click node_device_store "https://github.com/abhinavdatta/punarva/blob/main/src/state/deviceStore.ts"
click node_validation "https://github.com/abhinavdatta/punarva/blob/main/src/services/validation.ts"
click node_serial "https://github.com/abhinavdatta/punarva/blob/main/src/services/device/transports.ts"
click node_websocket "https://github.com/abhinavdatta/punarva/blob/main/src/services/device/webSocketTransport.ts"
click node_flash_page "https://github.com/abhinavdatta/punarva/blob/main/src/pages/FlashPage.tsx"
click node_flash_store "https://github.com/abhinavdatta/punarva/blob/main/src/state/flashStore.ts"
click node_flasher "https://github.com/abhinavdatta/punarva/blob/main/src/services/device/flasher.ts"
click node_compile "https://github.com/abhinavdatta/punarva/blob/main/src/services/device/firmwareCompile.ts"
click node_history_page "https://github.com/abhinavdatta/punarva/blob/main/src/pages/HistoryPage.tsx"
click node_history_store "https://github.com/abhinavdatta/punarva/blob/main/src/state/historyStore.ts"
click node_storage "https://github.com/abhinavdatta/punarva/blob/main/src/services/storage/safeStorage.ts"
click node_results_page "https://github.com/abhinavdatta/punarva/blob/main/src/pages/ResultsPage.tsx"
click node_results_report "https://github.com/abhinavdatta/punarva/blob/main/src/components/results/ResultsReport.tsx"
click node_csv_export "https://github.com/abhinavdatta/punarva/blob/main/src/services/csv/exportCsv.ts"
click node_csv_import "https://github.com/abhinavdatta/punarva/blob/main/src/services/csv/importCsv.ts"
click node_calibration "https://github.com/abhinavdatta/punarva/blob/main/src/services/calibration.ts"
click node_calibration_store "https://github.com/abhinavdatta/punarva/blob/main/src/state/calibrationStore.ts"
click node_overview "https://github.com/abhinavdatta/punarva/blob/main/src/pages/OverviewPage.tsx"
click node_technology "https://github.com/abhinavdatta/punarva/blob/main/src/pages/TechnologyPage.tsx"
click node_settings "https://github.com/abhinavdatta/punarva/blob/main/src/pages/SettingsPage.tsx"
click node_scene "https://github.com/abhinavdatta/punarva/blob/main/src/components/three/BatteryTesterScene.tsx"
click node_charts "https://github.com/abhinavdatta/punarva/blob/main/src/components/charts/TimeSeriesChart.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_battery_check,node_test_engine,node_test_store,node_demo_sampler,node_charts,node_user,node_browser toneBlue
class node_device_store,node_validation,node_serial,node_websocket,node_flash_page,node_flash_store,node_flasher,node_compile toneAmber
class node_history_page,node_history_store,node_results_page,node_results_report,node_csv_export,node_csv_import toneMint
class node_app,node_overview,node_technology,node_settings,node_scene toneRose
class node_storage,node_calibration,node_calibration_store,node_compile_bridge toneIndigo
```

## Components

### Diagnostics workflow

- [Battery Check](https://github.com/abhinavdatta/punarva/blob/main/src/pages/BatteryCheckPage.tsx): `src/pages/BatteryCheckPage.tsx`
- [Test engine](https://github.com/abhinavdatta/punarva/blob/main/src/state/testEngine.ts): `src/state/testEngine.ts`
- [Test state](https://github.com/abhinavdatta/punarva/blob/main/src/state/testStore.ts): `src/state/testStore.ts`
- [Demo sampler](https://github.com/abhinavdatta/punarva/blob/main/src/services/demo/sampler.ts): `src/services/demo/sampler.ts`
- [Time-series charts](https://github.com/abhinavdatta/punarva/blob/main/src/components/charts/TimeSeriesChart.tsx): `src/components/charts/TimeSeriesChart.tsx`

### Device and firmware

- [Device connection](https://github.com/abhinavdatta/punarva/blob/main/src/state/deviceStore.ts): `src/state/deviceStore.ts`
- [Reading validation](https://github.com/abhinavdatta/punarva/blob/main/src/services/validation.ts): `src/services/validation.ts`
- [Web Serial](https://github.com/abhinavdatta/punarva/blob/main/src/services/device/transports.ts): `src/services/device/transports.ts`
- [WebSocket bridge](https://github.com/abhinavdatta/punarva/blob/main/src/services/device/webSocketTransport.ts): `src/services/device/webSocketTransport.ts`
- [Firmware flashing](https://github.com/abhinavdatta/punarva/blob/main/src/pages/FlashPage.tsx): `src/pages/FlashPage.tsx`
- [Flash state](https://github.com/abhinavdatta/punarva/blob/main/src/state/flashStore.ts): `src/state/flashStore.ts`
- [ESP32 flasher](https://github.com/abhinavdatta/punarva/blob/main/src/services/device/flasher.ts): `src/services/device/flasher.ts`
- [Firmware compiler client](https://github.com/abhinavdatta/punarva/blob/main/src/services/device/firmwareCompile.ts): `src/services/device/firmwareCompile.ts`

### Reports and history

- [Test history](https://github.com/abhinavdatta/punarva/blob/main/src/pages/HistoryPage.tsx): `src/pages/HistoryPage.tsx`
- [History state](https://github.com/abhinavdatta/punarva/blob/main/src/state/historyStore.ts): `src/state/historyStore.ts`
- [Test report route](https://github.com/abhinavdatta/punarva/blob/main/src/pages/ResultsPage.tsx): `src/pages/ResultsPage.tsx`
- [Report and comparison](https://github.com/abhinavdatta/punarva/blob/main/src/components/results/ResultsReport.tsx): `src/components/results/ResultsReport.tsx`
- [CSV export](https://github.com/abhinavdatta/punarva/blob/main/src/services/csv/exportCsv.ts): `src/services/csv/exportCsv.ts`
- [CSV import](https://github.com/abhinavdatta/punarva/blob/main/src/services/csv/importCsv.ts): `src/services/csv/importCsv.ts`

### Product experience

- [Route shell](https://github.com/abhinavdatta/punarva/blob/main/src/App.tsx): `src/App.tsx`
- [Overview dashboard](https://github.com/abhinavdatta/punarva/blob/main/src/pages/OverviewPage.tsx): `src/pages/OverviewPage.tsx`
- [Technology view](https://github.com/abhinavdatta/punarva/blob/main/src/pages/TechnologyPage.tsx): `src/pages/TechnologyPage.tsx`
- [Settings](https://github.com/abhinavdatta/punarva/blob/main/src/pages/SettingsPage.tsx): `src/pages/SettingsPage.tsx`
- [3D product scene](https://github.com/abhinavdatta/punarva/blob/main/src/components/three/BatteryTesterScene.tsx): `src/components/three/BatteryTesterScene.tsx`

### Shared state and services

- [Safe storage](https://github.com/abhinavdatta/punarva/blob/main/src/services/storage/safeStorage.ts): `src/services/storage/safeStorage.ts`
- [Calibration service](https://github.com/abhinavdatta/punarva/blob/main/src/services/calibration.ts): `src/services/calibration.ts`
- [Calibration state](https://github.com/abhinavdatta/punarva/blob/main/src/state/calibrationStore.ts): `src/state/calibrationStore.ts`

### Other components

- **User**
- **Browser device APIs**
- **Local compile bridge**

## Connections

- User → Route shell: opens (evidence: `src/App.tsx`)
- Route shell → Battery Check: routes to (evidence: `src/App.tsx`)
- Route shell → Test report route: routes to (evidence: `src/App.tsx`)
- Route shell → Test history: routes to (evidence: `src/App.tsx`)
- Route shell → Firmware flashing: routes to (evidence: `src/App.tsx`)
- Route shell → Overview dashboard: routes to (evidence: `src/App.tsx`)
- Route shell → Technology view: routes to (evidence: `src/App.tsx`)
- Route shell → Settings: routes to (evidence: `src/App.tsx`)
- Battery Check → Test engine: starts test (evidence: `src/pages/BatteryCheckPage.tsx`)
- Battery Check → Test state: reads state (evidence: `src/pages/BatteryCheckPage.tsx`)
- Test engine → Test state: updates phases (evidence: `src/state/testEngine.ts`)
- Test engine → Demo sampler: samples demo (evidence: `src/state/testEngine.ts`)
- Test engine → Device connection: reads readings (evidence: `src/state/testEngine.ts`)
- Test engine → History state: adds record (evidence: `src/state/testEngine.ts`)
- Device connection → Reading validation: validates payloads (evidence: `src/state/deviceStore.ts`)
- Device connection → Web Serial: connects transport (evidence: `src/state/deviceStore.ts`)
- Device connection → WebSocket bridge: connects transport (evidence: `src/state/deviceStore.ts`)
- Web Serial → Browser device APIs: uses serial API (evidence: `README.md`)
- WebSocket bridge → Browser device APIs: opens socket (evidence: `README.md`)
- Firmware flashing → Flash state: controls flashing (evidence: `src/pages/FlashPage.tsx`)
- Firmware flashing → Firmware compiler client: compiles source (evidence: `src/pages/FlashPage.tsx`)
- Flash state → ESP32 flasher: runs flasher (evidence: `src/state/flashStore.ts`)
- Firmware compiler client → Local compile bridge: requests compile (evidence: `README.md`)
- Test history → History state: shows records (evidence: `README.md`)
- Test history → CSV import: imports CSV (evidence: `README.md`)
- Test history → CSV export: exports CSV (evidence: `README.md`)
- History state → Safe storage: persists records (evidence: `src/state/historyStore.ts`)
- Test report route → Report and comparison: renders report (evidence: `README.md`)
- Report and comparison → CSV export: exports samples (evidence: `src/components/results/ResultsReport.tsx`)
- Report and comparison → Calibration service: compares baseline (evidence: `src/components/results/ResultsReport.tsx`)
- Report and comparison → Calibration state: reads reference (evidence: `src/components/results/ResultsReport.tsx`)
- Report and comparison → Time-series charts: renders response charts (evidence: `src/components/results/ResultsReport.tsx`)
- Calibration state → Calibration service: uses comparison logic (evidence: `src/state/calibrationStore.ts`)
- Calibration state → Safe storage: persists settings (evidence: `src/state/calibrationStore.ts`)
- History state → Safe storage: uses storage (evidence: `src/state/historyStore.ts`)
- Overview dashboard → 3D product scene: shows visualization (evidence: `README.md`)
- Overview dashboard → Time-series charts: shows live charts (evidence: `README.md`)
- Settings → Device connection: configures connection (evidence: `src/pages/SettingsPage.tsx`)
- Settings → Calibration state: configures calibration (evidence: `src/pages/SettingsPage.tsx`)
