# themrityunjaypathak/autoiq architecture

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

- Interactive diagram: https://gitdiagram.com/themrityunjaypathak/autoiq
- Repository: https://github.com/themrityunjaypathak/autoiq

## Overview

#### Purpose and Entry Points
AutoIQ is a used-car price-estimation system trained on Cars24 listings. Runtime entry is the FastAPI app at `api/main.py`, configured through `api/config.py`; it loads serialized prediction assets from `models/pipe.pkl` and `models/model_freq.pkl`. A separate static browser frontend begins at `index.html` and submits prediction requests through `script.js`.

#### Serving API Boundary
The API accepts structured vehicle attributes—brand, model, year, odometer, engine capacity, fuel, transmission, and owner—and returns a formatted price range. `api/main.py` is the HTTP/control boundary, including health and prediction endpoints; `api/config.py` supplies environment-driven model locations, allowed CORS origins, and prediction-error metadata. Model deserialization and inference remain server-side.

#### Browser Client
The frontend is independently deployable static content, suitable for GitHub Pages rather than being hosted by the FastAPI process. `index.html` captures vehicle inputs, `script.js` serializes them into a `POST /predict` request and renders the response, and `style.css` provides presentation. CORS configuration in `api/config.py` bridges this client/API deployment boundary.

#### Prediction Assets and Inference
`models/pipe.pkl` represents the fitted Scikit-learn preprocessing-plus-regression pipeline, preserving training-time transformations during inference. The pipeline uses categorical encoding, ordinal owner handling, robust numerical scaling, and a tuned stacking regressor composed of Random Forest, XGBoost, Gradient Boosting, and ElasticNet meta-model. `models/model_freq.pkl` is an auxiliary serialized model-frequency artifact used by serving logic. The API must keep request field names/types aligned with the pipeline’s expected feature schema.

#### Data Acquisition
Source listings originate from Cars24. The scraping implementation and exploration are centered in `scrape_code/scrape_code.ipynb`, supported by reusable scraping functions in `utils/web_scraping.py`. Selenium renders dynamically loaded listing pages; BeautifulSoup parses listing fields; individual detail pages are queried for engine capacity. Raw collected output is stored at `scrape_data/scrape_data.csv`. Cars24 is an external, schema-fragile dependency outside the serving path.

#### Data Refinement and Feature Construction
The offline dataset pipeline turns raw listings into progressively cleaned Parquet datasets: `clean_data/clean_data.parquet`, `clean_data/clean_data_with_no_outlier.parquet`, and `clean_data/clean_data_after_eda.parquet`. Cleaning, outlier handling, EDA, and feature preparation are documented as sequential notebook stages in `notebooks/step_1_data_preprocessing.ipynb`, `notebooks/step_2_outlier_detection.ipynb`, and `notebooks/step_3_exploratory_data_analysis.ipynb`. Utilities such as `utils/read_data.py` and `utils/export_data.py` define the reusable storage boundary.

#### Training and Model Promotion
`notebooks/step_4_model_building.ipynb` trains and evaluates candidate regressors using train/test splitting, cross-validation, and leakage-safe Scikit-learn pipelines. The selected tuned stacking pipeline is serialized into `models/pipe.pkl` for API use. This is an offline promotion boundary: notebooks/data artifacts produce versioned model files; the API only consumes those files and does not retrain.

#### Runtime and Deployment
The Python service depends on FastAPI, Pandas, Scikit-learn, and XGBoost; scraping additionally uses Selenium, BeautifulSoup, Requests, and ChromeDriver tooling. `Dockerfile` packages the service and model artifacts into a container, with runtime environment variables supplied externally. The documented deployment model is Docker locally or via Docker Hub, with the API hosted on Render and the static frontend hosted on GitHub Pages.

Main entry points: [`api/main.py`](https://github.com/themrityunjaypathak/autoiq/blob/main/api/main.py) (FastAPI application), [`notebooks/step_4_model_building.ipynb`](https://github.com/themrityunjaypathak/autoiq/blob/main/notebooks/step_4_model_building.ipynb) (Model training and promotion), [`scrape_code/scrape_code.ipynb`](https://github.com/themrityunjaypathak/autoiq/blob/main/scrape_code/scrape_code.ipynb) (Listing scraper), [`models/pipe.pkl`](https://github.com/themrityunjaypathak/autoiq/blob/main/models/pipe.pkl) (Prediction pipeline)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Browser client"]
  node_browser(("User browser"))
  node_frontend["Static prediction UI<br/>HTML/JavaScript<br/>[index.html]"]
  node_frontend_script["Request client<br/>JavaScript<br/>[script.js]"]
end

subgraph group_serving["Prediction serving"]
  node_api{{"FastAPI application<br/>[main.py]"}}
  node_api_config["Runtime configuration<br/>Python config<br/>[config.py]"]
  node_pipeline[("Prediction pipeline<br/>serialized Scikit-learn model<br/>[pipe.pkl]")]
  node_model_frequency[("Model-frequency artifact<br/>serialized model artifact<br/>[model_freq.pkl]")]
  node_docker["Service container<br/>Docker image"]
end

subgraph group_data["Offline data pipeline"]
  node_cars24(("Cars24 listings<br/>external data source"))
  node_scraping["Listing scraper<br/>Jupyter notebook<br/>[scrape_code.ipynb]"]
  node_scraping_utils["Scraping utilities<br/>Python utilities<br/>[web_scraping.py]"]
  node_raw_data[("Raw listings<br/>CSV dataset<br/>[scrape_data.csv]")]
  node_preprocessing["Preprocessing stage<br/>Jupyter notebook"]
  node_outlier_detection["Outlier stage<br/>Jupyter notebook"]
  node_eda["EDA and feature preparation<br/>Jupyter notebook"]
  node_refined_data[("Training-ready data<br/>Parquet dataset")]
  node_model_training["Model training and promotion<br/>Jupyter notebook"]
end

node_browser -->|"loads"| node_frontend
node_frontend -->|"uses"| node_frontend_script
node_frontend_script -->|"POST /predict"| node_api
node_api_config -->|"configures"| node_api
node_api -->|"loads and infers with"| node_pipeline
node_api -->|"loads"| node_model_frequency
node_docker -->|"packages"| node_api
node_docker -->|"includes"| node_pipeline
node_cars24 -->|"listing pages"| node_scraping
node_scraping_utils -->|"supports"| node_scraping
node_scraping -->|"writes"| node_raw_data
node_raw_data -->|"input"| node_preprocessing
node_preprocessing -->|"cleaned Parquet"| node_outlier_detection
node_outlier_detection -->|"no-outlier Parquet"| node_eda
node_eda -->|"writes"| node_refined_data
node_refined_data -->|"training input"| node_model_training
node_model_training -->|"promotes serialized model"| node_pipeline
node_model_training -->|"serializes auxiliary artifact"| node_model_frequency

click node_frontend "https://github.com/themrityunjaypathak/autoiq/blob/main/index.html"
click node_frontend_script "https://github.com/themrityunjaypathak/autoiq/blob/main/script.js"
click node_api "https://github.com/themrityunjaypathak/autoiq/blob/main/api/main.py"
click node_api_config "https://github.com/themrityunjaypathak/autoiq/blob/main/api/config.py"
click node_pipeline "https://github.com/themrityunjaypathak/autoiq/blob/main/models/pipe.pkl"
click node_model_frequency "https://github.com/themrityunjaypathak/autoiq/blob/main/models/model_freq.pkl"
click node_docker "https://github.com/themrityunjaypathak/autoiq/tree/main/Dockerfile"
click node_scraping "https://github.com/themrityunjaypathak/autoiq/blob/main/scrape_code/scrape_code.ipynb"
click node_scraping_utils "https://github.com/themrityunjaypathak/autoiq/blob/main/utils/web_scraping.py"
click node_raw_data "https://github.com/themrityunjaypathak/autoiq/blob/main/scrape_data/scrape_data.csv"
click node_preprocessing "https://github.com/themrityunjaypathak/autoiq/blob/main/notebooks/step_1_data_preprocessing.ipynb"
click node_outlier_detection "https://github.com/themrityunjaypathak/autoiq/blob/main/notebooks/step_2_outlier_detection.ipynb"
click node_eda "https://github.com/themrityunjaypathak/autoiq/blob/main/notebooks/step_3_exploratory_data_analysis.ipynb"
click node_refined_data "https://github.com/themrityunjaypathak/autoiq/blob/main/clean_data/clean_data_after_eda.parquet"
click node_model_training "https://github.com/themrityunjaypathak/autoiq/blob/main/notebooks/step_4_model_building.ipynb"

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_frontend,node_frontend_script toneBlue
class node_api,node_api_config,node_pipeline,node_model_frequency,node_docker toneAmber
class node_cars24,node_scraping,node_scraping_utils,node_raw_data,node_preprocessing,node_outlier_detection,node_eda,node_refined_data,node_model_training toneMint
```

## Components

### Browser client

Independently deployed static frontend.

- **User browser**: browser
- [Static prediction UI](https://github.com/themrityunjaypathak/autoiq/blob/main/index.html): HTML/JavaScript · Collects vehicle attributes and renders price ranges. · `index.html`
- [Request client](https://github.com/themrityunjaypathak/autoiq/blob/main/script.js): JavaScript · Posts form data to /predict. · `script.js`

### Prediction serving

FastAPI inference boundary.

- [FastAPI application](https://github.com/themrityunjaypathak/autoiq/blob/main/api/main.py): FastAPI · Owns health and prediction HTTP endpoints. · `api/main.py`
- [Runtime configuration](https://github.com/themrityunjaypathak/autoiq/blob/main/api/config.py): Python config · Provides model locations, CORS origins, and error metadata. · `api/config.py`
- [Prediction pipeline](https://github.com/themrityunjaypathak/autoiq/blob/main/models/pipe.pkl): serialized Scikit-learn model · Fitted preprocessing and tuned stacking regressor. · `models/pipe.pkl`
- [Model-frequency artifact](https://github.com/themrityunjaypathak/autoiq/blob/main/models/model_freq.pkl): serialized model artifact · Auxiliary serving artifact. · `models/model_freq.pkl`
- [Service container](https://github.com/themrityunjaypathak/autoiq/tree/main/Dockerfile): Docker image · Packages API and prediction assets. · `Dockerfile`

### Offline data pipeline

Acquisition, refinement, and training flow.

- **Cars24 listings**: external data source · Schema-fragile source of used-car listings.
- [Listing scraper](https://github.com/themrityunjaypathak/autoiq/blob/main/scrape_code/scrape_code.ipynb): Jupyter notebook · Uses browser rendering, parsing, and detail-page lookups. · `scrape_code/scrape_code.ipynb`
- [Scraping utilities](https://github.com/themrityunjaypathak/autoiq/blob/main/utils/web_scraping.py): Python utilities · Reusable Selenium and BeautifulSoup scraping functions. · `utils/web_scraping.py`
- [Raw listings](https://github.com/themrityunjaypathak/autoiq/blob/main/scrape_data/scrape_data.csv): CSV dataset · `scrape_data/scrape_data.csv`
- [Preprocessing stage](https://github.com/themrityunjaypathak/autoiq/blob/main/notebooks/step_1_data_preprocessing.ipynb): Jupyter notebook · Cleans raw listings into Parquet datasets. · `notebooks/step_1_data_preprocessing.ipynb`
- [Outlier stage](https://github.com/themrityunjaypathak/autoiq/blob/main/notebooks/step_2_outlier_detection.ipynb): Jupyter notebook · Produces the no-outlier dataset. · `notebooks/step_2_outlier_detection.ipynb`
- [EDA and feature preparation](https://github.com/themrityunjaypathak/autoiq/blob/main/notebooks/step_3_exploratory_data_analysis.ipynb): Jupyter notebook · Produces the training-ready dataset. · `notebooks/step_3_exploratory_data_analysis.ipynb`
- [Training-ready data](https://github.com/themrityunjaypathak/autoiq/blob/main/clean_data/clean_data_after_eda.parquet): Parquet dataset · `clean_data/clean_data_after_eda.parquet`
- [Model training and promotion](https://github.com/themrityunjaypathak/autoiq/blob/main/notebooks/step_4_model_building.ipynb): Jupyter notebook · Evaluates candidates and serializes the selected pipeline. · `notebooks/step_4_model_building.ipynb`

## Connections

- User browser → Static prediction UI: loads
- Static prediction UI → Request client: uses
- Request client → FastAPI application: POST /predict · Sends structured vehicle attributes.
- Runtime configuration → FastAPI application: configures · Supplies CORS and model paths.
- FastAPI application → Prediction pipeline: loads and infers with
- FastAPI application → Model-frequency artifact: loads
- Service container → FastAPI application: packages
- Service container → Prediction pipeline: includes
- Cars24 listings → Listing scraper: listing pages
- Scraping utilities → Listing scraper: supports
- Listing scraper → Raw listings: writes
- Raw listings → Preprocessing stage: input
- Preprocessing stage → Outlier stage: cleaned Parquet
- Outlier stage → EDA and feature preparation: no-outlier Parquet
- EDA and feature preparation → Training-ready data: writes
- Training-ready data → Model training and promotion: training input
- Model training and promotion → Prediction pipeline: promotes serialized model
- Model training and promotion → Model-frequency artifact: serializes auxiliary artifact
