version: '3.8'

services:
  # MongoDB
  mongodb:
    image: mongo:7.0
    container_name: mana_pige_mongodb
    restart: unless-stopped
    environment:
      MONGO_INITDB_ROOT_USERNAME: ${MONGO_INITDB_ROOT_USERNAME:-admin}
      MONGO_INITDB_ROOT_PASSWORD: ${MONGO_INITDB_ROOT_PASSWORD:-password}
    # ports:
    #   - "27017:27017"
    volumes:
      - mongodb_data:/data/db
    networks:
      - mana_pige_network

  # MongoDB Viewer (Mongo Express)
  mongo-express:
    image: mongo-express:1.0.2
    container_name: mana_pige_mongo_express
    restart: unless-stopped
    ports:
      - "8083:8081"
    environment:
      ME_CONFIG_MONGODB_ADMINUSERNAME: ${MONGO_INITDB_ROOT_USERNAME:-admin}
      ME_CONFIG_MONGODB_ADMINPASSWORD: ${MONGO_INITDB_ROOT_PASSWORD:-password}
      ME_CONFIG_MONGODB_URL: mongodb://admin:password@mongodb:27017/
      ME_CONFIG_MONGODB_SERVER: mongodb
      ME_CONFIG_BASICAUTH_USERNAME: ${ME_CONFIG_BASICAUTH_USERNAME:-admin}
      ME_CONFIG_BASICAUTH_PASSWORD: ${ME_CONFIG_BASICAUTH_PASSWORD:-admin123}
      ME_CONFIG_SITE_BASEURL: /
    depends_on:
      - mongodb
    networks:
      - mana_pige_network

  # Redis
  redis:
    image: redis:7.2-alpine
    container_name: mana_pige_redis
    restart: unless-stopped
    # ports:
    #   - "6380:6379"
    volumes:
      - redis_data:/data
    networks:
      - mana_pige_network

  # Zookeeper (required for Kafka)
  zookeeper:
    image: confluentinc/cp-zookeeper:7.4.0
    container_name: mana_pige_zookeeper
    environment:
      ZOOKEEPER_CLIENT_PORT: 2181
      ZOOKEEPER_TICK_TIME: 2000
    # ports:
    #   - "2181:2181"
    networks:
      - mana_pige_network

  # Kafka
  kafka:
    image: confluentinc/cp-kafka:7.4.0
    container_name: mana_pige_kafka
    depends_on:
      - zookeeper
    
    environment:
      KAFKA_BROKER_ID: "1"
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092
      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
      KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
      KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
      KAFKA_AUTO_CREATE_TOPICS_ENABLE: 'true'
    networks:
      - mana_pige_network
  
  # API Gateway
  nginx:
   # Container name
   container_name: mana_pige_gateway 
   image: api-gateway:latest 
   build:
     context: .
     dockerfile: docker/nginx/Dockerfile
   # Volume for the nginx Docker container
   volumes:
     - ./docker/nginx/conf.d/:/etc/nginx/conf.d/
   # ports for the Nginx application service
   ports:
     - "8082:80"
   # The Nginx service depends on the Flask application services
   depends_on:
     - auth-service
     - account-service
     - notification-service
   # Network configuration
   networks:
    - mana_pige_network

  # Frontend - Next.js Application
  frontend: 
    container_name: mana_pige_frontend
    build:
      context: ./frontend
      dockerfile: ../docker/frontend/Dockerfile 
    ports:
      - "3000:3000"
    environment:
      - NODE_ENV=development 
      - NEXT_PUBLIC_API_URL=http://173.212.199.208:8082
      - NEXT_PUBLIC_WS_URL=ws://173.212.199.208:8082/ws
    volumes:
      - ./frontend:/app
      - /app/node_modules
      - /app/.next
    networks:
      - mana_pige_network
    restart: unless-stopped

  # Auth Service
  auth-service:
    build:
      context: ./backend
      dockerfile: ./auth-service/Dockerfile
    container_name: mana_pige_auth_service
    restart: unless-stopped 
    environment:
      - MONGODB_URL=mongodb://admin:password@mongodb:27017
      - DB_NAME=mana_pige_db
      - REDIS_URL=redis://redis:6379
      - KAFKA_BOOTSTRAP_SERVERS=kafka:9092
      - ACCOUNT_SERVICE_URL=http://account-service:8000
      - SECRET_KEY=${SECRET_KEY:-change-me-in-env}
      - ALLOWED_ORIGINS=${ALLOWED_ORIGINS:-http://localhost:3000,http://127.0.0.1:3000}
    depends_on:
      - mongodb
      - redis
      - kafka
    networks:
      - mana_pige_network
    volumes:
      - ./backend/shared:/app/shared

  # Account Service
  account-service:
    build:
      context: ./backend
      dockerfile: ./account-service/Dockerfile
    container_name: mana_pige_account_service
    restart: unless-stopped 
    environment:
      - MONGODB_URL=mongodb://admin:password@mongodb:27017
      - DB_NAME=mana_pige_db
      - REDIS_URL=redis://redis:6379
      - KAFKA_BOOTSTRAP_SERVERS=kafka:9092
      - AUTH_SERVICE_URL=http://auth-service:8000
      - SECRET_KEY=${SECRET_KEY:-change-me-in-env}
      - ALLOWED_ORIGINS=${ALLOWED_ORIGINS:-http://localhost:3000,http://127.0.0.1:3000}
    depends_on:
      - mongodb
      - redis
      - kafka
    networks:
      - mana_pige_network
    volumes:
      - ./backend/shared:/app/shared

  # Notification Service
  notification-service:
    build:
      context: ./backend
      dockerfile: ./notification-service/Dockerfile
    container_name: mana_pige_notification_service
    restart: unless-stopped 
    environment:
      - MONGODB_URL=mongodb://admin:password@mongodb:27017
      - DB_NAME=mana_pige_db
      - KAFKA_BOOTSTRAP_SERVERS=kafka:9092
      - SMTP_HOST=${SMTP_HOST:-smtp.gmail.com}
      - SMTP_PORT=${SMTP_PORT:-587}
      - SMTP_USERNAME=${SMTP_USERNAME:-}
      - SMTP_PASSWORD=${SMTP_PASSWORD:-}
      - SMTP_USE_TLS=${SMTP_USE_TLS:-true}
      - EMAIL_FROM=${EMAIL_FROM:-noreply@manapige.com}
      - EMAIL_FROM_NAME=${EMAIL_FROM_NAME:-Mana Pige}
      - BASE_URL=${BASE_URL:-http://localhost:3000}
    depends_on:
      - mongodb
      - kafka
    networks:
      - mana_pige_network
    volumes:
      - ./backend/shared:/app/shared
  

volumes:
  mongodb_data:
  redis_data:

networks:
  mana_pige_network:
    driver: bridge
  

