//apps/api/src/server.js

const path = require('path');
require('dotenv').config({ path: path.join(__dirname, '..', '..', '.env') });

const app = require('./app');
const { DatabaseClient } = require('../../../packages/db/client');

const PORT = process.env.PORT || 5000;

async function startServer() {
    try {
        // Initialize database
        const db = new DatabaseClient();
        await db.connect();
        console.log('Database connected');
        
        // Start server
        app.listen(PORT, () => {
            console.log(`AfriIntel API running on port ${PORT}`);
        });
    } catch (error) {
        console.error('Failed to start server:', error);
        process.exit(1);
    }
}

startServer();