# 0xros-200/dynamic-fare-and-occupancy-regressor-model architecture

> Architecture diagram of the GitHub repository 0xros-200/dynamic-fare-and-occupancy-regressor-model, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/0xros-200/dynamic-fare-and-occupancy-regressor-model
- Repository: https://github.com/0xros-200/dynamic-fare-and-occupancy-regressor-model

## Overview

This repository is a transit analytics platform: historical telemetry is prepared and used to train fare, occupancy, and delay regressors; events can then be predicted through an API or Kafka streaming path, with prediction records available to a dashboard. The graph preserves documented training, streaming, synthetic-data, and monitoring capabilities. Some streaming and training details are documented only in the README; edges based on that documentation cite it, and unsampled implementation details are not inferred.

Main entry points: [`api/server.py`](https://github.com/0xros-200/dynamic-fare-and-occupancy-regressor-model/blob/main/api/server.py) (Prediction API), [`spark/ingest.py`](https://github.com/0xros-200/dynamic-fare-and-occupancy-regressor-model/blob/main/spark/ingest.py) (Telemetry Ingestion), [`spark/train_pipeline.py`](https://github.com/0xros-200/dynamic-fare-and-occupancy-regressor-model/blob/main/spark/train_pipeline.py) (Model Training), [`stream/spark_streaming_predict.py`](https://github.com/0xros-200/dynamic-fare-and-occupancy-regressor-model/blob/main/stream/spark_streaming_predict.py) (Spark Streaming Predictor)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Data Preparation"]
  node_ingest["Telemetry Ingestion<br/>[ingest.py]"]
  node_parquet[("Prepared Parquet")]
  node_features["Feature Engineering"]
end

subgraph group_model["Modeling and Serving"]
  node_training["Model Training<br/>[train_pipeline.py]"]
  node_models[("Fare, Occupancy, Delay Models")]
  node_mlflow["MLflow Tracking"]
  node_evaluation["Batch Evaluation<br/>[batch_evaluate.py]"]
  node_api["Prediction API<br/>[server.py]"]
  node_predictor["Model Predictor<br/>[predictor.py]"]
end

subgraph group_streaming["Real-time Feeds"]
  node_producer["Kafka Producer<br/>[kafka_producer.py]"]
  node_kafka["Transit Event Topic"]
  node_generator["Synthetic Event Generator"]
  node_consumer["Spark Streaming Predictor"]
end

subgraph group_analytics["Analytics"]
  node_audit[("Prediction Audit Store<br/>[server.py]")]
  node_dashboard["Analytics Dashboard<br/>[app.py]"]
  node_loader["Prediction Data Loader<br/>[data_loader.py]"]
  node_charts["Plotly Visualizations<br/>[charts.py]"]
end

node_archive["Transit Archive"]
node_client(("API Clients"))

node_archive -->|"supplies telemetry"| node_ingest
node_ingest -->|"writes Parquet"| node_parquet
node_parquet -->|"reads splits"| node_features
node_ingest -->|"provides Spark session"| node_features
node_features -->|"produces features"| node_training
node_training -->|"saves models"| node_models
node_training -.->|"logs metrics"| node_mlflow
node_models -->|"evaluated by"| node_evaluation
node_client -->|"submits events"| node_api
node_api -->|"requests predictions"| node_predictor
node_predictor -->|"loads and predicts"| node_models
node_api -->|"records predictions"| node_audit
node_generator -->|"publishes events"| node_kafka
node_producer -->|"publishes telemetry"| node_kafka
node_kafka -->|"streams events"| node_consumer
node_consumer -->|"posts event batches"| node_api
node_consumer -->|"inserts predictions"| node_audit
node_audit -->|"stores prediction rows"| node_loader
node_dashboard -->|"loads predictions"| node_loader
node_dashboard -->|"renders charts"| node_charts

click node_ingest "https://github.com/0xros-200/dynamic-fare-and-occupancy-regressor-model/blob/main/spark/ingest.py"
click node_features "https://github.com/0xros-200/dynamic-fare-and-occupancy-regressor-model/blob/main/spark/feature_engineering.py"
click node_training "https://github.com/0xros-200/dynamic-fare-and-occupancy-regressor-model/blob/main/spark/train_pipeline.py"
click node_evaluation "https://github.com/0xros-200/dynamic-fare-and-occupancy-regressor-model/blob/main/spark/batch_evaluate.py"
click node_api "https://github.com/0xros-200/dynamic-fare-and-occupancy-regressor-model/blob/main/api/server.py"
click node_predictor "https://github.com/0xros-200/dynamic-fare-and-occupancy-regressor-model/blob/main/api/predictor.py"
click node_audit "https://github.com/0xros-200/dynamic-fare-and-occupancy-regressor-model/blob/main/api/server.py"
click node_producer "https://github.com/0xros-200/dynamic-fare-and-occupancy-regressor-model/blob/main/stream/kafka_producer.py"
click node_generator "https://github.com/0xros-200/dynamic-fare-and-occupancy-regressor-model/blob/main/stream/synthetic_generator.py"
click node_consumer "https://github.com/0xros-200/dynamic-fare-and-occupancy-regressor-model/blob/main/stream/spark_streaming_predict.py"
click node_dashboard "https://github.com/0xros-200/dynamic-fare-and-occupancy-regressor-model/blob/main/dashboard/app.py"
click node_loader "https://github.com/0xros-200/dynamic-fare-and-occupancy-regressor-model/blob/main/dashboard/data_loader.py"
click node_charts "https://github.com/0xros-200/dynamic-fare-and-occupancy-regressor-model/blob/main/dashboard/charts.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_ingest,node_parquet,node_features,node_client toneBlue
class node_training,node_models,node_mlflow,node_evaluation,node_api,node_predictor toneAmber
class node_producer,node_kafka,node_generator,node_consumer toneMint
class node_audit,node_dashboard,node_loader,node_charts toneRose
class node_archive toneIndigo
```

## Components

### Data Preparation

- [Telemetry Ingestion](https://github.com/0xros-200/dynamic-fare-and-occupancy-regressor-model/blob/main/spark/ingest.py): `spark/ingest.py`
- **Prepared Parquet**
- [Feature Engineering](https://github.com/0xros-200/dynamic-fare-and-occupancy-regressor-model/blob/main/spark/feature_engineering.py): `spark/feature_engineering.py`

### Modeling and Serving

- [Model Training](https://github.com/0xros-200/dynamic-fare-and-occupancy-regressor-model/blob/main/spark/train_pipeline.py): `spark/train_pipeline.py`
- **Fare, Occupancy, Delay Models**
- **MLflow Tracking**
- [Batch Evaluation](https://github.com/0xros-200/dynamic-fare-and-occupancy-regressor-model/blob/main/spark/batch_evaluate.py): `spark/batch_evaluate.py`
- [Prediction API](https://github.com/0xros-200/dynamic-fare-and-occupancy-regressor-model/blob/main/api/server.py): `api/server.py`
- [Model Predictor](https://github.com/0xros-200/dynamic-fare-and-occupancy-regressor-model/blob/main/api/predictor.py): `api/predictor.py`

### Real-time Feeds

- [Kafka Producer](https://github.com/0xros-200/dynamic-fare-and-occupancy-regressor-model/blob/main/stream/kafka_producer.py): `stream/kafka_producer.py`
- **Transit Event Topic**
- [Synthetic Event Generator](https://github.com/0xros-200/dynamic-fare-and-occupancy-regressor-model/blob/main/stream/synthetic_generator.py): `stream/synthetic_generator.py`
- [Spark Streaming Predictor](https://github.com/0xros-200/dynamic-fare-and-occupancy-regressor-model/blob/main/stream/spark_streaming_predict.py): `stream/spark_streaming_predict.py`

### Analytics

- [Prediction Audit Store](https://github.com/0xros-200/dynamic-fare-and-occupancy-regressor-model/blob/main/api/server.py): `api/server.py`
- [Analytics Dashboard](https://github.com/0xros-200/dynamic-fare-and-occupancy-regressor-model/blob/main/dashboard/app.py): `dashboard/app.py`
- [Prediction Data Loader](https://github.com/0xros-200/dynamic-fare-and-occupancy-regressor-model/blob/main/dashboard/data_loader.py): `dashboard/data_loader.py`
- [Plotly Visualizations](https://github.com/0xros-200/dynamic-fare-and-occupancy-regressor-model/blob/main/dashboard/charts.py): `dashboard/charts.py`

### Other components

- **Transit Archive**
- **API Clients**

## Connections

- Transit Archive → Telemetry Ingestion: supplies telemetry (evidence: `README.md`)
- Telemetry Ingestion → Prepared Parquet: writes Parquet (evidence: `spark/ingest.py`)
- Prepared Parquet → Feature Engineering: reads splits (evidence: `README.md`)
- Telemetry Ingestion → Feature Engineering: provides Spark session (evidence: `spark/feature_engineering.py`)
- Feature Engineering → Model Training: produces features (evidence: `README.md`)
- Model Training → Fare, Occupancy, Delay Models: saves models (evidence: `spark/train_pipeline.py`)
- Model Training → MLflow Tracking: logs metrics (evidence: `spark/train_pipeline.py`)
- Fare, Occupancy, Delay Models → Batch Evaluation: evaluated by (evidence: `spark/batch_evaluate.py`)
- API Clients → Prediction API: submits events (evidence: `README.md`)
- Prediction API → Model Predictor: requests predictions (evidence: `api/server.py`)
- Model Predictor → Fare, Occupancy, Delay Models: loads and predicts (evidence: `api/predictor.py`)
- Prediction API → Prediction Audit Store: records predictions (evidence: `api/server.py`)
- Synthetic Event Generator → Transit Event Topic: publishes events (evidence: `README.md`)
- Kafka Producer → Transit Event Topic: publishes telemetry (evidence: `README.md`)
- Transit Event Topic → Spark Streaming Predictor: streams events (evidence: `README.md`)
- Spark Streaming Predictor → Prediction API: posts event batches (evidence: `stream/spark_streaming_predict.py`)
- Spark Streaming Predictor → Prediction Audit Store: inserts predictions (evidence: `stream/spark_streaming_predict.py`)
- Prediction Audit Store → Prediction Data Loader: stores prediction rows (evidence: `dashboard/data_loader.py`)
- Analytics Dashboard → Prediction Data Loader: loads predictions (evidence: `dashboard/app.py`)
- Analytics Dashboard → Plotly Visualizations: renders charts (evidence: `dashboard/app.py`)
