services:
  proxy: # Proxy server + load balancer
    build:
      context: .
      dockerfile: ./docker/proxy/Dockerfile.proxy
    restart: unless-stopped
    ports:
      - "8000:80"
      - "6001:80"
    #   - "443:443" # no HTTPS in development
    volumes:
      - ./docker/proxy/proxy.conf:/etc/nginx/conf.d/default.conf
      - .:/var/www/html
    depends_on:
      - api
    networks:
      - proxynet
  api: # Laravel application php-fpm
    # 9000
    build:
      context: .
      dockerfile: ./Dockerfile.api
      target: dev
    restart: unless-stopped
    ports:
      - "5173:5173" # vite hot reload endpoint, just for dev
    volumes:
      - ./docker/api/php-fpm-dev.conf:/usr/local/etc/php-fpm.d/www.conf
      - .:/var/www/html
      - /var/www/html/vendor
      - /var/www/html/node_modules
    networks:
      - apinet
      - proxynet
    depends_on:
      - database
      - redis
  worker: # Laravel queue worker
    build:
      context: .
      dockerfile: ./Dockerfile.api
      target: worker
    restart: unless-stopped
    volumes:
      - .:/var/www/html
      - /var/www/html/vendor
      - /var/www/html/node_modules
    depends_on:
      - api
      - database
      - redis
    networks:
      - apinet
  scheduler: # Laravel scheduler
    build:
      context: .
      dockerfile: ./Dockerfile.api
      target: scheduler
    restart: unless-stopped
    volumes:
      - .:/var/www/html
      - /var/www/html/vendor
      - /var/www/html/node_modules
    networks:
      - apinet
    depends_on:
      - api
      - database
      - redis
  reverb: # Laravel reverb (websockets server)
    # 6001
    build:
      context: .
      dockerfile: ./Dockerfile.api
      target: reverb
    restart: unless-stopped
    volumes:
      - .:/var/www/html
      - /var/www/html/vendor
      - /var/www/html/node_modules
    # ports:
    # - "6001:6001" # no need to expose, reverse proxy will handle it
    # extra_hosts:
    # - "host.docker.internal:host-gateway" # only needed if we ever want to access host machine services
    networks:
      - apinet
      - proxynet
    depends_on:
      - api
  database: # PostgreSQL database
    image: postgis/postgis:17-3.5
    restart: unless-stopped
    # postgres needs more than default shared memory, which is 64MB
    shm_size: 128mb
    environment:
      POSTGRES_DB: shams
      POSTGRES_USER: shams
      POSTGRES_PASSWORD: shams
    ports:
      # only in dev, for testing purposes using DBMS software
      - "5432:5432"
    volumes:
      - pgdata:/var/lib/postgresql/data
    networks:
      - apinet
      - dbnet
  redis:
    image: redis:7
    restart: unless-stopped
    ports:
      # only in dev, for testing purposes using DBMS software
      - "6379:6379"
    volumes:
      - redisdata:/data
    networks:
      - apinet
  adminer:
    image: adminer
    restart: unless-stopped
    ports:
      - 8081:8080
    networks:
      - dbnet

networks:
  proxynet:
  apinet:
  dbnet:

volumes:
  pgdata:
  redisdata:
