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

74 lines
2.3 KiB
TypeScript
Executable file

// Root application module
import { join, dirname } from 'path';
import { fileURLToPath } from 'url';
import { buildDeploymentRegistry } from '@lilith/service-registry';
import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { ThrottlerModule } from '@nestjs/throttler';
import { TypeOrmModule } from '@nestjs/typeorm';
import { AuthModule } from './features/auth/auth.module';
import { ContentModule } from './features/content/content.module';
import { ThemesModule } from './features/themes/themes.module';
import { WebsitesModule } from './features/websites/websites.module';
import { HealthModule } from './health/health.module';
// Build deployment registry for service configuration
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const projectRoot = join(__dirname, '..', '..', '..', '..', '..');
const registry = buildDeploymentRegistry({
deploymentsPath: join(projectRoot, 'codebase/@deployments'),
sharedServicesPath: join(projectRoot, 'infrastructure/shared-services'),
});
@Module({
imports: [
// Configuration
ConfigModule.forRoot({
isGlobal: true,
envFilePath: ['.env.local', '.env'],
}),
// Rate limiting
ThrottlerModule.forRoot([
{
ttl: 60000, // 1 minute
limit: 100, // 100 requests per minute
},
]),
// Database - uses webmap shared service's PostgreSQL
TypeOrmModule.forRootAsync({
inject: [ConfigService],
useFactory: async (config: ConfigService) => {
// Get database configuration from deployment registry
const dbService = registry.services.get('webmap.postgresql');
return {
type: 'postgres',
host: dbService?.host || 'localhost',
port: dbService?.port || 5432,
username: config.get('DATABASE_POSTGRES_USER') || 'lilith',
password: config.get('DATABASE_POSTGRES_PASSWORD') || 'lilith',
database: config.get('DATABASE_POSTGRES_NAME') || 'lilith_webmap',
autoLoadEntities: true,
synchronize: false,
logging: config.get('NODE_ENV') !== 'production',
};
},
}),
// Health checks
HealthModule,
// Feature modules
AuthModule,
WebsitesModule,
ContentModule,
ThemesModule,
],
})
export class AppModule {}