# pryaxis/tshock architecture

> Architecture diagram of the GitHub repository pryaxis/tshock, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pryaxis/tshock
- Repository: https://github.com/pryaxis/tshock

## Overview

##### Project Type and Purpose
- TShock is a server-side toolbox and plugin framework for Terraria. It provides a rich API (TShockAPI) that implements server-side commands, player and permission management, anti-cheat mechanisms, and direct integration with Terraria internals.
- The project is organized as multiple .NET solutions/projects (e.g., TShockAPI, TShockLauncher, TShockInstaller, TShockPluginManager) set up to build, deploy, and manage a Terraria server environment.

##### Key Components
a. TShockAPI Core:
- This is the heart of the system and contains modules for handling configurations, database interactions, network communications, command-line interfaces (CLI), localization, file utilities, and hooks into Terraria.
- Within TShockAPI, you have specialized directories:
- Configuration: Manages server settings and configuration files.
- DB: Manages database interactions (ban management, group and user management, etc.).
- CLI: Handles command-line arguments and server start-up configurations.
- Net and Handlers: Manages network communications and data packets (including subdirectories like NetModules for specialized packet handling).
- Modules, Extensions, and Hooks: Provide extension points and add-on functionality for the server.
b. TShockLauncher:
- This component serves as an entry point for running the server. It bootstraps the TShockAPI, configures the runtime environment, and may include tests (as seen in TShockLauncher.Tests) to ensure server initialization and behavior.
c. TShockInstaller:
- A separate utility to install or set up the TShock server. It offers an installer experience for deploying the software.
d. TShockPluginManager:
- This project is responsible for managing plugins: easing the integration, installation, and updating of third-party add-ons to extend TShock’s functionality.
e. Supporting Components:
- Documentation (docs) and scripts (in the scripts folder) provide release automation, deployment, and build tooling.
- Internationalization (i18n) plays a major role in localizing the server responses and commands.

##### Relationships and Interactions
- How TShockLauncher interfaces with TShockAPI to start and manage the server runtime.
- TShockInstaller as a separate component that interacts with TShockAPI to configure a turnkey installation.
- TShockPluginManager as an external module that hooks into the TShockAPI to load and manage plugins.
- That several sub-components within TShockAPI (like the DB modules and CLI parsers) communicate with each other in a layered fashion.
- Direct interactions with the Terraria environment (with components accessing Terraria’s public fields and methods, akin to integration with the “Main” class in Terraria). Represent this as an external dependency or system that TShock interacts with directly.

##### Architectural Patterns and Design Principles
- Modular design. The separation of concerns is evident, with dedicated directories for database management, network handling, configuration, and extensions.
- The clear demarcation between the API core and by-products like the Launcher and Plugin Manager promotes a pluggable architecture where each module addresses a distinct responsibility.
- Furthermore, use of hooks and event-handling (illustrated in the Hooks subdirectory) demonstrates an event-driven component design.

- TShockLauncher to the API, showing it as the starting point for server operation.
- Attach TShockInstaller and TShockPluginManager as companion utilities that interface with or extend the API.
- Use annotations or legends to explain components (e.g., "Handles command parsing", "Manages database operations") where necessary.

## Diagram (Mermaid)

```mermaid
graph TD
    %% TShockAPI Core and its internal modules
    subgraph "TShockAPI Core"
        TSCore["TShockAPI Core\n(.NET 6)"]:::core
        Config["Configuration\n(Manages server settings)"]:::core
        DB["DB\n(Database interactions)"]:::core
        CLI["CLI\n(Command parsing)"]:::core
        Net["Net & Handlers\n(Network communications)"]:::core
        Modules["Modules & Extensions"]:::core
        Hooks["Hooks\n(Event handling)"]:::core
        Localization["Localization\n(Language support)"]:::core
        TSCore -->|"contains"| Config
        TSCore -->|"contains"| DB
        TSCore -->|"contains"| CLI
        TSCore -->|"contains"| Net
        TSCore -->|"contains"| Modules
        TSCore -->|"contains"| Hooks
        TSCore -->|"contains"| Localization
    end

    %% Runtime Components
    TShockLauncher["TShockLauncher"]:::utility
    TShockInstaller["TShockInstaller"]:::utility
    TShockPluginManager["TShockPluginManager"]:::utility

    %% DevOps & Deployment Components
    subgraph "DevOps & Deployment"
        Docs["Documentation"]:::utility
        Scripts["Scripts\n(Release automation)"]:::utility
    end

    %% External Dependency
    Terraria["Terraria Server"]:::external

    %% Supporting Internationalization
    I18n["Internationalization (i18n)"]:::utility

    %% Relationships between components
    TShockLauncher -->|"startup"| TSCore
    TShockInstaller -->|"configures"| TSCore
    TShockPluginManager -->|"loads_plugins"| TSCore
    TSCore <-->|"integrates"| Terraria
    Localization -->|"supports"| I18n

    %% Styles
    classDef core fill:#f8c291,stroke:#333,stroke-width:2px;
    classDef utility fill:#82ccdd,stroke:#333,stroke-width:2px;
    classDef external fill:#f6b93b,stroke:#333,stroke-width:2px;

    %% Click Events
    click TSCore "https://github.com/pryaxis/tshock/tree/general-devel/TShockAPI"
    click TShockLauncher "https://github.com/pryaxis/tshock/blob/general-devel/TShockLauncher/Program.cs"
    click TShockLauncher "https://github.com/pryaxis/tshock/blob/general-devel/TShockLauncher/TShockLauncher.csproj"
    click TShockInstaller "https://github.com/pryaxis/tshock/blob/general-devel/TShockInstaller/Program.cs"
    click TShockInstaller "https://github.com/pryaxis/tshock/blob/general-devel/TShockInstaller/TShockInstaller.csproj"
    click TShockPluginManager "https://github.com/pryaxis/tshock/tree/general-devel/TShockPluginManager"
    click I18n "https://github.com/pryaxis/tshock/tree/general-devel/i18n"
    click Docs "https://github.com/pryaxis/tshock/tree/general-devel/docs"
    click Scripts "https://github.com/pryaxis/tshock/tree/general-devel/scripts"
    click Terraria "https://github.com/pryaxis/tshock/tree/general-devel/TerrariaServerAPI"
```
