# sameer10237/train-help architecture

> Architecture diagram of the GitHub repository sameer10237/train-help, 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/sameer10237/train-help
- Repository: https://github.com/sameer10237/train-help

## Overview

TravelRescue AI helps Indian railway passengers understand disruptions, compare recovery options, and continue managing trips even when offline. The main journey runs from passenger trip/recovery views through journey search and deterministic ranking to rebooking and refund tracking; a hybrid chat advisor supplies explanations and next steps. A separate simulation supports obstacle injection and tactical rerouting. The README documents these capabilities, while sampled source confirms selected API, simulation, persistence, and fallback calls; unsampled subsystem links are omitted where implementation wiring is not visible.

Main entry points: [`components/trips/trips-view.tsx`](https://github.com/sameer10237/train-help/blob/main/components/trips/trips-view.tsx) (Trip management), [`app/api/chat/route.ts`](https://github.com/sameer10237/train-help/blob/main/app/api/chat/route.ts) (Chat API), [`app/(app)/simulation/page.tsx`](https://github.com/sameer10237/train-help/blob/main/app/(app)/simulation/page.tsx) (Simulation workspace), [`components/recovery/recovery-centre-view.tsx`](https://github.com/sameer10237/train-help/blob/main/components/recovery/recovery-centre-view.tsx) (Disruption recovery)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_passenger["Passenger experience"]
  node_landing["Landing experience<br/>[page.tsx]"]
  node_auth["Authentication<br/>[auth-context.tsx]"]
  node_trips["Trip management<br/>[trips-view.tsx]"]
  node_preferences["Travel preferences<br/>[page.tsx]"]
  node_offlinequeue["Offline mutation queue<br/>[sync-queue.ts]"]
end

subgraph group_recovery["Recovery and journeys"]
  node_recoveryview["Disruption recovery"]
  node_journeyapi["Journey search API<br/>[route.ts]"]
  node_journeyengine["Journey engine<br/>[engine.ts]"]
  node_fares["Fare estimation<br/>[fares.ts]"]
  node_matching["Option ranking<br/>[matching.ts]"]
  node_booking["Booking calculation<br/>[booking-engine.ts]"]
  node_rebookapi["Rebooking API<br/>[route.ts]"]
  node_refunds["Refund tracking"]
end

subgraph group_assistant["AI assistance"]
  node_chatapi["Chat API<br/>[route.ts]"]
  node_providers["AI providers<br/>[providers.ts]"]
  node_fallback["Offline advisor"]
end

subgraph group_simulation["Disruption simulation"]
  node_simulationui["Simulation workspace<br/>[page.tsx]"]
  node_planner["Rerouting planner<br/>[planner.ts]"]
  node_obstacles["Obstacle modeling<br/>[obstacles.ts]"]
  node_obstacledialog["Obstacle controls"]
  node_scenarioapi["Scenario persistence API<br/>[route.ts]"]
  node_persistence["Scenario persistence<br/>[persistence.ts]"]
end

subgraph group_data["Data and resilience"]
  node_trains["Rail data repository"]
  node_supabase[("Supabase client<br/>[supabase-client.ts]")]
  node_snapshot[("Snapshot fallback")]
  node_state[("Local state storage<br/>[state-storage.ts]")]
  node_syncapi["Trip sync API<br/>[route.ts]"]
  node_ratelimit["Rate limiter<br/>[rate-limit.ts]"]
end

node_traveler(("Passenger"))

node_traveler -->|"opens app"| node_landing
node_traveler -->|"reviews disruption"| node_recoveryview
node_traveler -->|"sets preferences"| node_preferences
node_traveler -->|"manages trips"| node_trips
node_recoveryview -.->|"requests alternatives"| node_journeyapi
node_journeyapi -->|"searches journeys"| node_journeyengine
node_journeyengine -->|"calculates fares"| node_fares
node_preferences -->|"ranks options"| node_matching
node_recoveryview -->|"compares alternatives"| node_matching
node_trips -->|"requests rebooking"| node_rebookapi
node_rebookapi -->|"checks limits"| node_ratelimit
node_rebookapi -->|"records rebooking"| node_trips
node_trips -->|"tracks refunds"| node_refunds
node_traveler -->|"asks advisor"| node_chatapi
node_chatapi -->|"checks limits"| node_ratelimit
node_chatapi -.->|"requests AI advice"| node_providers
node_chatapi -->|"uses fallback"| node_fallback
node_traveler -->|"runs simulation"| node_simulationui
node_simulationui -->|"generates plans"| node_planner
node_simulationui -->|"configures obstacles"| node_obstacledialog
node_obstacledialog -->|"models obstacles"| node_obstacles
node_simulationui -.->|"saves scenarios"| node_scenarioapi
node_scenarioapi -->|"persists scenarios"| node_persistence
node_trains -->|"reads railway data"| node_supabase
node_trains -->|"falls back to snapshot"| node_snapshot
node_trips -->|"queues mutations"| node_offlinequeue
node_offlinequeue -->|"replays mutations"| node_syncapi
node_syncapi -->|"checks limits"| node_ratelimit
node_traveler -->|"retains local state"| node_state

click node_landing "https://github.com/sameer10237/train-help/blob/main/app/page.tsx"
click node_auth "https://github.com/sameer10237/train-help/blob/main/context/auth-context.tsx"
click node_trips "https://github.com/sameer10237/train-help/blob/main/components/trips/trips-view.tsx"
click node_preferences "https://github.com/sameer10237/train-help/blob/main/app/(app)/preferences/page.tsx"
click node_offlinequeue "https://github.com/sameer10237/train-help/blob/main/lib/data/sync-queue.ts"
click node_recoveryview "https://github.com/sameer10237/train-help/blob/main/components/recovery/recovery-centre-view.tsx"
click node_journeyapi "https://github.com/sameer10237/train-help/blob/main/app/api/journeys/route.ts"
click node_journeyengine "https://github.com/sameer10237/train-help/blob/main/lib/journeys/engine.ts"
click node_fares "https://github.com/sameer10237/train-help/blob/main/lib/journeys/fares.ts"
click node_matching "https://github.com/sameer10237/train-help/blob/main/lib/matching.ts"
click node_booking "https://github.com/sameer10237/train-help/blob/main/lib/booking/booking-engine.ts"
click node_rebookapi "https://github.com/sameer10237/train-help/blob/main/app/api/rebook/route.ts"
click node_refunds "https://github.com/sameer10237/train-help/blob/main/components/trips/refund-tracker-card.tsx"
click node_chatapi "https://github.com/sameer10237/train-help/blob/main/app/api/chat/route.ts"
click node_providers "https://github.com/sameer10237/train-help/blob/main/lib/ai/providers.ts"
click node_fallback "https://github.com/sameer10237/train-help/blob/main/lib/ai/fallback-advisor.ts"
click node_simulationui "https://github.com/sameer10237/train-help/blob/main/app/(app)/simulation/page.tsx"
click node_planner "https://github.com/sameer10237/train-help/blob/main/lib/sim/planner.ts"
click node_obstacles "https://github.com/sameer10237/train-help/blob/main/lib/sim/obstacles.ts"
click node_obstacledialog "https://github.com/sameer10237/train-help/blob/main/components/sim/obstacle-dialog.tsx"
click node_scenarioapi "https://github.com/sameer10237/train-help/blob/main/app/api/sim/scenarios/route.ts"
click node_persistence "https://github.com/sameer10237/train-help/blob/main/lib/sim/persistence.ts"
click node_trains "https://github.com/sameer10237/train-help/blob/main/lib/data/train-repository.ts"
click node_supabase "https://github.com/sameer10237/train-help/blob/main/lib/data/supabase-client.ts"
click node_snapshot "https://github.com/sameer10237/train-help/blob/main/lib/data/snapshot-fallback.ts"
click node_state "https://github.com/sameer10237/train-help/blob/main/context/state-storage.ts"
click node_syncapi "https://github.com/sameer10237/train-help/blob/main/app/api/trips/sync/route.ts"
click node_ratelimit "https://github.com/sameer10237/train-help/blob/main/lib/rate-limit.ts"

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_landing,node_auth,node_trips,node_preferences,node_offlinequeue toneBlue
class node_recoveryview,node_journeyapi,node_journeyengine,node_fares,node_matching,node_booking,node_rebookapi,node_refunds toneAmber
class node_chatapi,node_providers,node_fallback toneMint
class node_simulationui,node_planner,node_obstacles,node_obstacledialog,node_scenarioapi,node_persistence toneRose
class node_trains,node_supabase,node_snapshot,node_state,node_syncapi,node_ratelimit,node_traveler toneIndigo
```

## Components

### Passenger experience

- [Landing experience](https://github.com/sameer10237/train-help/blob/main/app/page.tsx): `app/page.tsx`
- [Authentication](https://github.com/sameer10237/train-help/blob/main/context/auth-context.tsx): `context/auth-context.tsx`
- [Trip management](https://github.com/sameer10237/train-help/blob/main/components/trips/trips-view.tsx): `components/trips/trips-view.tsx`
- [Travel preferences](https://github.com/sameer10237/train-help/blob/main/app/(app)/preferences/page.tsx): `app/(app)/preferences/page.tsx`
- [Offline mutation queue](https://github.com/sameer10237/train-help/blob/main/lib/data/sync-queue.ts): `lib/data/sync-queue.ts`

### Recovery and journeys

- [Disruption recovery](https://github.com/sameer10237/train-help/blob/main/components/recovery/recovery-centre-view.tsx): `components/recovery/recovery-centre-view.tsx`
- [Journey search API](https://github.com/sameer10237/train-help/blob/main/app/api/journeys/route.ts): `app/api/journeys/route.ts`
- [Journey engine](https://github.com/sameer10237/train-help/blob/main/lib/journeys/engine.ts): `lib/journeys/engine.ts`
- [Fare estimation](https://github.com/sameer10237/train-help/blob/main/lib/journeys/fares.ts): `lib/journeys/fares.ts`
- [Option ranking](https://github.com/sameer10237/train-help/blob/main/lib/matching.ts): `lib/matching.ts`
- [Booking calculation](https://github.com/sameer10237/train-help/blob/main/lib/booking/booking-engine.ts): `lib/booking/booking-engine.ts`
- [Rebooking API](https://github.com/sameer10237/train-help/blob/main/app/api/rebook/route.ts): `app/api/rebook/route.ts`
- [Refund tracking](https://github.com/sameer10237/train-help/blob/main/components/trips/refund-tracker-card.tsx): `components/trips/refund-tracker-card.tsx`

### AI assistance

- [Chat API](https://github.com/sameer10237/train-help/blob/main/app/api/chat/route.ts): `app/api/chat/route.ts`
- [AI providers](https://github.com/sameer10237/train-help/blob/main/lib/ai/providers.ts): `lib/ai/providers.ts`
- [Offline advisor](https://github.com/sameer10237/train-help/blob/main/lib/ai/fallback-advisor.ts): `lib/ai/fallback-advisor.ts`

### Disruption simulation

- [Simulation workspace](https://github.com/sameer10237/train-help/blob/main/app/(app)/simulation/page.tsx): `app/(app)/simulation/page.tsx`
- [Rerouting planner](https://github.com/sameer10237/train-help/blob/main/lib/sim/planner.ts): `lib/sim/planner.ts`
- [Obstacle modeling](https://github.com/sameer10237/train-help/blob/main/lib/sim/obstacles.ts): `lib/sim/obstacles.ts`
- [Obstacle controls](https://github.com/sameer10237/train-help/blob/main/components/sim/obstacle-dialog.tsx): `components/sim/obstacle-dialog.tsx`
- [Scenario persistence API](https://github.com/sameer10237/train-help/blob/main/app/api/sim/scenarios/route.ts): `app/api/sim/scenarios/route.ts`
- [Scenario persistence](https://github.com/sameer10237/train-help/blob/main/lib/sim/persistence.ts): `lib/sim/persistence.ts`

### Data and resilience

- [Rail data repository](https://github.com/sameer10237/train-help/blob/main/lib/data/train-repository.ts): `lib/data/train-repository.ts`
- [Supabase client](https://github.com/sameer10237/train-help/blob/main/lib/data/supabase-client.ts): `lib/data/supabase-client.ts`
- [Snapshot fallback](https://github.com/sameer10237/train-help/blob/main/lib/data/snapshot-fallback.ts): `lib/data/snapshot-fallback.ts`
- [Local state storage](https://github.com/sameer10237/train-help/blob/main/context/state-storage.ts): `context/state-storage.ts`
- [Trip sync API](https://github.com/sameer10237/train-help/blob/main/app/api/trips/sync/route.ts): `app/api/trips/sync/route.ts`
- [Rate limiter](https://github.com/sameer10237/train-help/blob/main/lib/rate-limit.ts): `lib/rate-limit.ts`

### Other components

- **Passenger**

## Connections

- Passenger → Landing experience: opens app (evidence: `app/page.tsx`)
- Passenger → Disruption recovery: reviews disruption
- Passenger → Travel preferences: sets preferences
- Passenger → Trip management: manages trips
- Disruption recovery → Journey search API: requests alternatives
- Journey search API → Journey engine: searches journeys (evidence: `app/api/journeys/route.ts`)
- Journey engine → Fare estimation: calculates fares (evidence: `lib/journeys/engine.ts`)
- Travel preferences → Option ranking: ranks options
- Disruption recovery → Option ranking: compares alternatives
- Trip management → Rebooking API: requests rebooking
- Rebooking API → Rate limiter: checks limits (evidence: `app/api/rebook/route.ts`)
- Rebooking API → Trip management: records rebooking (evidence: `app/api/rebook/route.ts`)
- Trip management → Refund tracking: tracks refunds
- Passenger → Chat API: asks advisor
- Chat API → Rate limiter: checks limits (evidence: `app/api/chat/route.ts`)
- Chat API → AI providers: requests AI advice (evidence: `app/api/chat/route.ts`)
- Chat API → Offline advisor: uses fallback (evidence: `app/api/chat/route.ts`)
- Passenger → Simulation workspace: runs simulation
- Simulation workspace → Rerouting planner: generates plans (evidence: `app/(app)/simulation/page.tsx`)
- Simulation workspace → Obstacle controls: configures obstacles (evidence: `app/(app)/simulation/page.tsx`)
- Obstacle controls → Obstacle modeling: models obstacles (evidence: `components/sim/obstacle-dialog.tsx`)
- Simulation workspace → Scenario persistence API: saves scenarios
- Scenario persistence API → Scenario persistence: persists scenarios (evidence: `app/api/sim/scenarios/route.ts`)
- Rail data repository → Supabase client: reads railway data (evidence: `lib/data/train-repository.ts`)
- Rail data repository → Snapshot fallback: falls back to snapshot (evidence: `lib/data/train-repository.ts`)
- Trip management → Offline mutation queue: queues mutations
- Offline mutation queue → Trip sync API: replays mutations (evidence: `app/api/trips/sync/route.ts`)
- Trip sync API → Rate limiter: checks limits (evidence: `app/api/trips/sync/route.ts`)
- Passenger → Local state storage: retains local state
