# gdeep01/bindaas-blr architecture

> Architecture diagram of the GitHub repository gdeep01/bindaas-blr, 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/gdeep01/bindaas-blr
- Repository: https://github.com/gdeep01/bindaas-blr

## Overview

1. **High-level shape**
   - This is a **React 18 + TypeScript + Vite single-page application** deployed on **Vercel**, with **Supabase** serving as the backend database/auth/function layer.
   - The app is organized around city intel use cases for Bengaluru: traffic, commute planning, livability/mood, garbage reporting, landslide alerts, and AI-generated insights.

2. **Frontend shell and routing**
   - `src/main.tsx` bootstraps the app, `src/App.tsx` wires the top-level layout and routes, and `src/pages/*` contains the page-level screens.
   - Pages are feature-oriented rather than generic: `DashboardPage`, `CommutePage`, `MapPage`, `GarbagePage`, `LandslidePage`, `MoodIndexPage`, `AIInsightsPage`, plus auth callback and “my reports” flows.

3. **Presentation layer vs shared UI**
   - The UI is split into reusable primitives in `src/components/ui` and feature widgets in `src/components/*`.
   - Larger feature clusters exist for specific domains: `dashboard/`, `mood/`, and `garbage/`, which suggests the app composes many small cards/panels rather than a monolithic screen.
   - Map-related screens use `TrafficMap`, `TrafficMapInner`, `MapSearchBox`, and location-centric cards for hotspots, stations, and insights.

4. **Client-side state and data access**
   - Cross-cutting client state is handled with React contexts and hooks, especially `TrafficDataContext`.
   - Data access is mostly via custom hooks in `src/hooks`, such as auth/profile handling, notifications, install prompt, theme, locality metrics, route timing, and route reliability.
   - This keeps pages thin: they orchestrate UI and rely on hooks for computed data or API-backed state.

5. **Backend boundary: Supabase is the main server**
   - The only explicit backend integration in the frontend is `src/integrations/supabase/client.ts`.
   - Supabase provides authentication, Postgres storage, and serverless/edge execution; there is no separate custom Node backend in this repo.
   - Auth flows are visible in `AuthModal`, `AuthCallbackPage`, `useAuth`, `useProfile`, and edge functions like `on-user-created` and `update-display-name`.

6. **Data pipeline for traffic**
   - Traffic is the core real-time pipeline: **TomTom Traffic API → `traffic-scheduler` edge function → Supabase tables (`traffic_history` and related cached state) → frontend dashboards/maps**.
   - The frontend consumes prepared data rather than calling TomTom directly on every render.
   - `src/lib/trafficApi.ts`, `trafficHistory.ts`, `mapConstants.ts`, and `TrafficDataContext` are the client-side pieces that shape and consume this data.

7. **AI insights pipeline**
   - AI-generated traffic predictions are not computed in the browser; they are produced server-side by the `traffic-insights` Supabase function.
   - The README indicates **Gemini 1.5 Flash** reads the latest traffic snapshot, generates structured predictions, and stores them in Supabase for the frontend to read as a cache.
   - This is an important architectural boundary: expensive inference is decoupled from page loads.

8. **Batch/cron-driven data refresh**
   - Several Supabase migrations point to a scheduled-data architecture: `centralized_data_scheduler`, reduced scheduler frequency, and security/data integrity hardening.
   - The repo’s cron setup refreshes traffic periodically, and additional edge functions update livability scores and other derived datasets.
   - In other words, much of the app’s “live” feel comes from **scheduled ingestion and precomputation**, not real-time socket streaming.

9. **Domain subsystems**
   - **Commute planning:** route timing and reliability logic lives in `src/lib/commute.ts` and `src/lib/routeTiming.ts`, backed by a large historical `route_reliability` dataset.
   - **Livability / mood:** the `mood` feature set combines area scoring, comparisons, and metric bars using static datasets and hooks like `useLocalityMetrics` and `useLocalityScoreTrends`.
   - **Garbage reporting:** user-submitted reports combine photo upload, location capture, moderation/upvote flows, and official hotspot data.
   - **Disaster alerts:** landslide risk and natural-event data are surfaced via `landslide-predictions`, plus external feeds for earthquakes and events.

10. **Static data and derived analytics**
    - `src/data/*` contains bundled datasets for Bengaluru metro stations, property prices, garbage data, mood data, and traffic data.
    - These datasets feed visualizations and computed scores such as livability, property growth, and station/proximity-based metrics.
    - The app appears to mix **static reference datasets** with **fresh backend-fed operational data**, which is a key diagram boundary.

11. **Offline and installability**
    - The presence of `public/manifest.json`, `public/sw.js`, and `public/offline.html` indicates this is a **PWA-capable app**.
    - `useInstallPrompt` and `InstallPromptBanner` show that install UX is built into the frontend.
    - This matters architecturally because the app supports offline fallback and install prompts, not just standard SPA navigation.

12. **Notifications and user engagement**
    - `useNotifications` and `NotificationsPanel` suggest a user-facing notification subsystem, likely tied to Supabase-backed events or app-level alerts.
    - This is a secondary but important flow alongside auth and reporting, especially for civic alerts and updates.

13. **Maps and geospatial interaction**
    - Mapping is a major UI boundary, implemented with Leaflet and clustering support.
    - Several screens and widgets are geospatial: traffic corridors/hotspots, garbage reports, airport stations, and likely locality comparisons on map layers.
    - The map layer acts as the common visualization surface for many otherwise separate data products.

14. **Operational concerns and quality**
    - `supabase/migrations` and `supabase/sql` show the schema and scheduled-job logic are versioned alongside the app, which is important for diagramming deployment dependencies.
    - Tests exist for core computation in `src/lib/__tests__` and a Vitest setup in `src/test/setup.ts`, indicating the numeric/route-planning logic is treated as a stable computation layer.
    - Vercel handles SPA hosting and rewrite routing, while Supabase hosts the backend runtime and persistent state.

15. **Architectural summary**
    - The repo is best drawn as a **client-heavy civic intelligence SPA** with:
      - a React presentation layer,
      - a Supabase-backed data and auth layer,
      - scheduled ingestion/AI edge functions,
      - static reference datasets,
      - and PWA/offline capabilities.
    - The central design pattern is **precompute and cache on the backend, render and compare on the frontend**.

Main entry points: [`src/pages`](https://github.com/gdeep01/bindaas-blr/tree/main/src/pages) (Pages), [`supabase/functions`](https://github.com/gdeep01/bindaas-blr/tree/main/supabase/functions) (Edge functions), [`src/components`](https://github.com/gdeep01/bindaas-blr/tree/main/src/components) (Feature widgets), [`src/data`](https://github.com/gdeep01/bindaas-blr/tree/main/src/data) (Static data)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend app"]
  node_main(("Boot<br/>entrypoint<br/>[main.tsx]"))
  node_app["App shell<br/>router/layout<br/>[App.tsx]"]
  node_layout["Layout<br/>shell<br/>[AppLayout.tsx]"]
  node_pages["Pages<br/>screen set"]
  node_dashboard["Dashboard<br/>summary page<br/>[DashboardPage.tsx]"]
  node_map["Map<br/>geospatial page<br/>[MapPage.tsx]"]
  node_commute["Commute<br/>planning page<br/>[CommutePage.tsx]"]
  node_garbage["Garbage<br/>reporting page<br/>[GarbagePage.tsx]"]
  node_mood["Mood index<br/>livability page<br/>[MoodIndexPage.tsx]"]
  node_landslide["Landslide<br/>alert page<br/>[LandslidePage.tsx]"]
  node_ai["AI insights<br/>insight page<br/>[AIInsightsPage.tsx]"]
  node_trafficctx["Traffic context<br/>client state"]
  node_hooks["Hooks<br/>client logic"]
  node_ui["UI kit<br/>shared components"]
  node_featurewidgets["Feature widgets<br/>feature components"]
end

subgraph group_backend["Supabase backend"]
  node_supaclient["Supabase client<br/>backend client<br/>[client.ts]"]
  node_functions["Edge functions<br/>serverless"]
  node_scheduler["Traffic scheduler<br/>cron function<br/>[index.ts]"]
  node_insightsfn["Traffic insights<br/>ai function<br/>[index.ts]"]
  node_reportsfn["Civic reports<br/>reports api<br/>[index.ts]"]
  node_upvotefn["Garbage upvote<br/>moderation api<br/>[index.ts]"]
  node_landslidefn["Landslide predictions<br/>alert api<br/>[index.ts]"]
  node_livabilityfn["Livability refresh<br/>batch function<br/>[index.ts]"]
  node_migrations["Schema & jobs<br/>database migrations"]
end

subgraph group_data["Data layer"]
  node_datafiles["Static data<br/>bundled datasets"]
  node_trafficlib["Traffic lib<br/>traffic analytics<br/>[trafficApi.ts]"]
  node_commutelib["Commute logic<br/>route analytics<br/>[commute.ts]"]
  node_landslideapi["Landslide API<br/>external feed adapter<br/>[landslideApi.ts]"]
end

node_main -->|"bootstraps"| node_app
node_app -->|"uses"| node_layout
node_app -->|"routes to"| node_pages
node_pages -->|"includes"| node_dashboard
node_pages -->|"includes"| node_map
node_pages -->|"includes"| node_commute
node_pages -->|"includes"| node_garbage
node_pages -->|"includes"| node_mood
node_pages -->|"includes"| node_landslide
node_pages -->|"includes"| node_ai
node_dashboard -->|"composes"| node_featurewidgets
node_map -->|"reads"| node_trafficctx
node_map -->|"uses"| node_featurewidgets
node_commute -->|"computes with"| node_commutelib
node_garbage -->|"composes"| node_featurewidgets
node_mood -->|"composes"| node_featurewidgets
node_landslide -->|"reads"| node_landslideapi
node_ai -->|"reads"| node_insightsfn
node_hooks -->|"calls"| node_supaclient
node_supaclient -->|"invokes"| node_functions
node_functions -->|"contains"| node_scheduler
node_functions -->|"contains"| node_insightsfn
node_functions -->|"contains"| node_reportsfn
node_functions -->|"contains"| node_upvotefn
node_functions -->|"contains"| node_landslidefn
node_functions -->|"contains"| node_livabilityfn
node_scheduler -->|"refreshes"| node_trafficlib
node_insightsfn -->|"analyzes"| node_trafficlib
node_migrations -->|"defines"| node_scheduler
node_migrations -->|"supports"| node_reportsfn
node_datafiles -->|"feeds"| node_dashboard
node_datafiles -->|"feeds"| node_mood
node_datafiles -->|"feeds"| node_commutelib
node_datafiles -->|"feeds"| node_trafficlib
node_trafficctx -->|"derives from"| node_trafficlib
node_featurewidgets -->|"built on"| node_ui

click node_main "https://github.com/gdeep01/bindaas-blr/blob/main/src/main.tsx"
click node_app "https://github.com/gdeep01/bindaas-blr/blob/main/src/App.tsx"
click node_layout "https://github.com/gdeep01/bindaas-blr/blob/main/src/components/AppLayout.tsx"
click node_pages "https://github.com/gdeep01/bindaas-blr/tree/main/src/pages"
click node_dashboard "https://github.com/gdeep01/bindaas-blr/blob/main/src/pages/DashboardPage.tsx"
click node_map "https://github.com/gdeep01/bindaas-blr/blob/main/src/pages/MapPage.tsx"
click node_commute "https://github.com/gdeep01/bindaas-blr/blob/main/src/pages/CommutePage.tsx"
click node_garbage "https://github.com/gdeep01/bindaas-blr/blob/main/src/pages/GarbagePage.tsx"
click node_mood "https://github.com/gdeep01/bindaas-blr/blob/main/src/pages/MoodIndexPage.tsx"
click node_landslide "https://github.com/gdeep01/bindaas-blr/blob/main/src/pages/LandslidePage.tsx"
click node_ai "https://github.com/gdeep01/bindaas-blr/blob/main/src/pages/AIInsightsPage.tsx"
click node_trafficctx "https://github.com/gdeep01/bindaas-blr/blob/main/src/contexts/TrafficDataContext.tsx"
click node_hooks "https://github.com/gdeep01/bindaas-blr/tree/main/src/hooks"
click node_ui "https://github.com/gdeep01/bindaas-blr/tree/main/src/components/ui"
click node_featurewidgets "https://github.com/gdeep01/bindaas-blr/tree/main/src/components"
click node_supaclient "https://github.com/gdeep01/bindaas-blr/blob/main/src/integrations/supabase/client.ts"
click node_functions "https://github.com/gdeep01/bindaas-blr/tree/main/supabase/functions"
click node_scheduler "https://github.com/gdeep01/bindaas-blr/blob/main/supabase/functions/traffic-scheduler/index.ts"
click node_insightsfn "https://github.com/gdeep01/bindaas-blr/blob/main/supabase/functions/traffic-insights/index.ts"
click node_reportsfn "https://github.com/gdeep01/bindaas-blr/blob/main/supabase/functions/civic-reports/index.ts"
click node_upvotefn "https://github.com/gdeep01/bindaas-blr/blob/main/supabase/functions/garbage-upvote/index.ts"
click node_landslidefn "https://github.com/gdeep01/bindaas-blr/blob/main/supabase/functions/landslide-predictions/index.ts"
click node_livabilityfn "https://github.com/gdeep01/bindaas-blr/blob/main/supabase/functions/update-livability-scores/index.ts"
click node_migrations "https://github.com/gdeep01/bindaas-blr/tree/main/supabase/migrations"
click node_datafiles "https://github.com/gdeep01/bindaas-blr/tree/main/src/data"
click node_trafficlib "https://github.com/gdeep01/bindaas-blr/blob/main/src/lib/trafficApi.ts"
click node_commutelib "https://github.com/gdeep01/bindaas-blr/blob/main/src/lib/commute.ts"
click node_landslideapi "https://github.com/gdeep01/bindaas-blr/blob/main/src/lib/landslideApi.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_main,node_app,node_layout,node_pages,node_dashboard,node_map,node_commute,node_garbage,node_mood,node_landslide,node_ai,node_trafficctx,node_hooks,node_ui,node_featurewidgets toneBlue
class node_supaclient,node_functions,node_scheduler,node_insightsfn,node_reportsfn,node_upvotefn,node_landslidefn,node_livabilityfn,node_migrations toneAmber
class node_datafiles,node_trafficlib,node_commutelib,node_landslideapi toneMint
```

## Components

### Frontend app

React SPA shell, pages, and UI composition

- [Boot](https://github.com/gdeep01/bindaas-blr/blob/main/src/main.tsx): entrypoint · Starts the React app · `src/main.tsx`
- [App shell](https://github.com/gdeep01/bindaas-blr/blob/main/src/App.tsx): router/layout · Top-level routing and layout composition · `src/App.tsx`
- [Layout](https://github.com/gdeep01/bindaas-blr/blob/main/src/components/AppLayout.tsx): shell · Shared app chrome and navigation · `src/components/AppLayout.tsx`
- [Pages](https://github.com/gdeep01/bindaas-blr/tree/main/src/pages): screen set · Feature-oriented screens for dashboard, map, commute, alerts, and reports · `src/pages`
- [Dashboard](https://github.com/gdeep01/bindaas-blr/blob/main/src/pages/DashboardPage.tsx): summary page · Main civic intelligence overview · `src/pages/DashboardPage.tsx`
- [Map](https://github.com/gdeep01/bindaas-blr/blob/main/src/pages/MapPage.tsx): geospatial page · Traffic and locality map experience · `src/pages/MapPage.tsx`
- [Commute](https://github.com/gdeep01/bindaas-blr/blob/main/src/pages/CommutePage.tsx): planning page · Route timing and reliability views · `src/pages/CommutePage.tsx`
- [Garbage](https://github.com/gdeep01/bindaas-blr/blob/main/src/pages/GarbagePage.tsx): reporting page · Waste reporting and moderation flows · `src/pages/GarbagePage.tsx`
- [Mood index](https://github.com/gdeep01/bindaas-blr/blob/main/src/pages/MoodIndexPage.tsx): livability page · Area comparisons and livability scoring · `src/pages/MoodIndexPage.tsx`
- [Landslide](https://github.com/gdeep01/bindaas-blr/blob/main/src/pages/LandslidePage.tsx): alert page · Disaster risk and alert views · `src/pages/LandslidePage.tsx`
- [AI insights](https://github.com/gdeep01/bindaas-blr/blob/main/src/pages/AIInsightsPage.tsx): insight page · Traffic prediction and AI-generated analysis · `src/pages/AIInsightsPage.tsx`
- [Traffic context](https://github.com/gdeep01/bindaas-blr/blob/main/src/contexts/TrafficDataContext.tsx): client state · Shared traffic state and prepared data for the UI · `src/contexts/TrafficDataContext.tsx`
- [Hooks](https://github.com/gdeep01/bindaas-blr/tree/main/src/hooks): client logic · Auth, profile, notifications, install prompt, theme, and route metrics · `src/hooks`
- [UI kit](https://github.com/gdeep01/bindaas-blr/tree/main/src/components/ui): shared components · Reusable primitives and base widgets · `src/components/ui`
- [Feature widgets](https://github.com/gdeep01/bindaas-blr/tree/main/src/components): feature components · Dashboard, map, mood, garbage, and alert panels · `src/components`

### Supabase backend

Auth, storage, scheduled functions, and schema

- [Supabase client](https://github.com/gdeep01/bindaas-blr/blob/main/src/integrations/supabase/client.ts): backend client · Frontend connection point to Supabase · `src/integrations/supabase/client.ts`
- [Edge functions](https://github.com/gdeep01/bindaas-blr/tree/main/supabase/functions): serverless · Scheduled jobs, auth hooks, and civic APIs · `supabase/functions`
- [Traffic scheduler](https://github.com/gdeep01/bindaas-blr/blob/main/supabase/functions/traffic-scheduler/index.ts): cron function · Fetches and refreshes traffic snapshots · `supabase/functions/traffic-scheduler/index.ts`
- [Traffic insights](https://github.com/gdeep01/bindaas-blr/blob/main/supabase/functions/traffic-insights/index.ts): ai function · Generates structured predictions from recent traffic state · `supabase/functions/traffic-insights/index.ts`
- [Civic reports](https://github.com/gdeep01/bindaas-blr/blob/main/supabase/functions/civic-reports/index.ts): reports api · Creates and manages civic report records · `supabase/functions/civic-reports/index.ts`
- [Garbage upvote](https://github.com/gdeep01/bindaas-blr/blob/main/supabase/functions/garbage-upvote/index.ts): moderation api · Handles report upvotes and moderation signals · `supabase/functions/garbage-upvote/index.ts`
- [Landslide predictions](https://github.com/gdeep01/bindaas-blr/blob/main/supabase/functions/landslide-predictions/index.ts): alert api · Produces landslide risk outputs · `supabase/functions/landslide-predictions/index.ts`
- [Livability refresh](https://github.com/gdeep01/bindaas-blr/blob/main/supabase/functions/update-livability-scores/index.ts): batch function · Updates derived locality scores · `supabase/functions/update-livability-scores/index.ts`
- [Schema & jobs](https://github.com/gdeep01/bindaas-blr/tree/main/supabase/migrations): database migrations · Versioned database schema, security, and scheduler changes · `supabase/migrations`

### Data layer

Static datasets and derived analytics consumed by the app

- [Static data](https://github.com/gdeep01/bindaas-blr/tree/main/src/data): bundled datasets · Metro stations, prices, garbage, mood, and traffic seed data · `src/data`
- [Traffic lib](https://github.com/gdeep01/bindaas-blr/blob/main/src/lib/trafficApi.ts): traffic analytics · Traffic API, history, constants, and map shaping logic · `src/lib/trafficApi.ts`
- [Commute logic](https://github.com/gdeep01/bindaas-blr/blob/main/src/lib/commute.ts): route analytics · Route timing, commute comparison, and reliability calculations · `src/lib/commute.ts`
- [Landslide API](https://github.com/gdeep01/bindaas-blr/blob/main/src/lib/landslideApi.ts): external feed adapter · External geospatial and event feed integration · `src/lib/landslideApi.ts`

## Connections

- Boot → App shell: bootstraps · React entry mounts the app shell
- App shell → Layout: uses · Routes are rendered within shared chrome
- App shell → Pages: routes to · Top-level navigation reaches feature pages
- Pages → Dashboard: includes · Dashboard route
- Pages → Map: includes · Map route
- Pages → Commute: includes · Commute route
- Pages → Garbage: includes · Garbage route
- Pages → Mood index: includes · Mood route
- Pages → Landslide: includes · Landslide route
- Pages → AI insights: includes · AI insights route
- Dashboard → Feature widgets: composes · Dashboard is assembled from feature panels
- Map → Traffic context: reads · Map and traffic screens consume shared traffic state
- Map → Feature widgets: uses · Map screens use search, hotspots, stations, and insight cards
- Commute → Commute logic: computes with · Route planning uses timing and reliability logic
- Garbage → Feature widgets: composes · Report form and related panels
- Mood index → Feature widgets: composes · Livability comparison panels and bars
- Landslide → Landslide API: reads · Surface alerts and predictions from external feeds
- AI insights → Traffic insights: reads · AI page consumes stored predictions
- Hooks → Supabase client: calls · Auth, profile, notifications, and data hooks use Supabase
- Supabase client → Edge functions: invokes · Frontend reaches serverless endpoints through Supabase
- Edge functions → Traffic scheduler: contains · Traffic refresh job
- Edge functions → Traffic insights: contains · AI prediction job
- Edge functions → Civic reports: contains · Civic reporting API
- Edge functions → Garbage upvote: contains · Report voting/moderation API
- Edge functions → Landslide predictions: contains · Risk prediction API
- Edge functions → Livability refresh: contains · Derived score refresh job
- Traffic scheduler → Traffic lib: refreshes · Uses traffic API and history shaping
- Traffic insights → Traffic lib: analyzes · Builds predictions from current traffic snapshot
- Schema & jobs → Traffic scheduler: defines · Schema and cron coordination for scheduled refreshes
- Schema & jobs → Civic reports: supports · Database changes for civic reports and moderation
- Static data → Dashboard: feeds · Static datasets power summary views
- Static data → Mood index: feeds · Reference and scoring data for livability views
- Static data → Commute logic: feeds · Historical and reference data for route analysis
- Static data → Traffic lib: feeds · Seed and reference traffic data
- Traffic context → Traffic lib: derives from · Context shapes prepared traffic state
- Feature widgets → UI kit: built on · Feature components rely on shared primitives
