#!/bin/bash # Telegram Marketing Intelligence Agent System - Local Development Start echo "🚀 Starting Telegram Marketing Intelligence Agent System (Local Mode)" echo "==================================================================" echo "" # Colors for output GREEN='\033[0;32m' RED='\033[0;31m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color # Check if Docker is running for infrastructure if ! docker info > /dev/null 2>&1; then echo -e "${RED}❌ Docker is not running. Please start Docker for infrastructure services.${NC}" exit 1 fi echo "1. Starting Infrastructure Services with Docker..." echo "-------------------------------------------------" # Start only infrastructure services docker-compose up -d mongodb redis rabbitmq elasticsearch prometheus grafana # Wait for infrastructure echo -e "${YELLOW}⏳ Waiting for infrastructure services to be ready...${NC}" sleep 10 echo "" echo "2. Installing Dependencies..." echo "-----------------------------" # Install dependencies for all services services=( "api-gateway" "auth-service" "orchestrator" "gramjs-adapter" "message-queue" "analytics" "compliance-guard" "claude-agent" "monitoring-dashboard" "backup-service" "notification-service" "billing-service" ) for service in "${services[@]}"; do if [ -d "services/$service" ]; then echo -n "Installing dependencies for $service..." (cd "services/$service" && npm install --silent) 2>/dev/null echo -e " ${GREEN}✓${NC}" fi done # Frontend echo -n "Installing frontend dependencies..." (cd frontend && npm install --silent) 2>/dev/null echo -e " ${GREEN}✓${NC}" echo "" echo "3. Starting Backend Services..." echo "-------------------------------" # Function to start a service start_service() { local service_name=$1 local service_dir=$2 local port=$3 if [ ! -d "$service_dir" ]; then echo -e "${YELLOW}⚠️ $service_name directory not found, skipping...${NC}" return fi echo -n "Starting $service_name on port $port..." # Kill any existing process on the port lsof -ti:$port | xargs kill -9 2>/dev/null # Start the service cd "$service_dir" # Create .env file with local settings if it doesn't exist if [ ! -f .env ]; then cat > .env << EOF NODE_ENV=development PORT=$port MONGODB_URI=mongodb://localhost:27018/marketing_agent REDIS_HOST=localhost REDIS_PORT=6379 RABBITMQ_URL=amqp://admin:admin@localhost:5673 JWT_SECRET=dev-secret-key API_GATEWAY_URL=http://localhost:3000 EOF fi # Start the service nohup npm start > "../logs/$service_name.log" 2>&1 & echo $! > "../logs/$service_name.pid" echo -e " ${GREEN}✓${NC}" cd .. } # Create logs directory mkdir -p logs # Start all services start_service "API Gateway" "services/api-gateway" 3000 start_service "Auth Service" "services/auth-service" 3001 start_service "Campaign Orchestrator" "services/orchestrator" 3002 start_service "Telegram Adapter" "services/gramjs-adapter" 3003 start_service "Message Queue" "services/message-queue" 3004 start_service "Analytics Service" "services/analytics" 3005 start_service "Compliance Service" "services/compliance-guard" 3006 start_service "AI Service" "services/claude-agent" 3007 start_service "Monitoring Service" "services/monitoring-dashboard" 3008 start_service "Backup Service" "services/backup-service" 3009 start_service "Notification Service" "services/notification-service" 3010 start_service "Billing Service" "services/billing-service" 3011 echo "" echo "4. Starting Frontend..." echo "----------------------" echo -n "Starting Frontend development server..." cd frontend nohup npm run dev > ../logs/frontend.log 2>&1 & echo $! > ../logs/frontend.pid cd .. echo -e " ${GREEN}✓${NC}" echo "" echo "5. Service Status..." echo "-------------------" # Wait a bit for services to start sleep 5 # Check services echo -e "${BLUE}Infrastructure Services:${NC}" echo " MongoDB: localhost:27018" echo " Redis: localhost:6379 (internal)" echo " RabbitMQ: localhost:5673" echo " RabbitMQ Management: http://localhost:15673 (admin/admin)" echo "" echo -e "${BLUE}Application Services:${NC}" services_ports=( "API Gateway:3000" "Auth Service:3001" "Campaign Orchestrator:3002" "Telegram Adapter:3003" "Message Queue:3004" "Analytics Service:3005" "Compliance Service:3006" "AI Service:3007" "Monitoring Service:3008" "Backup Service:3009" "Notification Service:3010" "Billing Service:3011" "Frontend:5173" ) for service_port in "${services_ports[@]}"; do IFS=':' read -r name port <<< "$service_port" if lsof -Pi :$port -sTCP:LISTEN -t >/dev/null 2>&1; then echo -e " $name: ${GREEN}✓ Running${NC} on port $port" else echo -e " $name: ${RED}✗ Not running${NC}" fi done echo "" echo -e "${GREEN}✅ System started!${NC}" echo "" echo "📌 Access Points:" echo " Frontend: http://localhost:5173" echo " API Gateway: http://localhost:3000" echo " API Documentation: http://localhost:3000/api-docs" echo " RabbitMQ Management: http://localhost:15673 (admin/admin)" echo "" echo "📝 Default Admin Credentials:" echo " Email: admin@example.com" echo " Password: admin123" echo "" echo "🔍 View logs:" echo " tail -f logs/*.log" echo "" echo "🛑 To stop all services:" echo " ./stop-local.sh"