# docker-compose.yml
services:
  # ----- Backend API (Uvicorn/FastAPI/Django etc.) -----
  api:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: MAIA-API
    command: uvicorn main:app --host 0.0.0.0 --port 8000 --reload
    volumes:
      - .:/app
    ports:
      - "8000:8000"
    environment:
      - DB_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:5432/maia
      - REDIS_URL=redis://redis:6379/0
    depends_on:
      - db
      - redis
    networks:
      - maia_network
    env_file:
      - ./.env
    restart: unless-stopped

  # ----- Celery Worker -----
  worker:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: MAIA-Worker
    command: celery -A core.celery_app worker --loglevel=info
    volumes:
      - .:/app
    environment:
      - DB_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:5432/maia
      - REDIS_URL=redis://redis:6379/0
    depends_on:
      - db
      - redis
    env_file:
      - ./.env
    networks:
      - maia_network
    restart: unless-stopped

  # ----- Database (PostgreSQL) -----
  db:
    image: postgres:15 # Use a specific version
    container_name: MAIA-DB
    volumes:
      - postgres_data:/var/lib/postgresql/data # Persist data using a named volume
    environment:
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - POSTGRES_DB=maia
    env_file:
      - ./.env
    networks:
      - maia_network
    restart: unless-stopped

  # ----- Cache (Redis) -----
  redis:
    image: redis:7 # Use a specific version
    container_name: MAIA-Redis
    volumes:
      - redis_data:/data
    networks:
      - maia_network
    restart: unless-stopped

# ----- Volumes Definition -----
volumes:
  postgres_data: # Define the named volume for PostgreSQL
  redis_data:    # Define the named volume for Redis

# ----- Network Definition -----
networks:
  maia_network:   # Define a custom bridge network
    driver: bridge