version: '3.8'

services:
  # Base de données PostgreSQL
  postgres:
    image: postgres:15-alpine
    container_name: veza-postgres-prod
    environment:
      POSTGRES_DB: veza_prod
      POSTGRES_USER: veza_user
      POSTGRES_PASSWORD: veza_password
    volumes:
      - postgres_data:/var/lib/postgresql/data
      - ./scripts/database/init.sql:/docker-entrypoint-initdb.d/init.sql
    ports:
      - "5432:5432"
    networks:
      - veza-network
    restart: unless-stopped

  # Cache Redis
  redis:
    image: redis:7-alpine
    container_name: veza-redis-prod
    command: redis-server --appendonly yes
    volumes:
      - redis_data:/data
    ports:
      - "6379:6379"
    networks:
      - veza-network
    restart: unless-stopped

  # Backend API
  backend:
    build:
      context: ./veza-backend-api
      dockerfile: Dockerfile.backend
    container_name: veza-backend-prod
    environment:
      - DATABASE_URL=postgresql://veza_user:veza_password@postgres:5432/veza_prod?sslmode=disable
      - REDIS_URL=redis://redis:6379
      - PORT=8080
      - NODE_ENV=production
    ports:
      - "8080:8080"
    depends_on:
      - postgres
      - redis
    networks:
      - veza-network
    restart: unless-stopped

  # Frontend
  frontend:
    build:
      context: ./veza-frontend
      dockerfile: Dockerfile
    container_name: veza-frontend-prod
    environment:
      - VITE_API_URL=http://localhost:8080
      - VITE_WS_URL=ws://localhost:8081
    ports:
      - "3000:80"
    depends_on:
      - backend
    networks:
      - veza-network
    restart: unless-stopped

  # Chat Server (WebSocket)
  chat-server:
    build:
      context: ./veza-chat-server
      dockerfile: Dockerfile
    container_name: veza-chat-prod
    environment:
      - DATABASE_URL=postgresql://veza_user:veza_password@postgres:5432/veza_chat
      - REDIS_URL=redis://redis:6379
      - PORT=8081
      - RUST_LOG=info
    ports:
      - "8081:8081"
    depends_on:
      - postgres
      - redis
    networks:
      - veza-network
    restart: unless-stopped

  # Monitoring - Prometheus
  prometheus:
    image: prom/prometheus:latest
    container_name: veza-prometheus-prod
    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'
    ports:
      - "9090:9090"
    volumes:
      - ./config/prometheus.yml:/etc/prometheus/prometheus.yml
      - prometheus_data:/prometheus
    networks:
      - veza-network
    restart: unless-stopped

  # Monitoring - Grafana
  grafana:
    image: grafana/grafana:latest
    container_name: veza-grafana-prod
    environment:
      - GF_SECURITY_ADMIN_PASSWORD=admin
      - GF_USERS_ALLOW_SIGN_UP=false
    ports:
      - "3001:3000"
    volumes:
      - grafana_data:/var/lib/grafana
      - ./config/grafana/datasources:/etc/grafana/provisioning/datasources
      - ./config/grafana/dashboards:/etc/grafana/provisioning/dashboards
    depends_on:
      - prometheus
    networks:
      - veza-network
    restart: unless-stopped

volumes:
  postgres_data:
  redis_data:
  prometheus_data:
  grafana_data:

networks:
  veza-network:
    driver: bridge 