#!/usr/bin/env python3 """ Fresh Start Validation Script Checks all requirements for launching the system from scratch """ import os import sys import subprocess import json def check_file_exists(filepath, description): """Check if a critical file exists""" if os.path.exists(filepath): print(f"āœ… {description}: {filepath}") return True else: print(f"āŒ MISSING {description}: {filepath}") return False def check_docker_files(): """Check all Docker-related files""" print("🐳 Checking Docker files...") files = [ ("docker-compose.yml", "Main orchestration file"), ("agent/Dockerfile", "Agent service Docker config"), ("mcp/Dockerfile", "MCP service Docker config"), ("frontend/Dockerfile", "Frontend service Docker config"), ("neo4j/Dockerfile", "Neo4j service Docker config"), (".env.example", "Environment template") ] all_good = True for filepath, desc in files: all_good &= check_file_exists(filepath, desc) return all_good def check_frontend_files(): """Check frontend critical files""" print("\n🌐 Checking Frontend files...") files = [ ("frontend/package.json", "Frontend dependencies"), ("frontend/tsconfig.json", "TypeScript config"), ("frontend/tailwind.config.js", "Tailwind CSS config"), ("frontend/next.config.js", "Next.js config"), ("frontend/app/page.tsx", "Main chat interface"), ("frontend/app/layout.tsx", "Root layout"), ("frontend/types/cytoscape-fcose.d.ts", "Cytoscape types") ] all_good = True for filepath, desc in files: all_good &= check_file_exists(filepath, desc) return all_good def check_backend_files(): """Check backend service files""" print("\nšŸ”§ Checking Backend files...") files = [ ("agent/main.py", "Agent service main file"), ("agent/requirements.txt", "Agent dependencies"), ("mcp/main.py", "MCP service main file"), ("mcp/requirements.txt", "MCP dependencies"), ("postgres/init.sql", "PostgreSQL initialization"), ] all_good = True for filepath, desc in files: all_good &= check_file_exists(filepath, desc) return all_good def check_operational_files(): """Check operational scripts""" print("\nšŸ› ļø Checking Operational files...") files = [ ("ops/scripts/seed.py", "Basic seeding script"), ("ops/scripts/seed_comprehensive.py", "Comprehensive seeding script"), ("ops/scripts/validate.py", "System validation script"), ("ops/scripts/demo.ps1", "PowerShell demo script"), ("Makefile", "Build automation"), ("README.md", "Main documentation"), ("SYSTEM_OVERVIEW.md", "System overview") ] all_good = True for filepath, desc in files: all_good &= check_file_exists(filepath, desc) return all_good def check_env_variables(): """Check if .env.example has all required variables""" print("\nāš™ļø Checking Environment variables...") if not os.path.exists(".env.example"): print("āŒ .env.example file missing") return False with open(".env.example", "r") as f: env_content = f.read() required_vars = [ "NEO4J_AUTH", "NEO4J_BOLT_URL", "POSTGRES_PASSWORD", "POSTGRES_CONNECTION", "MCP_API_KEYS", "MCP_PORT", "AGENT_POLL_INTERVAL", "PAUSE_DURATION", "LLM_API_KEY", "LLM_MODEL" ] all_good = True for var in required_vars: if var in env_content: print(f"āœ… Environment variable: {var}") else: print(f"āŒ MISSING environment variable: {var}") all_good = False return all_good def check_docker_compose_structure(): """Check docker-compose.yml structure""" print("\nšŸ”— Checking Docker Compose structure...") if not os.path.exists("docker-compose.yml"): print("āŒ docker-compose.yml missing") return False try: import yaml with open("docker-compose.yml", "r") as f: compose = yaml.safe_load(f) required_services = ["neo4j", "postgres", "mcp", "agent", "frontend"] all_good = True for service in required_services: if service in compose.get("services", {}): print(f"āœ… Service defined: {service}") else: print(f"āŒ MISSING service: {service}") all_good = False return all_good except ImportError: print("āš ļø PyYAML not available, skipping structure check") return True except Exception as e: print(f"āŒ Error parsing docker-compose.yml: {e}") return False def check_package_json(): """Check frontend package.json for required dependencies""" print("\nšŸ“¦ Checking Frontend dependencies...") if not os.path.exists("frontend/package.json"): print("āŒ frontend/package.json missing") return False with open("frontend/package.json", "r") as f: package = json.load(f) required_deps = [ "next", "react", "react-dom", "typescript", "cytoscape", "cytoscape-fcose", "tailwindcss" ] all_deps = {**package.get("dependencies", {}), **package.get("devDependencies", {})} all_good = True for dep in required_deps: if dep in all_deps: print(f"āœ… Frontend dependency: {dep}") else: print(f"āŒ MISSING frontend dependency: {dep}") all_good = False return all_good def generate_startup_commands(): """Generate the exact commands for fresh startup""" print("\nšŸš€ Fresh Startup Commands:") print("=" * 50) print("# 1. Copy environment file") print("cp .env.example .env") print("") print("# 2. Edit .env and add your LLM API key") print("# LLM_API_KEY=your-openai-or-anthropic-key-here") print("") print("# 3. Clean any existing containers") print("docker-compose down") print("docker system prune -f") print("") print("# 4. Build and start services") print("docker-compose build") print("docker-compose up -d") print("") print("# 5. Wait for services to be healthy (30 seconds)") print("Start-Sleep 30") print("") print("# 6. Seed the database") print("docker-compose exec mcp python /app/ops/scripts/seed.py") print("") print("# 7. Open the interface") print("# Frontend: http://localhost:3000") print("# Neo4j Browser: http://localhost:7474 (neo4j/password)") print("=" * 50) def main(): print("šŸ” FRESH START VALIDATION") print("========================") print("") checks = [ ("Docker Files", check_docker_files), ("Frontend Files", check_frontend_files), ("Backend Files", check_backend_files), ("Operational Files", check_operational_files), ("Environment Variables", check_env_variables), ("Docker Compose Structure", check_docker_compose_structure), ("Frontend Dependencies", check_package_json) ] all_passed = True for check_name, check_func in checks: try: result = check_func() all_passed &= result except Exception as e: print(f"āŒ ERROR in {check_name}: {e}") all_passed = False print("\n" + "=" * 50) if all_passed: print("āœ… ALL CHECKS PASSED!") print("System is ready for fresh deployment") generate_startup_commands() else: print("āŒ SOME CHECKS FAILED") print("Please fix the missing files/configurations before deploying") print("=" * 50) return all_passed if __name__ == "__main__": success = main() sys.exit(0 if success else 1)