CureLens AI is a comprehensive medication safety platform that uses machine learning to predict drug interactions, assess personalized medication risks, and recommend safer alternatives. The system employs explainable AI techniques (SHAP/LIME) to provide transparent, interpretable predictions, helping healthcare professionals make informed decisions about medication safety.
Author: Mohamed Shiras Mohamed Saabith
University: University of Wolverhampton
Award: BSc.(Hons) Computer Science & Software Engineering
Contact: saabithsp@gmail.com
- Drug-Drug Interaction Prediction: Identifies potential interactions between medications with severity classification
- Personalized Risk Assessment: Evaluates medication risks based on patient-specific factors
- Safe Drug Recommendations: Suggests safer alternatives based on patient profile and current medications
- Explainable AI: All predictions come with SHAP/LIME explanations for transparency
- No LLM Dependencies: Uses only traditional ML models for reliability and predictability
curelens-ai/
├── ml/ # Machine Learning & Backend
│ ├── data/ # Data storage
│ │ ├── raw/ # Raw DrugBank XML files
│ │ ├── processed/ # Processed datasets
│ │ └── external/ # External datasets (TWOSIDES, BioSNAP)
│ ├── models/ # Model files
│ │ ├── artifacts/ # Trained model files (.pkl, .json)
│ │ └── configs/ # Model configurations
│ ├── src/ # Source code
│ │ ├── data/ # Data processing modules
│ │ ├── models/ # Model implementations
│ │ ├── explainability/ # SHAP/LIME implementations
│ │ └── utils/ # Utility functions
│ ├── api/ # REST API endpoints
│ │ ├── main.py # FastAPI application
│ │ └── routes/ # API route handlers
│ └── requirements.txt # Python dependencies
├── backend/ # Backend API (Unified FastAPI)
│ ├── main.py # Unified FastAPI app (Port 8000)
│ ├── routes/ # API route handlers
│ │ ├── users.py # User management endpoints
│ │ ├── history.py # History endpoints
│ │ └── models.py # ML model endpoints
│ ├── models/ # Database models
│ ├── config/ # Configuration
│ └── utils/ # Utilities
├── frontend/ # Frontend (React + TypeScript)
│ ├── components/ # React components
│ ├── pages/ # Page components
│ ├── services/ # API service layer
│ └── package.json # Node.js dependencies
└── tests/ # Unit and integration tests
- Python 3.8 or higher
- Node.js (for frontend)
- MongoDB (for database)
- pip package manager
- npm (comes with Node.js)
git clone https://github.com/curelens/curelens-ai.git
cd curelens-ai# Create virtual environment
python -m venv venv
# Activate virtual environment
# On Windows:
venv\Scripts\activate
# On Linux/Mac:
source venv/bin/activate
# Install Python dependencies
pip install -r requirements.txtcd frontend
# Install dependencies
npm install
# If you encounter React 19 dependency conflicts, use:
npm install --legacy-peer-depsIMPORTANT: The DrugBank database file is required for the ML models to work.
- Download the data folder from Google Drive
- Extract the downloaded folder at
ml/directory (the extracted folder should be insideml/) - Locate the
drugbank_database.xmlfile inside the extracted folder - it will be in araw/subfolder within the extracted folder - Copy the
drugbank_database.xmlfile from theraw/subfolder - Paste it directly into the
ml/folder (NOT inml/raw/, but directly inml/) - The final path should be:
ml/drugbank_database.xml
Note: The data/ folder and its contents are ignored by git. You must download the database file separately from Google Drive and copy only the XML file to ml/.
Create a .env file in the project root:
MONGODB_URI=mongodb://localhost:27017/
MONGODB_DATABASE=curelens_ai# Windows - Start MongoDB service or run:
mongod
# Linux/Mac
sudo systemctl start mongod
# or
mongodBefore running the application, you need to train the ML models:
# Quick test (5-10 minutes) - Recommended first
python ml/src/test_training_quick.py
# Full training (1-3 hours) - After quick test passes
python ml/src/train_pipeline.pyNote: Training results and model artifacts (.pkl, .json files) are saved to ml/models/artifacts/ and are ignored by git.
# From project root
python backend/main.py
# Or using uvicorn directly:
uvicorn backend.main:app --reload --host 0.0.0.0 --port 8000The API will be available at: http://localhost:8000
API documentation:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
# From frontend directory
cd frontend
npm run devThe frontend will be available at: http://localhost:3000 (or http://localhost:5173 for Vite default)
The project includes comprehensive testing covering Unit Testing, Integration Testing, and System Testing.
Total Tests: 70
- Backend/ML Tests: 53 tests (Python/pytest)
- Frontend Tests: 17 tests (TypeScript/Vitest)
Backend + ML Tests:
# From project root
pytest tests/ -vFrontend Tests:
# From frontend directory
cd frontend
npm testAll Tests (Backend + Frontend):
# Run sequentially
pytest tests/ -v
cd frontend && npm test
# Or using Python script
python run_tests.py --type all
cd frontend && npm testUnit Tests (20 tests):
# All unit tests (Backend + ML)
pytest tests/unit/ -v
# Backend unit tests only
pytest tests/unit/test_backend/ -v
# ML unit tests only
pytest tests/unit/test_ml/ -v
# Using markers
pytest -m unit -vIntegration Tests (6 tests):
# All integration tests
pytest tests/integration/ -v
# Backend integration tests
pytest tests/integration/test_api_routes.py -v
# ML integration tests
pytest tests/integration/test_ml_integration.py -v
# Using markers
pytest -m integration -vSystem Tests (27 tests):
# All system tests
pytest tests/system/ -v
# Performance tests (5 tests)
pytest tests/system/test_performance.py -v
pytest -m performance -v
# Security tests (8 tests)
pytest tests/system/test_security.py -v
pytest -m security -v
# Error handling tests (10 tests)
pytest tests/system/test_error_handling.py -v
pytest -m error_handling -v
# Using markers
pytest -m system -vEnd-to-End Tests (4 tests):
# All E2E tests
pytest tests/e2e/ -v
# User flow tests
pytest tests/e2e/test_user_flows.py -v
# ML workflow tests
pytest tests/e2e/test_ml_workflows.py -v
# Using markers
pytest -m e2e -vRun All Frontend Tests (17 tests):
cd frontend
npm testFrontend Test Categories:
- Component Tests: 7 tests (Loader, Footer, DynamicDrugInput, PatientProfileForm)
- Hook Tests: 2 tests (useAuth)
- Service Tests: 3 tests (registerUser, loginUser, checkInteraction)
- Integration Tests: 3 tests (Dashboard, InteractionChecker, RiskAssessment)
- E2E Tests: 2 tests (Registration flow, Login flow)
Frontend Test Options:
cd frontend
# Run with UI
npm run test:ui
# Run with coverage
npm run test:coverage
# Run integration tests only
npm run test:integrationBackend + ML Coverage:
# Generate HTML and terminal coverage reports
pytest tests/ --cov=backend --cov=ml/src --cov-report=html --cov-report=term
# Coverage for specific test categories
pytest tests/unit/ --cov=backend --cov=ml/src --cov-report=html:htmlcov/unit
pytest tests/integration/ --cov=backend --cov=ml/src --cov-report=html:htmlcov/integration
pytest tests/system/ --cov=backend --cov=ml/src --cov-report=html:htmlcov/system
# View HTML coverage report: Open htmlcov/index.html in browserFrontend Coverage:
cd frontend
npm run test:coverageThe project includes run_tests.py for convenient test execution:
# Run all tests
python run_tests.py --type all
# Run specific test categories
python run_tests.py --type unit
python run_tests.py --type integration
python run_tests.py --type e2e
python run_tests.py --type ml
# Run with coverage
python run_tests.py --type all --coverage
# Run specific test file
python run_tests.py --file tests/unit/test_backend/test_models.py
# Run specific test
python run_tests.py --test tests/unit/test_backend/test_models.py::test_create_user| Category | Subcategory | Count | Command |
|---|---|---|---|
| Unit Tests (3.5.1) | Backend Unit | 10 | pytest tests/unit/test_backend/ -v |
| ML Unit | 10 | pytest tests/unit/test_ml/ -v |
|
| Total Unit | 20 | pytest tests/unit/ -v |
|
| Integration Tests (3.5.2) | Backend Integration | 3 | pytest tests/integration/test_api_routes.py -v |
| ML Integration | 3 | pytest tests/integration/test_ml_integration.py -v |
|
| Total Integration | 6 | pytest tests/integration/ -v |
|
| System Tests (3.5.3) | Performance | 5 | pytest tests/system/test_performance.py -v |
| Security | 8 | pytest tests/system/test_security.py -v |
|
| Error Handling | 10 | pytest tests/system/test_error_handling.py -v |
|
| Total System | 23 | pytest tests/system/ -v |
|
| E2E Tests | Backend E2E | 2 | pytest tests/e2e/test_user_flows.py -v |
| ML E2E | 2 | pytest tests/e2e/test_ml_workflows.py -v |
|
| Total E2E | 4 | pytest tests/e2e/ -v |
|
| TOTAL (Backend/ML) | 53 | pytest tests/ -v |
|
| Frontend Tests | Component Unit | 7 | cd frontend && npm test |
| Hook Unit | 2 | cd frontend && npm test |
|
| Service Unit | 3 | cd frontend && npm test |
|
| Integration | 3 | cd frontend && npm test |
|
| E2E | 2 | cd frontend && npm test |
|
| Total Frontend | 17 | cd frontend && npm test |
|
| GRAND TOTAL | 70 | See commands above |
- Test Database:
curelens_test(automatically created and cleaned before each test) - Isolation: Each test runs independently with isolated test data
- Fixtures: Shared test fixtures in
tests/conftest.py - No Real Data Affected: All tests use mock/test data
Prerequisites for Testing:
- MongoDB must be running
- Virtual environment activated (if using one)
- All dependencies installed:
pip install -r requirements.txt cd frontend && npm install
You can save test output to files for documentation:
# Save results to files
pytest tests/unit/ -v > unit_test_results.txt
pytest tests/integration/ -v > integration_test_results.txt
pytest tests/system/ -v > system_test_results.txt
pytest tests/e2e/ -v > e2e_test_results.txt- Start the backend server:
python backend/main.py - Start the frontend:
cd frontend && npm run dev - Navigate to:
http://localhost:3000/#/admin(or your frontend URL) - Login with admin credentials
- Email:
admin@gmail.com - Password:
Admin@123 - Name: Mohamed Saabith
Use the admin creation script:
python backend/scripts/create_admin.py <email> <password> [name]Example:
python backend/scripts/create_admin.py admin@curelens.ai admin123 "Admin User"- User Management: View, delete users, grant/revoke admin privileges
- History Management: View, delete user history entries
- Usage Statistics: Charts and reports on system usage
- Dashboard: Overview of system metrics
All admin endpoints are prefixed with /api/admin:
POST /api/admin/login- Admin loginGET /api/admin/users- Get all usersDELETE /api/admin/users/{user_id}- Delete userPUT /api/admin/users/{user_id}/admin- Set admin statusGET /api/admin/history- Get all historyDELETE /api/admin/history/{history_id}- Delete history entryDELETE /api/admin/history/user/{user_id}- Delete user historyGET /api/admin/stats/usage- Get usage statisticsGET /api/admin/stats/summary- Get admin summary
POST /api/check-interaction- Check drug-drug interactionsPOST /api/batch/check-interactions- Batch check interactionsPOST /api/calculate-risk- Calculate personalized medication riskPOST /api/get-alternatives- Get safe drug alternativesGET /api/drugs/search- Search drugsGET /api/stats- System statisticsGET /api/explain/{model_id}/{prediction_id}- Get model explanations
POST /api/users/register- Register new userPOST /api/users/login- Login userGET /api/users/me- Get current userPUT /api/users/me- Update userDELETE /api/users/me- Delete user
POST /api/history- Create history entryGET /api/history/{user_id}- Get user historyGET /api/history/stats/{user_id}- Get history statisticsGET /api/history/{id}- Get specific entryDELETE /api/history/{id}- Delete entryDELETE /api/history- Delete all user history
| Model | Task | Metric | Score |
|---|---|---|---|
| Model 1 | Drug Interaction Prediction | ROC-AUC | >0.85 |
| Model 2 | Risk Assessment | ROC-AUC | >0.80 |
| Model 3 | Drug Recommendation | Precision@5 | >0.75 |
The backend is a unified FastAPI application that combines:
- User Management - Registration, login, profile management
- History Tracking - Save and retrieve user interaction history
- ML Model Predictions - Drug interactions, risk assessment, recommendations
All services run on a single FastAPI application (Port 8000).
The React frontend connects to the unified backend:
- All API calls go to
http://localhost:8000 - ML endpoints:
/api/* - User endpoints:
/api/users/* - History endpoints:
/api/history/*
When ML endpoints are called with the X-User-ID header, history is automatically saved:
- Interaction checks →
interaction_check - Risk assessments →
risk_assessment - Recommendations →
recommendation - Batch checks →
batch_check
Error: Failed to connect to MongoDB
Solution:
- Ensure MongoDB is running:
mongod - Check connection:
mongoshormongo - Verify
MONGODB_URIin.envfile
Error: ModuleNotFoundError: No module named 'backend'
Solution:
- Run commands from project root directory
- Ensure virtual environment is activated
- Install dependencies:
pip install -r requirements.txt
Error: Cannot find module '../../../components/Loader'
Solution:
- Run from
frontenddirectory - Ensure
npm installcompleted successfully - Check file paths in test files
- If React 19 conflicts:
npm install --legacy-peer-deps
Error: Database not found
Solution:
- Tests automatically create
curelens_testdatabase - Ensure MongoDB is accessible
- Check MongoDB connection string
Error: Model file not found
Solution:
- Train models first:
python ml/src/train_pipeline.py - Check that models exist in
ml/models/artifacts/ - Verify model files are
.pklformat
Error: drugbank_database.xml not found
Solution:
- Download the data folder from Google Drive
- Extract it at
ml/ - Copy
drugbank_database.xmlfrom the extracted folder (may be inraw/subfolder) - Paste it directly into
ml/folder (not inraw/) - Final path should be:
ml/drugbank_database.xml
Important: CureLens AI is a research tool designed to assist healthcare professionals. It should NOT be used as a replacement for professional medical advice. Always consult with qualified healthcare providers for medical decisions.
This project is licensed under the MIT License - see the LICENSE file for details.
- DrugBank for comprehensive drug data
- TWOSIDES and BioSNAP for interaction datasets
- SHAP and LIME libraries for explainability
For questions and support, please open an issue on GitHub or contact the team at contact@curelens-ai.com.