version: '3.8'

services:
  # PostgreSQL Database
  postgres:
    image: postgres:14-alpine
    container_name: peikarband-db
    environment:
      POSTGRES_USER: ${DB_USER:-peikarband}
      POSTGRES_PASSWORD: ${DB_PASSWORD:-peikarband}
      POSTGRES_DB: ${DB_NAME:-peikarband}
    ports:
      - "5432:5432"
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U peikarband"]
      interval: 10s
      timeout: 5s
      retries: 5

  # Redis Cache
  redis:
    image: redis:7-alpine
    container_name: peikarband-redis
    ports:
      - "6379:6379"
    volumes:
      - redis_data:/data
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 5s
      retries: 5

  # Peikarband Application
  app:
    build: .
    container_name: peikarband-app
    depends_on:
      - postgres
      - redis
    ports:
      - "3000:3000"
      - "8000:8000"
    environment:
      - DATABASE_URL=postgresql://peikarband:peikarband@postgres:5432/peikarband
      - REDIS_URL=redis://redis:6379/0
      - CELERY_BROKER_URL=redis://redis:6379/1
      - CELERY_RESULT_BACKEND=redis://redis:6379/2
      - SECRET_KEY=${SECRET_KEY}
      - JWT_SECRET_KEY=${JWT_SECRET_KEY}
      - ENVIRONMENT=production
    volumes:
      - ./:/app
    restart: unless-stopped

  # Celery Worker
  celery:
    build: .
    container_name: peikarband-celery
    command: celery -A src.infrastructure.tasks.celery_app worker -l info
    depends_on:
      - postgres
      - redis
    environment:
      - DATABASE_URL=postgresql://peikarband:peikarband@postgres:5432/peikarband
      - REDIS_URL=redis://redis:6379/0
      - CELERY_BROKER_URL=redis://redis:6379/1
      - CELERY_RESULT_BACKEND=redis://redis:6379/2
    volumes:
      - ./:/app
    restart: unless-stopped

  # Flower (Celery Monitoring)
  flower:
    build: .
    container_name: peikarband-flower
    command: celery -A src.infrastructure.tasks.celery_app flower
    depends_on:
      - redis
      - celery
    ports:
      - "5555:5555"
    environment:
      - CELERY_BROKER_URL=redis://redis:6379/1
    restart: unless-stopped

volumes:
  postgres_data:
  redis_data:

