Deployment Overview
CUIDO Backend can be deployed in multiple ways:Docker
Containerized deployment (recommended)
Node.js
Direct deployment with PM2 or systemd
Cloud Platforms
AWS, Azure, Google Cloud, or Heroku
Docker Deployment (Recommended)
Build Docker Image
Ensure you have a
Dockerfile in the root directory. If not, create one based on the configuration below.Dockerfile Example
Create aDockerfile in your project root:
Dockerfile
Docker Compose
Create adocker-compose.yml for easier orchestration:
docker-compose.yml
Run with Docker Compose
Run Single Container
Alternatively, run the container directly:Production Environment Variables
Create a production.env file:
.env.production
Generate Secure Secrets
Health Checks
The application provides a health check endpoint at/health:
Endpoint Details
Using Health Checks
Graceful Shutdown
The application handles graceful shutdown for zero-downtime deployments:server.js
How It Works
Process Management
For non-Docker deployments, use a process manager:PM2 (Recommended)
systemd
Create a systemd service:/etc/systemd/system/cuido-backend.service
Monitoring & Logging
Winston Logging
Logs are automatically written to:- Console: Formatted based on
NODE_ENV - Application logs:
logs/application-%DATE%.log(rotated daily) - Error logs:
logs/error-%DATE%.log(errors only)
Log Levels
Monitoring Tools
PM2 Monitoring
Docker Logs
Security Checklist
Environment Variables
- Use strong, randomly generated secrets
- Never commit
.envfiles - Use secret management tools (AWS Secrets Manager, Vault)
HTTPS/TLS
- Use reverse proxy (Nginx, Traefik) with TLS
- Enable HSTS headers (configured in
helmet) - Use valid SSL certificates (Let’s Encrypt)
Database Security
- Enable MongoDB authentication
- Use strong database passwords
- Restrict MongoDB network access
- Regular backups
Application Security
- Keep dependencies updated (
npm audit) - Use rate limiting (already configured)
- Validate all inputs (Zod validators)
- Enable CORS only for trusted origins
Performance Optimization
Compression
Response compression is enabled by default:app.js
Database Connection Pooling
Configured insrc/config/database.js:
Cluster Mode
Run multiple instances with PM2:Troubleshooting
Container Won't Start
Container Won't Start
Check logs:Common issues:
- Missing environment variables
- Invalid
ANTHROPIC_API_KEYformat - MongoDB connection failure
- Port already in use
High Memory Usage
High Memory Usage
Monitor with:Solutions:
- Reduce
maxPoolSizein database config - Check for memory leaks
- Restart container:
docker restart cuido-backend
Database Connection Errors
Database Connection Errors
Verify:
- MongoDB is running:
docker ps | grep mongo - Connection string is correct
- Network connectivity between containers
- Authentication credentials
Rate Limit Issues
Rate Limit Issues
Adjust in
.env:Deployment Platforms
AWS (ECS/Fargate)
- Push image to ECR
- Create ECS task definition
- Configure service with load balancer
- Set environment variables in task definition
Google Cloud (Cloud Run)
Heroku
Next Steps
Monitoring Setup
Integrate with DataDog, New Relic, or Prometheus
CI/CD Pipeline
Automate deployment with GitHub Actions
Backup Strategy
Implement automated database backups
Load Testing
Test with k6 or Artillery