# kartikshingde/ml_mini_project architecture

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

- Interactive diagram: https://gitdiagram.com/kartikshingde/ml_mini_project
- Repository: https://github.com/kartikshingde/ml_mini_project

## Overview

##### Project Type and Purpose
- This is a full-stack machine learning web application.
- Purpose: Allow users to input Titanic passenger features via a React frontend, send those to a Flask API, and return survival predictions from a pre-trained Random Forest ML model.

##### File-Structure Analysis
- Root folder (backend):
- app.py – Flask application exposing `/health` and `/predict` endpoints.
- requirements.txt – Python deps (Flask, Flask-CORS, pandas, numpy, scikit-learn, joblib, gunicorn).
- titanic_model.pkl – Serialized Random Forest model.
- titanic_dataset/ – CSVs for training/test (used by train_model.py if present).
- Frontend folder:
- package.json, vite.config.js – Node/Vite config.
- public/, src/ – React components (App.jsx, main.jsx), CSS, assets.

##### README Insights
- Ports: Frontend on 5173, Backend on 5000.
- ML: Random Forest, 7 features, ~84% accuracy.
- No external databases or messaging queues—model file is the only persistent store.

a. Main Components
1. Browser/Client (React Frontend)
2. API Server (Flask + CORS)
3. Model Loader & Predictor (joblib-loaded `.pkl`)
4. (Optional) Training Pipeline: train_model.py + titanic_dataset/
5. External Dependencies: scikit-learn, pandas, numpy

b. Relationships & Data Flows
- User enters form data in React → HTTP POST to Flask `/predict`.
- Flask endpoint receives JSON → Data preprocessing (pandas/numpy) → Pass to Random Forest model → Prediction + probability returned as JSON.
- React reads the JSON response → Updates UI (show prediction, confidence).
- (Health check) React or curl can GET `/health` → JSON status.
- Training flow (one-time): train_model.py reads CSVs → trains Random Forest → serializes to titanic_model.pkl → backend can load new model on restart.

c. Architectural Patterns & Principles
- Client-Server (separation of concerns).
- RESTful API (health and predict endpoints).
- Single-page application (React + Vite).
- Model serving as a micro-service (monolithic backend but logically separate model component).
- Config-as-code (requirements.txt, package.json, vite.config.js).

d. Key Technologies & Frameworks
- Frontend: React, Vite, pure CSS, JavaScript/JSX.
- Backend: Python Flask, Flask-CORS.
- ML: scikit-learn RandomForestClassifier, joblib serialization.
- Data: pandas, numpy.
- Dev tooling: virtualenv, npm, nodemodules.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client (React Frontend)"
        React["React Frontend"]:::frontend
        PackageJSON["package.json"]:::tooling
        ViteConfig["vite.config.js"]:::tooling
    end

    %% Server Layer
    subgraph "Server (Flask API)"
        API["Flask API Server"]:::backend
        Requirements["requirements.txt"]:::dep
        Dependencies["Flask-CORS, pandas, numpy, scikit-learn, joblib"]:::dep
        Model["Model (titanic_model.pkl)"]:::model
    end

    %% Training Pipeline
    subgraph "Training Pipeline" 
        Dataset["titanic_dataset"]:::dataset
    end

    %% Data Flows
    React -->|"POST /predict (5173→5000)"| API
    API -->|"load & infer"| Model
    Model -->|"prediction JSON"| API
    API -->|"200 OK JSON"| React
    React -->|"GET /health (5173→5000)"| API

    %% Optional Training Flow
    Dataset -.->|"trains & serializes"| Model

    %% Click Events
    click React "https://github.com/kartikshingde/ml_mini_project/tree/main/frontend/"
    click PackageJSON "https://github.com/kartikshingde/ml_mini_project/blob/main/frontend/package.json"
    click ViteConfig "https://github.com/kartikshingde/ml_mini_project/blob/main/frontend/vite.config.js"
    click API "https://github.com/kartikshingde/ml_mini_project/blob/main/app.py"
    click Requirements "https://github.com/kartikshingde/ml_mini_project/blob/main/requirements.txt"
    click Model "https://github.com/kartikshingde/ml_mini_project/blob/main/titanic_model.pkl"
    click Dataset "https://github.com/kartikshingde/ml_mini_project/tree/main/titanic_dataset/"

    %% Styles
    classDef frontend fill:#f9f,stroke:#333,stroke-width:1px,color:#000
    classDef backend fill:#bbf,stroke:#333,stroke-width:1px,color:#000
    classDef model fill:#bfb,stroke:#333,stroke-width:1px,color:#000
    classDef dataset fill:#ffb,stroke:#333,stroke-width:1px,color:#000
    classDef tooling fill:#ddf,stroke:#333,stroke-width:1px,color:#000
    classDef dep fill:#ffd,stroke:#333,stroke-width:1px,color:#000
```
