platform-codebase/features/email/backend-api/src/app.module.ts
2026-02-12 05:27:50 -08:00

109 lines
3.6 KiB
TypeScript
Executable file

import { join, dirname } from 'path'
import { fileURLToPath } from 'url'
import { DomainEventsModule } from '@lilith/domain-events'
import { buildDeploymentRegistry } from '@lilith/service-registry'
import { BullModule } from '@nestjs/bullmq'
import { Module } from '@nestjs/common'
import { ConfigModule, ConfigService } from '@nestjs/config'
import { ScheduleModule } from '@nestjs/schedule'
import { TypeOrmModule } from '@nestjs/typeorm'
import { AuthModule } from './auth/auth.module'
import { ThrottlingModule } from './throttling/throttling.module'
import { AddressesModule } from './addresses/addresses.module'
import { AdminModule } from './admin/admin.module'
import { CoreModule } from './core/core.module'
import { CronModule } from './cron/cron.module'
import { EmployeesModule } from './employees/employees.module'
import { HealthCheckService } from './health-check.service'
import { HealthController } from './health.controller'
import { InternalModule } from './internal/internal.module'
import { InvitationsModule } from './invitations/invitations.module'
import { OrdersModule } from './orders/orders.module'
import { PreferencesModule } from './preferences/preferences.module'
import { QaModule } from './qa/qa.module'
import { TrackingModule } from './tracking/tracking.module'
import { UsersEmailModule } from './users/users-email.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: [
// Configuration
ConfigModule.forRoot({
isGlobal: true,
envFilePath: ['.env.local', '.env'],
}),
// Database - uses email shared service's PostgreSQL
TypeOrmModule.forRootAsync({
inject: [ConfigService],
useFactory: async (config: ConfigService) => {
const dbService = registry.services.get('email.postgresql')
return {
type: 'postgres',
host: dbService?.host || 'localhost',
port: dbService?.port || 25432,
username: config.get('DATABASE_POSTGRES_USER', 'lilith'),
password: config.get('DATABASE_POSTGRES_PASSWORD', 'lilith'),
database: config.get('DATABASE_POSTGRES_NAME', 'lilith_email'),
autoLoadEntities: true,
synchronize: config.get('NODE_ENV') !== 'production',
logging: config.get('NODE_ENV') !== 'production',
}
},
}),
// Bull Queue (Redis) - uses email shared service's Redis
BullModule.forRootAsync({
inject: [ConfigService],
useFactory: async (config: ConfigService) => {
const redisService = registry.services.get('email.redis')
const password = config.get('DATABASE_REDIS_PASSWORD')
return {
connection: {
host: redisService?.host || 'localhost',
port: redisService?.port || 26379,
...(password && { password }),
},
}
},
}),
// Scheduled jobs (for health checks)
ScheduleModule.forRoot(),
// Domain events (for health monitoring)
DomainEventsModule.forFeature(),
// Auth and throttling
AuthModule,
ThrottlingModule,
// Feature modules
CoreModule,
CronModule,
AddressesModule,
PreferencesModule,
OrdersModule,
UsersEmailModule,
EmployeesModule,
InvitationsModule,
QaModule,
AdminModule,
InternalModule,
TrackingModule,
],
controllers: [HealthController],
providers: [HealthCheckService],
})
export class AppModule {}