# samarthg187/1050-light-website-ml-implementation architecture

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

- Interactive diagram: https://gitdiagram.com/samarthg187/1050-light-website-ml-implementation
- Repository: https://github.com/samarthg187/1050-light-website-ml-implementation

## Overview

1. This repository is a static, browser-first web app backed by JSON files in the GitHub repo itself. There is no traditional database or application server; the primary data store is the `readings/` folder plus the top-level `sessions.json` index.

2. The site has three main user-facing pages: `index.html` for the map overview, `SessionDetail.html` for per-session exploration, and `SubmitReading.html` for ingesting new CSV sessions. `Aboutuspage.html` is documentation/reference content rather than a data-driven view.

3. The homepage is the light-weight entry point. It fetches only `sessions.json`, not the full reading payloads, so it can place one map pin per session and color those pins by `avgClear`. This keeps the overview decoupled from the larger session files.

4. `SessionDetail.html` is the deep-dive view. It loads one file from `readings/session_XXX.json` based on the `session` query parameter, then renders session stats, a time-sequenced reading bar, and a modal spectral breakdown chart for a selected reading. This page is the main consumer of the full time-series payload.

5. The data model is split into two layers: a compact index in `sessions.json` and full session histories in `readings/*.json`. The index stores summary metadata such as date/time range, average and peak Clear channel values, row count, and GPS coordinates; the reading files store the per-interval sensor samples.

6. The underlying source data comes from an ESP32-based field sensor that samples every 2 seconds from an AS7341 spectral sensor, with timestamps from a DS1302 RTC and data written to SD card as CSV. The CSV structure contains 10 spectral channels plus `NIR`, `Clear`, and optionally `Lux_Est`; the web app’s upload path accepts both 12-column and 13-column variants.

7. `SubmitReading.html` is the ingestion boundary between raw field data and repo-backed storage. It parses a dropped CSV entirely in the browser, shows a preview and session summary, and then commits the generated session JSON into `readings/` while also updating `sessions.json`.

8. New session commits are pushed directly to GitHub using the GitHub Contents API, authenticated by a local `config.js` file that is intentionally gitignored. This means the repo itself is the persistence layer, and the browser is the client that writes to it when a user uploads data locally.

9. AI analysis is a separate server-side boundary. The browser sends a session summary to `api/analyse.js`, a Vercel serverless function, which then calls Anthropic Claude and returns a plain-English interpretation of the light pollution characteristics. The Anthropic API key stays on the server side in Vercel environment variables.

10. Deployment is split between static hosting and serverless execution on Vercel. The HTML/JS pages and JSON assets are served as static content, while `api/analyse.js` is deployed as a Vercel function. No custom build pipeline or framework runtime is involved.

11. The main external dependencies that shape the architecture are Leaflet/OpenStreetMap for the map UI, Anthropic for the AI commentary, and GitHub as the writable content store. Google Fonts are present for presentation, but they do not affect the data flow.

12. The key architectural flow is: sensor CSV → browser upload/parser → generated session JSON + summary index update in GitHub → homepage map reads `sessions.json` → detail page reads full session JSON → optional AI analysis via Vercel function. This repo is therefore a data-publishing dashboard with GitHub-backed persistence and a thin serverless AI augmentation layer.

Main entry points: [`SessionDetail.html`](https://github.com/samarthg187/1050-light-website-ml-implementation/blob/main/SessionDetail.html) (Session detail), [`vercel.json`](https://github.com/samarthg187/1050-light-website-ml-implementation/blob/main/vercel.json) (Vercel deploy), [`api/analyse.js`](https://github.com/samarthg187/1050-light-website-ml-implementation/blob/main/api/analyse.js) (AI analysis), [`index.html`](https://github.com/samarthg187/1050-light-website-ml-implementation/blob/main/index.html) (Map overview)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Browser app"]
  node_home["Map overview<br/>static page<br/>[index.html]"]
  node_detail["Session detail<br/>static page<br/>[SessionDetail.html]"]
  node_submit["Upload session<br/>static page<br/>[SubmitReading.html]"]
  node_about["About page<br/>static page<br/>[Aboutuspage.html]"]
  node_config["Local config<br/>auth config<br/>[.gitignore]"]
end

subgraph group_data["Repo data"]
  node_session_index[("Session index<br/>summary JSON<br/>[sessions.json]")]
  node_session_history["Session history<br/>time-series JSON<br/>[session_001.json]"]
  node_reading_archive[("Reading archive<br/>session JSON set<br/>[session_002.json]")]
  node_github_store[("GitHub contents<br/>writable store")]
end

subgraph group_server["Serverless AI"]
  node_analysis_api["AI analysis<br/>serverless function<br/>[analyse.js]"]
end

node_csv_source["Sensor CSV<br/>field export"]
node_sensor_node["ESP32 sensor<br/>field device"]
node_spectral_sensor["AS7341 sensor<br/>spectral sensor"]
node_rtc["DS1302 RTC<br/>clock module"]
node_anthropic["Claude API<br/>llm service"]
node_vercel["Vercel deploy<br/>hosting runtime<br/>[vercel.json]"]

node_sensor_node -->|"samples"| node_spectral_sensor
node_sensor_node -->|"timestamps"| node_rtc
node_spectral_sensor -->|"exports"| node_csv_source
node_rtc -->|"annotates"| node_csv_source
node_csv_source -->|"upload"| node_submit
node_submit -->|"writes"| node_github_store
node_config -->|"auth"| node_submit
node_github_store -->|"persists"| node_session_index
node_github_store -->|"persists"| node_reading_archive
node_session_index -->|"loads"| node_home
node_session_index -->|"summaries"| node_detail
node_reading_archive -->|"loads"| node_detail
node_home -->|"links"| node_detail
node_detail -->|"analyzes"| node_analysis_api
node_analysis_api -->|"calls"| node_anthropic
node_analysis_api -->|"returns"| node_detail
node_vercel -->|"hosts"| node_analysis_api
node_vercel -->|"serves"| node_home
node_vercel -->|"serves"| node_submit
node_vercel -->|"serves"| node_detail
node_about -->|"nav"| node_home

click node_home "https://github.com/samarthg187/1050-light-website-ml-implementation/blob/main/index.html"
click node_detail "https://github.com/samarthg187/1050-light-website-ml-implementation/blob/main/SessionDetail.html"
click node_submit "https://github.com/samarthg187/1050-light-website-ml-implementation/blob/main/SubmitReading.html"
click node_about "https://github.com/samarthg187/1050-light-website-ml-implementation/blob/main/Aboutuspage.html"
click node_session_index "https://github.com/samarthg187/1050-light-website-ml-implementation/blob/main/sessions.json"
click node_session_history "https://github.com/samarthg187/1050-light-website-ml-implementation/blob/main/readings/session_001.json"
click node_reading_archive "https://github.com/samarthg187/1050-light-website-ml-implementation/blob/main/readings/session_002.json"
click node_config "https://github.com/samarthg187/1050-light-website-ml-implementation/blob/main/.gitignore"
click node_analysis_api "https://github.com/samarthg187/1050-light-website-ml-implementation/blob/main/api/analyse.js"
click node_vercel "https://github.com/samarthg187/1050-light-website-ml-implementation/blob/main/vercel.json"

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_home,node_detail,node_submit,node_about,node_config toneBlue
class node_session_index,node_session_history,node_reading_archive,node_github_store toneAmber
class node_analysis_api toneMint
class node_csv_source,node_sensor_node,node_spectral_sensor,node_rtc,node_anthropic,node_vercel toneNeutral
```

## Components

### Browser app

Static pages that read, render, and write repository-backed data in the browser.

- [Map overview](https://github.com/samarthg187/1050-light-website-ml-implementation/blob/main/index.html): static page · Lightweight entry point that reads the session index and places one pin per session. · `index.html`
- [Session detail](https://github.com/samarthg187/1050-light-website-ml-implementation/blob/main/SessionDetail.html): static page · Deep-dive view for a single session with stats, timeline, and spectrum modal. · `SessionDetail.html`
- [Upload session](https://github.com/samarthg187/1050-light-website-ml-implementation/blob/main/SubmitReading.html): static page · Browser ingestion flow for parsing CSV, previewing data, and committing new sessions. · `SubmitReading.html`
- [About page](https://github.com/samarthg187/1050-light-website-ml-implementation/blob/main/Aboutuspage.html): static page · Documentation and reference content outside the main data-driven flow. · `Aboutuspage.html`
- [Local config](https://github.com/samarthg187/1050-light-website-ml-implementation/blob/main/.gitignore): auth config · Gitignored browser-local configuration holding GitHub API credentials. · `.gitignore`

### Repo data

GitHub-hosted JSON assets that act as the persistence layer.

- [Session index](https://github.com/samarthg187/1050-light-website-ml-implementation/blob/main/sessions.json): summary JSON · Compact metadata for each session including time range, coordinates, row count, and clear-channel summaries. · `sessions.json`
- [Session history](https://github.com/samarthg187/1050-light-website-ml-implementation/blob/main/readings/session_001.json): time-series JSON · Full per-session readings with spectral samples used by the detail view. · `readings/session_001.json`
- [Reading archive](https://github.com/samarthg187/1050-light-website-ml-implementation/blob/main/readings/session_002.json): session JSON set · Repository folder containing the full session payloads backing the deep-dive view. · `readings/session_002.json`
- **GitHub contents**: writable store · Repo-backed persistence layer updated directly by browser uploads via the GitHub Contents API.

### Serverless AI

Vercel function that augments session data with generated commentary.

- [AI analysis](https://github.com/samarthg187/1050-light-website-ml-implementation/blob/main/api/analyse.js): serverless function · Vercel endpoint that turns session summaries into plain-English light-pollution commentary. · `api/analyse.js`

### Other components

- **Sensor CSV**: field export · Raw CSV produced by the ESP32 and AS7341 sampling setup before browser ingestion.
- **ESP32 sensor**: field device · Microcontroller-based data source sampling the spectral sensor every two seconds.
- **AS7341 sensor**: spectral sensor · Primary light sensor providing the channel data captured in each reading.
- **DS1302 RTC**: clock module · Timestamp source embedded in the field logging hardware.
- **Claude API**: llm service · External model service used to generate the textual analysis.
- [Vercel deploy](https://github.com/samarthg187/1050-light-website-ml-implementation/blob/main/vercel.json): hosting runtime · Static hosting for pages and assets plus serverless execution for the analysis endpoint. · `vercel.json`

## Connections

- ESP32 sensor → AS7341 sensor: samples · Field device reads spectral channels from the sensor.
- ESP32 sensor → DS1302 RTC: timestamps · Field device uses RTC time for each sample.
- AS7341 sensor → Sensor CSV: exports · Sensor readings are written into CSV sessions.
- DS1302 RTC → Sensor CSV: annotates · Timestamp stream is embedded in the exported CSV.
- Sensor CSV → Upload session: upload · User drops a raw CSV into the browser ingestion page.
- Upload session → GitHub contents: writes · Parsed session JSON and index updates are committed to the repository.
- Local config → Upload session: auth · Local browser config provides GitHub API credentials.
- GitHub contents → Session index: persists · Session metadata is stored as the lightweight index.
- GitHub contents → Reading archive: persists · Full session histories are stored under the readings folder.
- Session index → Map overview: loads · Homepage reads only the compact index for map pins.
- Session index → Session detail: summaries · Detail page uses index metadata for session context.
- Reading archive → Session detail: loads · Detail page fetches one full session JSON by query parameter.
- Map overview → Session detail: links · Map pins open the selected session's deep-dive view.
- Session detail → AI analysis: analyzes · Browser sends a session summary to request AI commentary.
- AI analysis → Claude API: calls · Serverless function invokes Claude using server-side credentials.
- AI analysis → Session detail: returns · Generated interpretation is displayed back in the session view.
- Vercel deploy → AI analysis: hosts · Vercel executes the serverless analysis endpoint.
- Vercel deploy → Map overview: serves · Static hosting delivers the browser application and JSON assets.
- Vercel deploy → Upload session: serves · Static hosting delivers the upload page.
- Vercel deploy → Session detail: serves · Static hosting delivers the detail page.
- About page → Map overview: nav · Reference page sits alongside the main app navigation.
