# AirSaathi

AirSaathi is a static air-quality companion for families navigating winter smog in Indian cities. It combines Open-Meteo readings with practical, household-aware guidance; it is not a medical or regulatory monitoring service.

## Chosen vertical and persona

**Urban Air Quality Assistant (Challenge 6); Indian city families in winter smog.**

## Approach and logic

AirSaathi uses a deterministic rule engine first, then calculates illustrative impacts from the current form values. Gemini is optional and is used only to rephrase those existing recommendations; it cannot change the underlying guidance or impact figures. This keeps the core advice predictable and useful without an API key, while making generated wording an optional enhancement.

## How it works

1. Choose a city or use the browser's optional location control, then set household, commute, home setup, and distance.
2. AirSaathi fetches the Open-Meteo current and hourly PM2.5 response, reusing only a fresh cached API response.
3. The app estimates a PM2.5-only AQI and displays the current reading and 24-hour forecast.
4. The rule engine selects guidance for the current AQI band and form values; the impact calculator recomputes illustrative effects.
5. Optionally, Gemini rephrases the fixed recommendations. The page renders the current reading, forecast, guidance, and impact.

## Security

- A Content-Security-Policy, input validation and length limits, and abortable request timeouts constrain browser-side behavior.
- Dynamic results are rendered as text, not interpreted as HTML. Open-Meteo data is cached; generated recommendations and impacts are not.
- Gemini is optional. A key entered in this static app is exposed to the browser and the Gemini API; do not use a shared secret key.

## Accessibility

- Includes a skip link, keyboard-visible focus, form error descriptions, and an announced results region.
- Supports reduced-motion and system color-scheme preferences, with large touch targets.
- Forecast bars include time and value labels; color is not the only way to understand them.

## Problem statement to feature mapping

| Need                                      | AirSaathi feature                                                                                                                |
| ----------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
| Understand current local air conditions   | Open-Meteo geocoding and current PM2.5, shown with an explicitly estimated PM2.5-only Indian AQI                                 |
| Plan an outing around changing conditions | 24-hour hourly PM2.5 forecast, an accessible text-labelled bar chart, and the lowest forecast hour remaining today               |
| Get results for a location quickly        | City suggestions, optional browser geolocation, and a 30-minute cache of the raw Open-Meteo response                             |
| Make guidance relevant to a household     | Deterministic recommendations use the selected household, commute, home setup, distance, and AQI band                            |
| Understand illustrative effects           | Impact estimates show their assumptions and are recalculated from current form values                                            |
| Use the app with different access needs   | English/Hindi UI, keyboard-visible focus, skip link, live results, reduced-motion support, dark-mode support, and large controls |
| Keep browser-side requests constrained    | A Content-Security-Policy, bounded input validation, and abortable request timeouts                                              |

## Architecture

```mermaid
flowchart LR
  Household --> Form[Current form values]
  Form --> OpenMeteo[Open-Meteo]
  OpenMeteo --> Cache[30-minute response cache]
  Cache --> Engine[PM2.5 forecast, rules, and impact]
  Engine --> Results[Rendered guidance]
  Results -. Optional rephrasing .-> Gemini[Gemini]
```

## Screenshots

![English AirSaathi results with current PM2.5, forecast chart, and family guidance](docs/screenshot-en.png)

![Hindi AirSaathi results with current PM2.5, forecast chart, and family guidance](docs/screenshot-hi.png)

![AirSaathi results on a 390px mobile viewport](docs/screenshot-mobile.png)

Live demo: https://shivamdwivedicse.github.io/airsaathi-urban-air-quality/

## Assumptions

- Open-Meteo supplies modelled current and hourly PM2.5 values. Hourly values are requested for the next 24 local hours using the location's timezone.
- “Best time to go out today” means the remaining hour today with the lowest forecast PM2.5. It is a relative comparison, not a declaration that the air is safe.
- Cache expiry is measured from the time the response was fetched, not the timestamp reported by the API. Only the Open-Meteo response is cached; recommendations and impacts are recomputed from each submission.
- The displayed AQI is interpolated from PM2.5 alone using CPCB-style breakpoints. It is not the official multi-pollutant CPCB AQI.
- Emission factors in `src/constants.js` are rounded illustrative passenger-kilometre estimates based on UK DESNZ conversion factors, not current India-specific route measurements.
- The commute impact assumes five commute days per week. Exposure-shift examples, N95 filtration, and HEPA ratings are scenarios or test standards, not individual guarantees.
- A location lookup requires a valid city name; browser geolocation requires explicit permission and a secure context (HTTPS or localhost). If permission is denied, users can enter a city instead.
- Gemini is optional. Its response can only rephrase the fixed rule-based recommendations. A key entered in this static app is exposed to the browser and the Gemini API; do not use a shared secret key.

## Limitations

- Open-Meteo availability, geocoding, and modelled readings are not a substitute for a nearby regulatory monitor; data may be delayed or unavailable. A labelled sample reading appears when live data cannot be retrieved.
- Forecast uncertainty increases with time. A lower forecast does not guarantee safe air, and the app does not account for every pollutant, street-level condition, or personal exposure.
- The city suggestions are examples, not an exhaustive directory. Geolocation uses coordinates directly and displays “My location” rather than reverse-geocoding an address.
- Browser geolocation requires user permission. Request timeouts and input validation improve reliability but cannot guarantee network availability.
- AirSaathi is general planning information, not medical advice. Follow a clinician's advice and seek professional care for symptoms or health concerns.

## Setup

Requires Node.js 20.19+ (or a compatible newer LTS) for the lint tooling.

```sh
npm install
npm start
```

Open `http://localhost:8000`. A local server is recommended because browser module loading from `file://` can vary. Browser geolocation is available on localhost and HTTPS origins.

Gemini rewriting is optional; enter your own key in the form. `.env.example` documents the key name, but this static app does not read environment files.

## Tests and lint

```sh
npm test
npm run lint
npm run format
```

Tests use Node's built-in test runner and cover forecast selection, cache freshness and fallback behavior, input validation, geolocation denial, all AQI bands across household/home types, PM2.5 conversion, impact calculations, Gemini response handling, form parsing, and translation-key parity. **Test count: 36** (run `npm test` for the exact number). `npm run lint` runs ESLint and `prettier --check`; use `npm run format` to apply formatting.
