feat: Complete NestJS backend scaffold — 22 modules, 39 entities, WebSocket gateway
All checks were successful
Test Asgard Runner / test (push) Successful in 3s

Full backend rewrite from Rust/Axum to NestJS/TypeScript.
- 22 feature modules (auth, servers, wipes, maps, plugins, players, console,
  chat, team, notifications, settings, schedules, analytics, alerts, status,
  store, webstore, admin, setup, migration, users, licenses)
- 39 TypeORM entities matching PostgreSQL schema (12 migrations)
- Common infrastructure: JWT/RBAC guards, decorators, exception filter
- NATS service with pub/sub/request-reply
- Socket.IO WebSocket gateway with NATS bridge
- Docker: NestJS Dockerfile + updated docker-compose.yml
- Zero compile errors (npx tsc --noEmit clean)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Vantz Stockwell
2026-02-15 21:29:25 -05:00
parent 0f8d0dd14f
commit d20493d533
141 changed files with 13552 additions and 4 deletions

View File

@@ -0,0 +1,39 @@
import { IsString, IsOptional, IsInt, IsIn, ValidateIf } from 'class-validator';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
export class SetupServerDto {
@ApiProperty({ description: 'Connection type', enum: ['amp', 'pterodactyl', 'bare_metal'] })
@IsString()
@IsIn(['amp', 'pterodactyl', 'bare_metal'])
connection_type: 'amp' | 'pterodactyl' | 'bare_metal';
@ApiPropertyOptional({ description: 'Server IP address' })
@IsOptional()
@IsString()
server_ip?: string;
@ApiPropertyOptional({ description: 'Server RCON port' })
@IsOptional()
@IsInt()
server_port?: number;
@ApiPropertyOptional({ description: 'Game port (players connect to)' })
@IsOptional()
@IsInt()
game_port?: number;
@ApiPropertyOptional({ description: 'Panel API endpoint (for AMP/Pterodactyl)' })
@ValidateIf(o => o.connection_type === 'amp' || o.connection_type === 'pterodactyl')
@IsString()
panel_api_endpoint?: string;
@ApiPropertyOptional({ description: 'Panel API key (for AMP/Pterodactyl)' })
@ValidateIf(o => o.connection_type === 'amp' || o.connection_type === 'pterodactyl')
@IsString()
panel_api_key?: string;
@ApiPropertyOptional({ description: 'Panel server identifier (for AMP/Pterodactyl)' })
@ValidateIf(o => o.connection_type === 'amp' || o.connection_type === 'pterodactyl')
@IsString()
panel_server_identifier?: string;
}

View File

@@ -0,0 +1,27 @@
import { Controller, Post, Body } from '@nestjs/common';
import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
import { SetupService } from './setup.service';
import { SetupServerDto } from './dto/setup-server.dto';
import { CurrentTenant } from '../../common/decorators/current-tenant.decorator';
@ApiTags('setup')
@ApiBearerAuth()
@Controller('setup')
export class SetupController {
constructor(private readonly setupService: SetupService) {}
@Post('server')
@ApiOperation({ summary: 'Configure server connection during setup' })
async setupServer(
@CurrentTenant() licenseId: string,
@Body() dto: SetupServerDto,
) {
return this.setupService.setupServer(licenseId, dto);
}
@Post('complete')
@ApiOperation({ summary: 'Mark setup as complete' })
async completeSetup(@CurrentTenant() licenseId: string) {
return this.setupService.completeSetup(licenseId);
}
}

View File

@@ -0,0 +1,25 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { SetupController } from './setup.controller';
import { SetupService } from './setup.service';
import { ServerConnection } from '../../entities/server-connection.entity';
import { ServerConfig } from '../../entities/server-config.entity';
import { NotificationsConfig } from '../../entities/notifications-config.entity';
import { PublicSiteConfig } from '../../entities/public-site-config.entity';
import { AlertConfig } from '../../entities/alert-config.entity';
@Module({
imports: [
TypeOrmModule.forFeature([
ServerConnection,
ServerConfig,
NotificationsConfig,
PublicSiteConfig,
AlertConfig,
]),
],
controllers: [SetupController],
providers: [SetupService],
exports: [SetupService],
})
export class SetupModule {}

View File

@@ -0,0 +1,135 @@
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { ServerConnection } from '../../entities/server-connection.entity';
import { ServerConfig } from '../../entities/server-config.entity';
import { NotificationsConfig } from '../../entities/notifications-config.entity';
import { PublicSiteConfig } from '../../entities/public-site-config.entity';
import { AlertConfig } from '../../entities/alert-config.entity';
import { SetupServerDto } from './dto/setup-server.dto';
import * as crypto from 'crypto';
@Injectable()
export class SetupService {
constructor(
@InjectRepository(ServerConnection)
private readonly connectionRepo: Repository<ServerConnection>,
@InjectRepository(ServerConfig)
private readonly configRepo: Repository<ServerConfig>,
@InjectRepository(NotificationsConfig)
private readonly notifConfigRepo: Repository<NotificationsConfig>,
@InjectRepository(PublicSiteConfig)
private readonly publicSiteRepo: Repository<PublicSiteConfig>,
@InjectRepository(AlertConfig)
private readonly alertConfigRepo: Repository<AlertConfig>,
) {}
async setupServer(licenseId: string, dto: SetupServerDto): Promise<ServerConnection> {
// Check if connection already exists
let connection = await this.connectionRepo.findOne({
where: { license_id: licenseId },
});
if (!connection) {
connection = this.connectionRepo.create({
license_id: licenseId,
});
}
// Update connection details
connection.connection_type = dto.connection_type;
connection.server_ip = dto.server_ip || null;
connection.server_port = dto.server_port || null;
connection.game_port = dto.game_port || null;
connection.panel_api_endpoint = dto.panel_api_endpoint || null;
connection.panel_server_identifier = dto.panel_server_identifier || null;
// For bare metal, generate companion agent token
if (dto.connection_type === 'bare_metal') {
connection.companion_agent_token = crypto.randomBytes(32).toString('hex');
}
// Store encrypted API key if provided
if (dto.panel_api_key) {
// Stub - would encrypt in production
connection.panel_api_key_encrypted = dto.panel_api_key;
}
connection.updated_at = new Date();
const savedConnection = await this.connectionRepo.save(connection);
// Create default configurations if they don't exist
await this.createDefaultConfigs(licenseId);
return savedConnection;
}
async completeSetup(licenseId: string): Promise<{ message: string }> {
const connection = await this.connectionRepo.findOne({
where: { license_id: licenseId },
});
if (connection) {
// For bare metal, mark as connected immediately (waiting for agent)
if (connection.connection_type === 'bare_metal') {
connection.connection_status = 'connected';
connection.updated_at = new Date();
await this.connectionRepo.save(connection);
}
}
return { message: 'Setup complete' };
}
private async createDefaultConfigs(licenseId: string): Promise<void> {
// Create server config if not exists
const existingConfig = await this.configRepo.findOne({
where: { license_id: licenseId },
});
if (!existingConfig) {
const config = this.configRepo.create({
license_id: licenseId,
server_name: 'My Rust Server',
});
await this.configRepo.save(config);
}
// Create notifications config if not exists
const existingNotif = await this.notifConfigRepo.findOne({
where: { license_id: licenseId },
});
if (!existingNotif) {
const notifConfig = this.notifConfigRepo.create({
license_id: licenseId,
});
await this.notifConfigRepo.save(notifConfig);
}
// Create public site config if not exists
const existingPublic = await this.publicSiteRepo.findOne({
where: { license_id: licenseId },
});
if (!existingPublic) {
const publicConfig = this.publicSiteRepo.create({
license_id: licenseId,
});
await this.publicSiteRepo.save(publicConfig);
}
// Create alert config if not exists
const existingAlert = await this.alertConfigRepo.findOne({
where: { license_id: licenseId },
});
if (!existingAlert) {
const alertConfig = this.alertConfigRepo.create({
license_id: licenseId,
});
await this.alertConfigRepo.save(alertConfig);
}
}
}