# ayesha1209/predictionfailure architecture

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

- Interactive diagram: https://gitdiagram.com/ayesha1209/predictionfailure
- Repository: https://github.com/ayesha1209/predictionfailure

## Overview

##### Project Type & Purpose
- This is a full-stack, ML-powered web application (“Predictive Maintenance System”) built with Python and Flask.
- Purpose: Provide a real-time interface that takes machine parameters from a user, loads a pre-trained XGBoost model (pickled), predicts Time-To-Failure (TTF) for multiple components, and returns the results via a web UI or API.

##### File Structure Analysis
- Top-level files:
- app.py – Flask application entry point (controllers + routing)
- templates/index.html – Web UI
- test_data_xgb_enhanced.pkl, tttf_xgb_model_enhanced*.pkl – Serialized ML models/test data
- requirements.txt, runtime.txt, Procfile – Deployment configs (Heroku)
- No dedicated “model training” folder here; training pipeline lives elsewhere or upstream. This checkout focuses on serving/inference.

##### Key Architectural Components
a. Client (Browser or API Consumer)
b. Flask Web Server (app.py)
– Request handlers + business logic
– Loads/holds in memory the XGBoost model on startup
c. Model & Artifacts Store
– Local filesystem (pickle files)
– Could be abstracted to object storage (S3) or database in future
d. Preprocessor & Predictor
– Data validation & feature scaling/encoding (if included)
– Calls XGBoost model for multi-output regression
e. Presentation Layer
– Renders index.html template, form inputs, returns JSON or HTML
f. Deployment Environment
– WSGI server (Gunicorn recommended) behind a reverse proxy
– Heroku or Docker container (Procfile, runtime.txt, Dockerfile snippet)

##### Relationships & Data Flows
- Client submits input (form POST or JSON) →
Flask route “/predict” receives request →
Preprocessor normalizes & encodes inputs →
Predictor passes features to XGBoost model →
Model returns TTF predictions →
Flask formats response (JSON or HTML) →
Client displays results.
- On startup: Flask loads pickled model files into memory.

##### Architectural Patterns & Design Principles
- Monolithic ML inference service with clear separation:
- Presentation (templates)
- Controller (Flask routes)
- Model (pickle files & prediction logic)
- Future extensibility: swap filesystem storage for cloud storage, extract Preprocessor into its own service, scale with Gunicorn workers.
- Twelve-factor app principles: Procfile + requirements/runtime files for environment separation.

##### Technology Stack Highlights
- Python 3.x, Flask
- XGBoost via joblib/pickle files
- HTML/Jinja2 templates
- Deployment: Heroku (Procfile), optional Docker (Dockerfile)
- Dependencies managed via requirements.txt

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    Client["Browser / API Consumer"]:::frontend
    click Client "https://github.com/ayesha1209/predictionfailure/blob/main/templates/index.html"

    %% API & Compute Layer
    subgraph "API & Compute Layer"
        direction TB
        FlaskServer["Flask Web Server\n(Controllers & Routing)"]:::backend
        click FlaskServer "https://github.com/ayesha1209/predictionfailure/blob/main/app.py"
        Presentation["Presentation Layer\n(HTML / Jinja2 Templates)"]:::frontend
        click Presentation "https://github.com/ayesha1209/predictionfailure/blob/main/templates/index.html"
        Preprocessor["Preprocessor & Predictor"]:::backend
    end

    %% Storage Layer
    subgraph "Storage Layer"
        direction TB
        ModelStore[(Pickled XGBoost Models)]:::storage
        click ModelStore "https://github.com/ayesha1209/predictionfailure/blob/main/tttf_xgb_model_enhanced.pkl"
        BackupModel[(Backup Model)]:::storage
        click BackupModel "https://github.com/ayesha1209/predictionfailure/blob/main/tttf_xgb_model_enhanced_backup.pkl"
        TestData[(Test Data)]:::storage
        click TestData "https://github.com/ayesha1209/predictionfailure/blob/main/test_data_xgb_enhanced.pkl"
    end

    %% Deployment Environment
    subgraph "Deployment Environment"
        direction TB
        Deployment["Heroku / Docker"]:::deploy
        Procfile["Procfile"]:::deploy
        click Procfile "https://github.com/ayesha1209/predictionfailure/tree/main/Procfile"
        Runtime["runtime.txt"]:::deploy
        click Runtime "https://github.com/ayesha1209/predictionfailure/blob/main/runtime.txt"
        Requirements["requirements.txt"]:::deploy
        click Requirements "https://github.com/ayesha1209/predictionfailure/blob/main/requirements.txt"
        Readme["README.md"]:::deploy
        click Readme "https://github.com/ayesha1209/predictionfailure/blob/main/README.md"
    end

    %% Data Flows
    Client -->|"HTTP POST JSON / Form"| FlaskServer
    FlaskServer -->|"Render /predict endpoint"| Preprocessor
    Preprocessor -->|"Feature Vector"| FlaskServer
    FlaskServer -->|"Render HTML / JSON"| Client

    %% Model Loading & Prediction
    Deployment -->|Hosts| FlaskServer
    Deployment -->|Hosts| ModelStore
    ModelStore -->|Unpickled Model Object| FlaskServer
    BackupModel -->|Available Backup| FlaskServer

    %% Class Definitions
    classDef frontend fill:#D6EAF8,stroke:#2980B9,color:#154360;
    classDef backend fill:#D5F5E3,stroke:#27AE60,color:#145A32;
    classDef storage fill:#FCF3CF,stroke:#D68910,color:#7E5109;
    classDef deploy fill:#D7DBDD,stroke:#7B7D7D,color:#424949;
```
