version: '3.8'

services:
  # MySQL Database
  mysql:
    image: mysql:8.0
    container_name: flutterflow_sync_mysql
    environment:
      MYSQL_ROOT_PASSWORD: rootpassword
      MYSQL_DATABASE: flutterflow_sync
      MYSQL_USER: sync_user
      MYSQL_PASSWORD: sync_password
    ports:
      - "3306:3306"
    volumes:
      - mysql_data:/var/lib/mysql
      - ./server/sql/init.sql:/docker-entrypoint-initdb.d/init.sql
    networks:
      - sync_network
    restart: unless-stopped

  # Redis Cache
  redis:
    image: redis:7-alpine
    container_name: flutterflow_sync_redis
    ports:
      - "6379:6379"
    volumes:
      - redis_data:/data
    networks:
      - sync_network
    restart: unless-stopped
    command: redis-server --appendonly yes

  # Sync Middleware Server
  sync_server:
    build:
      context: ./server
      dockerfile: Dockerfile
    container_name: flutterflow_sync_server
    environment:
      - NODE_ENV=production
      - PORT=3000
      - DB_HOST=mysql
      - DB_PORT=3306
      - DB_NAME=flutterflow_sync
      - DB_USER=sync_user
      - DB_PASSWORD=sync_password
      - REDIS_URL=redis://redis:6379
      - SUPABASE_URL=${SUPABASE_URL}
      - SUPABASE_SERVICE_KEY=${SUPABASE_SERVICE_KEY}
      - SUPABASE_ANON_KEY=${SUPABASE_ANON_KEY}
      - JWT_SECRET=${JWT_SECRET}
      - SESSION_SECRET=${SESSION_SECRET}
      - DASHBOARD_USERNAME=${DASHBOARD_USERNAME:-admin}
      - DASHBOARD_PASSWORD=${DASHBOARD_PASSWORD:-admin123}
    ports:
      - "3000:3000"
    volumes:
      - ./server/logs:/app/logs
    depends_on:
      - mysql
      - redis
    networks:
      - sync_network
    restart: unless-stopped

  # Dashboard (if built separately)
  dashboard:
    build:
      context: ./dashboard
      dockerfile: Dockerfile
    container_name: flutterflow_sync_dashboard
    ports:
      - "3001:80"
    depends_on:
      - sync_server
    networks:
      - sync_network
    restart: unless-stopped

volumes:
  mysql_data:
    driver: local
  redis_data:
    driver: local

networks:
  sync_network:
    driver: bridge
