# gouravkar007/ai-based-maternal-health-preeclampsia-risk-prediction-system architecture

> Architecture diagram of the GitHub repository gouravkar007/ai-based-maternal-health-preeclampsia-risk-prediction-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/gouravkar007/ai-based-maternal-health-preeclampsia-risk-prediction-system
- Repository: https://github.com/gouravkar007/ai-based-maternal-health-preeclampsia-risk-prediction-system

## Overview

#### Purpose and Entry Points
This repository delivers an educational maternal-health screening product: a Streamlit application performs staged ML risk assessment for preeclampsia, provides guidance, reporting, analytics, and a Gemini-backed chatbot. The public landing page is `index.html`; the runnable application entry point is `AI-Based-Maternal-Health-Preeclampsia-Risk-Prediction-System/app/app.py`.

#### Deployment Topology
GitHub Pages serves the static landing page, which links users to the separately hosted Streamlit service. Render is the app hosting target and its service definition is in `AI-Based-Maternal-Health-Preeclampsia-Risk-Prediction-System/render.yaml`. Python 3.11+ is the runtime; primary libraries include Streamlit and scikit-learn, declared through `AI-Based-Maternal-Health-Preeclampsia-Risk-Prediction-System/pyproject.toml`.

#### Streamlit Application Shell
The UI orchestration, navigation, patient input forms, emergency checks, dashboard visualizations, prediction presentation, and report-generation flow are centralized in `AI-Based-Maternal-Health-Preeclampsia-Risk-Prediction-System/app/app.py`. Streamlit presentation settings are bounded in `AI-Based-Maternal-Health-Preeclampsia-Risk-Prediction-System/.streamlit/config.toml`. This is a server-rendered interactive Python app, not a separate frontend/API architecture.

#### Staged Clinical Risk Flow
The primary control flow is:
1. Collect maternal demographic and clinical intake values.
2. Run the general maternal-health classifier.
3. Return low-risk guidance directly, or escalate high-risk results.
4. Collect/use the targeted preeclampsia feature set and run its classifier.
5. Present risk-specific recommendations and optionally generate a downloadable PDF summary.

The two persisted model artifacts are `AI-Based-Maternal-Health-Preeclampsia-Risk-Prediction-System/app/models/maternal_health_model.pkl` and `AI-Based-Maternal-Health-Preeclampsia-Risk-Prediction-System/app/models/preeclampsia_model.pkl`.

#### Model Serving Boundary
`AI-Based-Maternal-Health-Preeclampsia-Risk-Prediction-System/app/models/loader.py` is the model-loading boundary between UI logic and serialized scikit-learn artifacts. The repository contains inference assets only; dataset ingestion, feature engineering, training, evaluation, and model selection are described as upstream work rather than represented as executable source directories. Runtime correctness therefore depends on app-provided features matching each serialized model’s expected preprocessing/schema.

#### Guidance, Safety, and State
Clinical advice and threshold-style guidance are data-driven through `AI-Based-Maternal-Health-Preeclampsia-Risk-Prediction-System/app/doctor_advice.json`, consumed by the app’s result and safety flows. `AI-Based-Maternal-Health-Preeclampsia-Risk-Prediction-System/app/cache.py` provides the caching boundary for expensive or repeatable runtime operations, likely including model/resource reuse. Outputs are screening guidance only, with no indicated persistence layer, user account system, or clinical-record integration.

#### Conversational AI Integration
`AI-Based-Maternal-Health-Preeclampsia-Risk-Prediction-System/app/chatbot.py` encapsulates chatbot behavior and the external Gemini API integration. This is the principal external runtime dependency beyond deployment hosting: Gemini credentials/network availability affect chat functionality, while core local ML predictions rely on packaged `.pkl` artifacts.

Main entry points: [`AI-Based-Maternal-Health-Preeclampsia-Risk-Prediction-System/app/app.py`](https://github.com/gouravkar007/ai-based-maternal-health-preeclampsia-risk-prediction-system/blob/main/AI-Based-Maternal-Health-Preeclampsia-Risk-Prediction-System/app/app.py) (App Shell & Navigation), [`AI-Based-Maternal-Health-Preeclampsia-Risk-Prediction-System/app/models/loader.py`](https://github.com/gouravkar007/ai-based-maternal-health-preeclampsia-risk-prediction-system/blob/main/AI-Based-Maternal-Health-Preeclampsia-Risk-Prediction-System/app/models/loader.py) (Model Loader), [`AI-Based-Maternal-Health-Preeclampsia-Risk-Prediction-System/render.yaml`](https://github.com/gouravkar007/ai-based-maternal-health-preeclampsia-risk-prediction-system/blob/main/AI-Based-Maternal-Health-Preeclampsia-Risk-Prediction-System/render.yaml) (Render Service), [`index.html`](https://github.com/gouravkar007/ai-based-maternal-health-preeclampsia-risk-prediction-system/blob/main/index.html) (Landing Page)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Public Entry"]
  node_landing["Landing Page<br/>static site<br/>[index.html]"]
  node_github_pages{{"GitHub Pages<br/>static host"}}
end

subgraph group_hosting["Deployment"]
  node_render{{"Render Service<br/>app host<br/>[render.yaml]"}}
  node_runtime["Python Runtime<br/>dependency manifest<br/>[pyproject.toml]"]
  node_streamlit_config["Streamlit Settings<br/>presentation config<br/>[config.toml]"]
end

subgraph group_app["Streamlit Screening App"]
  node_app_shell["App Shell &amp; Navigation<br/>Streamlit UI<br/>[app.py]"]
  node_intake["Clinical Intake &amp; Safety<br/>UI flow<br/>[app.py]"]
  node_risk_flow["Staged Risk Flow<br/>screening workflow<br/>[app.py]"]
  node_results_reports["Results &amp; PDF Report<br/>output flow<br/>[app.py]"]
  node_advice["Clinical Guidance<br/>advice data<br/>[doctor_advice.json]"]
  node_cache["Runtime Cache<br/>cache boundary<br/>[cache.py]"]
  node_chatbot["Health Chatbot<br/>Gemini client<br/>[chatbot.py]"]
end

subgraph group_ml["Local ML Inference"]
  node_model_loader["Model Loader<br/>inference boundary<br/>[loader.py]"]
  node_maternal_model[("Maternal Health Model<br/>serialized classifier")]
  node_preeclampsia_model[("Preeclampsia Model<br/>serialized classifier")]
end

node_gemini{{"Gemini API<br/>external AI service"}}

node_github_pages -->|"serves"| node_landing
node_landing -->|"links to app"| node_render
node_render -->|"hosts"| node_app_shell
node_runtime -.->|"defines runtime"| node_render
node_streamlit_config -.->|"configures"| node_app_shell
node_app_shell -->|"collects inputs"| node_intake
node_intake -->|"clinical features"| node_risk_flow
node_risk_flow -->|"requests inference"| node_model_loader
node_model_loader -->|"loads general model"| node_maternal_model
node_model_loader -->|"loads targeted model"| node_preeclampsia_model
node_risk_flow -->|"risk result"| node_results_reports
node_advice -->|"supplies guidance"| node_results_reports
node_cache -.->|"reuses resources"| node_model_loader
node_app_shell -->|"opens chat"| node_chatbot
node_chatbot -->|"API requests"| node_gemini

click node_landing "https://github.com/gouravkar007/ai-based-maternal-health-preeclampsia-risk-prediction-system/blob/main/index.html"
click node_render "https://github.com/gouravkar007/ai-based-maternal-health-preeclampsia-risk-prediction-system/blob/main/AI-Based-Maternal-Health-Preeclampsia-Risk-Prediction-System/render.yaml"
click node_runtime "https://github.com/gouravkar007/ai-based-maternal-health-preeclampsia-risk-prediction-system/blob/main/AI-Based-Maternal-Health-Preeclampsia-Risk-Prediction-System/pyproject.toml"
click node_streamlit_config "https://github.com/gouravkar007/ai-based-maternal-health-preeclampsia-risk-prediction-system/blob/main/AI-Based-Maternal-Health-Preeclampsia-Risk-Prediction-System/.streamlit/config.toml"
click node_app_shell "https://github.com/gouravkar007/ai-based-maternal-health-preeclampsia-risk-prediction-system/blob/main/AI-Based-Maternal-Health-Preeclampsia-Risk-Prediction-System/app/app.py"
click node_intake "https://github.com/gouravkar007/ai-based-maternal-health-preeclampsia-risk-prediction-system/blob/main/AI-Based-Maternal-Health-Preeclampsia-Risk-Prediction-System/app/app.py"
click node_risk_flow "https://github.com/gouravkar007/ai-based-maternal-health-preeclampsia-risk-prediction-system/blob/main/AI-Based-Maternal-Health-Preeclampsia-Risk-Prediction-System/app/app.py"
click node_results_reports "https://github.com/gouravkar007/ai-based-maternal-health-preeclampsia-risk-prediction-system/blob/main/AI-Based-Maternal-Health-Preeclampsia-Risk-Prediction-System/app/app.py"
click node_advice "https://github.com/gouravkar007/ai-based-maternal-health-preeclampsia-risk-prediction-system/blob/main/AI-Based-Maternal-Health-Preeclampsia-Risk-Prediction-System/app/doctor_advice.json"
click node_cache "https://github.com/gouravkar007/ai-based-maternal-health-preeclampsia-risk-prediction-system/blob/main/AI-Based-Maternal-Health-Preeclampsia-Risk-Prediction-System/app/cache.py"
click node_chatbot "https://github.com/gouravkar007/ai-based-maternal-health-preeclampsia-risk-prediction-system/blob/main/AI-Based-Maternal-Health-Preeclampsia-Risk-Prediction-System/app/chatbot.py"
click node_model_loader "https://github.com/gouravkar007/ai-based-maternal-health-preeclampsia-risk-prediction-system/blob/main/AI-Based-Maternal-Health-Preeclampsia-Risk-Prediction-System/app/models/loader.py"
click node_maternal_model "https://github.com/gouravkar007/ai-based-maternal-health-preeclampsia-risk-prediction-system/blob/main/AI-Based-Maternal-Health-Preeclampsia-Risk-Prediction-System/app/models/maternal_health_model.pkl"
click node_preeclampsia_model "https://github.com/gouravkar007/ai-based-maternal-health-preeclampsia-risk-prediction-system/blob/main/AI-Based-Maternal-Health-Preeclampsia-Risk-Prediction-System/app/models/preeclampsia_model.pkl"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_landing,node_github_pages toneBlue
class node_render,node_runtime,node_streamlit_config toneAmber
class node_app_shell,node_intake,node_risk_flow,node_results_reports,node_advice,node_cache,node_chatbot toneMint
class node_model_loader,node_maternal_model,node_preeclampsia_model toneRose
class node_gemini toneNeutral
```

## Components

### Public Entry

- [Landing Page](https://github.com/gouravkar007/ai-based-maternal-health-preeclampsia-risk-prediction-system/blob/main/index.html): static site · Public product entry page. · `index.html`
- **GitHub Pages**: static host

### Deployment

- [Render Service](https://github.com/gouravkar007/ai-based-maternal-health-preeclampsia-risk-prediction-system/blob/main/AI-Based-Maternal-Health-Preeclampsia-Risk-Prediction-System/render.yaml): app host · `AI-Based-Maternal-Health-Preeclampsia-Risk-Prediction-System/render.yaml`
- [Python Runtime](https://github.com/gouravkar007/ai-based-maternal-health-preeclampsia-risk-prediction-system/blob/main/AI-Based-Maternal-Health-Preeclampsia-Risk-Prediction-System/pyproject.toml): dependency manifest · Python 3.11+ with Streamlit and scikit-learn. · `AI-Based-Maternal-Health-Preeclampsia-Risk-Prediction-System/pyproject.toml`
- [Streamlit Settings](https://github.com/gouravkar007/ai-based-maternal-health-preeclampsia-risk-prediction-system/blob/main/AI-Based-Maternal-Health-Preeclampsia-Risk-Prediction-System/.streamlit/config.toml): presentation config · `AI-Based-Maternal-Health-Preeclampsia-Risk-Prediction-System/.streamlit/config.toml`

### Streamlit Screening App

- [App Shell & Navigation](https://github.com/gouravkar007/ai-based-maternal-health-preeclampsia-risk-prediction-system/blob/main/AI-Based-Maternal-Health-Preeclampsia-Risk-Prediction-System/app/app.py): Streamlit UI · Central orchestration for forms, dashboards, results, and reports. · `AI-Based-Maternal-Health-Preeclampsia-Risk-Prediction-System/app/app.py`
- [Clinical Intake & Safety](https://github.com/gouravkar007/ai-based-maternal-health-preeclampsia-risk-prediction-system/blob/main/AI-Based-Maternal-Health-Preeclampsia-Risk-Prediction-System/app/app.py): UI flow · Collects maternal values and performs emergency checks. · `AI-Based-Maternal-Health-Preeclampsia-Risk-Prediction-System/app/app.py`
- [Staged Risk Flow](https://github.com/gouravkar007/ai-based-maternal-health-preeclampsia-risk-prediction-system/blob/main/AI-Based-Maternal-Health-Preeclampsia-Risk-Prediction-System/app/app.py): screening workflow · Routes general-risk results to guidance or targeted screening. · `AI-Based-Maternal-Health-Preeclampsia-Risk-Prediction-System/app/app.py`
- [Results & PDF Report](https://github.com/gouravkar007/ai-based-maternal-health-preeclampsia-risk-prediction-system/blob/main/AI-Based-Maternal-Health-Preeclampsia-Risk-Prediction-System/app/app.py): output flow · Presents recommendations and downloadable summaries. · `AI-Based-Maternal-Health-Preeclampsia-Risk-Prediction-System/app/app.py`
- [Clinical Guidance](https://github.com/gouravkar007/ai-based-maternal-health-preeclampsia-risk-prediction-system/blob/main/AI-Based-Maternal-Health-Preeclampsia-Risk-Prediction-System/app/doctor_advice.json): advice data · Threshold-style screening guidance and recommendations. · `AI-Based-Maternal-Health-Preeclampsia-Risk-Prediction-System/app/doctor_advice.json`
- [Runtime Cache](https://github.com/gouravkar007/ai-based-maternal-health-preeclampsia-risk-prediction-system/blob/main/AI-Based-Maternal-Health-Preeclampsia-Risk-Prediction-System/app/cache.py): cache boundary · Reuses expensive runtime resources. · `AI-Based-Maternal-Health-Preeclampsia-Risk-Prediction-System/app/cache.py`
- [Health Chatbot](https://github.com/gouravkar007/ai-based-maternal-health-preeclampsia-risk-prediction-system/blob/main/AI-Based-Maternal-Health-Preeclampsia-Risk-Prediction-System/app/chatbot.py): Gemini client · Encapsulates conversational behavior and API access. · `AI-Based-Maternal-Health-Preeclampsia-Risk-Prediction-System/app/chatbot.py`

### Local ML Inference

- [Model Loader](https://github.com/gouravkar007/ai-based-maternal-health-preeclampsia-risk-prediction-system/blob/main/AI-Based-Maternal-Health-Preeclampsia-Risk-Prediction-System/app/models/loader.py): inference boundary · Separates UI logic from serialized scikit-learn models. · `AI-Based-Maternal-Health-Preeclampsia-Risk-Prediction-System/app/models/loader.py`
- [Maternal Health Model](https://github.com/gouravkar007/ai-based-maternal-health-preeclampsia-risk-prediction-system/blob/main/AI-Based-Maternal-Health-Preeclampsia-Risk-Prediction-System/app/models/maternal_health_model.pkl): serialized classifier · General maternal-health risk classifier. · `AI-Based-Maternal-Health-Preeclampsia-Risk-Prediction-System/app/models/maternal_health_model.pkl`
- [Preeclampsia Model](https://github.com/gouravkar007/ai-based-maternal-health-preeclampsia-risk-prediction-system/blob/main/AI-Based-Maternal-Health-Preeclampsia-Risk-Prediction-System/app/models/preeclampsia_model.pkl): serialized classifier · Targeted preeclampsia risk classifier. · `AI-Based-Maternal-Health-Preeclampsia-Risk-Prediction-System/app/models/preeclampsia_model.pkl`

### Other components

- **Gemini API**: external AI service · Chat depends on credentials and network availability.

## Connections

- GitHub Pages → Landing Page: serves
- Landing Page → Render Service: links to app
- Render Service → App Shell & Navigation: hosts
- Python Runtime → Render Service: defines runtime
- Streamlit Settings → App Shell & Navigation: configures
- App Shell & Navigation → Clinical Intake & Safety: collects inputs
- Clinical Intake & Safety → Staged Risk Flow: clinical features
- Staged Risk Flow → Model Loader: requests inference
- Model Loader → Maternal Health Model: loads general model
- Model Loader → Preeclampsia Model: loads targeted model
- Staged Risk Flow → Results & PDF Report: risk result
- Clinical Guidance → Results & PDF Report: supplies guidance
- Runtime Cache → Model Loader: reuses resources
- App Shell & Navigation → Health Chatbot: opens chat
- Health Chatbot → Gemini API: API requests
