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

  redis:
    image: redis:7-alpine
    ports:
      - "6380:6379"
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 5s
      timeout: 5s
      retries: 5

  api:
    build: .
    ports:
      - "8000:8000"
    depends_on:
      db:
        condition: service_healthy
      redis:
        condition: service_healthy
    environment:
      DATABASE_URL: postgresql+asyncpg://poorav:poorav@db:5432/poorav
      REDIS_URL: redis://redis:6379/0
      PYTHONPATH: /app
    volumes:
      - ./app:/app
    working_dir: /app
    command: uvicorn main:app --host 0.0.0.0 --port 8000

volumes:
  postgres_data:
