version: '3.9'

services:
  api:
    build: .
    ports:
      - '127.0.0.1:3000:3000'   # bind to localhost only - nginx proxies externally
    env_file:
      - .env
    environment:
      - PORT=3000
      - DATABASE_URL=postgresql://aiw_voice_user:${POSTGRES_PASSWORD}@postgres:5432/aiw_voice
    depends_on:
      postgres:
        condition: service_healthy
    restart: unless-stopped

  postgres:
    image: postgres:16-alpine
    ports:
      - '127.0.0.1:5432:5432'   # exposed to localhost so `npm run dev` can connect
    environment:
      POSTGRES_USER: aiw_voice_user
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_DB: aiw_voice
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ['CMD-SHELL', 'pg_isready -U aiw_voice_user -d aiw_voice']
      interval: 5s
      timeout: 5s
      retries: 5
    restart: unless-stopped

volumes:
  postgres_data:
