# laxmigs24/hotel-revenue-operations architecture

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

- Interactive diagram: https://gitdiagram.com/laxmigs24/hotel-revenue-operations
- Repository: https://github.com/laxmigs24/hotel-revenue-operations

## Overview

1. This repository is a small end-to-end analytics/ML system centered on one business problem: predict hotel booking cancellations and estimate revenue at risk. It has two distinct execution paths: an offline pipeline for data preparation/model training, and an online Streamlit app for decision support.

2. The raw data domain starts in `data/hotel_bookings.csv` and is transformed through a staged dataset chain: `hotel_bookings_clean.csv` after audit/deduplication, `hotel_bookings_eda.csv` for analysis, and `hotel_bookings_feature_engineered.csv` for modeling. Those files are the handoff artifacts between notebook stages.

3. The offline workflow is organized in `notebooks/01_data_audit.ipynb` through `04_modeling_evaluation.ipynb`. These notebooks are the primary orchestration layer for exploration, feature creation, model selection, threshold tuning, and evaluation. They are not just documentation; they produce the datasets and trained model used downstream.

4. `src/features.py` is the architectural core of the repo. It centralizes all feature-engineering logic so the notebooks and the app use the exact same transformations. That shared module is the main boundary that prevents train/serve skew, especially for bucket labels, ordinal categories, seasonal flags, and leakage-prone fields.

5. The modeling stack is scikit-learn-based. The README indicates the final estimator is `HistGradientBoostingClassifier`, wrapped with preprocessing components such as `OrdinalEncoder` and `ColumnTransformer`. The model selection process compares multiple classifiers, then chooses a business threshold based on asymmetric cost rather than a pure classification metric.

6. Model evaluation is business-aware, not only statistical. The system estimates expected revenue exposure using booking value logic and selects a decision threshold assuming missed cancellations are more expensive than false alarms. Explainability is handled with permutation importance, which is used in place of SHAP in this version.

7. The app layer lives in `app/streamlit_app.py` and consumes the trained model bundle. It exposes four user-facing modes: single-booking prediction, explanation of one booking, batch scoring for uploaded CSVs, and a segment dashboard for portfolio-level analysis. This is the main runtime interface for hotel managers.

8. Data flow into the app is feed-forward: user input or uploaded booking data is transformed using the same feature logic in `src/features.py`, then passed to the trained inference pipeline, then post-processed into risk probabilities, explanations, and revenue-at-risk summaries. The app is therefore a thin presentation and scoring layer, not a separate analytics implementation.

9. `tests/test_features.py` acts as a guardrail around the most failure-prone part of the system: feature consistency. The tests specifically protect against category-label mismatches and ordinal encoding bugs, so the architecture has a deliberate verification layer around shared feature definitions.

10. There is also a standalone SQL/SQLite analytical subsystem under `Database/` with `hotel_revenue.sql` and `hotel_revenue.db`. This is separate from the Python ML pipeline and demonstrates relational analysis, views, CTEs, window functions, and SQL-based revenue/cancellation calculations. It is best viewed as an auxiliary analytics layer rather than a production dependency of the Streamlit app.

11. The repository’s key boundary is between “feature definition” and “model/app usage.” Everything that affects the model input schema should flow through `src/features.py`; everything user-facing should consume the serialized model artifact rather than re-deriving logic. That separation is the main architectural safeguard in the project.

12. In diagram terms, the system is: raw booking data and SQL assets on one side; notebook-driven preparation and model training in the middle; a shared feature module and trained model artifact as the bridge; and a Streamlit decision-support app plus regression tests on the delivery side.

Main entry points: [`src/features.py`](https://github.com/laxmigs24/hotel-revenue-operations/blob/main/src/features.py) (Features), [`notebooks/01_data_audit.ipynb`](https://github.com/laxmigs24/hotel-revenue-operations/blob/main/notebooks/01_data_audit.ipynb) (Data audit), [`notebooks/03_feature_eng.ipynb`](https://github.com/laxmigs24/hotel-revenue-operations/blob/main/notebooks/03_feature_eng.ipynb) (Feature eng), [`notebooks/04_modeling_evaluation.ipynb`](https://github.com/laxmigs24/hotel-revenue-operations/blob/main/notebooks/04_modeling_evaluation.ipynb) (Model eval)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data_pipeline["Data pipeline"]
  node_raw_bookings[("Raw bookings<br/>dataset<br/>[hotel_bookings.csv]")]
  node_clean_bookings[("Cleaned data<br/>dataset")]
  node_eda_bookings[("EDA data<br/>dataset")]
  node_engineered_bookings[("Feature data<br/>dataset")]
  node_data_audit_nb["Data audit<br/>notebook"]
  node_eda_nb["EDA<br/>notebook<br/>[02_eda.ipynb]"]
  node_feature_nb["Feature eng<br/>notebook"]
end

subgraph group_shared_core["Shared core"]
  node_features_py["Features<br/>shared module<br/>[features.py]"]
end

subgraph group_modeling["Offline modeling"]
  node_modeling_nb["Model eval<br/>notebook"]
  node_train_script["Train script<br/>[train_model.py]"]
  node_rebuild_script["Rebuild script<br/>[rebuild_model.py]"]
  node_model_bundle[("Model bundle<br/>artifact")]
end

subgraph group_delivery["Decision app"]
  node_streamlit_app["Streamlit app<br/>web app<br/>[streamlit_app.py]"]
end

subgraph group_sql_analytics["SQL analytics"]
  node_sql_script["SQL analysis<br/>[hotel_revenue.sql]"]
  node_sql_db[("SQLite DB<br/>database<br/>[hotel_revenue.db]")]
end

subgraph group_verification["Verification"]
  node_feature_tests["Feature tests<br/>[test_features.py]"]
end

node_raw_bookings -->|"inspect"| node_data_audit_nb
node_data_audit_nb -->|"produce"| node_clean_bookings
node_clean_bookings -->|"analyze"| node_eda_nb
node_eda_nb -->|"stage"| node_eda_bookings
node_eda_bookings -->|"transform"| node_feature_nb
node_feature_nb -->|"emit"| node_engineered_bookings
node_engineered_bookings -->|"train"| node_modeling_nb
node_features_py -.->|"shared logic"| node_data_audit_nb
node_features_py -.->|"shared logic"| node_feature_nb
node_features_py -.->|"shared logic"| node_modeling_nb
node_features_py -.->|"shared logic"| node_streamlit_app
node_features_py -.->|"verify"| node_feature_tests
node_modeling_nb -->|"publish"| node_model_bundle
node_train_script -->|"build"| node_model_bundle
node_rebuild_script -->|"recreate"| node_model_bundle
node_model_bundle -->|"serve"| node_streamlit_app
node_sql_script -->|"populate"| node_sql_db

click node_raw_bookings "https://github.com/laxmigs24/hotel-revenue-operations/blob/main/data/hotel_bookings.csv"
click node_clean_bookings "https://github.com/laxmigs24/hotel-revenue-operations/blob/main/data/hotel_bookings_clean.csv"
click node_eda_bookings "https://github.com/laxmigs24/hotel-revenue-operations/blob/main/data/hotel_bookings_eda.csv"
click node_engineered_bookings "https://github.com/laxmigs24/hotel-revenue-operations/blob/main/data/hotel_bookings_feature_engineered.csv"
click node_data_audit_nb "https://github.com/laxmigs24/hotel-revenue-operations/blob/main/notebooks/01_data_audit.ipynb"
click node_eda_nb "https://github.com/laxmigs24/hotel-revenue-operations/blob/main/notebooks/02_eda.ipynb"
click node_feature_nb "https://github.com/laxmigs24/hotel-revenue-operations/blob/main/notebooks/03_feature_eng.ipynb"
click node_modeling_nb "https://github.com/laxmigs24/hotel-revenue-operations/blob/main/notebooks/04_modeling_evaluation.ipynb"
click node_features_py "https://github.com/laxmigs24/hotel-revenue-operations/blob/main/src/features.py"
click node_train_script "https://github.com/laxmigs24/hotel-revenue-operations/blob/main/train_model.py"
click node_rebuild_script "https://github.com/laxmigs24/hotel-revenue-operations/blob/main/rebuild_model.py"
click node_streamlit_app "https://github.com/laxmigs24/hotel-revenue-operations/blob/main/app/streamlit_app.py"
click node_feature_tests "https://github.com/laxmigs24/hotel-revenue-operations/blob/main/tests/test_features.py"
click node_sql_script "https://github.com/laxmigs24/hotel-revenue-operations/blob/main/Database/hotel_revenue.sql"
click node_sql_db "https://github.com/laxmigs24/hotel-revenue-operations/blob/main/Database/hotel_revenue.db"

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_raw_bookings,node_clean_bookings,node_eda_bookings,node_engineered_bookings,node_data_audit_nb,node_eda_nb,node_feature_nb toneBlue
class node_features_py toneAmber
class node_modeling_nb,node_train_script,node_rebuild_script,node_model_bundle toneMint
class node_streamlit_app toneRose
class node_sql_script,node_sql_db toneIndigo
class node_feature_tests toneTeal
```

## Components

### Data pipeline

Raw hotel bookings, staged datasets, and notebook-driven preparation.

- [Raw bookings](https://github.com/laxmigs24/hotel-revenue-operations/blob/main/data/hotel_bookings.csv): dataset · Source hotel booking records. · `data/hotel_bookings.csv`
- [Cleaned data](https://github.com/laxmigs24/hotel-revenue-operations/blob/main/data/hotel_bookings_clean.csv): dataset · Audited and deduplicated booking table. · `data/hotel_bookings_clean.csv`
- [EDA data](https://github.com/laxmigs24/hotel-revenue-operations/blob/main/data/hotel_bookings_eda.csv): dataset · Analysis-ready extract for exploration. · `data/hotel_bookings_eda.csv`
- [Feature data](https://github.com/laxmigs24/hotel-revenue-operations/blob/main/data/hotel_bookings_feature_engineered.csv): dataset · Model-ready engineered booking dataset. · `data/hotel_bookings_feature_engineered.csv`
- [Data audit](https://github.com/laxmigs24/hotel-revenue-operations/blob/main/notebooks/01_data_audit.ipynb): notebook · Audit, cleaning, and dataset validation stage. · `notebooks/01_data_audit.ipynb`
- [EDA](https://github.com/laxmigs24/hotel-revenue-operations/blob/main/notebooks/02_eda.ipynb): notebook · Exploration and analysis stage. · `notebooks/02_eda.ipynb`
- [Feature eng](https://github.com/laxmigs24/hotel-revenue-operations/blob/main/notebooks/03_feature_eng.ipynb): notebook · Feature creation and transformation stage. · `notebooks/03_feature_eng.ipynb`

### Shared core

Feature definitions reused by training, evaluation, and the app.

- [Features](https://github.com/laxmigs24/hotel-revenue-operations/blob/main/src/features.py): shared module · Canonical feature-engineering logic shared across pipeline and app. · `src/features.py`

### Offline modeling

Training, evaluation, and model bundle creation.

- [Model eval](https://github.com/laxmigs24/hotel-revenue-operations/blob/main/notebooks/04_modeling_evaluation.ipynb): notebook · Model selection, thresholding, and evaluation stage. · `notebooks/04_modeling_evaluation.ipynb`
- [Train script](https://github.com/laxmigs24/hotel-revenue-operations/blob/main/train_model.py): script · Training entrypoint for building the model artifact. · `train_model.py`
- [Rebuild script](https://github.com/laxmigs24/hotel-revenue-operations/blob/main/rebuild_model.py): script · Utility for regenerating the model bundle. · `rebuild_model.py`
- **Model bundle**: artifact · Serialized inference pipeline used by the app.

### Decision app

Streamlit scoring and explanation interface.

- [Streamlit app](https://github.com/laxmigs24/hotel-revenue-operations/blob/main/app/streamlit_app.py): web app · Decision-support interface for predictions, explanations, and batch scoring. · `app/streamlit_app.py`

### SQL analytics

Standalone relational analysis subsystem.

- [SQL analysis](https://github.com/laxmigs24/hotel-revenue-operations/blob/main/Database/hotel_revenue.sql): sql · SQLite analytical queries and revenue calculations. · `Database/hotel_revenue.sql`
- [SQLite DB](https://github.com/laxmigs24/hotel-revenue-operations/blob/main/Database/hotel_revenue.db): database · Standalone relational analysis database. · `Database/hotel_revenue.db`

### Verification

Guardrails around feature consistency.

- [Feature tests](https://github.com/laxmigs24/hotel-revenue-operations/blob/main/tests/test_features.py): test · Regression checks for feature consistency and encoding behavior. · `tests/test_features.py`

## Connections

- Raw bookings → Data audit: inspect · Audit notebook starts from the raw CSV.
- Data audit → Cleaned data: produce · Cleaning stage writes the audited dataset.
- Cleaned data → EDA: analyze · EDA consumes the cleaned dataset.
- EDA → EDA data: stage · Exploration branch uses the EDA extract.
- EDA data → Feature eng: transform · Feature engineering starts from analysis data.
- Feature eng → Feature data: emit · Notebook produces the model-ready dataset.
- Feature data → Model eval: train · Model evaluation runs on engineered features.
- Features → Data audit: shared logic · Shared feature definitions constrain upstream schema handling.
- Features → Feature eng: shared logic · Notebook uses the canonical feature transformations.
- Features → Model eval: shared logic · Modeling uses the same feature contract.
- Features → Streamlit app: shared logic · App applies the same transformations at inference time.
- Features → Feature tests: verify · Tests guard the shared feature boundary.
- Model eval → Model bundle: publish · Evaluation stage culminates in a serialized model artifact.
- Train script → Model bundle: build · Training script produces the reusable bundle.
- Rebuild script → Model bundle: recreate · Rebuild utility regenerates the artifact.
- Model bundle → Streamlit app: serve · The app consumes the trained inference pipeline.
- SQL analysis → SQLite DB: populate · SQL analysis is backed by the SQLite database.
