🚀 Initialize Musadaq SaaS: Full Backend + AI + React Dashboard + Docker Setup
This commit is contained in:
83
backend/src/app.module.ts
Normal file
83
backend/src/app.module.ts
Normal file
@@ -0,0 +1,83 @@
|
||||
/**
|
||||
* ════════════════════════════════════════════════════════════
|
||||
* مُصادَق (Musadaq) — Root Application Module
|
||||
* ════════════════════════════════════════════════════════════
|
||||
*/
|
||||
|
||||
import { Module } from '@nestjs/common';
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { ThrottlerModule, ThrottlerGuard } from '@nestjs/throttler';
|
||||
import { APP_GUARD } from '@nestjs/core';
|
||||
|
||||
import { BullModule } from '@nestjs/bull';
|
||||
import { envValidationSchema } from './config/env.validation';
|
||||
import { databaseConfig } from './config/database.config';
|
||||
|
||||
import { HealthController } from './modules/health/health.controller';
|
||||
import { AuthModule } from './modules/auth/auth.module';
|
||||
import { TenantsModule } from './modules/tenants/tenant.module';
|
||||
import { UsersModule } from './modules/users/user.module';
|
||||
import { CompaniesModule } from './modules/companies/company.module';
|
||||
import { SubscriptionsModule } from './modules/subscriptions/subscription.module';
|
||||
import { InvoicesModule } from './modules/invoices/invoice.module';
|
||||
import { AuditLogInterceptor } from './common/interceptors/audit-log.interceptor';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
// ── Configuration ─────────────────────────────────────────
|
||||
ConfigModule.forRoot({
|
||||
isGlobal: true,
|
||||
validationSchema: envValidationSchema,
|
||||
cache: true,
|
||||
}),
|
||||
|
||||
// ── Database (TypeORM) ────────────────────────────────────
|
||||
TypeOrmModule.forRootAsync(databaseConfig),
|
||||
|
||||
// ── Queue (Bull/Redis) ────────────────────────────────────
|
||||
BullModule.forRootAsync({
|
||||
imports: [ConfigModule],
|
||||
inject: [ConfigService],
|
||||
useFactory: (configService: ConfigService) => ({
|
||||
redis: {
|
||||
host: configService.getOrThrow<string>('REDIS_HOST'),
|
||||
port: configService.getOrThrow<number>('REDIS_PORT'),
|
||||
},
|
||||
}),
|
||||
}),
|
||||
|
||||
// ── Rate Limiting (Throttler) ─────────────────────────────
|
||||
ThrottlerModule.forRoot([{
|
||||
name: 'short',
|
||||
ttl: 1000, // 1 second
|
||||
limit: 3, // 3 requests
|
||||
}, {
|
||||
name: 'long',
|
||||
ttl: 60000, // 1 minute
|
||||
limit: 100, // 100 requests
|
||||
}]),
|
||||
|
||||
// ── Functional Modules ────────────────────────────────────
|
||||
AuthModule,
|
||||
TenantsModule,
|
||||
UsersModule,
|
||||
CompaniesModule,
|
||||
SubscriptionsModule,
|
||||
InvoicesModule,
|
||||
],
|
||||
providers: [
|
||||
// Global Rate Limiting Guard
|
||||
{
|
||||
provide: APP_GUARD,
|
||||
useClass: ThrottlerGuard,
|
||||
},
|
||||
// Global Audit Log Interceptor
|
||||
{
|
||||
provide: APP_INTERCEPTOR,
|
||||
useClass: AuditLogInterceptor,
|
||||
},
|
||||
],
|
||||
controllers: [HealthController],
|
||||
})
|
||||
export class AppModule {}
|
||||
Reference in New Issue
Block a user