services:
  db:
    image: postgres:18
    environment:
      POSTGRES_USER: inventory
      POSTGRES_PASSWORD: inventory_dev_password
      POSTGRES_DB: inventory2026
    ports:
      - "5433:5432"
    volumes:
      - postgres-data:/var/lib/postgresql
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U inventory -d inventory2026"]
      interval: 5s
      timeout: 5s
      retries: 20

  api:
    build:
      context: .
      dockerfile: apps/api/Dockerfile
    environment:
      DATABASE_URL: postgres://inventory:inventory_dev_password@db:5432/inventory2026
      API_PORT: 4000
      SESSION_SECRET: ${SESSION_SECRET:-replace-with-a-long-random-secret}
      CORS_ORIGIN: ${CORS_ORIGIN:-http://localhost:3000}
      PUBLIC_APP_URL: ${PUBLIC_APP_URL:-http://localhost:3000}
      SMTP_HOST: ${SMTP_HOST:-}
      SMTP_PORT: ${SMTP_PORT:-587}
      SMTP_USER: ${SMTP_USER:-}
      SMTP_PASS: ${SMTP_PASS:-}
      SMTP_FROM: ${SMTP_FROM:-SSS Inventory <inventory@example.com>}
    ports:
      - "4000:4000"
    depends_on:
      db:
        condition: service_healthy

  web:
    build:
      context: .
      dockerfile: apps/web/Dockerfile
    environment:
      PUBLIC_API_URL: ${PUBLIC_API_URL:-http://localhost:4000}
      NEXT_PUBLIC_API_URL: ${PUBLIC_API_URL:-http://localhost:4000}
    ports:
      - "3000:3000"
    depends_on:
      - api

volumes:
  postgres-data:
