# surajrana-git/himrakshak architecture

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

- Interactive diagram: https://gitdiagram.com/surajrana-git/himrakshak
- Repository: https://github.com/surajrana-git/himrakshak

## Overview

Himrakshak is a Himalayan road-disaster safety web app, also installable as a PWA and Android app. The main journey is to view live road risk, plan a route that weighs landslide risk and closures, then navigate with hazard alerts; travellers can also report conditions and consult local services. The graph includes documented offline maps, community events, SOS, and saved routes. Evidence is limited to the README and the sampled/indexed files; links for unsampled capabilities are dashed where their wiring is not shown.

Main entry points: [`lib/routes.ts`](https://github.com/surajrana-git/himrakshak/blob/main/lib/routes.ts) (Risk-scored routes), [`app/page.tsx`](https://github.com/surajrana-git/himrakshak/blob/main/app/page.tsx) (Live risk view), [`app/events/page.tsx`](https://github.com/surajrana-git/himrakshak/blob/main/app/events/page.tsx) (Community events), [`lib/trip.ts`](https://github.com/surajrana-git/himrakshak/blob/main/lib/trip.ts) (Trip navigation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["Traveller experience"]
  node_home["Live risk view<br/>[page.tsx]"]
  node_riskview["Risk map UI<br/>[RiskView.tsx]"]
  node_trip["Trip navigation<br/>[trip.ts]"]
end

subgraph group_safety["Risk and routing"]
  node_routeapi["Routes API<br/>[route.ts]"]
  node_routes["Risk-scored routes<br/>[routes.ts]"]
  node_valhalla["Road routing<br/>[valhalla.ts]"]
  node_terrain["Terrain risk<br/>[terrain.ts]"]
  node_risk["Risk scoring<br/>[risk.ts]"]
  node_weather["Rain data<br/>[weather.ts]"]
end

subgraph group_community["Community reports"]
  node_reports["Driver reports<br/>[reports.ts]"]
  node_contributions["Community contributions<br/>[contributions.ts]"]
  node_contributionform["Report and place form"]
  node_events["Community events<br/>[page.tsx]"]
end

subgraph group_services["Local services"]
  node_sos["SOS support<br/>[sos.ts]"]
  node_hotels["Hotel search<br/>[page.tsx]"]
  node_hotelapi["Hotel lookup API<br/>[route.ts]"]
end

subgraph group_platform["Persistence and offline"]
  node_auth["Authentication<br/>[auth.ts]"]
  node_savedroutes["Saved routes<br/>[saved-routes.ts]"]
  node_supabase[("Supabase<br/>[supabase.ts]")]
  node_offlinemaps["Offline maps<br/>[offline-maps.ts]"]
  node_serviceworker["Offline caching<br/>[sw.js]"]
end

node_traveller(("Traveller"))

node_traveller -->|"opens app"| node_home
node_home -->|"loads rain"| node_weather
node_home -->|"measures terrain"| node_terrain
node_home -->|"renders risk"| node_riskview
node_routeapi -->|"requests options"| node_routes
node_routes -->|"requests roads"| node_valhalla
node_routes -->|"gets rain"| node_weather
node_routes -->|"scores terrain"| node_terrain
node_routes -->|"scores stretches"| node_risk
node_trip -->|"uses route types"| node_routes
node_trip -->|"uses route types"| node_valhalla
node_contributionform -->|"submits entries"| node_contributions
node_events -->|"lists entries"| node_contributions
node_events -->|"lists reports"| node_reports
node_hotels -->|"searches hotels"| node_hotelapi
node_hotels -->|"gets GPS"| node_sos
node_auth -->|"uses client"| node_supabase
node_savedroutes -->|"reads and writes"| node_supabase
node_home -.->|"offers offline maps"| node_offlinemaps
node_serviceworker -.->|"caches map data"| node_offlinemaps
node_traveller -.->|"browses events"| node_events
node_traveller -.->|"submits reports"| node_contributionform
node_traveller -.->|"requests SOS"| node_sos
node_traveller -.->|"saves routes"| node_savedroutes

click node_home "https://github.com/surajrana-git/himrakshak/blob/main/app/page.tsx"
click node_riskview "https://github.com/surajrana-git/himrakshak/blob/main/components/RiskView.tsx"
click node_trip "https://github.com/surajrana-git/himrakshak/blob/main/lib/trip.ts"
click node_routeapi "https://github.com/surajrana-git/himrakshak/blob/main/app/api/routes/route.ts"
click node_routes "https://github.com/surajrana-git/himrakshak/blob/main/lib/routes.ts"
click node_valhalla "https://github.com/surajrana-git/himrakshak/blob/main/lib/valhalla.ts"
click node_terrain "https://github.com/surajrana-git/himrakshak/blob/main/lib/terrain.ts"
click node_risk "https://github.com/surajrana-git/himrakshak/blob/main/lib/risk.ts"
click node_weather "https://github.com/surajrana-git/himrakshak/blob/main/lib/weather.ts"
click node_reports "https://github.com/surajrana-git/himrakshak/blob/main/lib/reports.ts"
click node_contributions "https://github.com/surajrana-git/himrakshak/blob/main/lib/contributions.ts"
click node_contributionform "https://github.com/surajrana-git/himrakshak/blob/main/components/ContributionForm.tsx"
click node_events "https://github.com/surajrana-git/himrakshak/blob/main/app/events/page.tsx"
click node_sos "https://github.com/surajrana-git/himrakshak/blob/main/lib/sos.ts"
click node_hotels "https://github.com/surajrana-git/himrakshak/blob/main/app/hotels/page.tsx"
click node_hotelapi "https://github.com/surajrana-git/himrakshak/blob/main/app/api/hotels/route.ts"
click node_auth "https://github.com/surajrana-git/himrakshak/blob/main/lib/auth.ts"
click node_savedroutes "https://github.com/surajrana-git/himrakshak/blob/main/lib/saved-routes.ts"
click node_supabase "https://github.com/surajrana-git/himrakshak/blob/main/lib/supabase.ts"
click node_offlinemaps "https://github.com/surajrana-git/himrakshak/blob/main/lib/offline-maps.ts"
click node_serviceworker "https://github.com/surajrana-git/himrakshak/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_home,node_riskview,node_trip toneBlue
class node_routeapi,node_routes,node_valhalla,node_terrain,node_risk,node_weather toneAmber
class node_reports,node_contributions,node_contributionform,node_events toneMint
class node_sos,node_hotels,node_hotelapi toneRose
class node_auth,node_savedroutes,node_supabase,node_offlinemaps,node_serviceworker,node_traveller toneIndigo
```

## Components

### Traveller experience

- [Live risk view](https://github.com/surajrana-git/himrakshak/blob/main/app/page.tsx): `app/page.tsx`
- [Risk map UI](https://github.com/surajrana-git/himrakshak/blob/main/components/RiskView.tsx): `components/RiskView.tsx`
- [Trip navigation](https://github.com/surajrana-git/himrakshak/blob/main/lib/trip.ts): `lib/trip.ts`

### Risk and routing

- [Routes API](https://github.com/surajrana-git/himrakshak/blob/main/app/api/routes/route.ts): `app/api/routes/route.ts`
- [Risk-scored routes](https://github.com/surajrana-git/himrakshak/blob/main/lib/routes.ts): `lib/routes.ts`
- [Road routing](https://github.com/surajrana-git/himrakshak/blob/main/lib/valhalla.ts): `lib/valhalla.ts`
- [Terrain risk](https://github.com/surajrana-git/himrakshak/blob/main/lib/terrain.ts): `lib/terrain.ts`
- [Risk scoring](https://github.com/surajrana-git/himrakshak/blob/main/lib/risk.ts): `lib/risk.ts`
- [Rain data](https://github.com/surajrana-git/himrakshak/blob/main/lib/weather.ts): `lib/weather.ts`

### Community reports

- [Driver reports](https://github.com/surajrana-git/himrakshak/blob/main/lib/reports.ts): `lib/reports.ts`
- [Community contributions](https://github.com/surajrana-git/himrakshak/blob/main/lib/contributions.ts): `lib/contributions.ts`
- [Report and place form](https://github.com/surajrana-git/himrakshak/blob/main/components/ContributionForm.tsx): `components/ContributionForm.tsx`
- [Community events](https://github.com/surajrana-git/himrakshak/blob/main/app/events/page.tsx): `app/events/page.tsx`

### Local services

- [SOS support](https://github.com/surajrana-git/himrakshak/blob/main/lib/sos.ts): `lib/sos.ts`
- [Hotel search](https://github.com/surajrana-git/himrakshak/blob/main/app/hotels/page.tsx): `app/hotels/page.tsx`
- [Hotel lookup API](https://github.com/surajrana-git/himrakshak/blob/main/app/api/hotels/route.ts): `app/api/hotels/route.ts`

### Persistence and offline

- [Authentication](https://github.com/surajrana-git/himrakshak/blob/main/lib/auth.ts): `lib/auth.ts`
- [Saved routes](https://github.com/surajrana-git/himrakshak/blob/main/lib/saved-routes.ts): `lib/saved-routes.ts`
- [Supabase](https://github.com/surajrana-git/himrakshak/blob/main/lib/supabase.ts): `lib/supabase.ts`
- [Offline maps](https://github.com/surajrana-git/himrakshak/blob/main/lib/offline-maps.ts): `lib/offline-maps.ts`
- [Offline caching](https://github.com/surajrana-git/himrakshak/blob/main/public/sw.js): `public/sw.js`

### Other components

- **Traveller**

## Connections

- Traveller → Live risk view: opens app
- Live risk view → Rain data: loads rain (evidence: `app/page.tsx`)
- Live risk view → Terrain risk: measures terrain (evidence: `app/page.tsx`)
- Live risk view → Risk map UI: renders risk (evidence: `app/page.tsx`)
- Routes API → Risk-scored routes: requests options (evidence: `app/api/routes/route.ts`)
- Risk-scored routes → Road routing: requests roads (evidence: `lib/routes.ts`)
- Risk-scored routes → Rain data: gets rain (evidence: `lib/routes.ts`)
- Risk-scored routes → Terrain risk: scores terrain (evidence: `lib/routes.ts`)
- Risk-scored routes → Risk scoring: scores stretches (evidence: `lib/routes.ts`)
- Trip navigation → Risk-scored routes: uses route types (evidence: `lib/trip.ts`)
- Trip navigation → Road routing: uses route types (evidence: `lib/trip.ts`)
- Report and place form → Community contributions: submits entries (evidence: `components/ContributionForm.tsx`)
- Community events → Community contributions: lists entries (evidence: `app/events/page.tsx`)
- Community events → Driver reports: lists reports (evidence: `app/events/page.tsx`)
- Hotel search → Hotel lookup API: searches hotels (evidence: `app/hotels/page.tsx`)
- Hotel search → SOS support: gets GPS (evidence: `app/hotels/page.tsx`)
- Authentication → Supabase: uses client (evidence: `lib/auth.ts`)
- Saved routes → Supabase: reads and writes (evidence: `lib/saved-routes.ts`)
- Live risk view → Offline maps: offers offline maps
- Offline caching → Offline maps: caches map data
- Traveller → Community events: browses events
- Traveller → Report and place form: submits reports
- Traveller → SOS support: requests SOS
- Traveller → Saved routes: saves routes
