# mgaydash/k8s-terraria-server architecture

> Architecture diagram of the GitHub repository mgaydash/k8s-terraria-server, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mgaydash/k8s-terraria-server
- Repository: https://github.com/mgaydash/k8s-terraria-server

## Overview

##### Main Components
- Helm Chart: Acts as the packaging and deployment mechanism.
- Kubernetes Cluster: The environment where the chart is deployed.
- Deployment Component: Represented by the "deployment-terraria.yaml" template, which defines how the Terraria server pods are created and managed.
- Service Component: Defined in "service-terraria.yaml", this provides access to the running Terraria server.
- Ingress: Defined in "ingress.yaml", handling external HTTP/s routing, if enabled.
- Storage: The "pvc-terraria-data.yaml" template indicates that a Persistent Volume Claim is used for server data storage.
- Secrets: The "secret.yaml" template ensures sensitive information is stored securely.
- Backup Mechanism: The "cronjob-terraria-backup.yaml" template shows that scheduled backups are set up using Kubernetes CronJobs.
- Configuration Files & Scripts: The "files/serverconfig.txt" for server-specific settings and "install.sh" for running the installation.

##### Relationships and Interactions
- The Helm chart orchestrates the creation of all Kubernetes resources.
- The Deployment creates and manages the Terraria server pods, which mount the PVC for persistent storage.
- The Service exposes the Terraria server internally (and potentially externally, via the Ingress).
- The Secret resource is linked to the Deployment to securely provide sensitive configuration data.
- The CronJob periodically triggers backups, likely interfacing with the same storage (PVC) to secure critical data.
- The Ingress routes external traffic to the Service, ensuring accessibility from outside of the Kubernetes cluster.

##### Architectural Patterns and Design Principles
- Infrastructure as Code: The use of Helm templating means that your Kubernetes resources are defined in code and can be templated and versioned.
- Modular Design: Each template (deployment, service, PVC, secret, cronjob, ingress) forms a distinct component, which is a best practice for separating concerns.
- Declarative Configuration: Everything is declaratively defined, following GitOps principles.

## Diagram (Mermaid)

```mermaid
flowchart TD
    helmChart["Helm Chart"]:::helm
    k8sCluster["Kubernetes Cluster"]:::cluster
    dep["Terraria Deployment"]:::k8sResource
    svc["Terraria Service"]:::k8sResource
    pvc["Persistent Volume Claim"]:::k8sResource
    sec["Secret"]:::k8sResource
    bkup["Backup CronJob"]:::k8sResource
    ing["Ingress"]:::external
    conf["Server Configuration"]:::helm

    %% Connections from Helm Chart to Kubernetes Cluster components
    helmChart --> k8sCluster
    k8sCluster --> dep
    k8sCluster --> svc
    k8sCluster --> pvc
    k8sCluster --> sec
    k8sCluster --> bkup

    %% Internal relationships within the cluster
    svc -->|"routes_to"| dep
    dep -->|"mounts"| pvc
    dep -->|"uses"| sec
    bkup -->|"backs_up"| pvc

    %% External interactions
    ing -->|"forwards_to"| svc
    conf -->|"configures"| dep

    %% Styles
    classDef helm fill:#ADD8E6,stroke:#00008B,stroke-width:2px;
    classDef cluster fill:#E0FFE0,stroke:#008000,stroke-width:2px;
    classDef k8sResource fill:#FFFACD,stroke:#DAA520,stroke-width:2px;
    classDef external fill:#FFDAB9,stroke:#FF8C00,stroke-width:2px;

    %% Click Events
    click helmChart "https://github.com/mgaydash/k8s-terraria-server/blob/main/Chart.yaml"
    click k8sCluster "https://github.com/mgaydash/k8s-terraria-server/tree/main/templates"
    click dep "https://github.com/mgaydash/k8s-terraria-server/blob/main/templates/deployment-terraria.yaml"
    click svc "https://github.com/mgaydash/k8s-terraria-server/blob/main/templates/service-terraria.yaml"
    click pvc "https://github.com/mgaydash/k8s-terraria-server/blob/main/templates/pvc-terraria-data.yaml"
    click sec "https://github.com/mgaydash/k8s-terraria-server/blob/main/templates/secret.yaml"
    click bkup "https://github.com/mgaydash/k8s-terraria-server/blob/main/templates/cronjob-terraria-backup.yaml"
    click ing "https://github.com/mgaydash/k8s-terraria-server/blob/main/ingress.yaml"
    click conf "https://github.com/mgaydash/k8s-terraria-server/blob/main/files/serverconfig.txt"
```
