services:
  app:
    build:
      context: .
      dockerfile: docker/php/Dockerfile
    container_name: ai-crm-app
    restart: unless-stopped
    user: "${UID:-1000}:${GID:-1000}"
    volumes:
      - ./backend:/var/www
    working_dir: /var/www
    depends_on:
      - db
    networks:
      - ai-network

  webserver:
    image: nginx:latest
    container_name: ai-crm-nginx
    restart: unless-stopped
    ports:
      - "${NGINX_HTTP_PORT:-8080}:80"
    volumes:
      - ./backend:/var/www
      - ./docker/nginx:/etc/nginx/conf.d
    depends_on:
      - app
      - frontend
      - client
    networks:
      - ai-network

  db:
    image: mysql:8
    container_name: ai-crm-db
    restart: unless-stopped
    env_file:
      - .env
    environment:
      MYSQL_DATABASE: ${DB_DATABASE}
      MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
      MYSQL_USER: ${DB_USERNAME}
      MYSQL_PASSWORD: ${DB_PASSWORD}
    ports:
      - "3307:3306"
    volumes:
      - ai_crm_db_data:/var/lib/mysql  
    networks:
      - ai-network

  frontend:
    image: node:20-alpine
    container_name: ai-crm-frontend
    restart: unless-stopped 
    volumes:
      - ./frontend:/app
    working_dir: /app
    command: sh -c "npm install && npm run dev -- --host 0.0.0.0 --port 5173"
    ports: 
      - "5173:5173"
    depends_on:
      - app
    networks:
      - ai-network

  client:
    image: node:20-alpine
    container_name: ai-crm-client
    restart: unless-stopped
    volumes:
      - ./client:/app
    working_dir: /app
    command: sh -c "npm install && npm run dev -- --host 0.0.0.0 --port 5173"
    ports:
      - "5174:5173"
    depends_on:
      - app
    networks:
      - ai-network

volumes:
  ai_crm_db_data:
      
networks:
  ai-network:
    driver: bridge