services:
  pg:
    image: postgres:16-alpine
    environment:
      POSTGRES_USER: writer
      POSTGRES_PASSWORD: writer
      POSTGRES_DB: writer
    ports:
      - "5432:5432"
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U writer"]
      interval: 5s
      timeout: 3s
      retries: 10
    volumes:
      - pgdata:/var/lib/postgresql/data

  api:
    build:
      context: .
      dockerfile: apps/api/Dockerfile
    environment:
      DATABASE_URL: postgresql+asyncpg://writer:writer@pg:5432/writer
      DATABASE_URL_SYNC: postgresql+psycopg://writer:writer@pg:5432/writer
      APP_ENV: dev
    ports:
      - "8000:8000"
    depends_on:
      pg:
        condition: service_healthy

  web:
    build:
      context: ./apps/web
    environment:
      NEXT_PUBLIC_API_BASE: http://localhost:8000
    ports:
      - "3000:3000"
    depends_on:
      - api

volumes:
  pgdata:
