name: laravel-api

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
      args:
        INSTALL_DEV: "true"
    environment:
      INSTALL_DEV_DEPENDENCIES: "true"
    volumes:
      # Development bind mount: PHP sees application file changes immediately.
      - .:/var/www/html
      # Keep Linux Composer packages out of the Windows host vendor directory.
      - composer_vendor:/var/www/html/vendor
    restart: unless-stopped
    depends_on:
      db:
        condition: service_healthy
    networks:
      - backend

  nginx:
    image: nginx:1.27-alpine
    ports:
      - "${APP_PORT:-8000}:80"
    volumes:
      - ./public:/var/www/html/public:ro
      - ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf:ro
    restart: unless-stopped
    depends_on:
      - app
    healthcheck:
      test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://127.0.0.1/api/v1/health"]
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 15s
    networks:
      - backend

  db:
    image: postgres:16-alpine
    ports:
      - "${DB_FORWARD_PORT:-5432}:5432"
    environment:
      POSTGRES_DB: "${DB_DATABASE:-laravel}"
      POSTGRES_USER: "${DB_USERNAME:-laravel}"
      POSTGRES_PASSWORD: "${DB_PASSWORD:-secret}"
    volumes:
      - postgres_data:/var/lib/postgresql/data
    restart: unless-stopped
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${DB_USERNAME:-laravel} -d ${DB_DATABASE:-laravel}"]
      interval: 5s
      timeout: 5s
      retries: 10
    networks:
      - backend

  pgadmin:
    image: dpage/pgadmin4:9
    ports:
      - "${PGADMIN_PORT:-5050}:80"
    environment:
      PGADMIN_DEFAULT_EMAIL: "${PGADMIN_DEFAULT_EMAIL:-admin@example.com}"
      PGADMIN_DEFAULT_PASSWORD: "${PGADMIN_DEFAULT_PASSWORD:-admin}"
      PGADMIN_CONFIG_SERVER_MODE: "False"
    volumes:
      - pgadmin_data:/var/lib/pgadmin
      - ./backups:/var/lib/pgadmin/storage/backups
    restart: unless-stopped
    depends_on:
      db:
        condition: service_healthy
    networks:
      - backend

networks:
  backend:
    driver: bridge

volumes:
  postgres_data:
  pgadmin_data:
  composer_vendor:
