Predictive patient simulation powered by AI β helping clinicians visualize dialysis risks before they happen.
| Environment | URL | Status |
|---|---|---|
| Frontend | http://localhost:3000 |
β Running |
| Backend API | http://localhost:5000 |
β Running |
| Health Check | GET /health |
β
{"status":"OK"} |
π Note: This is a clinical decision support tool. All outputs require physician review.
- Toxin Buildup Modeling: Simulates uremic toxin accumulation over time using patient-specific parameters
- Fluid Accumulation Tracking: Predicts fluid retention based on intake and dialysis history
- Dynamic Risk Classification: Automatically categorizes risk as π΅ Low / π‘ Medium / π΄ High
- LLM Integration: Connects to OpenAI-compatible endpoints for natural language explanations
- Context-Aware Guidance: Generates patient-specific recommendations based on simulation output
- Safety-First Prompts: Built-in medical disclaimer and non-diagnostic guardrails
- Real-Time Charts: Live updating line graphs for toxin and fluid trends (Recharts)
- Scenario Testing: One-click "Skip Dialysis", "Delay 24h", and "Reset" simulations
- Responsive Design: Works seamlessly on desktop, tablet, and mobile devices
- MongoDB Storage: Saves all simulation runs with timestamps
- Audit Trail: Track patient parameter changes and risk progression over time
| Technology | Purpose | Version |
|---|---|---|
| Express.js | REST API framework | ^4.18.2 |
| Mongoose | MongoDB ODM | ^8.0.0 |
| Axios | HTTP client for LLM API | ^1.6.0 |
| dotenv | Environment variable management | ^16.3.1 |
| cors | Cross-origin request handling | ^2.8.5 |
| Technology | Purpose | Version |
|---|---|---|
| React 18 | UI library | ^18.2.0 |
| Vite | Build tool & dev server | ^5.0.0 |
| Tailwind CSS | Utility-first styling | ^3.4.0 |
| Recharts | Interactive data visualization | ^2.10.3 |
| Axios | API communication | ^1.6.0 |
| Lucide React | Icon library | ^0.294.0 |
| Component | Technology |
|---|---|
| Database | MongoDB (Local or Atlas) |
| LLM Provider | OpenAI-compatible API (Ollama, LiteLLM, etc.) |
| Deployment Ready | Docker, Vercel, Render, Railway |
βββββββββββββββββββββββββββββββββββββββββββββββββββ
β Frontend (React) β
β βββββββββββββββββββββββββββββββββββββββββββ β
β β β’ Input Form (Patient Parameters) β β
β β β’ Scenario Buttons (Skip/Delay/Reset) β β
β β β’ Recharts Visualization (Toxin/Fluid) β β
β β β’ AI Insight Card (Markdown Rendered) β β
β βββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββ¬ββββββββββββββββββ¬ββββββββββββββββββ
β HTTP/JSON β
βΌ βΌ
βββββββββββββββββββββββ βββββββββββββββββββββββ
β Backend (Node) β β LLM API Service β
β βββββββββββββββββ β β βββββββββββββββββ β
β β Simulation β β β β Prompt β β
β β Engine ββββΌββΌββΊβ Engineering β β
β β β’ Toxin Model β β β β β’ System Msg β β
β β β’ Fluid Model β β β β β’ Safety β β
β β β’ Risk Logic β β β β β’ Formatting β β
β βββββββββ¬ββββββββ β β βββββββββ¬ββββββββ β
β β β β β β
β βββββββββΌββββββββ β β βββββββββΌββββββββ β
β β MongoDB β β β β Response β β
β β β’ Simulation β β β β Parsing & β β
β β History β β β β Cleaning β β
β βββββββββββββββββ β β βββββββββββββββββ β
βββββββββββββββββββββββ βββββββββββββββββββββββ
- Node.js β₯ 18.x
- npm β₯ 9.x
- MongoDB β₯ 7.0 (local or Atlas)
- LLM API Access (Ollama, OpenAI-compatible endpoint)
# 1. Navigate to backend directory
cd ai-dialysis-digital-twin-backend
# 2. Install dependencies
npm install
# 3. Configure environment variables
cp .env.example .env
nano .env # Edit with your values (see below)
# 4. Start MongoDB (if running locally)
sudo systemctl start mongod # Linux
# or
brew services start mongodb-community # macOS
# 5. Start development server
npm run dev# Server
PORT=5000
NODE_ENV=development
# Database
MONGODB_URI=mongodb://127.0.0.1:27017/ai_dialysis_twin
# LLM API (OpenAI-compatible)
WEBUI_BASE_URL=https://chat.ivislabs.in/api
API_KEY= <our personal api key>
DEFAULT_MODEL=llama3.2-vision:latestπ‘ Testing LLM Connection:
curl -X POST $WEBUI_BASE_URL/chat/completions \ -H "Authorization: Bearer $API_KEY" \ -H "Content-Type: application/json" \ -d '{"model":"'$DEFAULT_MODEL'","messages":[{"role":"user","content":"Hello"}]}'
# 1. Navigate to frontend directory
cd ai-dialysis-digital-twin-frontend
# 2. Install dependencies
npm install
# 3. Start development server
npm run dev# Override API base URL if backend is on different host
VITE_API_BASE=http://localhost:5000β Default: Uses Vite proxy (
/simulateβhttp://localhost:5000/simulate)
Run patient simulation and return predictive data
{
"age": 65,
"weight": 75,
"hours_since_dialysis": 24,
"fluid_intake": 1.5
}{
"success": true,
"simulationId": "6789abcd1234...",
"toxin_levels_over_time": [5.0, 7.8, 10.6, ...],
"fluid_levels_over_time": [0.15, 0.21, 0.27, ...],
"hours": [0, 1, 2, ...],
"risk_level": "Low"
}| Risk Level | Toxin Threshold (mg/dL) | Clinical Interpretation |
|---|---|---|
| π΅ Low | < 45 |
Within acceptable post-dialysis range |
| π‘ Medium | 45 - 74 |
Elevated; monitor closely |
| π΄ High | β₯ 75 |
Critical; immediate clinical review recommended |
Generate human-readable AI explanation of simulation results
{
"risk_level": "Low",
"current_toxin": 15.2,
"current_fluid": 0.51,
"hours": 24
}{
"success": true,
"advice": "Fluid Accumulation: This measures how much extra fluid...\n\nRisk Classification: Low\n\nRecommendation: Continue current dialysis schedule..."
}π‘οΈ Safety Note: All AI responses include mandatory disclaimer: "For clinical support only. Not a substitute for professional medical advice."
Server health check endpoint
{
"status": "OK",
"timestamp": "2026-04-27T10:30:00.000Z"
}ai-dialysis-digital-twin/
βββ π ai-dialysis-digital-twin-backend/
β βββ π server.js # Express app entry point
β βββ π .env # Environment variables
β βββ π package.json # Backend dependencies
β βββ π controllers/ # Request handlers
β β βββ π simulationController.js
β βββ π models/ # Mongoose schemas
β β βββ π Simulation.js
β βββ π routes/ # API route definitions
β β βββ π simulation.js
β βββ π services/ # Business logic
β β βββ π simulationEngine.js # Toxin/fluid formulas
β β βββ π llmService.js # LLM API integration
β βββ π utils/ # Helpers
β βββ π db.js # MongoDB connection
β βββ π errorMiddleware.js # Global error handler
β
βββ π ai-dialysis-digital-twin-frontend/
βββ π vite.config.js # Vite + proxy config
βββ π tailwind.config.js # Tailwind CSS config
βββ π package.json # Frontend dependencies
βββ π src/
β βββ π main.jsx # React entry point
β βββ π App.jsx # Root component
β βββ π index.css # Global styles + Tailwind
β βββ π pages/
β β βββ π Dashboard.jsx # Main application page
β βββ π components/
β β βββ π InputForm.jsx # Patient data form
β β βββ π SimulationChart.jsx # Recharts visualization
β β βββ π AIInsightCard.jsx # LLM response display
β β βββ π ScenarioButtons.jsx # Skip/Delay/Reset controls
β βββ π services/
β β βββ π api.js # Axios API client
β βββ π utils/
β βββ π constants.js # Colors, thresholds, config
β βββ π formatText.js # Markdown cleaning utility
βββ π public/ # Static assets
# Terminal 1: Backend
cd ai-dialysis-digital-twin-backend && npm run dev
# Terminal 2: Frontend
cd ai-dialysis-digital-twin-frontend && npm run dev
# Open browser: http://localhost:3000| Field | Description | Example |
|---|---|---|
| Age | Patient age in years | 65 |
| Weight | Current weight in kg | 75 |
| Hours Since Dialysis | Time elapsed since last session | 24 |
| Fluid Intake | Daily fluid consumption in liters | 1.5 |
- Click "π Run Digital Twin Simulation"
- Wait ~2 seconds for backend processing
- View interactive charts updating in real-time
| Button | Effect | Use Case |
|---|---|---|
| βοΈ Skip Dialysis | Simulates missing next session (72h total) | Assess emergency risk |
| β° Delay by 24h | Pushes next session by 1 day (48h total) | Evaluate scheduling flexibility |
| π Reset | Returns to post-dialysis baseline (0h) | Compare against current state |
- π’ Green badge: Low risk β continue current protocol
- π‘ Amber badge: Medium risk β increase monitoring frequency
- π΄ Red badge: High risk β immediate clinical consultation advised
π‘ Pro Tip: Click scenario buttons after initial simulation to instantly compare risk trajectories.
# Test simulation endpoint
curl -X POST http://localhost:5000/simulate \
-H "Content-Type: application/json" \
-d '{"age":65,"weight":75,"hours_since_dialysis":36,"fluid_intake":1.8}'
# Test AI advice endpoint
curl -X POST http://localhost:5000/ai-advice \
-H "Content-Type: application/json" \
-d '{"risk_level":"Medium","current_toxin":52.3,"current_fluid":1.2,"hours":36}'
# Health check
curl http://localhost:5000/health- Form validation prevents invalid inputs
- Charts render with smooth animations
- Risk badge color matches classification logic
- AI insight card displays cleaned markdown (no
**symbols) - Scenario buttons update charts without page reload
- Responsive layout works on mobile (320px width)
- β No PHI (Protected Health Information) stored β all data is demo/simulated
- β Patient identifiers are auto-generated UUIDs, not real names/IDs
- β MongoDB connection uses local/Atlas with authentication recommended for production
- β System prompt explicitly prohibits diagnostic statements
- β All AI responses include mandatory medical disclaimer
- β Risk thresholds based on simplified clinical guidelines (not diagnostic criteria)
# For production deployment:
NODE_ENV=production
MONGODB_URI=mongodb+srv://user:pass@cluster.mongodb.net/ai_dialysis?retryWrites=true
CORS_ORIGIN=https://your-production-domain.com
RATE_LIMIT=100 # Requests per hour per IP- Fork the repository
- Create feature branch:
git checkout -b feature/amazing-feature - Commit changes:
git commit -m 'Add amazing feature' - Push to branch:
git push origin feature/amazing-feature - Open Pull Request with detailed description
- Backend: ESLint + Prettier config available on request
- Frontend: Tailwind utility classes preferred over custom CSS
- Commits: Conventional Commits format (
feat:,fix:,docs:)
| Role | Contributor |
|---|---|
| Full-Stack Development | [Your Name/Team Name] |
| Clinical Logic Design | Nephrology Consultant Review |
| UI/UX Design | Medical Dashboard Best Practices |
| AI Integration | OpenAI-Compatible LLM Providers |
π Special thanks to the open-source community: Express, Mongoose, React, Tailwind, Recharts, and Lucide.
Distributed under the MIT License. See LICENSE for more information.
MIT License
Copyright (c) 2026 AI Dialysis Digital Twin Team
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
π©Ί IMPORTANT: This application is a educational demonstration tool only.
- β NOT a medical device
- β NOT FDA-cleared or CE-marked
- β NOT intended for diagnosis, treatment, or clinical decision-making
- β FOR hackathon demonstration, educational purposes, and concept validation
All clinical decisions must be made by qualified healthcare professionals using approved medical devices and evidence-based guidelines. Always consult a nephrologist for dialysis management.
| Problem | Solution |
|---|---|
404 Not Found on /simulate |
Verify backend is running on port 5000; check vite.config.js proxy config |
| MongoDB connection error | Ensure mongod service is running; verify MONGODB_URI in .env |
AI insights show ** symbols |
Confirm formatText.js utility is imported in AIInsightCard.jsx |
| Charts not rendering | Check that backend response includes hours, toxin_levels_over_time, fluid_levels_over_time arrays of equal length |
| Tailwind styles not applying | Verify content array in tailwind.config.js includes "./src/**/*.{js,ts,jsx,tsx}" |
- Check browser DevTools β Console & Network tabs
- Review backend terminal logs for error messages
- Test API endpoints directly with
curl(see Testing section) - Open an issue in this repository with:
- Exact error message
- Steps to reproduce
- Node.js/npm versions (
node -v,npm -v)
β
Hackathon-Ready: Complete MERN stack, fully functional in <5 minutes
β
Clinically Grounded: Simplified but realistic dialysis physiology models
β
AI-Enhanced: LLM integration with safety guardrails, not just a wrapper
β
Production-Prepared: Modular architecture, error handling, environment config
β
Evaluator-Friendly: Clear documentation, one-command setup, visual demo flow
π Ready to demo?
# Backend cd backend && npm run dev # Frontend cd frontend && npm run dev # Open: http://localhost:3000
Built with β€οΈ for better patient outcomes π©Ίπ