version: '3.8'

services:
  # MongoDB
  mongodb:
    image: mongo:7.0
    container_name: mana_pige_mongodb
    restart: unless-stopped
    environment:
      MONGO_INITDB_ROOT_USERNAME: admin
      MONGO_INITDB_ROOT_PASSWORD: password
    ports:
      - "27017:27017"
    volumes:
      - mongodb_data:/data/db
    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
    ports:
      - "9092:9092"
    environment:
      KAFKA_BROKER_ID: 1
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost: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

  # Auth Service
  auth-service:
    build:
      context: .
      dockerfile: auth-service/Dockerfile
    container_name: mana_pige_auth_service
    restart: unless-stopped
    ports:
      - "8001:8000"
    environment:
      - MONGODB_URL=mongodb://admin:password@mongodb:27017
      - DB_NAME=auth_db
      - REDIS_URL=redis://redis:6379
      - KAFKA_BOOTSTRAP_SERVERS=kafka:9092
      - ACCOUNT_SERVICE_URL=http://account-service:8000
    depends_on:
      - mongodb
      - redis
      - kafka
    networks:
      - mana_pige_network
    volumes:
      - ./shared:/app/shared

  # Account Service
  account-service:
    build:
      context: .
      dockerfile: account-service/Dockerfile
    container_name: mana_pige_account_service
    restart: unless-stopped
    ports:
      - "8002:8000"
    environment:
      - MONGODB_URL=mongodb://admin:password@mongodb:27017
      - DB_NAME=account_db
      - REDIS_URL=redis://redis:6379
      - KAFKA_BOOTSTRAP_SERVERS=kafka:9092
      - AUTH_SERVICE_URL=http://auth-service:8000
    depends_on:
      - mongodb
      - redis
      - kafka
    networks:
      - mana_pige_network
    volumes:
      - ./shared:/app/shared

volumes:
  mongodb_data:
  redis_data:

networks:
  mana_pige_network:
    driver: bridge
