# onsrajhi/laptop-price-prediction architecture

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

- Interactive diagram: https://gitdiagram.com/onsrajhi/laptop-price-prediction
- Repository: https://github.com/onsrajhi/laptop-price-prediction

## Overview

##### Project type and purpose
- This is a self-contained, monolithic ML web application built with Streamlit.
- Purpose: allow end-users to input laptop specs via a web UI and receive a predicted price based on a pre-trained scikit-learn pipeline.

##### File structure
- Top-level files:
- app.py – the Streamlit app (UI + request handler)
- laptop-prediction.ipynb – exploratory notebook (data cleaning, EDA, model training)
- pipe.pkl – serialized ML pipeline (preprocessing + regression model)
- df.pkl – serialized processed DataFrame (encoders, feature references)
- laptop.csv – original raw dataset
- requirements.txt – Python dependencies
- .devcontainer folder – defines local dev container for consistent environment

##### README for additional insights
- Data flow: CSV → cleaning/feature-engineering → train/test → pipeline → pickle
- Streamlit app loads pipe.pkl + df.pkl to serve predictions
- Deployment target: Streamlit Cloud

##### Main components
a. User & Browser (External Actor)
b. Streamlit Web UI (app.py)
c. Business Logic Layer
– Input validation & form handling
– Pipeline loader
d. ML Pipeline (pipe.pkl)
– Feature encoders (from df.pkl)
– Preprocessing transformers
– Regression model
e. Data Artifacts (Data Stores)
– df.pkl: encodings & metadata
– pipe.pkl: trained pipeline
– laptop.csv: raw dataset (used offline)
f. Development Container (.devcontainer) – optional for local dev

##### Relationships and interactions
1. User opens browser → HTTP request to Streamlit server
2. app.py renders input form → user submits specs
3. app.py loads pipe.pkl & df.pkl from disk (once at startup)
4. Input passed through pipeline → model returns prediction
5. app.py displays result in browser
6. For local dev, .devcontainer ensures consistent environment

##### Architectural patterns & design principles
- Monolithic, layered architecture (UI + Logic + Model + Data)
- Separation of concerns: UI code in Streamlit calls into a distinct ML pipeline
- Artifacts versioned and immutable (pickle files)
- Dev environment codified via devcontainer

##### Detail level
- Initialization: Streamlit App loads pipeline at startup
- Request flow for each prediction
- Configuration (e.g., devcontainer for local Dockerized dev)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Actor
    User((User/Browser)):::external

    %% Streamlit Application
    subgraph "Streamlit Web App"
        App["Streamlit App"]:::compute
    end

    %% ML Pipeline Component
    subgraph "ML Pipeline"
        Pipeline["ML Pipeline"]:::compute
    end

    %% Data Artifacts
    subgraph "Data Artifacts"
        DF["df.pkl"]:::datastore
        PIPE["pipe.pkl"]:::datastore
        RAW["laptop.csv"]:::datastore
    end

    %% Model Development Notebook
    subgraph "Model Development"
        Notebook["Laptop prediction.ipynb"]:::compute
    end

    %% Configuration & Docs
    subgraph "Development & Docs"
        Dev[".devcontainer"]:::config
        Req["requirements.txt"]:::config
        README["README.md"]:::config
    end

    %% Connections
    User -->|"opens app"| App
    App -->|"load at startup"| PIPE
    App -->|"load at startup"| DF
    App -->|"predict(specs)"| Pipeline
    Pipeline -->|"uses metadata"| DF
    Pipeline -->|"model inference"| PIPE
    Notebook -->|"reads raw data"| RAW

    %% Click Events
    click App "https://github.com/onsrajhi/laptop-price-prediction/blob/main/app.py"
    click Notebook "https://github.com/onsrajhi/laptop-price-prediction/blob/main/Laptop prediction.ipynb"
    click PIPE "https://github.com/onsrajhi/laptop-price-prediction/blob/main/pipe.pkl"
    click DF "https://github.com/onsrajhi/laptop-price-prediction/blob/main/df.pkl"
    click RAW "https://github.com/onsrajhi/laptop-price-prediction/blob/main/laptop.csv"
    click Dev "https://github.com/onsrajhi/laptop-price-prediction/blob/main/.devcontainer/devcontainer.json"
    click Req "https://github.com/onsrajhi/laptop-price-prediction/blob/main/requirements.txt"
    click README "https://github.com/onsrajhi/laptop-price-prediction/blob/main/README.md"

    %% Styles
    classDef compute fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef datastore fill:#98FB98,stroke:#333,stroke-width:1px
    classDef external fill:#FFA500,stroke:#333,stroke-width:1px
    classDef config fill:#E6E6FA,stroke:#333,stroke-width:1px
```
