/** * @ai-summary Application entry point * @ai-context Starts the Fastify server with all feature capsules */ import { buildApp } from './app'; import { appConfig } from './core/config/config-loader'; import { logger } from './core/logging/logger'; const PORT = appConfig.config.server.port; async function start() { try { const app = await buildApp(); await app.listen({ port: PORT, host: '0.0.0.0' }); logger.info(`MotoVaultPro backend running`, { port: PORT, environment: appConfig.config.server.environment, nodeVersion: process.version, framework: 'Fastify' }); } catch (error) { logger.error('Failed to start server', { error }); process.exit(1); } } start(); // Graceful shutdown process.on('SIGTERM', () => { logger.info('SIGTERM received, shutting down gracefully'); process.exit(0); }); process.on('SIGINT', () => { logger.info('SIGINT received, shutting down gracefully'); process.exit(0); }); // Handle uncaught exceptions process.on('uncaughtException', (error) => { logger.error('Uncaught Exception', { error: error.message, stack: error.stack }); process.exit(1); }); process.on('unhandledRejection', (reason, promise) => { logger.error('Unhandled Rejection', { reason, promise }); process.exit(1); });