version: '3.8'

services:
  # Nginx as an API Gateway
  api_gateway:
    # Container name
    container_name: api_gateway 
    image: api-gateway:latest 
    build:
      context: ./backend
      dockerfile: docker/nginx/Dockerfile
    # Volume for the nginx Docker container
    volumes:
      - ./backend/docker/nginx/conf.d/:/etc/nginx/conf.d/
    # ports for the Nginx application service
    ports:
      - "8970:80"
    # The Nginx service depends on the Flask application services
    depends_on:
      - auth-service
    # Network configuration
    networks:
      - pige_network

  # Authentication Service
  auth-service:
    container_name: auth-service
    image: auth-service:latest
    build:
      context: ./backend/auth-service
      dockerfile: docker/Dockerfile
    ports:
      - "8971:8000"
    environment:
      - FLASK_DEBUG=development
      - MONGODB_URI=mongodb://mongo:27017/authdb
    volumes:
      - ./backend/auth-service/:/app
    depends_on:
      - mongo-database
    networks:
      - pige_network
 
  # Account Management Service
  account-service:
    container_name: account-service
    image: account-service:latest
    build:
      context: ./backend/account-service
      dockerfile: docker/Dockerfile
    ports:
      - "8972:8000"
    environment:
      - FLASK_DEBUG=development
      - MONGODB_URI=mongodb://mongo:27017/authdb
    volumes:
      - ./backend/account-service/:/app
    depends_on:
      - mongo-database
    networks:
      - pige_network
 
  # MongoDB Service
  mongo-database:
    container_name: mongo-database
    image: mongo:latest                  
    ports:
      - "27018:27017"             
    environment:
      - MONGO_INITDB_DATABASE=database    
    networks:
      - pige_network                  

  # MongoDB Viewer (AdminMongo)
  mongo-viewer:
    container_name: mongo-database-viewer
    image: mongo-express:latest        
    ports:
      - "8083:8081"              
    environment:
      ME_CONFIG_MONGODB_SERVER: "mongo-database"
      ME_CONFIG_BASICAUTH_USERNAME: "admin"
      ME_CONFIG_BASICAUTH_PASSWORD: "admin" 
    networks:
      - pige_network                   

  # RabbitMQ Service
  rabbitmq-server:
    container_name: rabbitmq-server
    image: rabbitmq:latest
    ports:
      - 5672:5672
      - 15672:15672
    networks:
      - pige_network
    environment:
      RABBITMQ_DEFAULT_USER: "guest"
      RABBITMQ_DEFAULT_PASS: "guest"

  # Frontend Service
  frontend-service:
    container_name: frontend-service 
    image: frontend-service:latest
    build:
      context: ./frontend
      target: development
      dockerfile: Dockerfile
    ports:
      - "3000:3000"
    volumes:
      - ./frontend/src:/app/src   
      - ./frontend/public:/app/public   
    networks:
      - pige_network

# Define networks for better isolation
networks:
  pige_network:
    driver: bridge              

 
 