# 03-princy/employee-salary-prediction architecture

> Architecture diagram of the GitHub repository 03-princy/employee-salary-prediction, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/03-princy/employee-salary-prediction
- Repository: https://github.com/03-princy/employee-salary-prediction

## Overview

##### Project type and purpose
- Type: A lightweight machine-learning service for predicting employee salary based on the UCI Adult dataset.
- Purpose: Train a predictive model (using train_model.py and notebooks), serialize artifacts (best_model.pkl, target_encoder.pkl), and expose an inference endpoint (via app.py).

##### File structure
- Root files:
– adult.csv: raw dataset
– train_model.py: training pipeline script
– best_model.pkl, target_encoder.pkl: serialized artifacts
– app.py: Flask (or similar) inference API
– Jupyter notebooks: exploratory data analysis and iterative model building
- No separate “frontend” directory, so the inference surface is a simple HTTP API.

##### Main components & interactions
a. Data Source
– adult.csv (raw input)
b. Training Pipeline
– train_model.py (ingests adult.csv)
– Preprocessor (target_encoder.pkl)
– Model Trainer (e.g., scikit-learn pipeline)
– Model Selection → best_model.pkl
c. Model Storage
– best_model.pkl, target_encoder.pkl (persisted to disk)
d. Inference Service
– app.py loads both pickles at startup
– Exposes HTTP endpoint (e.g., POST /predict)
– Input JSON → preprocess → model.predict() → output JSON
e. (Optional) Client
– Any HTTP client (curl, Postman, front-end) that consumes /predict

##### Architectural patterns & design principles
- Separation of concerns: training vs. inference
- Artifact versioning: keeping best_model.pkl separate from code
- Lightweight microservice: single-process web API
- Reproducibility: notebooks for EDA, train_model.py for pipeline

- Clear labels: “Raw Dataset,” “Preprocessor,” “Model Trainer,” “best_model.pkl,” “target_encoder.pkl,” “Flask API (app.py).”
- A note indicating that “adult.csv” lives on disk alongside code.

[Raw Dataset (adult.csv)]
│
▼ ingest
[Training Pipeline (train_model.py)]──►[target_encoder.pkl]
│                                    │
└──►[best_model.pkl]◄────────────────┘
│
▼ load on startup
[Inference Service (app.py) ──► HTTP API /predict ──► Client]

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Training Workflow
    subgraph "Training Workflow"
        RawDataset["Raw Dataset<br/>(adult.csv)"]:::data
        TrainingPipeline["Training Pipeline<br/>(train_model.py)"]:::compute
        TargetEncoder["Preprocessor Artifact<br/>(target_encoder.pkl)"]:::data
        BestModel["Model Artifact<br/>(best_model.pkl)"]:::data
    end

    %% Inference Workflow
    subgraph "Inference Workflow"
        InferenceService["Inference Service<br/>(Flask API: app.py)"]:::compute
        Client["Client (curl/Postman)"]:::external
    end

    %% Exploration & Prototyping
    subgraph "Exploration & Prototyping"
        Notebook1["EDA Notebook<br/>(employee salary prediction.ipynb)"]:::compute
        Notebook2["KNN Notebook<br/>(knn_adult_csv updated.ipynb)"]:::compute
    end

    %% README
    README["Project README<br/>(README.md)"]:::data

    %% Connections
    RawDataset -->|"ingest"| TrainingPipeline
    TrainingPipeline -->|"serialize"| TargetEncoder
    TrainingPipeline -->|"serialize"| BestModel
    TargetEncoder -->|"load on startup"| InferenceService
    BestModel -->|"load on startup"| InferenceService
    Client -->|"request JSON"| InferenceService
    InferenceService -->|"HTTP POST /predict"| Client

    %% Click Events
    click RawDataset "https://github.com/03-princy/employee-salary-prediction/blob/main/adult.csv"
    click TrainingPipeline "https://github.com/03-princy/employee-salary-prediction/blob/main/train_model.py"
    click TargetEncoder "https://github.com/03-princy/employee-salary-prediction/blob/main/target_encoder.pkl"
    click BestModel "https://github.com/03-princy/employee-salary-prediction/blob/main/best_model.pkl"
    click InferenceService "https://github.com/03-princy/employee-salary-prediction/blob/main/app.py"
    click Notebook1 "https://github.com/03-princy/employee-salary-prediction/blob/main/employee salary prediction.ipynb"
    click Notebook2 "https://github.com/03-princy/employee-salary-prediction/blob/main/knn_adult_csv updated.ipynb"
    click README "https://github.com/03-princy/employee-salary-prediction/blob/main/README.md"

    %% Styles
    classDef data fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef compute fill:#90EE90,stroke:#000,stroke-width:1px
    classDef external fill:#FFA500,stroke:#000,stroke-width:1px
```
