version: '3.8'

services:
  postgres:
    image: postgres:15-alpine
    container_name: optiflow-db
    restart: always
    environment:
      POSTGRES_USER: optiflow
      POSTGRES_PASSWORD: ${DB_PASSWORD}
      POSTGRES_DB: optiflow
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U optiflow"]
      interval: 5s
      timeout: 5s
      retries: 5

  app:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: optiflow-app
    restart: always
    ports:
      - "3000:3000"
    environment:
      DATABASE_URL: postgresql://optiflow:${DB_PASSWORD}@postgres:5432/optiflow
      NEXT_PUBLIC_API_URL: https://yourdomain.com
    depends_on:
      postgres:
        condition: service_healthy

volumes:
  postgres_data:
