# neeraj-kb/h2s_app architecture

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

- Interactive diagram: https://gitdiagram.com/neeraj-kb/h2s_app
- Repository: https://github.com/neeraj-kb/h2s_app

## Overview

Setu is a local-first PWA for reading passive H₂S dosimeter badges. A worker or supervisor enters shift details, captures a badge with the phone camera, and confirms or adjusts three sampled regions: white reference, exposure strip, and expiry patch. The main application coordinates color correction, dose-range estimation, expiry verification, result display, and optional saving; saved readings support history and CSV export. The README also describes lab experiment logging and an admin telemetry portal. The sampled source confirms the main orchestration and storage paths; those unsampled views are represented only at their documented enclosing modules.

Main entry points: [`src/main.js`](https://github.com/neeraj-kb/h2s_app/blob/main/src/main.js) (App controller), [`src/storage/db.js`](https://github.com/neeraj-kb/h2s_app/blob/main/src/storage/db.js) (Local records), [`src/storage/csvExport.js`](https://github.com/neeraj-kb/h2s_app/blob/main/src/storage/csvExport.js) (CSV export), [`src/ui/views.js`](https://github.com/neeraj-kb/h2s_app/blob/main/src/ui/views.js) (Application views)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_capture["Badge capture"]
  node_camera["Camera capture<br/>[camera.js]"]
  node_autodetect["Point detection<br/>[autoDetect.js]"]
  node_sampling["Tap sampling<br/>[tapCalibration.js]"]
end

subgraph group_analysis["Reading analysis"]
  node_color["White correction<br/>[colorCorrection.js]"]
  node_dose["Dose range<br/>[doseEstimate.js]"]
  node_expiry["Expiry check<br/>[expiryCheck.js]"]
end

subgraph group_records["Records and reporting"]
  node_database[("Local records<br/>[db.js]")]
  node_csv["CSV export<br/>[csvExport.js]"]
  node_experiments["Experiment chart"]
end

subgraph group_app["Application and offline"]
  node_main["App controller<br/>[main.js]"]
  node_views["Application views<br/>[views.js]"]
  node_serviceworker["Offline caching<br/>[sw.js]"]
end

node_worker(("Worker / supervisor"))
node_indexeddb[("IndexedDB")]
node_download(("Browser download"))
node_browser(("Browser runtime"))

node_worker -->|"enters and requests"| node_main
node_main -->|"starts or captures"| node_camera
node_main -->|"stops stream"| node_camera
node_main -->|"detects points"| node_autodetect
node_main -->|"maps taps and samples"| node_sampling
node_main -->|"corrects colors"| node_color
node_main -->|"estimates dose range"| node_dose
node_main -->|"checks validity"| node_expiry
node_main -->|"updates and displays"| node_views
node_views -->|"draws chart"| node_experiments
node_main -->|"reads and writes records"| node_database
node_database -->|"reads and writes"| node_indexeddb
node_main -->|"exports readings"| node_csv
node_csv -->|"triggers download"| node_download
node_main -->|"registers"| node_serviceworker
node_serviceworker -->|"caches requests"| node_browser

click node_main "https://github.com/neeraj-kb/h2s_app/blob/main/src/main.js"
click node_camera "https://github.com/neeraj-kb/h2s_app/blob/main/src/capture/camera.js"
click node_autodetect "https://github.com/neeraj-kb/h2s_app/blob/main/src/capture/autoDetect.js"
click node_sampling "https://github.com/neeraj-kb/h2s_app/blob/main/src/capture/tapCalibration.js"
click node_views "https://github.com/neeraj-kb/h2s_app/blob/main/src/ui/views.js"
click node_color "https://github.com/neeraj-kb/h2s_app/blob/main/src/colorimetry/colorCorrection.js"
click node_dose "https://github.com/neeraj-kb/h2s_app/blob/main/src/colorimetry/doseEstimate.js"
click node_expiry "https://github.com/neeraj-kb/h2s_app/blob/main/src/colorimetry/expiryCheck.js"
click node_database "https://github.com/neeraj-kb/h2s_app/blob/main/src/storage/db.js"
click node_csv "https://github.com/neeraj-kb/h2s_app/blob/main/src/storage/csvExport.js"
click node_experiments "https://github.com/neeraj-kb/h2s_app/blob/main/src/ui/components/experimentsChart.js"
click node_serviceworker "https://github.com/neeraj-kb/h2s_app/blob/main/public/sw.js"

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_camera,node_autodetect,node_sampling,node_download,node_browser toneBlue
class node_color,node_dose,node_expiry,node_indexeddb toneAmber
class node_database,node_csv,node_experiments toneMint
class node_main,node_views,node_serviceworker,node_worker toneRose
```

## Components

### Badge capture

- [Camera capture](https://github.com/neeraj-kb/h2s_app/blob/main/src/capture/camera.js): `src/capture/camera.js`
- [Point detection](https://github.com/neeraj-kb/h2s_app/blob/main/src/capture/autoDetect.js): `src/capture/autoDetect.js`
- [Tap sampling](https://github.com/neeraj-kb/h2s_app/blob/main/src/capture/tapCalibration.js): `src/capture/tapCalibration.js`

### Reading analysis

- [White correction](https://github.com/neeraj-kb/h2s_app/blob/main/src/colorimetry/colorCorrection.js): `src/colorimetry/colorCorrection.js`
- [Dose range](https://github.com/neeraj-kb/h2s_app/blob/main/src/colorimetry/doseEstimate.js): `src/colorimetry/doseEstimate.js`
- [Expiry check](https://github.com/neeraj-kb/h2s_app/blob/main/src/colorimetry/expiryCheck.js): `src/colorimetry/expiryCheck.js`

### Records and reporting

- [Local records](https://github.com/neeraj-kb/h2s_app/blob/main/src/storage/db.js): `src/storage/db.js`
- [CSV export](https://github.com/neeraj-kb/h2s_app/blob/main/src/storage/csvExport.js): `src/storage/csvExport.js`
- [Experiment chart](https://github.com/neeraj-kb/h2s_app/blob/main/src/ui/components/experimentsChart.js): `src/ui/components/experimentsChart.js`

### Application and offline

- [App controller](https://github.com/neeraj-kb/h2s_app/blob/main/src/main.js): `src/main.js`
- [Application views](https://github.com/neeraj-kb/h2s_app/blob/main/src/ui/views.js): `src/ui/views.js`
- [Offline caching](https://github.com/neeraj-kb/h2s_app/blob/main/public/sw.js): `public/sw.js`

### Other components

- **Worker / supervisor**
- **IndexedDB**
- **Browser download**
- **Browser runtime**

## Connections

- Worker / supervisor → App controller: enters and requests
- App controller → Camera capture: starts or captures
- App controller → Camera capture: stops stream
- App controller → Point detection: detects points
- App controller → Tap sampling: maps taps and samples
- App controller → White correction: corrects colors
- App controller → Dose range: estimates dose range
- App controller → Expiry check: checks validity
- App controller → Application views: updates and displays
- Application views → Experiment chart: draws chart
- App controller → Local records: reads and writes records
- Local records → IndexedDB: reads and writes
- App controller → CSV export: exports readings
- CSV export → Browser download: triggers download
- App controller → Offline caching: registers
- Offline caching → Browser runtime: caches requests
