# sonu-kr-pandit/yatrihan architecture

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

- Interactive diagram: https://gitdiagram.com/sonu-kr-pandit/yatrihan
- Repository: https://github.com/sonu-kr-pandit/yatrihan

## Overview

Yatrigan is a real-time Indian Railways tracking application. Passengers search for a train, open its journey view, and follow live status, route and station details; the tracking page also exposes map, weather, analytics, and terrain views. Server route handlers fetch RailRadar and enrichment data, with caching, while client hooks refresh journey and search data. Favorites and recent searches provide supporting user features. Some panels and services were not excerpted, so those links are included only where the README or source index supports them.

Main entry points: [`app/train/[id]/page.tsx`](https://github.com/sonu-kr-pandit/yatrihan/blob/main/app/train/%5Bid%5D/page.tsx) (Journey tracking page), [`lib/railradar.ts`](https://github.com/sonu-kr-pandit/yatrihan/blob/main/lib/railradar.ts) (RailRadar client), [`hooks/useTrainSearch.ts`](https://github.com/sonu-kr-pandit/yatrihan/blob/main/hooks/useTrainSearch.ts) (Search query hook), [`app/api/analytics/[id]/route.ts`](https://github.com/sonu-kr-pandit/yatrihan/blob/main/app/api/analytics/%5Bid%5D/route.ts) (Analytics API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["Passenger experience"]
  node_home["Train search home<br/>[page.tsx]"]
  node_search_hook["Search query hook<br/>[useTrainSearch.ts]"]
  node_search_ui["Search results<br/>[SearchResults.tsx]"]
  node_favorites_page["Saved trains page<br/>[page.tsx]"]
  node_favorite_button["Favorite control<br/>[FavoriteButton.tsx]"]
  node_share_page["Shared journey page<br/>[page.tsx]"]
end

subgraph group_journey["Journey tracking"]
  node_train_page["Journey tracking page<br/>[page.tsx]"]
  node_journey_hook["Live journey hook<br/>[useLiveJourney.ts]"]
  node_map["Live route map<br/>[MapView.tsx]"]
  node_timeline["Station timeline<br/>[Timeline.tsx]"]
end

subgraph group_enrichment["Route intelligence"]
  node_weather_panel["Station weather<br/>[WeatherPanel.tsx]"]
  node_analytics_panel["Journey analytics"]
  node_terrain_panel["Terrain points<br/>[TerrainPanel.tsx]"]
end

subgraph group_services["Data services"]
  node_search_api["Train search API<br/>[route.ts]"]
  node_train_db[("Local train catalog<br/>[trains-db.ts]")]
  node_train_api["Journey API<br/>[route.ts]"]
  node_railradar["RailRadar client<br/>[railradar.ts]"]
  node_cache[("Response cache<br/>[cache.ts]")]
  node_weather_api["Weather API<br/>[route.ts]"]
  node_weather_service["OpenWeather client<br/>[openweather.ts]"]
  node_analytics_api["Analytics API<br/>[route.ts]"]
  node_elevation_service["Elevation client<br/>[opentopography.ts]"]
  node_terrain_api["Terrain API<br/>[route.ts]"]
  node_overpass["Overpass client<br/>[overpass.ts]"]
end

subgraph group_state["Client state"]
  node_favorites_store[("Favorites state<br/>[favorites.ts]")]
  node_search_store[("Recent searches<br/>[search.ts]")]
  node_journey_store[("Journey preferences<br/>[journey.ts]")]
end

node_passenger(("Passenger"))
node_maptiler["MapTiler tiles"]

node_passenger -->|"searches trains"| node_home
node_home -->|"queries"| node_search_hook
node_search_hook -->|"fetches results"| node_search_api
node_search_api -->|"searches trains"| node_railradar
node_search_api -->|"falls back"| node_train_db
node_railradar -->|"uses catalog"| node_train_db
node_search_hook -->|"loads instant matches"| node_train_db
node_home -->|"reads recent searches"| node_search_store
node_search_hook -->|"supplies results"| node_search_ui
node_passenger -->|"opens train"| node_train_page
node_train_page -->|"loads journey"| node_journey_hook
node_journey_hook -->|"polls journey"| node_train_api
node_train_api -->|"gets live journey"| node_railradar
node_train_api -->|"reads and writes"| node_cache
node_train_page -->|"uses refresh setting"| node_journey_store
node_train_page -->|"renders map view"| node_map
node_map -->|"loads vector tiles"| node_maptiler
node_train_page -->|"renders route timeline"| node_timeline
node_train_page -->|"renders weather view"| node_weather_panel
node_weather_panel -->|"requests station weather"| node_weather_api
node_weather_api -->|"gets weather"| node_weather_service
node_weather_api -->|"reads and writes"| node_cache
node_train_page -->|"renders analytics"| node_analytics_panel
node_analytics_panel -->|"requests analytics"| node_analytics_api
node_analytics_api -->|"gets journey"| node_railradar
node_analytics_api -->|"gets elevation profile"| node_elevation_service
node_analytics_api -->|"reads and writes"| node_cache
node_train_page -->|"renders terrain view"| node_terrain_panel
node_terrain_panel -->|"requests route points"| node_terrain_api
node_terrain_api -->|"gets journey route"| node_railradar
node_terrain_api -->|"gets terrain features"| node_overpass
node_terrain_api -->|"reads and writes"| node_cache
node_favorites_page -->|"loads saved trains"| node_favorites_store
node_favorites_page -->|"renders controls"| node_favorite_button
node_train_page -->|"renders control"| node_favorite_button
node_favorite_button -->|"updates favorites"| node_favorites_store
node_passenger -.->|"opens shared journey"| node_share_page

click node_home "https://github.com/sonu-kr-pandit/yatrihan/blob/main/app/page.tsx"
click node_search_hook "https://github.com/sonu-kr-pandit/yatrihan/blob/main/hooks/useTrainSearch.ts"
click node_search_api "https://github.com/sonu-kr-pandit/yatrihan/blob/main/app/api/search/route.ts"
click node_search_ui "https://github.com/sonu-kr-pandit/yatrihan/blob/main/components/search/SearchResults.tsx"
click node_train_db "https://github.com/sonu-kr-pandit/yatrihan/blob/main/lib/trains-db.ts"
click node_train_page "https://github.com/sonu-kr-pandit/yatrihan/blob/main/app/train/%5Bid%5D/page.tsx"
click node_journey_hook "https://github.com/sonu-kr-pandit/yatrihan/blob/main/hooks/useLiveJourney.ts"
click node_train_api "https://github.com/sonu-kr-pandit/yatrihan/blob/main/app/api/train/%5Bid%5D/route.ts"
click node_railradar "https://github.com/sonu-kr-pandit/yatrihan/blob/main/lib/railradar.ts"
click node_cache "https://github.com/sonu-kr-pandit/yatrihan/blob/main/lib/cache.ts"
click node_map "https://github.com/sonu-kr-pandit/yatrihan/blob/main/features/maps/MapView.tsx"
click node_timeline "https://github.com/sonu-kr-pandit/yatrihan/blob/main/components/journey/Timeline.tsx"
click node_weather_panel "https://github.com/sonu-kr-pandit/yatrihan/blob/main/features/weather/WeatherPanel.tsx"
click node_weather_api "https://github.com/sonu-kr-pandit/yatrihan/blob/main/app/api/weather/route.ts"
click node_weather_service "https://github.com/sonu-kr-pandit/yatrihan/blob/main/lib/openweather.ts"
click node_analytics_panel "https://github.com/sonu-kr-pandit/yatrihan/blob/main/features/analytics/AnalyticsDashboard.tsx"
click node_analytics_api "https://github.com/sonu-kr-pandit/yatrihan/blob/main/app/api/analytics/%5Bid%5D/route.ts"
click node_elevation_service "https://github.com/sonu-kr-pandit/yatrihan/blob/main/lib/opentopography.ts"
click node_terrain_panel "https://github.com/sonu-kr-pandit/yatrihan/blob/main/features/terrain/TerrainPanel.tsx"
click node_terrain_api "https://github.com/sonu-kr-pandit/yatrihan/blob/main/app/api/terrain/route.ts"
click node_overpass "https://github.com/sonu-kr-pandit/yatrihan/blob/main/lib/overpass.ts"
click node_favorites_page "https://github.com/sonu-kr-pandit/yatrihan/blob/main/app/favorites/page.tsx"
click node_favorite_button "https://github.com/sonu-kr-pandit/yatrihan/blob/main/features/favorites/FavoriteButton.tsx"
click node_favorites_store "https://github.com/sonu-kr-pandit/yatrihan/blob/main/store/favorites.ts"
click node_search_store "https://github.com/sonu-kr-pandit/yatrihan/blob/main/store/search.ts"
click node_journey_store "https://github.com/sonu-kr-pandit/yatrihan/blob/main/store/journey.ts"
click node_share_page "https://github.com/sonu-kr-pandit/yatrihan/blob/main/app/share/%5Bid%5D/page.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_home,node_search_hook,node_search_ui,node_favorites_page,node_favorite_button,node_share_page toneBlue
class node_train_page,node_journey_hook,node_map,node_timeline toneAmber
class node_weather_panel,node_analytics_panel,node_terrain_panel toneMint
class node_search_api,node_train_db,node_train_api,node_railradar,node_cache,node_weather_api,node_weather_service,node_analytics_api,node_elevation_service,node_terrain_api,node_overpass toneRose
class node_favorites_store,node_search_store,node_journey_store,node_passenger,node_maptiler toneIndigo
```

## Components

### Passenger experience

- [Train search home](https://github.com/sonu-kr-pandit/yatrihan/blob/main/app/page.tsx): `app/page.tsx`
- [Search query hook](https://github.com/sonu-kr-pandit/yatrihan/blob/main/hooks/useTrainSearch.ts): `hooks/useTrainSearch.ts`
- [Search results](https://github.com/sonu-kr-pandit/yatrihan/blob/main/components/search/SearchResults.tsx): `components/search/SearchResults.tsx`
- [Saved trains page](https://github.com/sonu-kr-pandit/yatrihan/blob/main/app/favorites/page.tsx): `app/favorites/page.tsx`
- [Favorite control](https://github.com/sonu-kr-pandit/yatrihan/blob/main/features/favorites/FavoriteButton.tsx): `features/favorites/FavoriteButton.tsx`
- [Shared journey page](https://github.com/sonu-kr-pandit/yatrihan/blob/main/app/share/%5Bid%5D/page.tsx): `app/share/[id]/page.tsx`

### Journey tracking

- [Journey tracking page](https://github.com/sonu-kr-pandit/yatrihan/blob/main/app/train/%5Bid%5D/page.tsx): `app/train/[id]/page.tsx`
- [Live journey hook](https://github.com/sonu-kr-pandit/yatrihan/blob/main/hooks/useLiveJourney.ts): `hooks/useLiveJourney.ts`
- [Live route map](https://github.com/sonu-kr-pandit/yatrihan/blob/main/features/maps/MapView.tsx): `features/maps/MapView.tsx`
- [Station timeline](https://github.com/sonu-kr-pandit/yatrihan/blob/main/components/journey/Timeline.tsx): `components/journey/Timeline.tsx`

### Route intelligence

- [Station weather](https://github.com/sonu-kr-pandit/yatrihan/blob/main/features/weather/WeatherPanel.tsx): `features/weather/WeatherPanel.tsx`
- [Journey analytics](https://github.com/sonu-kr-pandit/yatrihan/blob/main/features/analytics/AnalyticsDashboard.tsx): `features/analytics/AnalyticsDashboard.tsx`
- [Terrain points](https://github.com/sonu-kr-pandit/yatrihan/blob/main/features/terrain/TerrainPanel.tsx): `features/terrain/TerrainPanel.tsx`

### Data services

- [Train search API](https://github.com/sonu-kr-pandit/yatrihan/blob/main/app/api/search/route.ts): `app/api/search/route.ts`
- [Local train catalog](https://github.com/sonu-kr-pandit/yatrihan/blob/main/lib/trains-db.ts): `lib/trains-db.ts`
- [Journey API](https://github.com/sonu-kr-pandit/yatrihan/blob/main/app/api/train/%5Bid%5D/route.ts): `app/api/train/[id]/route.ts`
- [RailRadar client](https://github.com/sonu-kr-pandit/yatrihan/blob/main/lib/railradar.ts): `lib/railradar.ts`
- [Response cache](https://github.com/sonu-kr-pandit/yatrihan/blob/main/lib/cache.ts): `lib/cache.ts`
- [Weather API](https://github.com/sonu-kr-pandit/yatrihan/blob/main/app/api/weather/route.ts): `app/api/weather/route.ts`
- [OpenWeather client](https://github.com/sonu-kr-pandit/yatrihan/blob/main/lib/openweather.ts): `lib/openweather.ts`
- [Analytics API](https://github.com/sonu-kr-pandit/yatrihan/blob/main/app/api/analytics/%5Bid%5D/route.ts): `app/api/analytics/[id]/route.ts`
- [Elevation client](https://github.com/sonu-kr-pandit/yatrihan/blob/main/lib/opentopography.ts): `lib/opentopography.ts`
- [Terrain API](https://github.com/sonu-kr-pandit/yatrihan/blob/main/app/api/terrain/route.ts): `app/api/terrain/route.ts`
- [Overpass client](https://github.com/sonu-kr-pandit/yatrihan/blob/main/lib/overpass.ts): `lib/overpass.ts`

### Client state

- [Favorites state](https://github.com/sonu-kr-pandit/yatrihan/blob/main/store/favorites.ts): `store/favorites.ts`
- [Recent searches](https://github.com/sonu-kr-pandit/yatrihan/blob/main/store/search.ts): `store/search.ts`
- [Journey preferences](https://github.com/sonu-kr-pandit/yatrihan/blob/main/store/journey.ts): `store/journey.ts`

### Other components

- **Passenger**
- **MapTiler tiles**

## Connections

- Passenger → Train search home: searches trains
- Train search home → Search query hook: queries (evidence: `app/page.tsx`)
- Search query hook → Train search API: fetches results (evidence: `hooks/useTrainSearch.ts`)
- Train search API → RailRadar client: searches trains (evidence: `app/api/search/route.ts`)
- Train search API → Local train catalog: falls back (evidence: `app/api/search/route.ts`)
- RailRadar client → Local train catalog: uses catalog (evidence: `lib/railradar.ts`)
- Search query hook → Local train catalog: loads instant matches (evidence: `hooks/useTrainSearch.ts`)
- Train search home → Recent searches: reads recent searches (evidence: `app/page.tsx`)
- Search query hook → Search results: supplies results (evidence: `components/search/SearchResults.tsx`)
- Passenger → Journey tracking page: opens train
- Journey tracking page → Live journey hook: loads journey (evidence: `app/train/[id]/page.tsx`)
- Live journey hook → Journey API: polls journey (evidence: `hooks/useLiveJourney.ts`)
- Journey API → RailRadar client: gets live journey (evidence: `app/api/train/[id]/route.ts`)
- Journey API → Response cache: reads and writes (evidence: `app/api/train/[id]/route.ts`)
- Journey tracking page → Journey preferences: uses refresh setting
- Journey tracking page → Live route map: renders map view (evidence: `app/train/[id]/page.tsx`)
- Live route map → MapTiler tiles: loads vector tiles
- Journey tracking page → Station timeline: renders route timeline (evidence: `app/train/[id]/page.tsx`)
- Journey tracking page → Station weather: renders weather view (evidence: `app/train/[id]/page.tsx`)
- Station weather → Weather API: requests station weather
- Weather API → OpenWeather client: gets weather (evidence: `app/api/weather/route.ts`)
- Weather API → Response cache: reads and writes (evidence: `app/api/weather/route.ts`)
- Journey tracking page → Journey analytics: renders analytics (evidence: `app/train/[id]/page.tsx`)
- Journey analytics → Analytics API: requests analytics
- Analytics API → RailRadar client: gets journey (evidence: `app/api/analytics/[id]/route.ts`)
- Analytics API → Elevation client: gets elevation profile (evidence: `app/api/analytics/[id]/route.ts`)
- Analytics API → Response cache: reads and writes (evidence: `app/api/analytics/[id]/route.ts`)
- Journey tracking page → Terrain points: renders terrain view (evidence: `app/train/[id]/page.tsx`)
- Terrain points → Terrain API: requests route points
- Terrain API → RailRadar client: gets journey route (evidence: `app/api/terrain/route.ts`)
- Terrain API → Overpass client: gets terrain features (evidence: `app/api/terrain/route.ts`)
- Terrain API → Response cache: reads and writes (evidence: `app/api/terrain/route.ts`)
- Saved trains page → Favorites state: loads saved trains (evidence: `app/favorites/page.tsx`)
- Saved trains page → Favorite control: renders controls (evidence: `app/favorites/page.tsx`)
- Journey tracking page → Favorite control: renders control (evidence: `app/train/[id]/page.tsx`)
- Favorite control → Favorites state: updates favorites
- Passenger → Shared journey page: opens shared journey
