Add project scaffolding and development infrastructure: - Add environment configuration files (.env.development, .env.example) with database, JWT, security, AI integration, logging, and CORS settings - Add .gitignore to exclude build artifacts, logs, IDE files, and environment variables - Add .prettierrc with single quotes and trailing commas configuration - Add multi-stage Dockerfile with development, build, and production stages - Ad
106 lines
3.3 KiB
TypeScript
106 lines
3.3 KiB
TypeScript
import { Module } from '@nestjs/common';
|
|
import { ConfigModule, ConfigService } from '@nestjs/config';
|
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
|
import { ThrottlerModule, ThrottlerGuard } from '@nestjs/throttler';
|
|
import { APP_GUARD, APP_FILTER, APP_INTERCEPTOR } from '@nestjs/core';
|
|
|
|
// Config
|
|
import { appConfig, databaseConfig, jwtConfig, securityConfig, aiConfig } from './config';
|
|
|
|
// Common
|
|
import { JwtAuthGuard } from './common/guards/jwt-auth.guard';
|
|
import { AllExceptionsFilter } from './common/filters/all-exceptions.filter';
|
|
import { TransformInterceptor } from './common/interceptors/transform.interceptor';
|
|
import { LoggingInterceptor } from './common/interceptors/logging.interceptor';
|
|
|
|
// Modules
|
|
import { AuthModule } from './modules/auth/auth.module';
|
|
import { CategoriesModule } from './modules/categories/categories.module';
|
|
import { TransactionsModule } from './modules/transactions/transactions.module';
|
|
import { BudgetsModule } from './modules/budgets/budgets.module';
|
|
import { GoalsModule } from './modules/goals/goals.module';
|
|
import { RecommendationsModule } from './modules/recommendations/recommendations.module';
|
|
import { AnalyticsModule } from './modules/analytics/analytics.module';
|
|
import { AiModule } from './modules/ai/ai.module';
|
|
|
|
import { AppController } from './app.controller';
|
|
import { AppService } from './app.service';
|
|
|
|
@Module({
|
|
imports: [
|
|
// Configuration
|
|
ConfigModule.forRoot({
|
|
isGlobal: true,
|
|
load: [appConfig, databaseConfig, jwtConfig, securityConfig, aiConfig],
|
|
envFilePath: ['.env.development', '.env'],
|
|
}),
|
|
|
|
// Database
|
|
TypeOrmModule.forRootAsync({
|
|
imports: [ConfigModule],
|
|
useFactory: (configService: ConfigService) => ({
|
|
type: 'postgres',
|
|
host: configService.get('database.host'),
|
|
port: configService.get('database.port'),
|
|
username: configService.get('database.username'),
|
|
password: configService.get('database.password'),
|
|
database: configService.get('database.database'),
|
|
entities: [__dirname + '/**/*.entity{.ts,.js}'],
|
|
synchronize: configService.get('database.synchronize'),
|
|
logging: configService.get('database.logging'),
|
|
}),
|
|
inject: [ConfigService],
|
|
}),
|
|
|
|
// Rate Limiting
|
|
ThrottlerModule.forRootAsync({
|
|
imports: [ConfigModule],
|
|
useFactory: (configService: ConfigService) => ({
|
|
throttlers: [{
|
|
ttl: (configService.get<number>('security.rateLimitWindow') || 15) * 1000,
|
|
limit: configService.get<number>('security.rateLimitMax') || 100,
|
|
}],
|
|
}),
|
|
inject: [ConfigService],
|
|
}),
|
|
|
|
// Feature Modules
|
|
AuthModule,
|
|
CategoriesModule,
|
|
TransactionsModule,
|
|
BudgetsModule,
|
|
GoalsModule,
|
|
RecommendationsModule,
|
|
AnalyticsModule,
|
|
AiModule,
|
|
],
|
|
controllers: [AppController],
|
|
providers: [
|
|
AppService,
|
|
// Global Guards
|
|
{
|
|
provide: APP_GUARD,
|
|
useClass: ThrottlerGuard,
|
|
},
|
|
{
|
|
provide: APP_GUARD,
|
|
useClass: JwtAuthGuard,
|
|
},
|
|
// Global Filters
|
|
{
|
|
provide: APP_FILTER,
|
|
useClass: AllExceptionsFilter,
|
|
},
|
|
// Global Interceptors
|
|
{
|
|
provide: APP_INTERCEPTOR,
|
|
useClass: LoggingInterceptor,
|
|
},
|
|
{
|
|
provide: APP_INTERCEPTOR,
|
|
useClass: TransformInterceptor,
|
|
},
|
|
],
|
|
})
|
|
export class AppModule {}
|