Multi-Language Chat Agent - Deployment Setup
This document provides a comprehensive overview of the deployment configuration and setup for the Multi-Language Chat Agent application.
🚀 Quick Start
Docker Deployment (Recommended)
git clone <repository-url>
cd chat-agent
cp config/production.env .env
docker-compose up -d
curl http://localhost:5000/health/
Manual Deployment
python scripts/setup_environment.py --environment production
make run-prod
📁 Configuration Files Overview
Docker Configuration
| File |
Purpose |
Environment |
Dockerfile |
Production container build |
Production |
Dockerfile.dev |
Development container with hot reload |
Development |
docker-compose.yml |
Production services orchestration |
Production |
docker-compose.dev.yml |
Development services with volumes |
Development |
nginx.conf |
Reverse proxy configuration |
Production |
.dockerignore |
Docker build optimization |
All |
Environment Configuration
| File |
Purpose |
Usage |
config/development.env |
Development environment variables |
Development |
config/production.env |
Production environment template |
Production |
config/testing.env |
Testing environment configuration |
Testing |
.env.example |
Environment template with examples |
Reference |
Database Configuration
| File |
Purpose |
Usage |
migrations/001_initial_schema.sql |
Database schema definition |
All environments |
migrations/migrate.py |
Migration management script |
All environments |
scripts/init_db.py |
Database initialization utility |
Setup |
Deployment Scripts
| File |
Purpose |
Usage |
scripts/setup_environment.py |
Automated environment setup |
Setup |
scripts/init_db.py |
Database management |
Setup/Maintenance |
Makefile |
Common development tasks |
Development |
🏗️ Architecture Overview
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Nginx │ │ Chat Agent │ │ PostgreSQL │
│ (Reverse Proxy)│────│ Application │────│ Database │
│ │ │ │ │ │
└─────────────────┘ └─────────────────┘ └─────────────────┘
│
│
┌─────────────────┐
│ Redis │
│ (Cache/ │
│ Sessions) │
└─────────────────┘
🔧 Configuration Management
Environment-Specific Settings
The application supports three environments with different configurations:
Development
- Debug mode enabled
- Detailed logging
- Local database
- Hot reload
- Development tools
Production
- Optimized for performance
- Security hardened
- Production database
- Monitoring enabled
- Error handling
Testing
- In-memory database
- Isolated test data
- Minimal logging
- Fast execution
Configuration Hierarchy
- Environment Variables (highest priority)
.env file
- Config class defaults
- Application defaults (lowest priority)
🐳 Docker Deployment
Production Deployment
docker-compose up -d
docker-compose --profile production up -d
docker-compose up -d --scale chat-agent=3
Development Deployment
docker-compose -f docker-compose.dev.yml up -d
docker-compose -f docker-compose.dev.yml logs -f
Docker Services
| Service |
Purpose |
Ports |
Dependencies |
chat-agent |
Main application |
5000 |
postgres, redis |
postgres |
Database |
5432 |
- |
redis |
Cache/Sessions |
6379 |
- |
nginx |
Reverse proxy |
80, 443 |
chat-agent |
🗄️ Database Management
Initialization
python scripts/init_db.py init --config production
python scripts/init_db.py status --config production
python scripts/init_db.py seed --config production
Migrations
python migrations/migrate.py migrate --config production
python migrations/migrate.py status --config production
Backup and Restore
make backup-db
make restore-db
🔍 Health Monitoring
Health Check Endpoints
| Endpoint |
Purpose |
Use Case |
/health/ |
Basic health check |
Load balancer |
/health/detailed |
Component status |
Monitoring |
/health/ready |
Readiness probe |
Kubernetes |
/health/live |
Liveness probe |
Kubernetes |
/health/metrics |
Application metrics |
Monitoring |
Example Health Check
curl http://localhost:5000/health/
curl http://localhost:5000/health/detailed | jq
Monitoring Integration
The health endpoints are designed to work with:
- Load Balancers: Nginx, HAProxy, AWS ALB
- Container Orchestration: Kubernetes, Docker Swarm
- Monitoring Systems: Prometheus, Grafana, DataDog
🔒 Security Configuration
Production Security Checklist
Environment Variables Security
python -c "import secrets; print(secrets.token_urlsafe(32))"
export SECRET_KEY="your_secure_key"
export GROQ_API_KEY="your_api_key"
📊 Performance Optimization
Application Performance
- Connection Pooling: Database and Redis connections
- Caching: Redis for sessions and frequent data
- Async Processing: WebSocket for real-time communication
- Load Balancing: Multiple application instances
Database Performance
CREATE INDEX CONCURRENTLY idx_messages_session_timestamp
ON messages(session_id, timestamp);
CREATE INDEX CONCURRENTLY idx_sessions_user_active
ON chat_sessions(user_id, is_active);
Redis Configuration
maxmemory 512mb
maxmemory-policy allkeys-lru
save 900 1
save 300 10
🚨 Troubleshooting
Common Issues
1. Container Won't Start
docker-compose logs chat-agent
docker-compose exec chat-agent curl localhost:5000/health/
2. Database Connection Failed
docker-compose exec postgres psql -U chatuser -d chat_agent_db -c "SELECT 1;"
docker-compose exec chat-agent env | grep DATABASE
3. Redis Connection Issues
docker-compose exec redis redis-cli ping
docker-compose logs redis
Log Analysis
docker-compose logs -f chat-agent
docker-compose logs -f postgres
docker-compose logs -f
📈 Scaling
Horizontal Scaling
docker-compose up -d --scale chat-agent=3
Load Balancing
upstream chat_agent {
server chat-agent_1:5000;
server chat-agent_2:5000;
server chat-agent_3:5000;
}
Database Scaling
- Read Replicas: For read-heavy workloads
- Connection Pooling: PgBouncer for connection management
- Partitioning: For large message tables
🔄 CI/CD Integration
GitHub Actions Example
name: Deploy to Production
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build and Deploy
run: |
docker-compose build
docker-compose up -d
- name: Health Check
run: |
sleep 30
curl -f http://localhost:5000/health/ || exit 1
📚 Additional Resources
🆘 Support
For deployment issues:
- Check the troubleshooting section
- Review application logs
- Verify configuration settings
- Test health endpoints
- Check system resources
📝 Changelog
Version 1.0.0
- Initial deployment configuration
- Docker containerization
- Health monitoring
- Environment management
- Database migrations
- Security hardening