import { spawn } from 'child_process';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
import fs from 'fs';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const rootDir = dirname(__dirname);
// Ensure data directory exists
const dataDir = join(rootDir, 'data');
if (!fs.existsSync(dataDir)) {
fs.mkdirSync(dataDir, { recursive: true });
}
console.log('π Starting ADL System...\n');
// Start GraphQL server
const graphql = spawn('node', ['backend/graphql-server.js'], {
cwd: rootDir,
stdio: 'inherit',
shell: true,
env: { ...process.env, GRAPHQL_PORT: '4000' }
});
// Wait a bit for GraphQL to start
await new Promise(resolve => setTimeout(resolve, 2000));
// Start MCP HTTP server
const mcpHttp = spawn('node', ['mcp-server/http-server.js'], {
cwd: rootDir,
stdio: 'inherit',
shell: true,
env: { ...process.env, MCP_HTTP_PORT: '5000', GRAPHQL_URL: 'http://localhost:4000/graphql' }
});
// Wait a bit for MCP to start
await new Promise(resolve => setTimeout(resolve, 1000));
// Start UI server
const ui = spawn('node', ['ui/server.js'], {
cwd: rootDir,
stdio: 'inherit',
shell: true,
env: { ...process.env, UI_PORT: '3000' }
});
console.log('\nβ
All services started!');
console.log('π GraphQL Server: http://localhost:4000/graphql');
console.log('π MCP HTTP Server: http://localhost:5000');
console.log('π UI Application: http://localhost:3000');
console.log('π‘ MCP Stdio Server: Run "node mcp-server/server.js" separately for AI assistant integration\n');
// Handle shutdown
process.on('SIGINT', () => {
console.log('\n\nπ Shutting down services...');
graphql.kill();
mcpHttp.kill();
ui.kill();
process.exit(0);
});
// Keep the process running
graphql.on('exit', (code) => {
console.error(`GraphQL server exited with code ${code}`);
mcpHttp.kill();
ui.kill();
process.exit(code);
});
mcpHttp.on('exit', (code) => {
console.error(`MCP HTTP server exited with code ${code}`);
graphql.kill();
ui.kill();
process.exit(code);
});
ui.on('exit', (code) => {
console.error(`UI server exited with code ${code}`);
graphql.kill();
mcpHttp.kill();
process.exit(code);
});