# carrot-hu23/dst-admin-go architecture

> Architecture diagram of the GitHub repository carrot-hu23/dst-admin-go, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/carrot-hu23/dst-admin-go
- Repository: https://github.com/carrot-hu23/dst-admin-go

## Overview

##### 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).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    Client["Client Browser"]:::webUI
    click Client "https://github.com/carrot-hu23/dst-admin-go/tree/main/static/"

    %% Server Layer
    subgraph "HTTP Server (Go)"
        direction TB
        Main["main.go"]:::server
        click Main "https://github.com/carrot-hu23/dst-admin-go/blob/main/main.go"
        Init["bootstrap/init.go"]:::server
        click Init "https://github.com/carrot-hu23/dst-admin-go/blob/main/bootstrap/init.go"
        Router["Router Layer"]:::server
        click Router "https://github.com/carrot-hu23/dst-admin-go/blob/main/router/entry.go"
        subgraph "Middleware"
            direction TB
            SecInt["SecurityInterceptor.go"]:::server
            click SecInt "https://github.com/carrot-hu23/dst-admin-go/blob/main/middleware/SecurityInterceptor.go"
            AuthHandler["authHandler.go"]:::server
            click AuthHandler "https://github.com/carrot-hu23/dst-admin-go/blob/main/middleware/authHandler.go"
            ErrHandle["errorHandle.go"]:::server
            click ErrHandle "https://github.com/carrot-hu23/dst-admin-go/blob/main/middleware/errorHandle.go"
        end
        subgraph "Controller/API Layer"
            direction TB
            GameConsoleAPI["gameConsoleApi.go"]:::server
            click GameConsoleAPI "https://github.com/carrot-hu23/dst-admin-go/blob/main/api/gameConsoleApi.go"
            SteamAPI["steamApi.go"]:::server
            click SteamAPI "https://github.com/carrot-hu23/dst-admin-go/blob/main/api/steamApi.go"
            WebhookAPI["webhookApi.go"]:::server
            click WebhookAPI "https://github.com/carrot-hu23/dst-admin-go/blob/main/api/webhookApi.go"
        end
        subgraph "Service Layer"
            direction TB
            GameService["gameService.go"]:::server
            click GameService "https://github.com/carrot-hu23/dst-admin-go/blob/main/service/gameService.go"
            GameConsoleService["gameConsoleService.go"]:::server
            click GameConsoleService "https://github.com/carrot-hu23/dst-admin-go/blob/main/service/gameConsoleService.go"
            BackupService["backupService.go"]:::server
            click BackupService "https://github.com/carrot-hu23/dst-admin-go/blob/main/service/backupService.go"
            ClusterManager["clusterManger.go"]:::server
            click ClusterManager "https://github.com/carrot-hu23/dst-admin-go/blob/main/service/clusterManger.go"
        end
        subgraph "Scheduler (Timed Tasks)"
            direction TB
            ScheduleCore["schedule.go"]:::scheduler
            click ScheduleCore "https://github.com/carrot-hu23/dst-admin-go/blob/main/schedule/schedule.go"
            ImageSchedule["ImageSchedule.go"]:::scheduler
            click ImageSchedule "https://github.com/carrot-hu23/dst-admin-go/blob/main/schedule/ImageSchedule.go"
            Strategy["strategy.go"]:::scheduler
            click Strategy "https://github.com/carrot-hu23/dst-admin-go/blob/main/schedule/strategy.go"
        end
        Utils["Utilities"]:::server
        click Utils "https://github.com/carrot-hu23/dst-admin-go/tree/main/utils/"
    end

    %% Persistence Layer
    subgraph "Persistence"
        direction TB
        DB[(Database)]:::persistence
        click DB "https://github.com/carrot-hu23/dst-admin-go/blob/main/config/database/database.go"
        Models["ORM Models"]:::persistence
        click Models "https://github.com/carrot-hu23/dst-admin-go/tree/main/model/"
        FileStorage[(File Storage)]:::persistence
    end

    %% External Systems
    subgraph "External Systems"
        direction TB
        ThirdSteamAPI["Steam Web API"]:::external
        GameServers["Game Servers (SSH/SteamCMD)"]:::external
        PythonCLI["Python CLI Tool"]:::external
        click PythonCLI "https://github.com/carrot-hu23/dst-admin-go/tree/main/py-dst-cli/"
    end

    %% Connections
    Client -->|"HTTP(S)/JSON"| Router
    Client -->|"WebSocket frames"| GameConsoleAPI
    Main --> Init
    Init --> Router
    Router --> SecInt
    SecInt --> AuthHandler
    AuthHandler --> ErrHandle
    ErrHandle --> GameConsoleAPI
    GameConsoleAPI --> GameService
    SteamAPI --> GameService
    WebhookAPI --> GameService
    GameService --> DB
    GameService --> FileStorage
    BackupService --> FileStorage
    ClusterManager --> GameServers
    ScheduleCore -.->|"triggers"| BackupService
    ScheduleCore -.->|"triggers"| ImageSchedule
    ScheduleCore -.->|"triggers"| Strategy
    GameConsoleService --> GameServers
    GameConsoleService -->|"WebSocket"| Client
    GameService --> ThirdSteamAPI
    DB --> Models
    PythonCLI -.->|"REST calls"| Router

    %% Styles
    classDef webUI fill:#D6EFFF,stroke:#333,stroke-width:1px
    classDef server fill:#FFE0B3,stroke:#333,stroke-width:1px
    classDef persistence fill:#DFFFE0,stroke:#333,stroke-width:1px
    classDef external fill:#E0E0E0,stroke:#333,stroke-width:1px
    classDef scheduler fill:#FFD8B3,stroke:#333,stroke-width:1px
```
