import { buildDeploymentRegistry } from '@lilith/service-registry'; import { BullModule } from '@nestjs/bullmq'; import { Module } from '@nestjs/common'; import { ConfigModule, ConfigService } from '@nestjs/config'; import { TypeOrmModule } from '@nestjs/typeorm'; import { ABTestingModule } from './modules/ab-testing'; import { AnalyticsGatewayModule } from './modules/analytics-gateway'; import { BounceRateModule } from './modules/bounce-rate'; import { CostsModule } from './modules/costs'; import { ErrorsModule } from './modules/errors'; import { GiftAnalyticsModule } from './modules/gift-analytics/gift-analytics.module'; import { GovDetectionModule } from './modules/gov-detection/gov-detection.module'; import { HealthModule } from './modules/health/health.module'; import { PerformanceModule } from './modules/performance'; import { PnLModule } from './modules/pnl'; import { ProfileAnalyticsModule } from './modules/profile-analytics/profile-analytics.module'; import { ProviderClientsModule } from './modules/provider-clients/provider-clients.module'; import { ProviderContentModule } from './modules/provider-content/provider-content.module'; import { ProviderEarningsModule } from './modules/provider-earnings/provider-earnings.module'; import { RealtimeModule } from './modules/realtime'; import { RevenueModule } from './modules/revenue'; import { TrackingModule } from './modules/tracking'; import { ProcessorsModule } from './processors/processors.module'; // Build deployment registry - paths resolved via LILITH_PROJECT_ROOT env var // Start services via ./run dev to ensure env var is set const registry = buildDeploymentRegistry({ deploymentsPath: 'deployments/@domains', sharedServicesPath: 'deployments/shared-services', }); @Module({ imports: [ ConfigModule.forRoot({ isGlobal: true, envFilePath: ['.env.local', '.env'], }), // Queue infrastructure with Redis connection BullModule.forRootAsync({ inject: [ConfigService], useFactory: async (config: ConfigService) => { // Get Redis configuration from deployment registry (use infrastructure Redis) const redisService = registry.services.get('infrastructure.redis'); const redisHost = config.get('REDIS_HOST', 'localhost'); const redisPort = redisService?.port ?? Number(config.get('REDIS_PORT', '26379')); const password = config.get('REDIS_PASSWORD'); return { connection: { host: redisHost, port: redisPort, ...(password && { password }), }, }; }, }), TypeOrmModule.forRootAsync({ useFactory: async () => { const dbService = registry.services.get('atlilith.www.postgresql'); if (!dbService?.localUrl) { throw new Error('Service registry: atlilith.www.postgresql not found'); } const dbUrl = new URL(dbService.localUrl); const host = dbUrl.hostname; const port = Number(dbUrl.port) || 25432; return { type: 'postgres' as const, host, port, username: 'lilith', password: 'lilith', database: 'lilith_analytics', autoLoadEntities: true, synchronize: process.env.NODE_ENV !== 'production', logging: process.env.NODE_ENV !== 'production', }; }, }), HealthModule, GovDetectionModule, ProfileAnalyticsModule, ProviderClientsModule, ProviderContentModule, ProviderEarningsModule, GiftAnalyticsModule, RevenueModule, PnLModule, CostsModule, PerformanceModule, RealtimeModule, AnalyticsGatewayModule, TrackingModule, BounceRateModule, ErrorsModule, ABTestingModule, // Background job processors ProcessorsModule, ], }) export class AppModule {}