# taha-ter/injury_recovery_model architecture

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

- Interactive diagram: https://gitdiagram.com/taha-ter/injury_recovery_model
- Repository: https://github.com/taha-ter/injury_recovery_model

## Overview

##### Project type and purpose
- This is a full-stack, monolithic web application built with Python/Flask that serves a machine-learning model for predicting recovery time after an injury.
- The README confirms its goal: ingest historical injury data, train a predictive model, and expose visualizations and predictions via a web UI.

##### File structure
Top-level:
- application.py – the Flask app entry point (routes, session management, model inference).
- train_model.py – script to preprocess data (injury1.csv), train the ML pipeline, and dump artifacts (preprocessor.pkl, recovery_model.pkl).
- injury_recovery_model.pkl – a bundled model (or wrapper) for inference.
- requirements.txt – Python dependencies.
injury_recovery_model/
- flask_session/ – on-disk session store.
- static/ – CSS, JS, images, and graph scripts (pie.js, graph.js, jquery.js).
- templates/ – HTML templates (layout.html, index.html; external-page subfolder for injuries.html, injury_recover.html).

##### README for additional insights
- No explicit architecture section, but mentions Data Analysis, Predictive Modeling, and Visualization as three core capabilities.
- No external services (e.g., databases or message queues) are referenced—sessions and model artifacts are file-based.

##### Main components & their relationships
a. Frontend layer (Client Browser):
– HTML templates (layout, index, external pages)
– Static assets (CSS styling, JavaScript charting libraries)
b. Web/API layer (Flask app):
– application.py: HTTP endpoints for pages, form submissions, AJAX calls for charts.
– Flask-Session: persistent session storage in the flask_session directory.
c. Model layer (ML artifacts):
– Preprocessor (preprocessor.pkl) transforms user inputs into feature vectors.
– RecoveryModel (recovery_model.pkl) generates the prediction.
– Optionally an aggregated bundle (injury_recovery_model.pkl).
– train_model.py is a standalone pipeline that reads injury1.csv, generates these artifacts.
d. Data layer (for training):
– Raw data file (injury1.csv).
e. (Optional) Dependency layer:
– Python libraries (Flask, scikit-learn, pandas, etc. defined in requirements.txt).

Interactions:
- User → Browser → HTTP GET/POST → Flask → loads pickle → predicts → Flask → renders HTML/JSON → Browser
- Admin/Dev → CLI → `python train_model.py` → reads CSV → writes new .pkl artifacts
- Flask-Session intercepts requests to load/store session data on disk.

##### Architectural patterns & design principles
- MVC-style separation: Templates (View), application.py (Controller), model artifacts (Model).
- Three-tier web application: client, server, model/data.
- File-based session management (no external Redis/DB).
- Reusable training pipeline decoupled from serving code.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend Layer"
        Browser["User Browser"]:::frontend
        Templates["HTML Templates"]:::frontend
        StaticAssets["Static Assets"]:::frontend
    end

    %% Web/API Layer
    subgraph "Web/API Layer"
        FlaskApp["Flask App\n(application.py)"]:::backend
        SessionStore["Session Store\n(flask_session/)"]:::backend
    end

    %% Model Layer
    subgraph "Model Layer"
        Preprocessor["Preprocessor\n(preprocessor.pkl)"]:::ml
        RecoveryModel["Recovery Model\n(recovery_model.pkl)"]:::ml
        ModelBundle["Model Bundle\n(injury_recovery_model.pkl)"]:::ml
    end

    %% Data Layer
    subgraph "Data Layer"
        TrainingData["Injury Data\n(injury1.csv)"]:::data
    end

    %% Training Pipeline
    subgraph "Training Pipeline"
        TrainScript["Training Script\n(train_model.py)"]:::ml
    end

    %% Dependency & Documentation
    subgraph "Dependency & Documentation"
        Requirements["requirements.txt"]:::dep
        Docs["README.md"]:::dep
    end

    %% Interactions
    Browser -->|"HTTP GET/POST"| FlaskApp
    FlaskApp -->|"loads pickles"| Preprocessor
    FlaskApp -->|"invokes"| RecoveryModel
    FlaskApp -->|"serves HTML/JSON"| Browser
    FlaskApp -->|"stores sessions"| SessionStore

    TrainScript -->|"reads"| TrainingData
    TrainScript -->|"generates"| Preprocessor
    TrainScript -->|"generates"| RecoveryModel
    TrainScript -->|"bundles as"| ModelBundle

    %% Click Events
    click Templates "https://github.com/taha-ter/injury_recovery_model/tree/main/injury_recovery_model/templates/"
    click StaticAssets "https://github.com/taha-ter/injury_recovery_model/tree/main/injury_recovery_model/static/"
    click FlaskApp "https://github.com/taha-ter/injury_recovery_model/blob/main/injury_recovery_model/application.py"
    click SessionStore "https://github.com/taha-ter/injury_recovery_model/tree/main/injury_recovery_model/flask_session/"
    click Preprocessor "https://github.com/taha-ter/injury_recovery_model/blob/main/injury_recovery_model/preprocessor.pkl"
    click RecoveryModel "https://github.com/taha-ter/injury_recovery_model/blob/main/injury_recovery_model/recovery_model.pkl"
    click ModelBundle "https://github.com/taha-ter/injury_recovery_model/blob/main/injury_recovery_model/injury_recovery_model.pkl"
    click TrainingData "https://github.com/taha-ter/injury_recovery_model/blob/main/injury_recovery_model/injury1.csv"
    click TrainScript "https://github.com/taha-ter/injury_recovery_model/blob/main/injury_recovery_model/train_model.py"
    click Requirements "https://github.com/taha-ter/injury_recovery_model/blob/main/injury_recovery_model/requirements.txt"
    click Docs "https://github.com/taha-ter/injury_recovery_model/blob/main/README.md"

    %% Styles
    classDef frontend fill:#cfe2f3,stroke:#333,stroke-width:1px
    classDef backend fill:#d9ead3,stroke:#333,stroke-width:1px
    classDef ml fill:#fce5cd,stroke:#333,stroke-width:1px
    classDef data fill:#d9d2e9,stroke:#333,stroke-width:1px
    classDef dep fill:#f4cccc,stroke:#333,stroke-width:1px
```
