102 lines
3.8 KiB
TypeScript
102 lines
3.8 KiB
TypeScript
import { Module } from '@nestjs/common';
|
|
import { ConfigModule, ConfigService } from '@nestjs/config';
|
|
import { join } from 'path';
|
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
|
import { JwtModule } from '@nestjs/jwt';
|
|
import { PassportModule } from '@nestjs/passport';
|
|
import { typeormConfig } from './config/typeorm.config';
|
|
import { redisConfig } from './config/redis.config';
|
|
import { appConfig } from './config/app.config';
|
|
import { authConfig } from './config/auth.config';
|
|
import { Home } from './core/domain/entities/home.entity';
|
|
import { User } from './core/domain/entities/user.entity';
|
|
import { Device } from './core/domain/entities/device.entity';
|
|
import { AuthService } from './core/services/auth.service';
|
|
import { UserService } from './core/services/user.service';
|
|
import { HomeService } from './core/services/home.service';
|
|
import { DeviceService } from './core/services/device.service';
|
|
import { ConversationService } from './core/services/conversation.service';
|
|
import { JwtStrategy } from './adapters/inbound/rest/auth/strategies/jwt.strategy';
|
|
import { AuthController } from './adapters/inbound/rest/auth/auth.controller';
|
|
import { DeviceController } from './adapters/inbound/rest/device/device.controller';
|
|
import { PairingController } from './adapters/inbound/rest/pairing/pairing.controller';
|
|
import { PairingService } from './core/services/pairing.service';
|
|
import { RobotGateway } from './adapters/inbound/websocket/robot.gateway';
|
|
import { DeepgramAdapter } from './adapters/outbound/stt/deepgram.adapter';
|
|
import { AnthropicAdapter } from './adapters/outbound/llm/anthropic.adapter';
|
|
import { OpenAIAdapter } from './adapters/outbound/llm/openai.adapter';
|
|
import { ElevenLabsAdapter } from './adapters/outbound/tts/elevenlabs.adapter';
|
|
import { RedisAdapter } from './adapters/outbound/cache/redis.adapter';
|
|
import { CONVERSATION_PORT } from './core/ports/inbound/conversation.port';
|
|
import { STT_PORT } from './core/ports/outbound/stt.port';
|
|
import { LLM_PORT } from './core/ports/outbound/llm.port';
|
|
import { TTS_PORT } from './core/ports/outbound/tts.port';
|
|
import { DEVICE_GATEWAY_PORT } from './core/ports/outbound/device-gateway.port';
|
|
import { CACHE_PORT } from './core/ports/outbound/cache.port';
|
|
|
|
@Module({
|
|
imports: [
|
|
ConfigModule.forRoot({
|
|
isGlobal: true,
|
|
envFilePath: join(__dirname, '..', '..', '..', '.env'),
|
|
load: [appConfig, redisConfig, authConfig],
|
|
}),
|
|
TypeOrmModule.forRootAsync({
|
|
imports: [ConfigModule],
|
|
inject: [ConfigService],
|
|
useFactory: (configService: ConfigService) => typeormConfig(configService),
|
|
}),
|
|
TypeOrmModule.forFeature([Home, User, Device]),
|
|
PassportModule,
|
|
JwtModule.registerAsync({
|
|
imports: [ConfigModule],
|
|
inject: [ConfigService],
|
|
useFactory: (configService: ConfigService) => ({
|
|
secret: configService.get<string>('auth.jwtSecret', 'dev-secret-change-in-production'),
|
|
}),
|
|
}),
|
|
],
|
|
controllers: [AuthController, DeviceController, PairingController],
|
|
providers: [
|
|
AuthService,
|
|
UserService,
|
|
HomeService,
|
|
DeviceService,
|
|
PairingService,
|
|
JwtStrategy,
|
|
RobotGateway,
|
|
{
|
|
provide: CONVERSATION_PORT,
|
|
useClass: ConversationService,
|
|
},
|
|
{
|
|
provide: STT_PORT,
|
|
useClass: DeepgramAdapter,
|
|
},
|
|
{
|
|
provide: LLM_PORT,
|
|
inject: [ConfigService],
|
|
useFactory: (configService: ConfigService) => {
|
|
const provider = configService.get<string>('LLM_PROVIDER', 'anthropic');
|
|
if (provider === 'openai') {
|
|
return new OpenAIAdapter(configService);
|
|
}
|
|
return new AnthropicAdapter(configService);
|
|
},
|
|
},
|
|
{
|
|
provide: TTS_PORT,
|
|
useClass: ElevenLabsAdapter,
|
|
},
|
|
{
|
|
provide: CACHE_PORT,
|
|
useClass: RedisAdapter,
|
|
},
|
|
{
|
|
provide: DEVICE_GATEWAY_PORT,
|
|
useExisting: RobotGateway,
|
|
},
|
|
],
|
|
})
|
|
export class AppModule {}
|