# ashandilgith/fetal_health architecture

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

- Interactive diagram: https://gitdiagram.com/ashandilgith/fetal_health
- Repository: https://github.com/ashandilgith/fetal_health

## Overview

##### Project type and purpose
- This is a full-stack, end-to-end machine-learning application for predicting fetal health status from CTG data.
- It supports data ingestion, model training, artifact management, a serving API, and a simple web UI.

##### File structure
- Top-level
- file_creation.py – orchestration or data-prep script
- fetal-health-system/ – main project directory
- fetal-health-system/backend/
- app.py / app2.py – web service entry points (likely Flask or FastAPI)
- requirements.txt – Python dependencies
- model/
– model.py, model2.py – training code
– fetal_model.pkl, fetal_best_model_713PM.pkl – trained model artifacts
– scaler.pkl, scaler_713PM.pkl – preprocessing objects
– test_model.py, test_model2.py – unit tests for training logic
- utils/alerts.py – notification utility
- fetal-health-system/data/
- fetal_health.csv – raw dataset
- fetal-health-system/templates/
- index.html, index2.html – HTML pages for user input & results

##### README for additional insights
- Confirms an ML pipeline: data → training (TensorFlow/Keras) → classification.
- Tech stack: Python, TensorFlow/Keras, Scikit-learn, Pandas/NumPy, optional FastAPI/Streamlit.
- Goal: assist healthcare professionals with fetal health decision support.

a. Main components
- Data Layer (fetal_health.csv)
- Training Pipeline (model.py/model2.py)
- Model Artifacts (PKL files & scalers)
- Serving API (app.py/app2.py + alerts.py)
- Frontend UI (HTML templates)
- QA Layer (test_model.py/test_model2.py)
b. Relationships & interactions
1. Data Layer → Training Pipeline
2. Training Pipeline → Model Artifacts
3. API loads Model Artifacts & Scaler
4. Frontend issues HTTP requests to API → receives classification & alerts
c. Architectural patterns
- Layered architecture separating offline batch training from online serving
- Explicit model versioning and artifact management
- Separation of concerns: data, training, serving, presentation, testing
d. Key technologies
- TensorFlow/Keras (modeling)
- Scikit-learn (preprocessing)
- Flask or FastAPI (API server)
- Jinja2 HTML templates (UI)
- Pandas/NumPy (data handling)

##### Essential details to capture
- Multiple model versions (fetal_model.pkl vs fetal_best_model_713PM.pkl)
- Scaler objects alongside models
- utils/alerts.py as a dedicated notification micro-module
- test scripts as a separate QA layer
- The flow of data from raw CSV through training into live predictions

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Batch Processing Layer"
        FC["file_creation.py"]:::dataTraining
        CSV["fetal_health.csv"]:::dataTraining
        subgraph "Training Pipeline"
            M1["model.py"]:::dataTraining
            M2["model2.py"]:::dataTraining
        end
        subgraph "Model Artifacts"
            A1["fetal_model.pkl"]:::dataTraining
            A2["fetal_best_model_713PM.pkl"]:::dataTraining
            S1["scaler.pkl"]:::dataTraining
            S2["scaler_713PM.pkl"]:::dataTraining
        end
    end

    subgraph "Online Serving Layer"
        subgraph "API Layer"
            API1["app.py"]:::api
            API2["app2.py"]:::api
            Alerts["alerts.py"]:::util
        end
        subgraph "Frontend UI"
            UI1["index.html"]:::frontend
            UI2["index2.html"]:::frontend
        end
    end

    subgraph "QA Layer"
        T1["test_model.py"]:::qa
        T2["test_model2.py"]:::qa
    end

    FC --> CSV
    CSV --> M1
    CSV --> M2
    M1 --> A1
    M1 --> S1
    M2 --> A2
    M2 --> S2
    A1 --> API1
    S1 --> API1
    A2 --> API2
    S2 --> API2
    UI1 -->|requests| API1
    API1 -->|responses| UI1
    UI2 -->|requests| API2
    API2 -->|responses| UI2
    API1 --> Alerts
    API2 --> Alerts
    M1 --> T1
    M2 --> T2

    click CSV "https://github.com/ashandilgith/fetal_health/blob/main/fetal-health-system/data/fetal_health.csv"
    click M1 "https://github.com/ashandilgith/fetal_health/blob/main/fetal-health-system/backend/model/model.py"
    click M2 "https://github.com/ashandilgith/fetal_health/blob/main/fetal-health-system/backend/model/model2.py"
    click A1 "https://github.com/ashandilgith/fetal_health/blob/main/fetal-health-system/backend/model/fetal_model.pkl"
    click A2 "https://github.com/ashandilgith/fetal_health/blob/main/fetal-health-system/backend/model/fetal_best_model_713PM.pkl"
    click S1 "https://github.com/ashandilgith/fetal_health/blob/main/fetal-health-system/backend/model/scaler.pkl"
    click S2 "https://github.com/ashandilgith/fetal_health/blob/main/fetal-health-system/backend/model/scaler_713PM.pkl"
    click API1 "https://github.com/ashandilgith/fetal_health/blob/main/fetal-health-system/backend/app.py"
    click API2 "https://github.com/ashandilgith/fetal_health/blob/main/fetal-health-system/backend/app2.py"
    click Alerts "https://github.com/ashandilgith/fetal_health/blob/main/fetal-health-system/backend/utils/alerts.py"
    click UI1 "https://github.com/ashandilgith/fetal_health/blob/main/fetal-health-system/templates/index.html"
    click UI2 "https://github.com/ashandilgith/fetal_health/blob/main/fetal-health-system/templates/index2.html"
    click T1 "https://github.com/ashandilgith/fetal_health/blob/main/fetal-health-system/backend/model/test_model.py"
    click T2 "https://github.com/ashandilgith/fetal_health/blob/main/fetal-health-system/backend/model/test_model2.py"
    click FC "https://github.com/ashandilgith/fetal_health/blob/main/file_creation.py"

    classDef dataTraining fill:#BBDEFB,stroke:#0D47A1
    classDef api fill:#C8E6C9,stroke:#1B5E20
    classDef frontend fill:#FFF9C4,stroke:#F57F17
    classDef util fill:#E0E0E0,stroke:#424242
    classDef qa fill:#EEEEEE,stroke:#424242,stroke-dasharray:5 5
```
