AI-Powered Diabetes Risk Assessment Platform with Full Stack Architecture
A modern, responsive web application for predicting diabetes risk using machine learning. Built with React, Vite, and ONNX runtime for edge-based predictions.
- Overview
- Features
- Tech Stack
- Prerequisites
- Installation
- Project Structure
- Available Scripts
- Routes & Pages
- API Documentation
- Usage Guide
- Deployment
- Troubleshooting
- Contributing
- License
The Diabetes Prediction Application is a comprehensive full-stack web platform designed to help users assess their diabetes risk through intelligent machine learning models. It features a modern React frontend and a robust Flask backend API, providing a seamless, secure, and user-friendly interface for health risk assessment.
Architecture:
- Frontend: React + Vite SPA deployed on Vercel
- Backend: Flask API with scikit-learn ML model deployed on Render
- Database: Trained ML model (diabetes_model.pkl) with scikit-learn
Key Highlights:
- ⚡ Lightning-fast predictions with Vite + React frontend
- 🔒 Secure client-side authentication with localStorage
- 🧠 scikit-learn powered ML model for diabetes prediction
- 🌐 RESTful API with CORS support for cross-origin requests
- 📱 Fully responsive design for all devices
- 🎨 Clean and intuitive user interface
- 🚀 Full-stack deployment on Vercel (frontend) & Render (backend)
- 📊 Probability-based predictions with accuracy metrics
| Feature | Description | Status |
|---|---|---|
| User Authentication | Secure login and session management | ✅ Implemented |
| ML-Based Prediction | scikit-learn powered diabetes risk assessment | ✅ Implemented |
| Probability Analysis | Risk percentage calculation and insights | ✅ Implemented |
| RESTful API | Flask backend with comprehensive error handling | ✅ Implemented |
| CORS Support | Cross-origin requests for seamless integration | ✅ Implemented |
| Protected Routes | Secure navigation with authentication guards | ✅ Implemented |
| Responsive Design | Mobile, tablet, and desktop support | ✅ Implemented |
| Real-time Feedback | Instant prediction results with probability | ✅ Implemented |
| Professional UI | Modern and intuitive interface | ✅ Implemented |
| Model Persistence | Joblib serialized ML model with prediction | ✅ Implemented |
| Category | Technology | Version | Purpose |
|---|---|---|---|
| Frontend Framework | React | 19.1.1 | UI library |
| Build Tool | Vite | 7.1.2 | Fast bundler & dev server |
| Routing | React Router DOM | 7.8.2 | Client-side routing |
| ML Runtime | ONNX Runtime Web | 1.14.0 | Optional edge ML inference |
| Styling | CSS3 | Latest | Responsive design |
| Linting | ESLint | 9.33.0 | Code quality |
| Node.js | Node | 18+ | Runtime environment |
| Deployment | Vercel | Latest | Production hosting |
| Category | Technology | Version | Purpose |
|---|---|---|---|
| Framework | Flask | 3.0.0+ | Web framework |
| CORS | flask-cors | 3.0.0+ | Cross-origin requests |
| ML Library | scikit-learn | 1.0.0+ | Machine learning model |
| Data Processing | pandas | 1.3.0+ | Data manipulation |
| Numerical Computing | numpy | 1.20.0+ | Array operations |
| Model Serialization | joblib | 1.0.0+ | Model persistence |
| WSGI Server | Gunicorn | 21.0.0+ | Production server |
| Language | Python | 3.9+ | Backend runtime |
| Deployment | Render | Latest | Production hosting |
Before you begin, ensure you have the following installed on your system:
| Tool | Version | Download |
|---|---|---|
| Node.js | 18.0.0 or higher | nodejs.org |
| npm | 9.0.0 or higher | Included with Node.js |
| Modern Browser | Chrome/Firefox/Safari/Edge | Any modern browser |
| Tool | Version | Download |
|---|---|---|
| Python | 3.9 or higher | python.org |
| pip | 21.0 or higher | Included with Python |
| Virtual Environment | venv | Built-in with Python |
| Tool | Version | Download |
|---|---|---|
| Git | Latest | git-scm.com |
git clone https://github.com/yourusername/diabetes-frontend.git
cd Diabetes_Frontend-mainnpm installThis will install all required packages:
- React and React DOM
- React Router for navigation
- ONNX Runtime for optional ML inference
- ESLint for code quality
- Vite as the build tool
Create a .env file in the root directory:
VITE_API_URL=https://your-backend-api.com
VITE_PORT=5173npm run devThe frontend will be available at http://localhost:5173
cd backendOn Windows:
python -m venv venv
venv\Scripts\activateOn macOS/Linux:
python3 -m venv venv
source venv/bin/activatepip install -r requirements.txtThis will install:
- Flask web framework
- flask-cors for CORS support
- scikit-learn for ML model
- numpy and pandas for data processing
- joblib for model loading
- gunicorn for production server
Ensure diabetes_model.pkl exists in the backend/ directory. This is the trained ML model.
python app.pyThe backend API will be available at http://localhost:5000
Run this to set up both frontend and backend at once:
Windows:
# Frontend setup
npm install
# Backend setup
cd backend
python -m venv venv
venv\Scripts\activate
pip install -r requirements.txt
python app.pymacOS/Linux:
# Frontend setup
npm install
# Backend setup (in another terminal)
cd backend
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
python app.pyDiabetes_Frontend-main/
│
├── public/ # Static assets
│ ├── diabetes_model.onnx # Optional ONNX ML model
│ └── ort/ # ONNX Runtime files
│
├── src/ # Frontend source code
│ ├── components/ # Reusable React components
│ │ ├── Footer.jsx # Footer component
│ │ ├── Navbar.jsx # Navigation bar
│ │ └── PredictionForm.jsx # Prediction form
│ │
│ ├── pages/ # Page components
│ │ ├── Home.jsx # Home page
│ │ └── Prediction.jsx # Prediction page
│ │
│ ├── App.jsx # Main app component
│ ├── Login.jsx # Login page
│ ├── ProtectedRoute.jsx # Route guard component
│ ├── main.jsx # Application entry point
│ └── index.css # Global styles
│
├── backend/ # Backend source code
│ ├── app.py # Flask application (main server)
│ ├── diabetes_model.pkl # Trained scikit-learn model
│ ├── requirements.txt # Python dependencies
│ ├── Procfile # Deployment configuration
│ ├── runtime.txt # Python runtime version
│ └── venv/ # Virtual environment (local development)
│
├── eslint.config.js # ESLint configuration
├── vite.config.js # Vite configuration
├── vercel.json # Vercel deployment config (frontend)
├── package.json # Node.js dependencies & scripts
├── index.html # HTML template
└── README.md # Documentation (this file)
Run these commands in the project directory:
| Command | Description | Purpose |
|---|---|---|
npm run dev |
Start development server | Local development with HMR |
npm run build |
Build for production | Create optimized bundle |
npm run lint |
Run ESLint | Check code quality |
npm run preview |
Preview production build | Test production build locally |
# Start development with hot reload
npm run dev
# In another terminal, check code quality
npm run lint
# Build for production
npm run build
# Preview the production build
npm run previewThe backend Flask API provides endpoints for prediction and health checks.
Development: http://localhost:5000
Production: https://your-backend-api.com
GET /Response:
{
"message": "Diabetes Prediction API is running!"
}Status Code: 200 OK
POST /predict
Content-Type: application/jsonRequest Body:
{
"pregnancies": 6,
"glucose": 148,
"bloodPressure": 72,
"skinThickness": 35,
"insulin": 0,
"bmi": 33.6,
"dpf": 0.627,
"age": 50
}| Field | Type | Description | Range |
|---|---|---|---|
pregnancies |
int | Number of pregnancies | 0-17 |
glucose |
int | Plasma glucose concentration | 0-199 |
bloodPressure |
int | Diastolic blood pressure | 0-122 |
skinThickness |
int | Triceps skin fold thickness | 0-99 |
insulin |
int | 2-hour serum insulin | 0-846 |
bmi |
float | Body Mass Index | 0-67.1 |
dpf |
float | Diabetes Pedigree Function | 0.078-2.42 |
age |
int | Age in years | 21-81 |
Success Response (200):
{
"prediction": 1,
"probability": 78.45
}| Field | Type | Description |
|---|---|---|
prediction |
int | 0 = No Diabetes, 1 = Diabetes Positive |
probability |
float | Percentage confidence (0-100) |
Error Response (400):
{
"error": "Error message describing what went wrong"
}The backend has CORS enabled for all origins in development. For production, configure allowed origins in app.py:
CORS(app, resources={r"/predict": {"origins": ["https://your-frontend-url.com"]}})| Route | Component | Access | Purpose |
|---|---|---|---|
/ |
Home | Public | Landing page & app overview |
/login |
Login | Public | User authentication |
/predict |
Prediction | Protected | Diabetes risk prediction form |
- Home Page: Accessible to all users
- Login Page: Accessible to all users (redirects if already logged in)
- Prediction Page: Protected by
ProtectedRoute- requires authentication - Authentication: Client-side via localStorage (
isLoggedIn,username)
- Overview of the application
- Information about diabetes prediction
- Call-to-action buttons for login/prediction
- Simple authentication form
- Input: Username
- Stores credentials in localStorage
- Redirects to prediction page on success
- Accessible only when authenticated
- Input health parameters (age, BMI, glucose, etc.)
- Real-time prediction results
- Display risk assessment
The form collects the following health metrics:
{
age: number,
gender: string,
bmi: number,
bloodPressure: number,
glucose: number,
insulinLevel: number,
pregnancies: number,
skinThickness: number
}Default Behavior: The app calls the remote API endpoint:
POST https://diabetes-k80q.onrender.com/predict
Content-Type: application/json
{
"feature1": value,
"feature2": value,
...
}
Optional: Use local ONNX Runtime by enabling the diabetes_model.onnx inference in your code.
Login Form → Validate Input → Store in localStorage
→ Set isLoggedIn=true → Redirect to /predict
localStorage.setItem('isLoggedIn', 'true');
localStorage.setItem('username', 'username');localStorage.removeItem('isLoggedIn');
localStorage.removeItem('username');This project is configured for Vercel deployment:
# Install Vercel CLI (if not already installed)
npm i -g vercel
# Deploy from root directory
vercel- Push to GitHub:
git push origin main - Connect GitHub repo to Vercel dashboard
- Vercel will auto-deploy on every push
The vercel.json file is already configured with:
- SPA routing (all routes redirect to index.html)
- Proper caching headers
- Environment variables support
Production URL: https://your-app.vercel.app (configured in Vercel dashboard)
Deploy the Flask backend to production using Render or Heroku.
-
Create Render Account: Visit render.com
-
Push Backend to GitHub (if not already):
git add backend/ git commit -m "Add backend code" git push origin main -
Connect Repository:
- Create new Web Service
- Connect your GitHub repo
- Select root directory:
backend/
-
Configure Environment:
- Runtime: Python 3
- Build Command:
pip install -r requirements.txt - Start Command:
gunicorn app:app
-
Deploy: Click "Create Web Service"
Production URL: https://your-backend-api.onrender.com
# Install Heroku CLI
# Visit: https://devcenter.heroku.com/articles/heroku-cli
# Login to Heroku
heroku login
# Create new Heroku app
heroku create your-app-name
# Set buildpack
heroku buildpacks:set heroku/python
# Deploy
git push heroku mainVITE_API_URL=https://your-backend-api.onrender.com
VITE_PORT=5173Set in deployment dashboard:
FLASK_ENV=production
Default Vite setup with React Fast Refresh enabled.
Code quality rules enforce:
- React best practices
- Proper hook usage
- Code consistency
Create .env file for custom configuration:
VITE_API_URL=https://your-api-endpoint.com
VITE_MODEL_PATH=/diabetes_model.onnxI welcome contributions! Here's how to help:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Follow ESLint rules:
npm run lint - Keep components small and focused
- Use meaningful commit messages
- Add comments for complex logic
- Test your changes locally
Run linting to ensure code quality:
npm run lintFix linting issues automatically:
npm run lint -- --fixThis project is licensed under the MIT License - see the LICENSE file for details.
For questions, issues, or suggestions:
- Open an Issue
- Start a Discussion
- Email: your-email@example.com
Made with ❤️ for better healthcare through AI