A Flask web application that provides a 3D digital twin visualization of health data using Three.js. The app displays real-time health metrics with color-coded body zones representing different health indicators.
- 3D Humanoid Body Visualization built with Three.js
- Real-time health data fetched from the Health API
- Color-coded zones:
- Heart area: Green (normal), Red (high), Blue (low)
- Legs: Opacity based on daily steps/energy level
- Head: Glow effect based on sleep quality
- Side panel dashboard showing all current metrics
- Auto-refresh every 30 seconds
- Responsive design with dark theme
- Backend: Python Flask
- Frontend: Three.js (CDN)
- Data Source: Health API at
https://health-api-production-f082.up.railway.app
health-digital-twin/
├── app.py # Flask application
├── requirements.txt # Python dependencies
├── Dockerfile # Docker configuration
├── railway.json # Railway deployment config
├── README.md # This file
├── static/ # Static files (if needed)
└── templates/
└── index.html # Main HTML template with Three.js
- Python 3.11+
- pip
- Health API token (set as environment variable)
-
Clone the repository:
git clone <repository-url> cd health-digital-twin
-
Create and activate virtual environment (recommended):
python -m venv venv # On Windows: # venv\Scripts\activate # On macOS/Linux: source venv/bin/activate
-
Install dependencies:
pip install -r requirements.txt
-
Set environment variable:
# On macOS/Linux: export HEALTH_API_TOKEN="your_api_token_here" # On Windows (PowerShell): $env:HEALTH_API_TOKEN="your_api_token_here"
-
Run the application:
python app.py
-
Open browser: Navigate to
http://localhost:5000
- Create a new repository on GitHub
- Push the code:
git init git add . git commit -m "Initial commit" git remote add origin <your-repo-url> git push -u origin main
- Sign up at railway.app
- Connect your GitHub repository
- Set environment variables in Railway dashboard:
HEALTH_API_TOKEN: Your Health API token
- Deploy:
- Railway will automatically detect the
Dockerfileand deploy - The app will be available at your Railway domain
- Railway will automatically detect the
The railway.json file configures:
- Build process using Nixpacks
- Python 3.11 environment
- Gunicorn server with 2 workers
- Health check endpoint
| Variable | Description | Required |
|---|---|---|
HEALTH_API_TOKEN |
Your Health API authentication token | Yes |
PORT |
Port to run the application (default: 5000) | No |
| Endpoint | Description |
|---|---|
GET / |
Main page with 3D visualization |
GET /api/health |
Current health data (JSON) |
GET /api/health/today |
Today's health data (alias) |
The API returns JSON with the following fields:
{
"heartRate": 72,
"steps": 5000,
"sleepHours": 7.5,
"waterMl": 1500,
"activeCalories": 300,
"weightKg": 75.0,
"timestamp": "2026-04-08T08:45:00"
}- Green (#4ecdc4): Normal (60-100 BPM)
- Red (#ff6b6b): High (> 100 BPM)
- Blue (#3498db): Low (< 60 BPM)
- Opacity increases with more steps
- Range: 30% (low activity) to 100% (high activity)
- Purple glow intensity based on sleep hours
- ≥ 8 hours: Strong glow
- 6-7.9 hours: Moderate glow
- < 6 hours: Dim glow
-
No health data showing:
- Check that
HEALTH_API_TOKENis set correctly - Verify the API is accessible from your network
- Check that
-
Three.js errors:
- Ensure browser supports WebGL
- Check browser console for specific errors
-
Port already in use:
- Change the port:
PORT=8080 python app.py
- Change the port:
export FLASK_ENV=development
export HEALTH_API_TOKEN="your_token"
python app.pycurl http://localhost:5000/api/healthMIT License - feel free to use and modify.
For issues or questions, please open an issue on the repository.