services:
  db:
    image: mongo:7
    container_name: rhl-lieferscheine-db
    restart: unless-stopped
    environment:
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: supersecret
    volumes:
      - db_data:/data/db
    # Do not publish MongoDB to the host in the base/server compose.
    # Containers can still reach it via the Compose network (service name: "db").
    expose:
      - "27017"
    healthcheck:
      test:
        [
          "CMD",
          "mongosh",
          "--quiet",
          "mongodb://root:supersecret@localhost:27017/admin?authSource=admin",
          "--eval",
          "db.adminCommand('ping').ok",
        ]
      interval: 10s
      timeout: 5s
      retries: 10
      start_period: 20s

  app:
    build: .
    container_name: rhl-lieferscheine-app
    restart: unless-stopped
    env_file:
      - ${ENV_FILE:-.env.docker}
    depends_on:
      db:
        condition: service_healthy
    ports:
      - "3000:3000"
    volumes:
      # Server mount: real NAS
      - /mnt/niederlassungen:/mnt/niederlassungen:ro
    command: sh -c "node scripts/validate-env.mjs && npm run start"

volumes:
  db_data:
