# r-samarth/chargewise architecture

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

- Interactive diagram: https://gitdiagram.com/r-samarth/chargewise
- Repository: https://github.com/r-samarth/chargewise

## Overview

ChargeWise helps Karnataka EV drivers discover charging stations and plan trips with verified station data, vehicle-specific energy estimates, and route-aware charging stops. The workflow runs from user sign-in and vehicle selection through station discovery or trip planning, then returns a route and saved-trip options. Admin data verification/import, analytics, notifications, and user/vehicle management are additional product branches. The source excerpts show the API entry point, trip orchestration, station service/repository, and frontend API/auth flow; other subsystem links rely on the README or source-index references, so unsampled details are not expanded.

Main entry points: [`backend/app/main.py`](https://github.com/r-samarth/chargewise/blob/main/backend/app/main.py) (FastAPI entry and router), [`backend/app/repositories/station_repo.py`](https://github.com/r-samarth/chargewise/blob/main/backend/app/repositories/station_repo.py) (Spatial station queries), [`frontend/src/App.tsx`](https://github.com/r-samarth/chargewise/blob/main/frontend/src/App.tsx) (React app routes), [`frontend/src/lib/api.ts`](https://github.com/r-samarth/chargewise/blob/main/frontend/src/lib/api.ts) (API client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Driver web app"]
  node_app["React app routes<br/>[App.tsx]"]
  node_authui["Auth context<br/>[AuthContext.tsx]"]
  node_vehicleui["Vehicle management<br/>[VehiclesPage.tsx]"]
  node_stationui["Station discovery"]
  node_plannerui["Trip planner and results"]
  node_tripstore["Trip state<br/>[tripStore.ts]"]
  node_api_client["API client<br/>[api.ts]"]
end

subgraph group_api["API and identity"]
  node_backend["FastAPI entry and router<br/>[main.py]"]
  node_user_api["User and vehicle APIs<br/>[users.py]"]
  node_station_api["Station API<br/>[stations.py]"]
  node_trip_api["Trip API<br/>[trips.py]"]
  node_admin_api["Admin API<br/>[admin.py]"]
  node_analytics_api["Analytics API<br/>[analytics.py]"]
  node_notifications_api["Notifications API<br/>[notifications.py]"]
  node_firebase_auth{{"Firebase Authentication"}}
end

subgraph group_planning["Trip intelligence"]
  node_trip_service["Trip orchestration<br/>[trip_service.py]"]
  node_planner["Charging-stop planner<br/>[planner.py]"]
  node_compatibility["Connector compatibility<br/>[compatibility.py]"]
  node_energy["Energy estimation<br/>[energy.py]"]
  node_osrm{{"Driving route service<br/>[osrm.py]"}}
  node_elevation{{"Elevation data<br/>[elevation.py]"}}
end

subgraph group_stations["Station data"]
  node_station_service["Station discovery service<br/>[station_service.py]"]
  node_station_repo["Spatial station queries<br/>[station_repo.py]"]
  node_station_model["Station and connector records<br/>[station.py]"]
  node_amenity_model["Amenity records<br/>[amenity.py]"]
  node_operator_model["Operator records<br/>[operator.py]"]
  node_admin_service["Station administration<br/>[admin_service.py]"]
  node_osm["OpenStreetMap data<br/>[osm_parser.py]"]
end

subgraph group_persistence["Persistence and integrations"]
  node_postgres[("PostgreSQL and PostGIS")]
  node_db_session["Database session<br/>[session.py]"]
  node_base_model["ORM base<br/>[base.py]"]
  node_user_model["User records<br/>[user.py]"]
  node_vehicle_model["Vehicle records<br/>[vehicle.py]"]
end

node_driver(("EV driver"))

node_driver -->|"uses"| node_app
node_app -->|"provides auth"| node_authui
node_authui -->|"authenticates"| node_firebase_auth
node_authui -->|"syncs profile"| node_api_client
node_app -->|"routes to"| node_vehicleui
node_app -->|"routes to"| node_stationui
node_app -->|"routes to"| node_plannerui
node_plannerui -.->|"stores trip state"| node_tripstore
node_vehicleui -->|"requests data"| node_api_client
node_stationui -.->|"requests stations"| node_api_client
node_plannerui -.->|"submits plans"| node_api_client
node_api_client -.->|"calls API"| node_backend
node_backend -->|"mounts"| node_user_api
node_backend -->|"mounts"| node_station_api
node_backend -->|"mounts"| node_trip_api
node_backend -->|"mounts"| node_admin_api
node_backend -->|"mounts"| node_analytics_api
node_backend -->|"mounts"| node_notifications_api
node_trip_service -->|"plans stops"| node_planner
node_trip_service -->|"fetches route"| node_osrm
node_trip_service -->|"fetches elevations"| node_elevation
node_planner -->|"checks fit"| node_compatibility
node_planner -->|"estimates use"| node_energy
node_trip_service -->|"loads candidates"| node_station_repo
node_station_service -->|"queries"| node_station_repo
node_station_repo -->|"reads records"| node_station_model
node_station_repo -->|"reads amenities"| node_amenity_model
node_station_repo -->|"reads operators"| node_operator_model
node_admin_api -->|"invokes"| node_admin_service
node_admin_service -->|"uses queries"| node_station_repo
node_osm -.->|"imports station data"| node_station_model
node_station_repo -->|"queries spatial data"| node_postgres
node_db_session -->|"opens sessions"| node_postgres
node_station_model -->|"inherits ORM"| node_base_model
node_amenity_model -->|"inherits ORM"| node_base_model
node_operator_model -->|"inherits ORM"| node_base_model
node_user_model -->|"inherits ORM"| node_base_model
node_vehicle_model -->|"inherits ORM"| node_base_model
node_vehicle_model -.->|"stores vehicles"| node_postgres

click node_app "https://github.com/r-samarth/chargewise/blob/main/frontend/src/App.tsx"
click node_authui "https://github.com/r-samarth/chargewise/blob/main/frontend/src/context/AuthContext.tsx"
click node_vehicleui "https://github.com/r-samarth/chargewise/blob/main/frontend/src/pages/VehiclesPage.tsx"
click node_stationui "https://github.com/r-samarth/chargewise/blob/main/frontend/src/pages/StationsExplorerPage.tsx"
click node_plannerui "https://github.com/r-samarth/chargewise/blob/main/frontend/src/pages/TripPlannerPage.tsx"
click node_tripstore "https://github.com/r-samarth/chargewise/blob/main/frontend/src/store/tripStore.ts"
click node_api_client "https://github.com/r-samarth/chargewise/blob/main/frontend/src/lib/api.ts"
click node_backend "https://github.com/r-samarth/chargewise/blob/main/backend/app/main.py"
click node_user_api "https://github.com/r-samarth/chargewise/blob/main/backend/app/api/v1/users.py"
click node_station_api "https://github.com/r-samarth/chargewise/blob/main/backend/app/api/v1/stations.py"
click node_trip_api "https://github.com/r-samarth/chargewise/blob/main/backend/app/api/v1/trips.py"
click node_admin_api "https://github.com/r-samarth/chargewise/blob/main/backend/app/api/v1/admin.py"
click node_analytics_api "https://github.com/r-samarth/chargewise/blob/main/backend/app/api/v1/analytics.py"
click node_notifications_api "https://github.com/r-samarth/chargewise/blob/main/backend/app/api/v1/notifications.py"
click node_trip_service "https://github.com/r-samarth/chargewise/blob/main/backend/app/services/trip_service.py"
click node_planner "https://github.com/r-samarth/chargewise/blob/main/backend/app/algorithms/planner.py"
click node_compatibility "https://github.com/r-samarth/chargewise/blob/main/backend/app/algorithms/compatibility.py"
click node_energy "https://github.com/r-samarth/chargewise/blob/main/backend/app/algorithms/energy.py"
click node_osrm "https://github.com/r-samarth/chargewise/blob/main/backend/app/integrations/osrm.py"
click node_elevation "https://github.com/r-samarth/chargewise/blob/main/backend/app/integrations/elevation.py"
click node_station_service "https://github.com/r-samarth/chargewise/blob/main/backend/app/services/station_service.py"
click node_station_repo "https://github.com/r-samarth/chargewise/blob/main/backend/app/repositories/station_repo.py"
click node_station_model "https://github.com/r-samarth/chargewise/blob/main/backend/app/models/station.py"
click node_amenity_model "https://github.com/r-samarth/chargewise/blob/main/backend/app/models/amenity.py"
click node_operator_model "https://github.com/r-samarth/chargewise/blob/main/backend/app/models/operator.py"
click node_admin_service "https://github.com/r-samarth/chargewise/blob/main/backend/app/services/admin_service.py"
click node_osm "https://github.com/r-samarth/chargewise/blob/main/backend/app/integrations/osm_parser.py"
click node_db_session "https://github.com/r-samarth/chargewise/blob/main/backend/app/database/session.py"
click node_base_model "https://github.com/r-samarth/chargewise/blob/main/backend/app/database/base.py"
click node_user_model "https://github.com/r-samarth/chargewise/blob/main/backend/app/models/user.py"
click node_vehicle_model "https://github.com/r-samarth/chargewise/blob/main/backend/app/models/vehicle.py"

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_app,node_authui,node_vehicleui,node_stationui,node_plannerui,node_tripstore,node_api_client toneBlue
class node_backend,node_user_api,node_station_api,node_trip_api,node_admin_api,node_analytics_api,node_notifications_api,node_firebase_auth toneAmber
class node_trip_service,node_planner,node_compatibility,node_energy,node_osrm,node_elevation toneMint
class node_station_service,node_station_repo,node_station_model,node_amenity_model,node_operator_model,node_admin_service,node_osm toneRose
class node_postgres,node_db_session,node_base_model,node_user_model,node_vehicle_model,node_driver toneIndigo
```

## Components

### Driver web app

- [React app routes](https://github.com/r-samarth/chargewise/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Auth context](https://github.com/r-samarth/chargewise/blob/main/frontend/src/context/AuthContext.tsx): `frontend/src/context/AuthContext.tsx`
- [Vehicle management](https://github.com/r-samarth/chargewise/blob/main/frontend/src/pages/VehiclesPage.tsx): `frontend/src/pages/VehiclesPage.tsx`
- [Station discovery](https://github.com/r-samarth/chargewise/blob/main/frontend/src/pages/StationsExplorerPage.tsx): `frontend/src/pages/StationsExplorerPage.tsx`
- [Trip planner and results](https://github.com/r-samarth/chargewise/blob/main/frontend/src/pages/TripPlannerPage.tsx): `frontend/src/pages/TripPlannerPage.tsx`
- [Trip state](https://github.com/r-samarth/chargewise/blob/main/frontend/src/store/tripStore.ts): `frontend/src/store/tripStore.ts`
- [API client](https://github.com/r-samarth/chargewise/blob/main/frontend/src/lib/api.ts): `frontend/src/lib/api.ts`

### API and identity

- [FastAPI entry and router](https://github.com/r-samarth/chargewise/blob/main/backend/app/main.py): `backend/app/main.py`
- [User and vehicle APIs](https://github.com/r-samarth/chargewise/blob/main/backend/app/api/v1/users.py): `backend/app/api/v1/users.py`
- [Station API](https://github.com/r-samarth/chargewise/blob/main/backend/app/api/v1/stations.py): `backend/app/api/v1/stations.py`
- [Trip API](https://github.com/r-samarth/chargewise/blob/main/backend/app/api/v1/trips.py): `backend/app/api/v1/trips.py`
- [Admin API](https://github.com/r-samarth/chargewise/blob/main/backend/app/api/v1/admin.py): `backend/app/api/v1/admin.py`
- [Analytics API](https://github.com/r-samarth/chargewise/blob/main/backend/app/api/v1/analytics.py): `backend/app/api/v1/analytics.py`
- [Notifications API](https://github.com/r-samarth/chargewise/blob/main/backend/app/api/v1/notifications.py): `backend/app/api/v1/notifications.py`
- **Firebase Authentication**

### Trip intelligence

- [Trip orchestration](https://github.com/r-samarth/chargewise/blob/main/backend/app/services/trip_service.py): `backend/app/services/trip_service.py`
- [Charging-stop planner](https://github.com/r-samarth/chargewise/blob/main/backend/app/algorithms/planner.py): `backend/app/algorithms/planner.py`
- [Connector compatibility](https://github.com/r-samarth/chargewise/blob/main/backend/app/algorithms/compatibility.py): `backend/app/algorithms/compatibility.py`
- [Energy estimation](https://github.com/r-samarth/chargewise/blob/main/backend/app/algorithms/energy.py): `backend/app/algorithms/energy.py`
- [Driving route service](https://github.com/r-samarth/chargewise/blob/main/backend/app/integrations/osrm.py): `backend/app/integrations/osrm.py`
- [Elevation data](https://github.com/r-samarth/chargewise/blob/main/backend/app/integrations/elevation.py): `backend/app/integrations/elevation.py`

### Station data

- [Station discovery service](https://github.com/r-samarth/chargewise/blob/main/backend/app/services/station_service.py): `backend/app/services/station_service.py`
- [Spatial station queries](https://github.com/r-samarth/chargewise/blob/main/backend/app/repositories/station_repo.py): `backend/app/repositories/station_repo.py`
- [Station and connector records](https://github.com/r-samarth/chargewise/blob/main/backend/app/models/station.py): `backend/app/models/station.py`
- [Amenity records](https://github.com/r-samarth/chargewise/blob/main/backend/app/models/amenity.py): `backend/app/models/amenity.py`
- [Operator records](https://github.com/r-samarth/chargewise/blob/main/backend/app/models/operator.py): `backend/app/models/operator.py`
- [Station administration](https://github.com/r-samarth/chargewise/blob/main/backend/app/services/admin_service.py): `backend/app/services/admin_service.py`
- [OpenStreetMap data](https://github.com/r-samarth/chargewise/blob/main/backend/app/integrations/osm_parser.py): `backend/app/integrations/osm_parser.py`

### Persistence and integrations

- **PostgreSQL and PostGIS**
- [Database session](https://github.com/r-samarth/chargewise/blob/main/backend/app/database/session.py): `backend/app/database/session.py`
- [ORM base](https://github.com/r-samarth/chargewise/blob/main/backend/app/database/base.py): `backend/app/database/base.py`
- [User records](https://github.com/r-samarth/chargewise/blob/main/backend/app/models/user.py): `backend/app/models/user.py`
- [Vehicle records](https://github.com/r-samarth/chargewise/blob/main/backend/app/models/vehicle.py): `backend/app/models/vehicle.py`

### Other components

- **EV driver**

## Connections

- EV driver → React app routes: uses (evidence: `frontend/src/App.tsx`)
- React app routes → Auth context: provides auth (evidence: `frontend/src/App.tsx`)
- Auth context → Firebase Authentication: authenticates (evidence: `frontend/src/context/AuthContext.tsx`)
- Auth context → API client: syncs profile (evidence: `frontend/src/context/AuthContext.tsx`)
- React app routes → Vehicle management: routes to (evidence: `frontend/src/App.tsx`)
- React app routes → Station discovery: routes to (evidence: `frontend/src/App.tsx`)
- React app routes → Trip planner and results: routes to (evidence: `frontend/src/App.tsx`)
- Trip planner and results → Trip state: stores trip state
- Vehicle management → API client: requests data
- Station discovery → API client: requests stations
- Trip planner and results → API client: submits plans
- API client → FastAPI entry and router: calls API
- FastAPI entry and router → User and vehicle APIs: mounts (evidence: `backend/app/main.py`)
- FastAPI entry and router → Station API: mounts (evidence: `backend/app/main.py`)
- FastAPI entry and router → Trip API: mounts (evidence: `backend/app/main.py`)
- FastAPI entry and router → Admin API: mounts (evidence: `backend/app/main.py`)
- FastAPI entry and router → Analytics API: mounts (evidence: `backend/app/main.py`)
- FastAPI entry and router → Notifications API: mounts (evidence: `backend/app/main.py`)
- Trip orchestration → Charging-stop planner: plans stops (evidence: `backend/app/services/trip_service.py`)
- Trip orchestration → Driving route service: fetches route (evidence: `backend/app/services/trip_service.py`)
- Trip orchestration → Elevation data: fetches elevations (evidence: `backend/app/services/trip_service.py`)
- Charging-stop planner → Connector compatibility: checks fit (evidence: `backend/app/algorithms/planner.py`)
- Charging-stop planner → Energy estimation: estimates use (evidence: `backend/app/algorithms/planner.py`)
- Trip orchestration → Spatial station queries: loads candidates (evidence: `backend/app/services/trip_service.py`)
- Station discovery service → Spatial station queries: queries (evidence: `backend/app/services/station_service.py`)
- Spatial station queries → Station and connector records: reads records (evidence: `backend/app/repositories/station_repo.py`)
- Spatial station queries → Amenity records: reads amenities (evidence: `backend/app/repositories/station_repo.py`)
- Spatial station queries → Operator records: reads operators (evidence: `backend/app/repositories/station_repo.py`)
- Admin API → Station administration: invokes (evidence: `backend/app/api/v1/admin.py`)
- Station administration → Spatial station queries: uses queries (evidence: `backend/app/services/admin_service.py`)
- OpenStreetMap data → Station and connector records: imports station data
- Spatial station queries → PostgreSQL and PostGIS: queries spatial data (evidence: `backend/app/repositories/station_repo.py`)
- Database session → PostgreSQL and PostGIS: opens sessions (evidence: `backend/app/database/session.py`)
- Station and connector records → ORM base: inherits ORM (evidence: `backend/app/models/station.py`)
- Amenity records → ORM base: inherits ORM (evidence: `backend/app/models/amenity.py`)
- Operator records → ORM base: inherits ORM (evidence: `backend/app/models/operator.py`)
- User records → ORM base: inherits ORM (evidence: `backend/app/models/user.py`)
- Vehicle records → ORM base: inherits ORM (evidence: `backend/app/models/vehicle.py`)
- Vehicle records → PostgreSQL and PostGIS: stores vehicles
