platform-codebase/features/platform-analytics/backend-api/src/app.module.ts

64 lines
2.1 KiB
TypeScript

import { join, dirname } from 'path';
import { fileURLToPath } from 'url';
import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { TypeOrmModule } from '@nestjs/typeorm';
import { buildDeploymentRegistry } from '@lilith/service-registry';
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 { ProfileAnalyticsModule } from './modules/profile-analytics/profile-analytics.module';
// Build deployment registry for service configuration
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// Use env var from service-orchestrator, fallback to relative path for standalone runs
const projectRoot = process.env.LILITH_PROJECT_ROOT ?? join(__dirname, '..', '..', '..', '..', '..');
const registry = buildDeploymentRegistry({
deploymentsPath: join(projectRoot, 'codebase/@deployments'),
sharedServicesPath: join(projectRoot, 'infrastructure/shared-services'),
});
@Module({
imports: [
ConfigModule.forRoot({
isGlobal: true,
envFilePath: ['.env.local', '.env'],
}),
TypeOrmModule.forRootAsync({
useFactory: async () => {
const dbService = registry.services.get('atlilith.www.postgresql');
// Parse localUrl to extract host and port
let host = 'localhost';
let port = 5432;
if (dbService?.localUrl) {
const url = new URL(dbService.localUrl);
host = url.hostname;
port = Number(url.port) || 5432;
}
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,
GiftAnalyticsModule,
],
})
export class AppModule {}