# Docker Compose configuration for Comment Sentiment Analyzer # Provides complete development and production environment setup version: "3.8" services: # ============================================================================ # Backend API Service # ============================================================================ api: build: context: ./backend dockerfile: Dockerfile target: production container_name: comment-analyzer-api restart: unless-stopped ports: - "${API_PORT:-3000}:5628" environment: # Application Configuration - NODE_ENV=${NODE_ENV:-production} - PORT=3000 - HOST=0.0.0.0 # Database Configuration - DATABASE_URL=postgresql://${POSTGRES_USER:-analyzer}:${POSTGRES_PASSWORD:-secure_password}@db:5432/${POSTGRES_DB:-comment_analyzer} # Redis Configuration - REDIS_URL=redis://redis:6379 # JWT Configuration - JWT_SECRET=${JWT_SECRET:-your-super-secure-jwt-secret-key-change-this-in-production} - JWT_EXPIRES_IN=${JWT_EXPIRES_IN:-7d} # OAuth Configuration - GOOGLE_CLIENT_ID=${GOOGLE_CLIENT_ID} - GOOGLE_CLIENT_SECRET=${GOOGLE_CLIENT_SECRET} - FACEBOOK_APP_ID=${FACEBOOK_APP_ID} - FACEBOOK_APP_SECRET=${FACEBOOK_APP_SECRET} - TWITTER_API_KEY=${TWITTER_API_KEY} - TWITTER_API_SECRET=${TWITTER_API_SECRET} - TIKTOK_CLIENT_KEY=${TIKTOK_CLIENT_KEY} - TIKTOK_CLIENT_SECRET=${TIKTOK_CLIENT_SECRET} # AI Service Configuration - OPENAI_API_KEY=${OPENAI_API_KEY} - GEMINI_API_KEY=${GEMINI_API_KEY} # Application URLs - FRONTEND_URL=${FRONTEND_URL:-http://localhost:5628} - API_BASE_URL=${API_BASE_URL:-http://localhost:5628} # Monitoring and Logging - LOG_LEVEL=${LOG_LEVEL:-info} - ENABLE_METRICS=${ENABLE_METRICS:-true} # Security Configuration - CORS_ORIGIN=${CORS_ORIGIN:-http://localhost:5628} - RATE_LIMIT_WINDOW_MS=${RATE_LIMIT_WINDOW_MS:-900000} - RATE_LIMIT_MAX_REQUESTS=${RATE_LIMIT_MAX_REQUESTS:-100} depends_on: db: condition: service_healthy redis: condition: service_healthy networks: - comment-analyzer-network volumes: # Mount logs directory for persistent logging - ./logs:/app/logs # Mount uploads directory for file storage - ./uploads:/app/uploads healthcheck: test: ["CMD", "curl", "-f", "http://localhost:5628/health"] interval: 30s timeout: 10s retries: 3 start_period: 60s # ============================================================================ # Frontend Application Service # ============================================================================ frontend: build: context: ./frontend dockerfile: Dockerfile target: production args: - NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL:-http://localhost:5628} - NEXT_PUBLIC_APP_URL=${NEXT_PUBLIC_APP_URL:-http://localhost:5628} container_name: comment-analyzer-frontend restart: unless-stopped ports: - "${FRONTEND_PORT:-5628}" environment: - NODE_ENV=${NODE_ENV:-production} - NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL:-http://localhost:5628} - NEXT_PUBLIC_APP_URL=${NEXT_PUBLIC_APP_URL:-http://localhost:5628} depends_on: - api networks: - comment-analyzer-network healthcheck: test: ["CMD", "curl", "-f", "http://localhost:5628/api/health"] interval: 30s timeout: 10s retries: 3 start_period: 60s # ============================================================================ # PostgreSQL Database Service # ============================================================================ db: image: postgres:15-alpine container_name: comment-analyzer-db restart: unless-stopped ports: - "${POSTGRES_PORT:-5432}:5432" environment: - POSTGRES_DB=${POSTGRES_DB:-comment_analyzer} - POSTGRES_USER=${POSTGRES_USER:-analyzer} - POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-secure_password} - POSTGRES_INITDB_ARGS=--encoding=UTF-8 --lc-collate=C --lc-ctype=C volumes: # Persistent database storage - postgres_data:/var/lib/postgresql/data # Database initialization scripts - ./database/init:/docker-entrypoint-initdb.d # Database backups - ./database/backups:/backups networks: - comment-analyzer-network healthcheck: test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-analyzer} -d ${POSTGRES_DB:-comment_analyzer}"] interval: 10s timeout: 5s retries: 5 start_period: 30s command: > postgres -c shared_preload_libraries=pg_stat_statements -c pg_stat_statements.track=all -c max_connections=200 -c shared_buffers=256MB -c effective_cache_size=1GB -c maintenance_work_mem=64MB -c checkpoint_completion_target=0.9 -c wal_buffers=16MB -c default_statistics_target=100 -c random_page_cost=1.1 -c effective_io_concurrency=200 -c work_mem=4MB -c min_wal_size=1GB -c max_wal_size=4GB # ============================================================================ # Redis Cache Service # ============================================================================ redis: image: redis:7-alpine container_name: comment-analyzer-redis restart: unless-stopped ports: - "${REDIS_PORT:-6379}:6379" command: > redis-server --appendonly yes --appendfsync everysec --maxmemory 512mb --maxmemory-policy allkeys-lru --tcp-keepalive 60 --timeout 300 volumes: # Persistent Redis storage - redis_data:/data # Redis configuration - ./redis/redis.conf:/usr/local/etc/redis/redis.conf networks: - comment-analyzer-network healthcheck: test: ["CMD", "redis-cli", "ping"] interval: 10s timeout: 5s retries: 5 start_period: 30s # ============================================================================ # Nginx Reverse Proxy (Production) # ============================================================================ nginx: image: nginx:alpine container_name: comment-analyzer-nginx restart: unless-stopped ports: - "${HTTP_PORT:-80}:80" - "${HTTPS_PORT:-443}:443" volumes: # Nginx configuration - ./nginx/nginx.conf:/etc/nginx/nginx.conf - ./nginx/conf.d:/etc/nginx/conf.d # SSL certificates (if using HTTPS) - ./nginx/ssl:/etc/nginx/ssl # Static files - ./nginx/static:/var/www/static # Logs - ./nginx/logs:/var/log/nginx depends_on: - api - frontend networks: - comment-analyzer-network profiles: - production # ============================================================================ # Monitoring Services (Optional) # ============================================================================ # Prometheus for metrics collection prometheus: image: prom/prometheus:latest container_name: comment-analyzer-prometheus restart: unless-stopped ports: - "${PROMETHEUS_PORT:-9090}:9090" volumes: - ./monitoring/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml - prometheus_data:/prometheus command: - "--config.file=/etc/prometheus/prometheus.yml" - "--storage.tsdb.path=/prometheus" - "--web.console.libraries=/etc/prometheus/console_libraries" - "--web.console.templates=/etc/prometheus/consoles" - "--storage.tsdb.retention.time=200h" - "--web.enable-lifecycle" networks: - comment-analyzer-network profiles: - monitoring # Grafana for metrics visualization grafana: image: grafana/grafana:latest container_name: comment-analyzer-grafana restart: unless-stopped ports: - "${GRAFANA_PORT:-3002}:5628" environment: - GF_SECURITY_ADMIN_USER=${GRAFANA_USER:-admin} - GF_SECURITY_ADMIN_PASSWORD=${GRAFANA_PASSWORD:-admin} - GF_USERS_ALLOW_SIGN_UP=false volumes: - grafana_data:/var/lib/grafana - ./monitoring/grafana/provisioning:/etc/grafana/provisioning - ./monitoring/grafana/dashboards:/var/lib/grafana/dashboards depends_on: - prometheus networks: - comment-analyzer-network profiles: - monitoring # ============================================================================ # Network Configuration # ============================================================================ networks: comment-analyzer-network: driver: bridge ipam: config: - subnet: 172.20.0.0/16 # ============================================================================ # Volume Configuration # ============================================================================ volumes: # Database storage postgres_data: driver: local # Redis storage redis_data: driver: local # Monitoring storage prometheus_data: driver: local grafana_data: driver: local