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,3 @@
export { NatsService } from './nats.service';
export { NatsBridgeService } from './nats-bridge.service';
export { SteamService } from './steam.service';

View File

@@ -0,0 +1,44 @@
import { Injectable, OnModuleInit, Logger } from '@nestjs/common';
import { NatsService } from './nats.service';
@Injectable()
export class NatsBridgeService implements OnModuleInit {
private readonly logger = new Logger(NatsBridgeService.name);
private listeners: Map<string, Set<(event: string, data: unknown) => void>> = new Map();
constructor(private nats: NatsService) {}
onModuleInit() {
this.nats.subscribe('corrosion.*.companion.heartbeat', (data, subject) => {
const licenseId = subject.split('.')[1];
this.emit(licenseId, 'heartbeat', data);
});
this.nats.subscribe('corrosion.*.console.output', (data, subject) => {
const licenseId = subject.split('.')[1];
this.emit(licenseId, 'console_output', data);
});
this.logger.log('NATS bridge subscriptions initialized');
}
addListener(licenseId: string, callback: (event: string, data: unknown) => void): void {
if (!this.listeners.has(licenseId)) {
this.listeners.set(licenseId, new Set());
}
this.listeners.get(licenseId)!.add(callback);
}
removeListener(licenseId: string, callback: (event: string, data: unknown) => void): void {
this.listeners.get(licenseId)?.delete(callback);
}
private emit(licenseId: string, event: string, data: unknown): void {
const callbacks = this.listeners.get(licenseId);
if (callbacks) {
for (const cb of callbacks) {
cb(event, data);
}
}
}
}

View File

@@ -0,0 +1,73 @@
import { Injectable, OnModuleInit, OnModuleDestroy, Logger } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { connect, NatsConnection, StringCodec, Subscription } from 'nats';
@Injectable()
export class NatsService implements OnModuleInit, OnModuleDestroy {
private readonly logger = new Logger(NatsService.name);
private nc: NatsConnection | null = null;
private sc = StringCodec();
constructor(private config: ConfigService) {}
async onModuleInit() {
try {
const url = this.config.get<string>('nats.url') || 'nats://localhost:4222';
this.nc = await connect({ servers: url });
this.logger.log(`Connected to NATS at ${url}`);
} catch (err) {
this.logger.warn(`NATS connection failed — running in offline mode: ${(err as Error).message}`);
}
}
async onModuleDestroy() {
if (this.nc) {
await this.nc.drain();
}
}
async publish(subject: string, data: Record<string, unknown>): Promise<void> {
if (!this.nc) {
this.logger.debug(`[OFFLINE] Would publish to ${subject}: ${JSON.stringify(data)}`);
return;
}
this.nc.publish(subject, this.sc.encode(JSON.stringify(data)));
}
async request(subject: string, data: Record<string, unknown>, timeout = 5000): Promise<unknown> {
if (!this.nc) {
this.logger.debug(`[OFFLINE] Would request ${subject}: ${JSON.stringify(data)}`);
return null;
}
const msg = await this.nc.request(subject, this.sc.encode(JSON.stringify(data)), { timeout });
return JSON.parse(this.sc.decode(msg.data));
}
subscribe(subject: string, callback: (data: unknown, subject: string) => void): Subscription | null {
if (!this.nc) {
this.logger.debug(`[OFFLINE] Would subscribe to ${subject}`);
return null;
}
const sub = this.nc.subscribe(subject);
(async () => {
for await (const msg of sub) {
try {
const parsed = JSON.parse(this.sc.decode(msg.data));
callback(parsed, msg.subject);
} catch {
callback(this.sc.decode(msg.data), msg.subject);
}
}
})();
return sub;
}
/** Publish a command to a specific license's server */
async sendServerCommand(licenseId: string, action: string, payload: Record<string, unknown> = {}): Promise<void> {
await this.publish(`corrosion.${licenseId}.cmd.server`, {
action,
...payload,
timestamp: new Date().toISOString(),
});
}
}

View File

@@ -0,0 +1,24 @@
import { Injectable, Logger } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
@Injectable()
export class SteamService {
private readonly logger = new Logger(SteamService.name);
private apiKey: string;
constructor(private config: ConfigService) {
this.apiKey = this.config.get<string>('steam.apiKey') || '';
}
async checkForceWipe(): Promise<{ isForceWipe: boolean; expectedDate: string | null }> {
// Stub — would check Steam API for Rust staging branch updates
return { isForceWipe: false, expectedDate: null };
}
async getPlayerSummary(steamId: string): Promise<{ personaname: string; avatarfull: string } | null> {
if (!this.apiKey) return null;
// Stub — would call ISteamUser/GetPlayerSummaries/v2
this.logger.debug(`Would fetch Steam profile for ${steamId}`);
return null;
}
}