services:
  # PHP Application with Apache
  app:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: slm-app
    ports:
      - "80:80"
    volumes:
      - ./:/var/www/html
    depends_on:
      - elasticsearch
    environment:
      - APP_ENV=development
    networks:
      - slm-network

  # Node.js API REST
  # Modo desarrollo: usa volumen para hot-reload
  api:
    image: node:18-alpine
    container_name: slm-api
    working_dir: /app
    ports:
      - "3000:3000"
    volumes:
      - ./api:/app
      - /app/node_modules  # Persist node_modules in container
    depends_on:
      - elasticsearch
    environment:
      - NODE_OPTIONS="--max-old-space-size=2048 --expose-gc"
      - NODE_ENV=development
      - API_PORT=3000
      - ES_SERVER=http://elasticsearch:9200
      - DEV_ES_INDEX=slm-app-dev
      - TZ=America/Mexico_City
    command: sh -c "npm install && npm run dev"
    restart: unless-stopped
    networks:
      - slm-network
    # Modo producción: descomenta las siguientes líneas y comenta 'image' arriba
    # build:
    #   context: ./api
    #   dockerfile: Dockerfile
    # command: node server.js

  # Elasticsearch
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.9.3
    container_name: slm-elasticsearch
    environment:
      - discovery.type=single-node
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
      - xpack.security.enabled=false
    ports:
      - "9200:9200"
      - "9300:9300"
    volumes:
      - elasticsearch-data:/usr/share/elasticsearch/data
    networks:
      - slm-network

  # Kibana (Optional - for Elasticsearch visualization)
  kibana:
    image: docker.elastic.co/kibana/kibana:7.9.3
    container_name: slm-kibana
    ports:
      - "5601:5601"
    environment:
      - ELASTICSEARCH_HOSTS=http://elasticsearch:9200
    depends_on:
      - elasticsearch
    networks:
      - slm-network

  # MailHog (Development email testing)
  mailhog:
    image: mailhog/mailhog
    container_name: slm-mailhog
    ports:
      - "1025:1025"
      - "8025:8025"
    networks:
      - slm-network

volumes:
  elasticsearch-data:
    driver: local

networks:
  slm-network:
    driver: bridge
