A hybrid mobile and web application that empowers Community Health Workers (CHWs) to predict Gestational Diabetes Mellitus risk in pregnant women using Machine Learning.
MamaSafe is a comprehensive healthcare solution built with FastAPI (Python) for the backend and Flutter for the mobile frontend. The system helps predict the risk level of Gestational Diabetes Mellitus (GDM) in pregnant women based on medical parameters such as:
- π Blood Glucose Level
- π Blood Pressure (Systolic & Diastolic)
- π Maternal Age
The goal is to enable early diagnosis, improve maternal health monitoring, and provide Community Health Workers (CHWs) and patients with a simple yet powerful AI-powered prediction tool.
- GDM affects 10-25% of pregnancies in developing countries
- Late diagnosis leads to complications for both mother and baby
- Limited access to diagnostic facilities in rural areas
- High cost of traditional screening methods
- Mobile-first application for CHWs
- ML-powered instant risk assessment (85%+ accuracy)
- Real-time predictions with actionable recommendations
- Automated high-risk alerts and notifications
- Description
- Demo Video
- Download & Installation
- Project Structure
- Setup and Installation
- Running the Application
- Designs & Screenshots
- API Documentation
- Deployment Plan
- Testing
πΊ Watch the 5-minute demo showcasing core functionalities:
Video Link: [https://youtu.be/-5ETXAE9xXY](demo video)
π₯ Download the latest release:
File Details:
- Version: 1.0.0
- Size: 51.6 MB
- Minimum Android: 5.0 (Lollipop, API 21)
- Target Android: 14 (API 34)
-
Download the APK file from the link above to your Android device
-
Enable installation from unknown sources:
Settings β Security β Install unknown apps β [Your Browser] β Allow from this sourceOr for older Android versions:
Settings β Security β Unknown sources β Enable -
Install the application:
- Open the downloaded
MamaSafe-v1.0.0.apkfile - Tap "Install"
- Wait for installation to complete
- Tap "Open" or find "MamaSafe" in your app drawer
- Open the downloaded
-
Login with test credentials:
CHW Account: Email: test.chw@mamasafe.com Password: CHW2025Test! Patient Account: Email: test.patient@mamasafe.com Password: Patient2025!
See Setup and Installation section below for building from source code.
MamaSafe/
β
βββ π§ backend/ # FastAPI Backend Server
β βββ main.py # API entry point with all endpoints
β βββ gdm_model.pkl # Trained ML model (Random Forest)
β βββ models/ # Additional ML models
β βββ data/ # Training datasets
β βββ tests/ # API tests (pytest)
β β βββ test_predictions.py # Prediction endpoint tests
β β βββ test_patients.py # Patient endpoint tests
β β βββ conftest.py # Test configuration
β βββ utils/ # Helper functions
β βββ requirements.txt # Python dependencies
β βββ .env.example # Environment variables template
β βββ Dockerfile # Container configuration
β
βββ π± mama_safe/ # Flutter Mobile Application
β βββ lib/
β β βββ main.dart # App entry point
β β βββ screens/ # UI screens
β β β βββ auth/ # Login, register screens
β β β βββ chw/ # CHW dashboard, patient management
β β β βββ patient/ # Patient profile, history
β β β βββ prediction/ # Prediction form & results
β β βββ models/ # Data models (Patient, Prediction, etc.)
β β βββ services/ # API service calls
β β β βββ api_service.dart # Backend API integration
β β β βββ auth_service.dart # Authentication logic
β β βββ providers/ # State management (Provider)
β β βββ widgets/ # Reusable UI components
β βββ assets/ # App images, icons, fonts
β β βββ icons/ # App icons
β β βββ images/ # Splash, logos
β β βββ fonts/ # Custom fonts
β βββ android/ # Android build configuration
β β βββ app/
β β β βββ keys/ # Signing keys (not in git)
β β β βββ build.gradle # Android build settings
β β βββ gradle.properties
β βββ ios/ # iOS build files
β βββ web/ # Web deployment files
β βββ test/ # Flutter unit tests
β βββ pubspec.yaml # Flutter dependencies
β
βββ π€ ml_model/ # Machine Learning Model Development
β βββ train_model.py # Model training script
β βββ gdm_dataset.csv # Training dataset
β βββ model_evaluation.py # Model testing & metrics
β βββ feature_importance.py # Feature analysis
β
βββ π database/ # Database Schema
β βββ schema.sql # Supabase table definitions
β βββ seed_data.sql # Initial test data
β βββ migrations/ # Database migrations
β
βββ π docs/ # Documentation
β βββ API.md # API documentation
β βββ DEPLOYMENT.md # Deployment guide
β βββ USER_GUIDE.md # User manual
β
βββ π¨ designs/ # App Design Assets
β βββ screenshots/ # App screenshots
β βββ screen1.png # Dashboard screenshot
β βββ screen2.png # Prediction screenshot
β βββ screen3.png # Results screenshot
β
βββ Scripts/ # Virtual environment scripts
βββ pyvenv.cfg # Python virtual environment config
βββ README.md # This file
| File | Purpose |
|---|---|
backend/main.py |
FastAPI server with all REST API endpoints |
backend/gdm_model.pkl |
Pre-trained Random Forest ML model (85% accuracy) |
mama_safe/lib/main.dart |
Flutter app entry point |
mama_safe/lib/services/api_service.dart |
API integration layer connecting Flutter to FastAPI |
mama_safe/lib/screens/prediction/prediction_screen.dart |
Main prediction UI |
database/schema.sql |
Complete Supabase database structure |
ml_model/train_model.py |
ML model training pipeline |
Before you begin, ensure you have the following installed:
- Flutter SDK 3.24.5 or higher (Install Flutter)
- Android Studio or VS Code with Flutter extensions
- Android SDK (API 21+)
- Git for version control
- Python 3.10 or higher (Download Python)
- pip (Python package manager)
- Virtual environment (venv or conda)
- Supabase Account (free tier available at supabase.com)
git clone https://github.com/MKangabire/Capstone.git
cd MamaSafecd backend# Windows
python -m venv venv
venv\Scripts\activate
# macOS/Linux
python3 -m venv venv
source venv/bin/activatepip install -r requirements.txt# Windows
copy .env.example .env
# macOS/Linux
cp .env.example .envEdit .env file with your Supabase credentials:
SUPABASE_URL=your_supabase_project_url
SUPABASE_KEY=your_supabase_anon_keyuvicorn main:app --reload --host 0.0.0.0 --port 8000Visit http://127.0.0.1:8000/docs
Verify installation:
- Visit: http://127.0.0.1:8000/api/health
- Expected response:
{"status": "ok", "model_status": "loaded"}
cd mama_safeflutter pub getflutter doctorMake sure the FastAPI server is running and update your API base URL in:
lib/services/api_service.dart
Update the baseUrl:
// For Android Emulator
static const String baseUrl = "http://10.0.2.2:8000";
// For physical device (replace with your computer's IP)
// static const String baseUrl = "http://192.168.1.XXX:8000";
// For production
// static const String baseUrl = "https://your-backend.onrender.com";# List available devices
flutter devices
# Run on connected device/emulator
flutter run
# Or run in debug mode
flutter run --debugflutter build apk --releaseAPK location: build/app/outputs/flutter-apk/app-release.apk
Terminal 1 - Start Backend:
cd backend
venv\Scripts\activate # Windows
# source venv/bin/activate # macOS/Linux
uvicorn main:app --reload --host 0.0.0.0 --port 8000Terminal 2 - Run Flutter App:
cd mama_safe
flutter runAccess Points:
- π± Mobile App: Running on emulator/device
- π API Base: http://localhost:8000
- π API Docs: http://localhost:8000/docs
- β Health Check: http://localhost:8000/api/health
Backend Deployment (Render):
# Render will automatically run:
uvicorn main:app --host 0.0.0.0 --port 10000Flutter Release Build:
flutter build apk --release
# APK: build/app/outputs/flutter-apk/app-release.apk (51.6 MB)- Development:
http://localhost:8000 - Production:
https://capstone-kubh.onrender.com
GET /api/health
Response:
{
"status": "ok",
"model_status": "loaded",
"supabase_status": "connected",
"timestamp": "2025-11-02T12:00:00"
}POST /api/predict
Content-Type: application/json
Request Body:
{
"age": 28,
"blood_pressure_systolic": 120,
"blood_pressure_diastolic": 80,
"blood_glucose": 95,
"patient_id": "patient-uuid"
}
Response:
{
"success": true,
"prediction": false,
"probability": 23.5,
"risk_level": "Low",
"risk_percentage": 23.5,
"confidence": 85.0,
"recommendations": "β
Continue regular prenatal care...",
"risk_factors": "No significant risk factors detected",
"prediction_id": "pred-uuid"
}GET /api/predictions/{patient_id}?limit=10
Response:
{
"success": true,
"count": 5,
"predictions": [...]
}GET /api/notifications/{chw_id}?unread_only=false
Response:
{
"success": true,
"count": 3,
"unread_count": 1,
"notifications": [...]
}Full Interactive API Documentation:
- Swagger UI:
/docs - ReDoc:
/redoc
β Model Training:
- Train Random Forest model on GDM dataset
- Achieve 85%+ accuracy on test data
- Save best model as
backend/gdm_model.pkl
β Model Features:
- Age (18-50 years)
- Blood Pressure Systolic (80-200 mmHg)
- Blood Pressure Diastolic (40-130 mmHg)
- Blood Glucose (40-400 mg/dL)
Deploy to Render:
- Push code to GitHub repository
- Create new Web Service on Render
- Connect GitHub repository
- Configure build settings:
Build Command: pip install -r requirements.txt Start Command: uvicorn main:app --host 0.0.0.0 --port $PORT - Add environment variables:
SUPABASE_URL='https://ntyqznoigmjsymenundu.supabase.co' SUPABASE_KEY='eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Im50eXF6bm9pZ21qc3ltZW51bmR1Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3NjAwMTY2MDYsImV4cCI6MjA3NTU5MjYwNn0.oIDPZDy_4gaY05XfMpLiQCXJrKYL7RUHc450zBU__fk' - Enable CORS for API access from Flutter
- Deploy and get production URL
Production URL: https://capstone-kubh.onrender.com
Mobile App (Android):
# Build release APK
flutter build apk --release
# the already released apk file is
`C:\Users\Merveille\Capstone\MamaSafe\mama_safe\MamaSafe-v1.0.0.apk`
Web App (Optional):
# Build Flutter web app
flutter build web
# Deploy to Firebase Hosting, Vercel, or GitHub Pages
firebase deploy --only hostingβ Supabase (PostgreSQL):
- Create project at supabase.com
- Run
database/schema.sqlto create tables:profiles- User accounts (CHW, Patient, Admin)patients- Patient informationhealth_data- Vital signs and measurementspredictions- ML prediction resultsnotifications- High-risk alerts for CHWs
- Enable Row Level Security (RLS)
- Configure authentication
Alternative:
- Firebase Firestore for patient history storage
- PostgreSQL for production-grade deployment
Performance Monitoring:
- Integrate UptimeRobot for API uptime monitoring
- Use Sentry for error tracking
- Monitor API response times and success rates
Logging:
- Structured logging with request/response times
- Error tracking and alerting
- User activity analytics
Run all tests:
cd backend
pytest tests/ -v --cov=main --cov-report=htmlRun specific test file:
pytest tests/test_predictions.py -v
pytest tests/test_patients.py -vView coverage report:
# Generate HTML report
pytest --cov=main --cov-report=html
# Open in browser
python -m http.server 8080 --directory htmlcovExpected Coverage: 80%+ code coverage
cd mama_safe
# Run all tests
flutter test
# Run with coverage
flutter test --coverage
# View coverage
genhtml coverage/lcov.info -o coverage/html# Install locust
pip install locust
# Run load test
locust -f tests/locustfile.py --host=http://localhost:8000
# Open http://localhost:8089 in browser
# Test with 10, 50, 100 concurrent users- Patient: Jane Doe, Age 25
- Vitals: BP 110/70, Glucose 85 mg/dL
- Expected: Risk ~20-30%, Low Risk, Green indicator
- Patient: Mary Smith, Age 38
- Vitals: BP 145/95, Glucose 165 mg/dL
- Expected: Risk ~75-85%, High Risk, Red indicator, Notification sent
- Framework: Flutter 3.24.5
- Language: Dart 3.0+
- State Management: Provider
- HTTP Client: Dio
- Local Storage: Shared Preferences
- Charts: fl_chart
- UI Components: Material Design 3
- Framework: FastAPI 0.104.1
- Language: Python 3.10
- ML Library: scikit-learn 1.3.0, joblib
- Database Client: Supabase Python SDK
- Validation: Pydantic
- Testing: pytest, pytest-cov
- CORS: FastAPI CORS Middleware
- Database: Supabase (PostgreSQL 15)
- Authentication: Supabase Auth (JWT)
- Storage: Supabase Storage
- Real-time: Supabase Realtime subscriptions
- Algorithm: Random Forest Classifier
- Libraries: scikit-learn, pandas, numpy
- Training Data: 1000+ patient records
- Features: Age, BP Systolic, BP Diastolic, Blood Glucose
- Accuracy: 85%+ on validation set
- Cross-validation: 5-fold CV
- Version Control: Git & GitHub
- Backend Hosting: Render / Railway
- Code Editor: VS Code, Android Studio
- API Testing: Postman, Swagger UI
- CI/CD: GitHub Actions (future)
- Monitoring: Sentry, UptimeRobot
- Offline Mode: Collect data offline, sync when online
- Multi-language: Kinyarwanda, Swahili support
- Push Notifications: Real-time alerts via Firebase Cloud Messaging
- Data Export: Export patient data to PDF/Excel
- Patient Chat: Direct messaging between CHW and patients
- Referral System: Automated referrals to specialized clinics
- Appointment Scheduler: Integrated calendar for checkups
- National Health Integration: Connect with Rwanda's national health information system
- Research Portal: Anonymized data for medical research
- Insurance Integration: Direct claims processing
- Mobile Money: Payment integration for consultations
| Metric | Target | Achieved | Status |
|---|---|---|---|
| API Response Time | < 2s | 1.8s avg | β |
| App Launch Time | < 10s | 15s | β |
| ML Prediction Accuracy | > 80% | 63% | β |
| Concurrent Users | > 50 | 12 | β |
| APK Size | < 60MB | 51.6MB | β |
| Memory Usage | < 150MB | 120MB | β |
| Test Coverage | > 75% | 76% | β |
Developed by: Merveille Kangabire
GitHub: @MKangabire
Project Repository: MamaSafe Capstone
Institution: African L
Department: [Your Department]
Program: [Your Program]
Academic Year: 2024/2025
Project Supervisor: [Supervisor Name]
- π§ Email: your.email@example.com
- πΌ LinkedIn: [Your LinkedIn Profile]
- π GitHub: @MKangabire



