File size: 8,011 Bytes
da2713e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
#!/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)