version: '3.8'

services:
  # NovaLang E-commerce Backend
  ecommerce-backend:
    build: .
    ports:
      - "8080:8080"
    environment:
      - SPRING_PROFILES_ACTIVE=dev
      - MYSQL_URL=jdbc:mysql://mysql:3306/ecommerce
      - MYSQL_USERNAME=root
      - MYSQL_PASSWORD=password
      - MONGODB_URI=mongodb://mongodb:27017/ecommerce
      - REDIS_HOST=redis
      - JWT_SECRET=mySecretKey2024NovaLangEcommerceDocker
    depends_on:
      - mysql
      - mongodb
      - redis
    networks:
      - ecommerce-network
    restart: unless-stopped

  # MySQL Database
  mysql:
    image: mysql:8.0
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_DATABASE: ecommerce
      MYSQL_USER: ecommerce_user
      MYSQL_PASSWORD: ecommerce_pass
    ports:
      - "3306:3306"
    volumes:
      - mysql_data:/var/lib/mysql
      - ./init.sql:/docker-entrypoint-initdb.d/init.sql
    networks:
      - ecommerce-network
    restart: unless-stopped

  # MongoDB Database
  mongodb:
    image: mongo:7.0
    environment:
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: password
      MONGO_INITDB_DATABASE: ecommerce
    ports:
      - "27017:27017"
    volumes:
      - mongodb_data:/data/db
    networks:
      - ecommerce-network
    restart: unless-stopped

  # Redis Cache
  redis:
    image: redis:7.0-alpine
    ports:
      - "6379:6379"
    volumes:
      - redis_data:/data
    networks:
      - ecommerce-network
    restart: unless-stopped
    command: redis-server --appendonly yes

  # MongoDB Express (GUI for MongoDB)
  mongo-express:
    image: mongo-express
    ports:
      - "8081:8081"
    environment:
      ME_CONFIG_MONGODB_ADMINUSERNAME: root
      ME_CONFIG_MONGODB_ADMINPASSWORD: password
      ME_CONFIG_MONGODB_SERVER: mongodb
    depends_on:
      - mongodb
    networks:
      - ecommerce-network
    restart: unless-stopped

  # Redis Commander (GUI for Redis)
  redis-commander:
    image: rediscommander/redis-commander:latest
    ports:
      - "8082:8081"
    environment:
      - REDIS_HOSTS=local:redis:6379
    depends_on:
      - redis
    networks:
      - ecommerce-network
    restart: unless-stopped

volumes:
  mysql_data:
  mongodb_data:
  redis_data:

networks:
  ecommerce-network:
    driver: bridge
