version: "3.8"

services:
  api:
    image: jhumanj/opnform-api:dev
    container_name: opnform-api
    volumes:
      - ./api:/usr/share/nginx/html:delegated
      - /usr/share/nginx/html/vendor # Exclude vendor directory from the mount
      - ./api/storage:/usr/share/nginx/html/storage:delegated
    environment:
      APP_ENV: local
      APP_DEBUG: true
      APP_DEV_CORS: true
      # Database settings
      DB_HOST: db
      DB_DATABASE: ${DB_DATABASE:-forge}
      DB_USERNAME: ${DB_USERNAME:-forge}
      DB_PASSWORD: ${DB_PASSWORD:-forge}
      DB_CONNECTION: ${DB_CONNECTION:-pgsql}
      # Override production settings for minimal setup
      CACHE_DRIVER: file
      SESSION_DRIVER: file
      QUEUE_CONNECTION: sync
      # Storage settings
      FILESYSTEM_DISK: local
      LOCAL_FILESYSTEM_VISIBILITY: public
      # PHP Configuration
      PHP_MEMORY_LIMIT: "1G"
      PHP_MAX_EXECUTION_TIME: "600"
      PHP_UPLOAD_MAX_FILESIZE: "64M"
      PHP_POST_MAX_SIZE: "64M"
      # Development settings
      PHP_IDE_CONFIG: serverName=Docker
      XDEBUG_MODE: ${XDEBUG_MODE:-off}
      XDEBUG_CONFIG: client_host=host.docker.internal
      APP_URL: http://localhost
      FRONT_URL: http://localhost:3000
    depends_on:
      db:
        condition: service_healthy

  ui:
    image: jhumanj/opnform-client:dev
    container_name: opnform-client
    command: sh -c "npm install && NITRO_HOST=0.0.0.0 NITRO_PORT=3000 npm run dev"
    volumes:
      - ./client:/app:delegated
      - /app/node_modules # Keep container's node_modules
    environment:
      NODE_ENV: development
      NUXT_PUBLIC_APP_ENV: development
      HOST: "0.0.0.0"
      PORT: 3000
      # HMR settings
      CHOKIDAR_USEPOLLING: "true"
      WATCHPACK_POLLING: "true"
      VITE_HMR_HOST: "localhost"
      VITE_HMR_PORT: 24678
      # API settings
      NUXT_PUBLIC_APP_URL_BASE: "http://localhost"
      NUXT_PUBLIC_API_BASE: "http://localhost/api"
    extra_hosts:
      - "host.docker.internal:host-gateway"
    ports:
      - "3000:3000"      # Main dev server
      - "24678:24678"    # Vite HMR port

  db:
    image: postgres:16
    container_name: opnform-db
    environment:
      POSTGRES_DB: ${DB_DATABASE:-forge}
      POSTGRES_USER: ${DB_USERNAME:-forge}
      POSTGRES_PASSWORD: ${DB_PASSWORD:-forge}
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${DB_USERNAME:-forge}"]
      interval: 5s
      timeout: 5s
      retries: 5
    ports:
      - "5432:5432"
    volumes:
      - postgres-data:/var/lib/postgresql/data

  ingress:
    image: nginx:1
    container_name: opnform-ingress
    volumes:
      - ./docker/nginx.dev.conf:/etc/nginx/templates/default.conf.template
    environment:
      NGINX_HOST: localhost
      NGINX_PORT: 80
      NGINX_MAX_BODY_SIZE: 64m
    ports:
      - "80:80"
    depends_on:
      api:
        condition: service_started
      ui:
        condition: service_started

volumes:
  postgres-data: 