version: '3.8'

services:
  db:
    image: postgres:16-alpine
    container_name: alemno_db
    ports:
      - "5432:5432"
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
      POSTGRES_DB: alemno_payments
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres -d alemno_payments"]
      interval: 5s
      timeout: 5s
      retries: 5

  redis:
    image: redis:7-alpine
    container_name: alemno_redis
    ports:
      - "6379:6379"
    volumes:
      - redis_data:/data

  web:
    build: .
    container_name: alemno_web
    ports:
      - "3000:3000"
    volumes:
      - .:/app
      - /app/.venv
    environment:
      - POSTGRES_HOST=db
      - POSTGRES_PORT=5432
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
      - POSTGRES_DB=alemno_payments
      - REDIS_HOST=redis
      - REDIS_PORT=6379
      - REDIS_DB=0
      - GEMINI_API_KEY
    depends_on:
      db:
        condition: service_healthy
      redis:
        condition: service_started

  worker:
    build: .
    container_name: alemno_worker
    volumes:
      - .:/app
      - /app/.venv
    environment:
      - POSTGRES_HOST=db
      - POSTGRES_PORT=5432
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
      - POSTGRES_DB=alemno_payments
      - REDIS_HOST=redis
      - REDIS_PORT=6379
      - REDIS_DB=0
      - GEMINI_API_KEY
    command: celery -A app.worker.celery_app worker --loglevel=info
    depends_on:
      db:
        condition: service_healthy
      redis:
        condition: service_started

volumes:
  postgres_data:
  redis_data:
