# nakshatra-naksh/ridershipforcast architecture

> Architecture diagram of the GitHub repository nakshatra-naksh/ridershipforcast, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nakshatra-naksh/ridershipforcast
- Repository: https://github.com/nakshatra-naksh/ridershipforcast

## Overview

1. This repo is a three-tier forecasting system: a React/Vite frontend, a Node.js/Express API layer, and a Python machine-learning engine. The main architectural boundary is between user interaction and model execution; the backend orchestrates the Python process rather than embedding the ML code in Node.

2. The frontend lives under `src/` and is a single-page app bootstrapped by `src/main.jsx` and `src/App.jsx`. It provides the interactive forecasting workflow: choose route, choose stop, pick a date, submit a forecast request, and display results.

3. The UI is decomposed into focused components:
   - `RouteSelector` and `StopSelector` handle transit-filter selection.
   - `DatePicker` collects the forecast date.
   - `ForecastResults` renders the returned forecast summary and metrics.
   - `ModelChart` visualizes the predicted hourly series.
   This separation suggests a presentation layer built around a single forecast request/response flow.

4. Frontend state and API calls are isolated in `src/services/forecastService.js`. That service is the client-side integration point with the backend, which keeps request logic out of the UI components and makes the forecast API the main contract between tiers.

5. The static transit reference data is bundled in `src/data/routes.js` and `src/data/stops.js`. These files likely drive the selector options and define the routing/stop hierarchy that constrains user input before the forecast request is sent.

6. The backend entry point is `server.js`, which is the orchestration layer for the application. Based on the README, it exposes an API endpoint such as `/api/forecast` and invokes the Python forecast script as a subprocess, acting as the bridge between HTTP requests and the ML pipeline.

7. The forecasting engine is `forecast.py`, which implements the SARIMAX time-series workflow described in the README. Its responsibilities are data loading, stop-level filtering, model training/validation, future hourly prediction, and returning forecast values plus evaluation metrics such as MAE/RMSE and confidence.

8. The core dataset is `aggregated_hourly_data.csv`, a stop-level hourly passenger-count history. This is the main data source for the ML engine and is the reason the architecture is centered on time-series forecasting rather than transactional or streaming ingestion.

9. The system’s data flow is:
   user selection in React → API call via `forecastService` → Express route in `server.js` → Python execution in `forecast.py` → forecast output returned to the frontend → chart/results rendering. This end-to-end path is the most important diagram arrow sequence.

10. The runtime stack is split by responsibility: Vite/React for the browser UI, Node.js for HTTP orchestration, Python with pandas/numpy/statsmodels for forecasting. `requirements.txt` and `package.json` confirm the dual-runtime setup, while `vite.config.js` and `index.html` support frontend bundling.

11. Styling and presentation are kept in CSS files alongside components, including `src/App.css`, `src/index.css`, and component-specific styles such as `DatePicker.css`, `RouteSelector.css`, `StopSelector.css`, and `ForecastResults.css`. This indicates the visualization layer is self-contained and does not affect the model pipeline.

12. Operationally, `start.sh` and the README’s run instructions imply the repo is designed to launch both the API and the frontend together. The important deployment boundary is therefore not microservices, but a coordinated local/full-stack startup with a single backend API serving the ML requests.

13. For an architecture diagram, the main boxes should be: Browser UI, React components/services, Express API, Python SARIMAX engine, and CSV dataset. The key external dependency is the Python scientific stack; the key internal dependency is the API contract that carries route/stop/date inputs and forecast outputs across the language boundary.

Main entry points: [`src/App.jsx`](https://github.com/nakshatra-naksh/ridershipforcast/blob/master/src/App.jsx) (App Shell), [`forecast.py`](https://github.com/nakshatra-naksh/ridershipforcast/blob/master/forecast.py) (SARIMAX Engine), [`server.js`](https://github.com/nakshatra-naksh/ridershipforcast/blob/master/server.js) (Express API), [`src/main.jsx`](https://github.com/nakshatra-naksh/ridershipforcast/blob/master/src/main.jsx) (Bootstrapped UI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Browser UI"]
  node_browser(("Browser<br/>client"))
  node_app["App Shell<br/>react SPA<br/>[App.jsx]"]
  node_main["Bootstrapped UI<br/>react entry<br/>[main.jsx]"]
  node_route_selector["Route Selector<br/>ui component<br/>[RouteSelector.jsx]"]
  node_stop_selector["Stop Selector<br/>ui component<br/>[StopSelector.jsx]"]
  node_date_picker["Date Picker<br/>ui component<br/>[DatePicker.jsx]"]
  node_results["Forecast Results<br/>ui component"]
  node_chart["Model Chart<br/>visualization<br/>[ModelChart.jsx]"]
  node_service["Forecast Service<br/>api client<br/>[forecastService.js]"]
end

subgraph group_backend["API Orchestration"]
  node_api["Express API<br/>node server<br/>[server.js]"]
  node_python_bridge["Python Bridge<br/>subprocess bridge<br/>[server.js]"]
end

subgraph group_ml["Forecast Engine"]
  node_engine["SARIMAX Engine<br/>python ml<br/>[forecast.py]"]
  node_dataset[("Hourly CSV<br/>training data")]
end

subgraph group_shared["Shared Assets"]
  node_routes_data["Routes Data<br/>static reference<br/>[routes.js]"]
  node_stops_data["Stops Data<br/>static reference<br/>[stops.js]"]
  node_frontend_styles["UI Styles<br/>css assets<br/>[App.css]"]
  node_runtime_configs["Runtime Configs<br/>build/runtime<br/>[package.json]"]
end

node_browser -->|"loads"| node_main
node_main -->|"mounts"| node_app
node_app -->|"composes"| node_route_selector
node_app -->|"composes"| node_stop_selector
node_app -->|"composes"| node_date_picker
node_app -->|"renders"| node_results
node_app -->|"renders"| node_chart
node_route_selector -->|"reads"| node_routes_data
node_stop_selector -->|"reads"| node_stops_data
node_app -->|"requests"| node_service
node_service -->|"calls"| node_api
node_api -->|"orchestrates"| node_python_bridge
node_python_bridge -->|"invokes"| node_engine
node_engine -->|"trains on"| node_dataset
node_engine -->|"returns"| node_results
node_engine -->|"feeds"| node_chart
node_frontend_styles -->|"styles"| node_app
node_runtime_configs -->|"supports"| node_api

click node_app "https://github.com/nakshatra-naksh/ridershipforcast/blob/master/src/App.jsx"
click node_main "https://github.com/nakshatra-naksh/ridershipforcast/blob/master/src/main.jsx"
click node_route_selector "https://github.com/nakshatra-naksh/ridershipforcast/blob/master/src/components/RouteSelector.jsx"
click node_stop_selector "https://github.com/nakshatra-naksh/ridershipforcast/blob/master/src/components/StopSelector.jsx"
click node_date_picker "https://github.com/nakshatra-naksh/ridershipforcast/blob/master/src/components/DatePicker.jsx"
click node_results "https://github.com/nakshatra-naksh/ridershipforcast/blob/master/src/components/ForecastResults.jsx"
click node_chart "https://github.com/nakshatra-naksh/ridershipforcast/blob/master/src/components/ModelChart.jsx"
click node_service "https://github.com/nakshatra-naksh/ridershipforcast/blob/master/src/services/forecastService.js"
click node_routes_data "https://github.com/nakshatra-naksh/ridershipforcast/blob/master/src/data/routes.js"
click node_stops_data "https://github.com/nakshatra-naksh/ridershipforcast/blob/master/src/data/stops.js"
click node_api "https://github.com/nakshatra-naksh/ridershipforcast/blob/master/server.js"
click node_python_bridge "https://github.com/nakshatra-naksh/ridershipforcast/blob/master/server.js"
click node_engine "https://github.com/nakshatra-naksh/ridershipforcast/blob/master/forecast.py"
click node_dataset "https://github.com/nakshatra-naksh/ridershipforcast/blob/master/aggregated_hourly_data.csv"
click node_frontend_styles "https://github.com/nakshatra-naksh/ridershipforcast/blob/master/src/App.css"
click node_runtime_configs "https://github.com/nakshatra-naksh/ridershipforcast/blob/master/package.json"

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_browser,node_app,node_main,node_route_selector,node_stop_selector,node_date_picker,node_results,node_chart,node_service toneBlue
class node_api,node_python_bridge toneAmber
class node_engine,node_dataset toneMint
class node_routes_data,node_stops_data,node_frontend_styles,node_runtime_configs toneRose
```

## Components

### Browser UI

React/Vite presentation layer for selecting inputs and showing forecasts.

- **Browser**: client · User-facing runtime where the forecast workflow is executed.
- [App Shell](https://github.com/nakshatra-naksh/ridershipforcast/blob/master/src/App.jsx): react SPA · Top-level React application composition and forecast flow container. · `src/App.jsx`
- [Bootstrapped UI](https://github.com/nakshatra-naksh/ridershipforcast/blob/master/src/main.jsx): react entry · Client entry point that mounts the React app. · `src/main.jsx`
- [Route Selector](https://github.com/nakshatra-naksh/ridershipforcast/blob/master/src/components/RouteSelector.jsx): ui component · Chooses the transit route for forecasting. · `src/components/RouteSelector.jsx`
- [Stop Selector](https://github.com/nakshatra-naksh/ridershipforcast/blob/master/src/components/StopSelector.jsx): ui component · Chooses the stop filtered by the selected route. · `src/components/StopSelector.jsx`
- [Date Picker](https://github.com/nakshatra-naksh/ridershipforcast/blob/master/src/components/DatePicker.jsx): ui component · Collects the forecast date input. · `src/components/DatePicker.jsx`
- [Forecast Results](https://github.com/nakshatra-naksh/ridershipforcast/blob/master/src/components/ForecastResults.jsx): ui component · Displays forecast summary and evaluation metrics. · `src/components/ForecastResults.jsx`
- [Model Chart](https://github.com/nakshatra-naksh/ridershipforcast/blob/master/src/components/ModelChart.jsx): visualization · Plots the predicted hourly series. · `src/components/ModelChart.jsx`
- [Forecast Service](https://github.com/nakshatra-naksh/ridershipforcast/blob/master/src/services/forecastService.js): api client · Client-side contract for sending forecast requests to the backend. · `src/services/forecastService.js`

### API Orchestration

Node/Express layer that receives requests and launches the forecasting engine.

- [Express API](https://github.com/nakshatra-naksh/ridershipforcast/blob/master/server.js): node server · HTTP orchestration layer and forecast endpoint boundary. · `server.js`
- [Python Bridge](https://github.com/nakshatra-naksh/ridershipforcast/blob/master/server.js): subprocess bridge · Launches the forecasting script from Node and returns results across the language boundary. · `server.js`

### Forecast Engine

Python SARIMAX workflow and its data source.

- [SARIMAX Engine](https://github.com/nakshatra-naksh/ridershipforcast/blob/master/forecast.py): python ml · Time-series forecasting workflow that loads data, trains, predicts, and computes metrics. · `forecast.py`
- [Hourly CSV](https://github.com/nakshatra-naksh/ridershipforcast/blob/master/aggregated_hourly_data.csv): training data · Aggregated stop-level hourly passenger counts used by the model. · `aggregated_hourly_data.csv`

### Shared Assets

Static inputs and app entry points that support the runtime flow.

- [Routes Data](https://github.com/nakshatra-naksh/ridershipforcast/blob/master/src/data/routes.js): static reference · Transit route options used by the selector UI. · `src/data/routes.js`
- [Stops Data](https://github.com/nakshatra-naksh/ridershipforcast/blob/master/src/data/stops.js): static reference · Stop options and route-stop relationships used by the selector UI. · `src/data/stops.js`
- [UI Styles](https://github.com/nakshatra-naksh/ridershipforcast/blob/master/src/App.css): css assets · Presentation styling for the React components and app shell. · `src/App.css`
- [Runtime Configs](https://github.com/nakshatra-naksh/ridershipforcast/blob/master/package.json): build/runtime · Frontend bundling and backend dependency manifests supporting the split runtime. · `package.json`

## Connections

- Browser → Bootstrapped UI: loads · The browser loads the React entry point.
- Bootstrapped UI → App Shell: mounts · Bootstraps the top-level app shell.
- App Shell → Route Selector: composes · App shell includes route selection.
- App Shell → Stop Selector: composes · App shell includes stop selection.
- App Shell → Date Picker: composes · App shell includes date input.
- App Shell → Forecast Results: renders · App shell displays forecast output.
- App Shell → Model Chart: renders · App shell displays the prediction chart.
- Route Selector → Routes Data: reads · Route options are sourced from static reference data.
- Stop Selector → Stops Data: reads · Stop options are sourced from static reference data.
- App Shell → Forecast Service: requests · UI workflow submits forecast requests through the client service.
- Forecast Service → Express API: calls · Forecast service sends the HTTP request to the backend API.
- Express API → Python Bridge: orchestrates · Express route delegates model execution to the subprocess bridge.
- Python Bridge → SARIMAX Engine: invokes · Node launches the Python forecasting script.
- SARIMAX Engine → Hourly CSV: trains on · The SARIMAX workflow reads historical hourly passenger data.
- SARIMAX Engine → Forecast Results: returns · Forecast values and metrics are sent back to the API and then the UI.
- SARIMAX Engine → Model Chart: feeds · Predicted series powers the model chart visualization.
- UI Styles → App Shell: styles · Shared CSS supports the React shell and components.
- Runtime Configs → Express API: supports · Project manifests and runtime setup support the server layer.
