version: '3.8'
services:
  backend:
    build: ./backend
    container_name: stoeberhunde-backend
    ports:
      - "5000:5000"
    environment:
      - NODE_ENV=production
      - MONGO_URI=mongodb://mongo:27017/stoeberhunde
      - JWT_SECRET=${JWT_SECRET:-CHANGE_ME_IN_PRODUCTION}
      - JWT_EXPIRES_IN=24h
      - CORS_ORIGIN=http://localhost:8080
      - GEOCODE_URL=https://nominatim.openstreetmap.org/search
      - GEOCODE_USER_AGENT=stoeberhunde-app/1.0
      - GEOCODE_MIN_DELAY_MS=1100
    depends_on:
      - mongo
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "wget", "-q", "--spider", "http://localhost:5000/health"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s
  
  frontend:
    build: 
      context: ./frontend
      args:
        - REACT_APP_API_URL=http://localhost:5000
    container_name: stoeberhunde-frontend
    ports:
      - "8080:80"
    depends_on:
      - backend
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "wget", "-q", "--spider", "http://localhost/health"]
      interval: 30s
      timeout: 10s
      retries: 3
  
  mongo:
    image: mongo:7.0
    container_name: stoeberhunde-mongo
    # Port intentionally NOT exposed externally
    volumes:
      - mongo-data:/data/db
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "mongosh", "--eval", "db.adminCommand('ping')"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s

volumes:
  mongo-data: