Architecture Overview
| Component | Technology | Hosting | Status |
|---|---|---|---|
| Frontend | React 18 + Vite | Vercel | ✅ Live |
| Backend | FastAPI + Docker | Render | ✅ Live |
| Database | InfluxDB 2.x | InfluxDB Cloud | ✅ Live |
Live Deployment
InfluxDB Cloud Setup
Set up the time-series database for sensor data storage.Create InfluxDB Cloud account
- Go to InfluxDB Cloud
- Sign up for a free account
- Select AWS us-east-1 region (recommended)
Create a bucket
- Navigate to Load Data → Buckets
- Click Create Bucket
- Name:
sensor_data - Retention: 30 days (adjust as needed)
Generate API token
- Navigate to Load Data → API Tokens
- Click Generate API Token → Read/Write Token
- Grant permissions:
- Read access to
sensor_databucket - Write access to
sensor_databucket
- Read access to
- Save the token securely (you won’t see it again)
Backend Deployment (Render)
Deploy the FastAPI backend as a Docker container on Render.Create Render account
- Go to Render
- Sign up or log in with GitHub
Create new Web Service
- Click New → Web Service
- Connect your GitHub repository
- Select the repository:
PREDICTIVE-MAINTENANCE
Configure service settings
Set the following configuration:
| Field | Value |
|---|---|
| Name | predictive-maintenance-backend |
| Region | Oregon (US West) or closest to you |
| Branch | main |
| Root Directory | backend |
| Environment | Docker |
| Dockerfile Path | backend/Dockerfile |
| Instance Type | Free (or paid for production) |
Deploy
- Click Create Web Service
- Render will automatically:
- Build the Docker image from
backend/Dockerfile - Deploy the container
- Assign a URL:
https://your-service.onrender.com
- Build the Docker image from
- Monitor logs for successful startup
Render Cold Starts
The frontend automatically sends a 10-minute keep-alive ping to/ping to prevent cold starts during active browser sessions.
Frontend Deployment (Vercel)
Deploy the React dashboard to Vercel with automatic HTTPS and global CDN.Create Vercel account
- Go to Vercel
- Sign up with GitHub
Configure build settings
Set the following configuration:
| Field | Value |
|---|---|
| Framework Preset | Vite |
| Root Directory | frontend |
| Build Command | npm run build |
| Output Directory | dist |
| Install Command | npm install |
Add environment variables (optional)
In Settings → Environment Variables, add:
This is optional if you’re using Vercel rewrites (recommended approach).
Configure API rewrites
The Update the
frontend/vercel.json file handles API proxying:destination URLs to match your Render backend URL.Deploy
- Click Deploy
- Vercel will:
- Install dependencies
- Build the React app
- Deploy to global CDN
- Assign a URL:
https://your-project.vercel.app
- Automatic deployments trigger on every push to
main
Custom Domain (Optional)
Update DNS
Add these DNS records at your domain provider:
| Type | Name | Value |
|---|---|---|
| A | pm | 76.76.21.21 |
| CNAME | pm | cname.vercel-dns.com |
Systemd Deployment (Linux Servers)
For bare-metal Linux servers, use the systemd service for process management.Run setup script
The automated setup script installs dependencies and configures systemd:This script:
- Installs Python 3.11+, pip, venv
- Creates
/opt/predictive-maintenancedirectory - Sets up Python virtual environment
- Installs backend dependencies
- Configures systemd service
- Starts the service automatically
Systemd Service Configuration
The service is defined in/etc/systemd/system/predictive-maintenance.service:
Restart=always- Auto-restart on failureRestartSec=5- Wait 5 seconds before restart- Logs to systemd journal
- Starts after network is available
Environment Variables Reference
Backend (Render)
| Variable | Required | Description | Example |
|---|---|---|---|
ENVIRONMENT | Yes | Runtime mode | production |
PORT | Yes | Server port | 8000 |
INFLUX_URL | Yes | InfluxDB Cloud URL | https://us-east-1-1.aws.cloud2.influxdata.com |
INFLUX_TOKEN | Yes | InfluxDB API token | kg2i8Mq... |
INFLUX_ORG | Yes | Organization ID | 67c4314d97304c09 |
INFLUX_BUCKET | Yes | Bucket name | sensor_data |
Frontend (Vercel)
| Variable | Required | Description | Example |
|---|---|---|---|
VITE_API_URL | No | Backend URL (if not using rewrites) | https://your-backend.onrender.com |
Monitoring and Observability
Health Checks
Logs
Render: Access logs via dashboard → Service → Logs Vercel: View logs in dashboard → Project → Functions InfluxDB: Monitor queries at https://cloud2.influxdata.com Systemd: View logs with:Metrics
InfluxDB Cloud provides built-in metrics:- Data points written per second
- Query response time
- Storage usage
- API request rate
Troubleshooting
Backend 503 Errors
Problem: Service unavailable on Render Solution: Check deployment logs for:- InfluxDB connection failures
- Missing environment variables
- ML model loading errors (lazy imports)
Frontend API Errors
Problem:Network Error or CORS issues
Solution: Verify Vercel rewrites are working:
- Check
frontend/vercel.jsondestination URLs - Inspect browser DevTools → Network tab
- Ensure requests to
/api/*proxy to Render
InfluxDB Token Scope Issues
Problem:unauthorized access errors
Solution: Regenerate token with correct permissions:
- Go to InfluxDB Cloud → API Tokens
- Create new Read/Write Token
- Grant access to
sensor_databucket - Update
INFLUX_TOKENin Render environment variables - Restart the service
Degradation Index (DI) State Loss
Problem: Health score resets after backend restart Solution: The system automatically hydrates DI from InfluxDB on startup via|> last(). If this fails:
- Check InfluxDB connection
- Verify
degradation_indexmeasurement exists - Use
POST /system/purgeto explicitly reset DI to 0.0
Windows Binary Errors on Vercel
Problem: Error 126 during build Solution: Removenode_modules from Git:
Performance Optimization
Backend
-
Enable Gunicorn for production (multi-worker):
- Cache ML models in memory (already implemented)
- Batch InfluxDB writes for high-frequency data
- Use connection pooling for database clients
Frontend
- Enable Vercel Edge Caching for static assets
- Lazy load components using React.lazy()
- Optimize chart rendering with data sampling
- Use service workers for offline capability
Database
-
Downsample old data using InfluxDB tasks:
- Set appropriate retention policies (30 days for raw data)
- Use continuous queries for pre-aggregation
Security Best Practices
-
Never commit secrets to version control
- Use
.envfiles locally - Use platform environment variables in production
- Use
-
Rotate API tokens regularly
- InfluxDB tokens every 90 days
- Backend service credentials quarterly
-
Enable CORS restrictions in
backend/api/main.py: -
Use HTTPS everywhere
- Vercel provides automatic SSL
- Render provides automatic SSL
- InfluxDB Cloud enforces HTTPS
- Implement rate limiting using FastAPI middleware
- Validate all inputs with Pydantic schemas
- Monitor for anomalous API usage in logs
Scaling Considerations
Horizontal Scaling
Render: Upgrade to paid plan for:- Auto-scaling based on CPU/memory
- Multiple instances with load balancing
- 99.9% uptime SLA
Vertical Scaling
For high-frequency data (>1000 data points/sec):- Upgrade Render instance type (2GB → 4GB RAM)
- Use InfluxDB Dedicated instances
- Implement data batching in backend
Next Steps
- Review API Reference for integration
- Explore Docker Deployment for local testing
- Check Architecture for system design
- Monitor your deployment with the built-in health dashboard