How carrot-hu23/dst-admin-go works
Project Type & Purpose
• It’s a full-stack “Don’t Starve Together” server admin panel, written in Go, exposing a web UI to manage game rooms, mods, backups, snapshots, stats, and live console.
• It embeds static HTML/JS under /static, routes through Go’s HTTP server, and persists state in a relational database.
• It also includes a separate Python CLI (py-dst-cli) for command-line operations.
File Structure & Key Architectural Patterns
• Entry point: main.go → calls bootstrap/init.go to load config.yml and initialize global state (DB, logging, etc.).
• Routing layer: router/*.go defines HTTP endpoints, mapping to handlers in the api/ folder.
• Middleware: middleware/* provides security, auth, error handling.
• Controller/API layer: api/*.go contains functions to parse requests, call services, return JSON or WebSocket frames.
• Service layer: service/* contains business logic (e.g., backupService.go, gameService.go, clusterManger.go).
• Data layer: model/*.go defines ORM entities, and config/database/database.go manages DB connections.
• Scheduler: schedule/* implements timed tasks (backups, stats).
• Utilities: utils/* – file, shell, DST-specific helpers.
• Static assets: static/ – client-side scripts, templates, shell scripts for server install.
• External integrations: SteamCMD, remote SSH calls, Steam Web API, Webhooks, WebSockets for live console.
README for Additional Clues
• Single-binary deploy via Docker or native, uses config.yml for port and DB.
• The UI is server-hosted; no SPA framework visible.
• Deployable on Windows and Linux, low footprint.
Main Components
A. Client Browser
– Fetches static HTML/JS/CSS.
– Opens WebSocket connections for live console.
B. HTTP Server (Go)
– Bootstrap & Init (config loader, DI)
– Router (HTTP & WS endpoints)
– Middleware (auth, error handling)
– Controller/API layer
– Service layer
– Scheduler (cron/timers)
C. Database
– MySQL/PostgreSQL (configured by config/database)
D. File Storage
– Disk storage for backups, snapshots under a configured directory.
E. External Game Servers
– SSH/CLI calls via SteamCMD to start/stop servers
– Game console streaming over WebSocket
F. Third-Party APIs
– Steam Web API (via api/steamApi.go)
– Webhook endpoints
Relationships & Data Flows
• HTTP Server → DB (reads/writes via model).
• HTTP Server → File Storage (read/write snapshots & backups).
• Scheduler → Service → DB/File Storage.
• Service → External Game Servers (shell commands).
• API layer ↔ Third-Party APIs.
• API layer → WebSocket → Client.
Architectural Patterns & Design Principles
• Layered architecture: Presentation (static + router) → Controller/API → Service → Data (ORM).
• Separation of concerns: middleware, config, utils, schedule.
• Dependency injection via bootstrap/init.
• Single binary, Docker-friendly, cross-platform.
• Extensible CLI tool sits alongside as a separate module.
Technologies & Frameworks
• Go (net/http or Gin-like routing).
• Go modules.
• Relational DB (MySQL/Postgres).
• Shell commands (SteamCMD).
• Python CLI for advanced scripts.
• Docker (Dockerfile + entrypoint scripts).