platform-codebase/features/analytics/backend/src/app.module.ts
Quinn Ftw 09bc4a5eec Enhance analytics tracking system
- Add interaction event tracking with view duration
- Implement VPN detection service
- Add comprehensive test factories
- Update frontend API integration

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-30 01:35:08 -08:00

168 lines
4.2 KiB
TypeScript

import { Module } from '@nestjs/common'
import { ConfigModule, ConfigService } from '@nestjs/config'
import { TypeOrmModule } from '@nestjs/typeorm'
import { ScheduleModule } from '@nestjs/schedule'
import { BullModule } from '@nestjs/bullmq'
import { ThrottlerModule } from '@nestjs/throttler'
import { CacheModule } from '@nestjs/cache-manager'
import { HealthController } from './health/health.controller'
import { AnalyticsController, AdminAnalyticsController } from './controllers'
// Entities
import {
ContentView,
RevenueMetric,
EngagementMetric,
DashboardSnapshot,
ListingPerformance,
ListingVariant,
RankingSnapshot,
PlatformCost,
PlatformError,
ABTest,
ConversionEvent,
InteractionEvent,
SessionFingerprint,
} from './entities'
// Services
import {
RedisService,
QueueService,
AnalyticsService,
ReportsService,
ListingPerformanceService,
RankingTransparencyService,
ReviewAnalyticsService,
ClientAnalyticsService,
AdminAnalyticsService,
SubscriberAnalyticsService,
ContentMetadataService,
ANALYTICS_QUEUE,
} from './services'
// Processors
import { AnalyticsProcessor } from './processors'
// Auth
import { JwtAuthGuard, AdminGuard } from './auth'
@Module({
imports: [
// Load environment variables from .env files
ConfigModule.forRoot({
isGlobal: true,
envFilePath: ['.env.local', '.env'],
}),
// TypeORM database connection
TypeOrmModule.forRootAsync({
inject: [ConfigService],
useFactory: (config: ConfigService) => ({
type: 'postgres',
host: config.get('DATABASE_HOST', 'localhost'),
port: config.get<number>('DATABASE_PORT', 5432),
username: config.get('DATABASE_USER', 'postgres'),
password: config.get('DATABASE_PASSWORD', 'postgres'),
database: config.get('DATABASE_NAME', 'lilith_analytics'),
ssl: config.get('DATABASE_SSL') === 'true' ? { rejectUnauthorized: false } : false,
entities: [
ContentView,
RevenueMetric,
EngagementMetric,
DashboardSnapshot,
ListingPerformance,
ListingVariant,
RankingSnapshot,
PlatformCost,
PlatformError,
ABTest,
ConversionEvent,
InteractionEvent,
SessionFingerprint,
],
synchronize: config.get('NODE_ENV') !== 'production',
logging: config.get('NODE_ENV') === 'development',
}),
}),
// TypeORM entity registration for repositories
TypeOrmModule.forFeature([
ContentView,
RevenueMetric,
EngagementMetric,
DashboardSnapshot,
ListingPerformance,
ListingVariant,
RankingSnapshot,
PlatformCost,
PlatformError,
ABTest,
ConversionEvent,
InteractionEvent,
SessionFingerprint,
]),
// BullMQ for job processing
BullModule.forRootAsync({
inject: [ConfigService],
useFactory: (config: ConfigService) => ({
connection: {
host: config.get('REDIS_HOST', 'localhost'),
port: config.get<number>('REDIS_PORT', 6379),
password: config.get('REDIS_PASSWORD') || undefined,
db: config.get<number>('REDIS_DB', 1),
},
}),
}),
// Register analytics queue
BullModule.registerQueue({
name: ANALYTICS_QUEUE,
}),
// Scheduled jobs
ScheduleModule.forRoot(),
// Rate limiting
ThrottlerModule.forRoot([
{
ttl: 60000,
limit: 100,
},
]),
// Caching
CacheModule.registerAsync({
inject: [ConfigService],
useFactory: (config: ConfigService) => ({
ttl: config.get<number>('CACHE_TTL', 300000),
max: config.get<number>('CACHE_MAX', 100),
}),
}),
],
controllers: [HealthController, AnalyticsController, AdminAnalyticsController],
providers: [
// Auth guards
JwtAuthGuard,
AdminGuard,
// Services
RedisService,
QueueService,
AnalyticsService,
ReportsService,
ListingPerformanceService,
RankingTransparencyService,
ReviewAnalyticsService,
ClientAnalyticsService,
AdminAnalyticsService,
SubscriberAnalyticsService,
ContentMetadataService,
// Processors
AnalyticsProcessor,
],
})
export class AppModule {}