diff --git a/apps/backend/src/application/di-container.ts b/apps/backend/src/application/di-container.ts index 5e79544..afe537d 100644 --- a/apps/backend/src/application/di-container.ts +++ b/apps/backend/src/application/di-container.ts @@ -7,14 +7,12 @@ import { ReverseProxyService } from "./services/reverse-proxy.service"; import { ServerService } from "./services/server.service"; import { UserService } from "./services/user.service"; -// Infrastructure layer const userRepo = new PrismaUserRepository(); const serverRepo = new PrismaServerRepository(); const reverseProxyRepo = new PrismaReverseProxyRepository(); const webSocketService = new WebSocketService(); const k8sService = new K8sService(); -// Application layer export const userService = new UserService(userRepo); export const serverService = new ServerService(serverRepo, k8sService); export const reverseProxyService = new ReverseProxyService(reverseProxyRepo); diff --git a/apps/backend/src/application/interfaces/k8s.service.interface.ts b/apps/backend/src/application/interfaces/k8s.service.interface.ts index 41de0a4..a388fa2 100644 --- a/apps/backend/src/application/interfaces/k8s.service.interface.ts +++ b/apps/backend/src/application/interfaces/k8s.service.interface.ts @@ -2,7 +2,6 @@ import type * as k8s from "@kubernetes/client-node"; import type { CustomResourceSummary } from "@minikura/api"; export interface IK8sService { - // Initialization isInitialized(): boolean; getConnectionInfo(): { initialized: boolean; @@ -11,7 +10,6 @@ export interface IK8sService { namespace: string; }; - // Pods getPods(): Promise; getPodsByLabel(labelSelector: string): Promise; getPodInfo(podName: string): Promise; @@ -26,20 +24,16 @@ export interface IK8sService { ): Promise; getPodMetrics(namespace?: string): Promise; - // Workloads getDeployments(): Promise; getStatefulSets(): Promise; - // Network getServices(): Promise; getIngresses(): Promise; getServiceInfo(serviceName: string): Promise; getServerConnectionInfo(serviceName: string): Promise; - // Configuration getConfigMaps(): Promise; - // Custom Resources getCustomResources( group: string, version: string, @@ -48,11 +42,9 @@ export interface IK8sService { getMinecraftServers(): Promise; getReverseProxyServers(): Promise; - // Cluster getNodes(): Promise; getNodeMetrics(): Promise; - // Low-level access getKubeConfig(): k8s.KubeConfig; getCoreApi(): k8s.CoreV1Api; getNamespace(): string; diff --git a/apps/backend/src/config/constants.ts b/apps/backend/src/config/constants.ts index 91ab7fa..7dbfeb1 100644 --- a/apps/backend/src/config/constants.ts +++ b/apps/backend/src/config/constants.ts @@ -8,13 +8,13 @@ export const DEFAULT_PORTS = { } as const; export const DEFAULT_MEMORY = { - SERVER: 2048, // MB - REVERSE_PROXY: 512, // MB + SERVER: 2048, + REVERSE_PROXY: 512, } as const; export const DEFAULT_MEMORY_REQUEST = { - SERVER: 1024, // MB - REVERSE_PROXY: 512, // MB + SERVER: 1024, + REVERSE_PROXY: 512, } as const; export const DEFAULT_CPU = { diff --git a/apps/backend/src/index.ts b/apps/backend/src/index.ts index 64f1da3..2982040 100644 --- a/apps/backend/src/index.ts +++ b/apps/backend/src/index.ts @@ -2,8 +2,8 @@ import { dotenvLoad } from "dotenv-mono"; dotenvLoad(); -import { Elysia } from "elysia"; import { node } from "@elysiajs/node"; +import { Elysia } from "elysia"; import { logger } from "./infrastructure/logger"; import { auth } from "./middleware/auth"; import { authPlugin } from "./middleware/auth-plugin"; @@ -15,7 +15,6 @@ import { serverRoutes } from "./routes/servers"; import { terminalRoutes } from "./routes/terminal"; import { userRoutes } from "./routes/users"; -// Register event handlers import "./infrastructure/event-handlers"; const app = new Elysia({ adapter: node() }) @@ -33,8 +32,7 @@ const app = new Elysia({ adapter: node() }) .use(authPlugin) .group("/api", (app) => app.use(userRoutes).use(serverRoutes).use(reverseProxyRoutes).use(k8sRoutes).use(terminalRoutes) - ) - .get("/health", () => ({ status: "ok" })); + ); export type App = typeof app; diff --git a/apps/backend/src/infrastructure/repositories/prisma/reverse-proxy.repository.impl.ts b/apps/backend/src/infrastructure/repositories/prisma/reverse-proxy.repository.impl.ts index fa6df35..27c3d17 100644 --- a/apps/backend/src/infrastructure/repositories/prisma/reverse-proxy.repository.impl.ts +++ b/apps/backend/src/infrastructure/repositories/prisma/reverse-proxy.repository.impl.ts @@ -95,7 +95,6 @@ export class PrismaReverseProxyRepository implements ReverseProxyRepository { throw new NotFoundError("ReverseProxyServer", id); } - // Update proxy fields const updated = await prisma.reverseProxyServer.update({ where: { id }, data: { diff --git a/apps/backend/src/infrastructure/repositories/prisma/server.repository.impl.ts b/apps/backend/src/infrastructure/repositories/prisma/server.repository.impl.ts index b07fb13..402079c 100644 --- a/apps/backend/src/infrastructure/repositories/prisma/server.repository.impl.ts +++ b/apps/backend/src/infrastructure/repositories/prisma/server.repository.impl.ts @@ -107,12 +107,10 @@ export class PrismaServerRepository implements ServerRepository { throw new NotFoundError("Server", id); } - // Handle env variables separately if (input.env_variables !== undefined) { await this.replaceEnvVariables(id, input.env_variables); } - // Update server fields const updated = await prisma.server.update({ where: { id }, data: { diff --git a/apps/backend/src/routes/k8s.ts b/apps/backend/src/routes/k8s.ts index b31027b..8e8d0cf 100644 --- a/apps/backend/src/routes/k8s.ts +++ b/apps/backend/src/routes/k8s.ts @@ -46,7 +46,6 @@ export const k8sRoutes = new Elysia({ prefix: "/k8s" }) }; const logs = await k8sService.getPodLogs(params.podName, options); - // Return as plain text const headers = (set.headers ?? {}) as Record; headers["content-type"] = "text/plain"; set.headers = headers; diff --git a/apps/backend/src/services/k8s.ts b/apps/backend/src/services/k8s.ts index b059f4e..8548fde 100644 --- a/apps/backend/src/services/k8s.ts +++ b/apps/backend/src/services/k8s.ts @@ -6,9 +6,7 @@ import type { IK8sService } from "../application/interfaces/k8s.service.interfac import { logger } from "../infrastructure/logger"; import { ClusterOperations } from "./kubernetes/operations/cluster.operations"; import { CustomResourceOperations } from "./kubernetes/operations/custom-resource.operations"; -import { NetworkOperations } from "./kubernetes/operations/network.operations"; import { PodOperations } from "./kubernetes/operations/pod.operations"; -import { WorkloadOperations } from "./kubernetes/operations/workload.operations"; import { K8sResources } from "./kubernetes/resources"; const CUSTOM_RESOURCE_VERSION = "v1alpha1"; @@ -56,8 +54,6 @@ export class K8sService implements IK8sService { private initializeOperations(): void { this.podOps = new PodOperations(this.coreApi, this.namespace); - this.workloadOps = new WorkloadOperations(this.appsApi, this.namespace); - this.networkOps = new NetworkOperations(this.coreApi, this.networkingApi, this.namespace); this.clusterOps = new ClusterOperations(this.coreApi, this.customObjectsApi, this.namespace); this.customResourceOps = new CustomResourceOperations(this.customObjectsApi, this.namespace); } diff --git a/apps/backend/src/services/websocket.ts b/apps/backend/src/services/websocket.ts index 2ab8df2..e1a2723 100644 --- a/apps/backend/src/services/websocket.ts +++ b/apps/backend/src/services/websocket.ts @@ -33,7 +33,6 @@ export class WebSocketService implements IWebSocketService { timestamp: new Date().toISOString(), }); - // Send to all connected clients, removing any that fail let failedClients = 0; this.clients.forEach((client) => { try { diff --git a/packages/db/prisma/schema.prisma b/packages/db/prisma/schema.prisma index 69d5de5..c83e72b 100644 --- a/packages/db/prisma/schema.prisma +++ b/packages/db/prisma/schema.prisma @@ -7,7 +7,6 @@ datasource db { provider = "postgresql" } -// Better Auth Models model User { id String @id name String @@ -68,7 +67,6 @@ model Verification { @@map("verification") } -// Application Models enum ServerType { STATEFUL STATELESS @@ -141,16 +139,13 @@ model Server { env_variables CustomEnvironmentVariable[] @relation("ServerEnvVars") api_key String @unique - // Minecraft specific configurations jar_type MinecraftServerJarType @default(VANILLA) minecraft_version String @default("LATEST") // e.g., "LATEST", "1.20.4", "SNAPSHOT" - // JVM Options jvm_opts String? // Custom JVM options use_aikar_flags Boolean @default(false) use_meowice_flags Boolean @default(false) - // Server Properties (common ones) difficulty ServerDifficulty @default(EASY) game_mode GameMode @default(SURVIVAL) max_players Int @default(20) diff --git a/packages/k8s-operator/src/config/constants.ts b/packages/k8s-operator/src/config/constants.ts index fb2c0a8..33517a4 100644 --- a/packages/k8s-operator/src/config/constants.ts +++ b/packages/k8s-operator/src/config/constants.ts @@ -10,7 +10,6 @@ export const NAMESPACE = process.env.KUBERNETES_NAMESPACE || "minikura"; export const ENABLE_CRD_REFLECTION = process.env.ENABLE_CRD_REFLECTION === "true"; -// Resource types export const RESOURCE_TYPES = { MINECRAFT_SERVER: { kind: "MinecraftServer", @@ -26,8 +25,7 @@ export const RESOURCE_TYPES = { }, }; -// Polling intervals (in milliseconds) -export const SYNC_INTERVAL = 30 * 1000; // 30 seconds +export const SYNC_INTERVAL = 30 * 1000; export const IMAGES = { MINECRAFT: "itzg/minecraft-server", diff --git a/packages/k8s-operator/src/config/resource-defaults.ts b/packages/k8s-operator/src/config/resource-defaults.ts index 71ac6c3..6925e75 100644 --- a/packages/k8s-operator/src/config/resource-defaults.ts +++ b/packages/k8s-operator/src/config/resource-defaults.ts @@ -9,7 +9,6 @@ export const RESOURCE_DEFAULTS = { }, } as const; -// 80% of container memory goes to JVM heap; 20% headroom export const JAVA_MEMORY_FACTOR = 0.8; export const DEFAULT_SERVER_MEMORY = "1G"; diff --git a/packages/k8s-operator/src/types/index.ts b/packages/k8s-operator/src/types/index.ts index eb4be62..0507c69 100644 --- a/packages/k8s-operator/src/types/index.ts +++ b/packages/k8s-operator/src/types/index.ts @@ -4,7 +4,6 @@ import type { Server as PrismaServer, } from "@minikura/db"; -// Base interface export interface CustomResource { apiVersion: string; kind: string; @@ -45,8 +44,6 @@ export interface MinecraftServerCRD extends CustomResource { status?: MinecraftServerStatus; } -// Reverse Proxy Types - export type ReverseProxyConfig = Pick< PrismaReverseProxyServer, | "id" diff --git a/packages/shared/src/errors.ts b/packages/shared/src/errors.ts index dcf58af..231185f 100644 --- a/packages/shared/src/errors.ts +++ b/packages/shared/src/errors.ts @@ -7,8 +7,6 @@ export function getErrorMessage(error: unknown): string { } return String(error); } - -/** Returns age string like "3d", "12h", "5m" */ export function getAge(timestamp: Date | string | undefined): string { if (!timestamp) return "unknown"; diff --git a/packages/shared/src/logger.ts b/packages/shared/src/logger.ts index 6250e04..c3dba23 100644 --- a/packages/shared/src/logger.ts +++ b/packages/shared/src/logger.ts @@ -1,16 +1,12 @@ import pino from "pino"; export function createLogger(component: string): pino.Logger; +export function createLogger(context: Record): pino.Logger; export function createLogger( - context: Record, -): pino.Logger; -export function createLogger( - componentOrContext: string | Record, + componentOrContext: string | Record ): pino.Logger { const isString = typeof componentOrContext === "string"; - const baseContext = isString - ? { component: componentOrContext } - : componentOrContext; + const baseContext = isString ? { component: componentOrContext } : componentOrContext; return pino({ level: process.env.LOG_LEVEL || "info",