# omiiii1221/used-car-price-prediction architecture

> Architecture diagram of the GitHub repository omiiii1221/used-car-price-prediction, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/omiiii1221/used-car-price-prediction
- Repository: https://github.com/omiiii1221/used-car-price-prediction

## Overview

##### Project Type and Purpose
- This is a **full-stack, web-based Machine Learning application** built with Flask.
- Purpose: Expose a Random Forest regression model over HTTP so end-users can enter car specs (year, KM driven, fuel type, etc.) in a browser form and receive a resale-price prediction.

##### File Structure
- Top-Level Files
– app.py: The Flask application (controller + entry point)
– rf_model.joblib: Serialized Random Forest model (inference artifact)
– cars24data_cleaned.xlsx: Raw dataset used during training
– used_car_Price_Prediction.ipynb: Jupyter notebook for exploratory analysis and model training
– requirements.txt: Dependency list
- Directories
– static/: CSS (style.css), JS or images served as static assets (client-side)
– templates/: Jinja2 HTML templates (view layer)
- Dev & Config
– .vscode/: Editor settings (not part of runtime)

##### README for Tech Stack & Workflow
- **Backend**: Python + Flask
- **Modeling**: scikit-learn (RandomForestRegressor), Pandas, NumPy
- **Frontend**: HTML/CSS via Jinja2 templates
- **Runtime**:
1. User opens form (GET /)
2. Submits specs (POST /predict)
3. app.py loads rf_model.joblib, preprocesses inputs (via Pandas), runs inference, returns rendered HTML

##### Main Components & Their Relationships
┌──────────────┐        ┌─────────────────┐        ┌───────────────────┐
│   Web Client │  HTTP  │   Flask Server  │  In-Process │   ML Inference   │
│ (Browser UI) │ ─────► │   (app.py)      │ ─────────► │ (joblib+Pandas)  │
└──────────────┘ ◀───── └─────────────────┘ ◀─────────┘                   │
▲                   │            │                               │
│ Static Assets     │            └──────────┬────────────────────┘
│ (CSS, JS, Images) │                       │
│                   │              ┌────────▼─────────┐
│                   └──────────────►│ Data Store       │
│                                  │ (rf_model.joblib,│
│                                  │  cars24data*.xlsx)│
│                                  └──────────────────┘

- **Flow**:
a. Browser requests HTML form → Flask serves Jinja2 template + static CSS
b. User submits form → Flask route receives POST → Pandas transforms data → RandomForest.predict() → Flask returns result page
c. Model and data live on disk; loaded at startup or per-request

##### Architectural Patterns & Design Principles
- **Monolithic, MVC-style**:
- Model: rf_model.joblib + preprocessing code
- View: Jinja2 templates + static assets
- Controller: Flask routes in app.py
- **Layered Design**: Presentation → Application Logic → ML Inference → Data
- **Separation of Concerns**: Static vs. dynamic content, training vs. runtime inference

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        direction TB
        Browser["Web Client<br>(Browser UI)"]:::client
        Static["Static Assets<br>(CSS, JS, Images)"]:::client
    end

    %% Server Layer
    subgraph "Server Layer"
        direction TB

        subgraph "API / Web Layer"
            direction TB
            App["Flask App<br>(app.py)"]:::server
            Templates["Jinja2 Templates<br>(templates/index.html)"]:::server
        end

        subgraph "Inference Layer"
            direction TB
            Preproc["Data Preprocessing<br>(Pandas)"]:::ml
            Model["Random Forest Model<br>(rf_model.joblib)"]:::ml
        end

        %% Data Store
        DataStore["Data Store<br>(rf_model.joblib, cars24data_cleaned.xlsx)"]:::storage
    end

    %% Dev & Config
    subgraph "Development & Documentation"
        direction TB
        Notebook["Training Notebook<br>(used_car_Price_Prediction.ipynb)"]:::docs
        README["Project Docs<br>(README.md)"]:::docs
        Requirements["Dependencies<br>(requirements.txt)"]:::docs
        Config["Editor Config<br>(.vscode/)"]:::docs
        Structure["Project Structure<br>(structure.txt)"]:::docs
    end

    %% Client to Server Interactions
    Browser -->|"GET /"| App
    App -->|"Render Form"| Templates
    Templates --> Browser

    Browser -->|"Request Static"| Static
    Static --> Browser

    Browser -->|"Submit Specs (POST /predict)"| App
    App -->|"Preprocess Inputs"| Preproc
    Preproc -->|"Load & Preprocess Data"| Model
    Model -->|"Predict Price"| App
    App -->|"Render Result"| Browser

    %% Server Data Store
    App -->|"Load Model/Data"| DataStore
    Preproc --> DataStore

    %% Dev & Docs References
    Notebook --> DataStore
    Requirements --> App
    README --> App
    Config --> App
    Structure --> App

    %% Click Events
    click App "https://github.com/omiiii1221/used-car-price-prediction/blob/main/app.py"
    click Model "https://github.com/omiiii1221/used-car-price-prediction/blob/main/rf_model.joblib"
    click DataStore "https://github.com/omiiii1221/used-car-price-prediction/blob/main/rf_model.joblib"
    click DataStore "https://github.com/omiiii1221/used-car-price-prediction/blob/main/cars24data_cleaned.xlsx"
    click Notebook "https://github.com/omiiii1221/used-car-price-prediction/blob/main/used_car_Price_Prediction.ipynb"
    click Static "https://github.com/omiiii1221/used-car-price-prediction/blob/main/static/style.css"
    click Templates "https://github.com/omiiii1221/used-car-price-prediction/blob/main/templates/index.html"
    click README "https://github.com/omiiii1221/used-car-price-prediction/blob/main/README.md"
    click Requirements "https://github.com/omiiii1221/used-car-price-prediction/blob/main/requirements.txt"
    click Config "https://github.com/omiiii1221/used-car-price-prediction/tree/main/.vscode/"
    click Structure "https://github.com/omiiii1221/used-car-price-prediction/blob/main/structure.txt"

    %% Styles
    classDef client fill:#d4f8d4,stroke:#2f6627,color:#000
    classDef server fill:#d0e7ff,stroke:#1a4c8b,color:#000
    classDef ml fill:#ffe2b3,stroke:#b36b00,color:#000
    classDef storage fill:#e0e0e0,stroke:#666,color:#000
    classDef docs fill:#f0d9ff,stroke:#7a338d,color:#000
```
