# sawatkins/upfast-tf architecture

> Architecture diagram of the GitHub repository sawatkins/upfast-tf, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sawatkins/upfast-tf
- Repository: https://github.com/sawatkins/upfast-tf

## Overview

##### Main Components

A. Frontend Layer:
- Web Interface (Static files and Templates)
- Relationship between templates, static assets, and the Go server
- Main template layouts and partials structure

B. Backend Layer:
- Go Web Server
- Handlers for CLI and Web requests
- Models for data structure
- SQLite Database integration

C. Infrastructure Layer:
- AWS EC2 Instances (TF2 Servers)
- Terraform Configuration
- Server Installation Scripts
- Prometheus Monitoring

**[Client Layer]**
- ↓↑
**[Application Layer]**
- ↓↑
**[Infrastructure Layer]**

##### Detailed Component Breakdown

Client Layer:
- Static assets (CSS, JS, images)
- Template rendering flow

Application Layer:
- Main Go server component
- Handler routes (/handlers)
- Database interactions
- Models structure

Infrastructure Layer:
- Terraform modules (cli/modules/tf2_server_module)
- AWS EC2 instances
- Server installation process
- Prometheus monitoring system

##### Key Flows to Highlight

A. Server Provisioning Flow:
- CLI → Terraform → AWS EC2 → Server Install Script → Running TF2 Server

B. Monitoring Flow:
- TF2 Server → Prometheus → Backend → Frontend Dashboard

C. User Interaction Flow:
- Browser → Go Server → Templates → Rendered Page

##### Important Elements

- Database schema representation (SQLite)
- AWS EC2 instance configurations
- Terraform module structure
- Template rendering pipeline
- Monitoring data flow
- API endpoints and handlers

##### Technical Details to Note

- Relationship between main.go and handlers
- CLI automation tools
- Monitoring integration points
- Template inheritance structure

##### Specific Implementation Notes

- Template structure (templates/layouts/main.html relationship with partials)
- Terraform module configuration (cli/modules/tf2_server_module)
- Handler routing system (handlers/cli-handler.go and handlers/handlers.go)

Remember to emphasize the infrastructure automation aspects, as this is a key feature of the platform, while also showing how it integrates with the web interface and monitoring system.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        Browser["Web Browser"]
        CLI["Command Line Interface"]
    end

    subgraph Frontend
        Templates["Templates"]:::templates
        StaticAssets["Static Assets"]:::static
        MainLayout["Main Layout"]:::template
        Partials["Template Partials"]:::template
        CSS["CSS Styles"]:::static
        JS["JavaScript"]:::static
    end

    subgraph Backend
        GoServer["Go Web Server"]:::server
        WebHandlers["Web Handlers"]:::handler
        CLIHandlers["CLI Handlers"]:::handler
        Models["Data Models"]:::model
        DB[(SQLite Database)]:::database
        DBIntegration["Database Integration"]:::database
    end

    subgraph Infrastructure
        TerraformModule["Terraform Module"]:::infra
        TerraformConfig["Main Terraform Config"]:::infra
        InstallScript["Server Installation Script"]:::infra
        AutomationTool["Server Automation Tool"]:::infra
        EC2["AWS EC2 Instances"]:::aws
        TF2Server["TF2 Server"]:::game
        Prometheus["Prometheus Monitoring"]:::monitoring
    end

    Browser --> GoServer
    CLI --> CLIHandlers
    GoServer --> Templates
    GoServer --> StaticAssets
    Templates --> MainLayout
    Templates --> Partials
    StaticAssets --> CSS
    StaticAssets --> JS
    
    GoServer --> WebHandlers
    GoServer --> CLIHandlers
    WebHandlers --> Models
    CLIHandlers --> Models
    Models --> DBIntegration
    DBIntegration --> DB
    
    CLIHandlers --> TerraformModule
    TerraformModule --> TerraformConfig
    TerraformConfig --> EC2
    EC2 --> InstallScript
    InstallScript --> TF2Server
    AutomationTool --> TF2Server
    TF2Server --> Prometheus
    Prometheus --> GoServer

    %% Component Mappings
    click Templates "https://github.com/sawatkins/upfast-tf/blob/main/templates/layouts/main.html"
    click Partials "https://github.com/sawatkins/upfast-tf/tree/main/templates/partials/"
    click StaticAssets "https://github.com/sawatkins/upfast-tf/tree/main/static/"
    click CSS "https://github.com/sawatkins/upfast-tf/blob/main/static/css/style.css"
    click JS "https://github.com/sawatkins/upfast-tf/blob/main/static/js/index.js"
    click GoServer "https://github.com/sawatkins/upfast-tf/blob/main/main.go"
    click WebHandlers "https://github.com/sawatkins/upfast-tf/blob/main/handlers/handlers.go"
    click CLIHandlers "https://github.com/sawatkins/upfast-tf/blob/main/handlers/cli-handler.go"
    click Models "https://github.com/sawatkins/upfast-tf/blob/main/models/models.go"
    click DBIntegration "https://github.com/sawatkins/upfast-tf/blob/main/database/database.go"
    click TerraformModule "https://github.com/sawatkins/upfast-tf/tree/main/cli/modules/tf2_server_module/"
    click TerraformConfig "https://github.com/sawatkins/upfast-tf/blob/main/cli/main.tf"
    click InstallScript "https://github.com/sawatkins/upfast-tf/blob/main/cli/server_install.sh"
    click AutomationTool "https://github.com/sawatkins/upfast-tf/blob/main/cli/upfast.py"
    click MainLayout "https://github.com/sawatkins/upfast-tf/blob/main/templates/layouts/main.html"

    classDef templates fill:#e1f5fe,stroke:#01579b
    classDef template fill:#e1f5fe,stroke:#01579b
    classDef static fill:#e8f5e9,stroke:#2e7d32
    classDef server fill:#0277bd,stroke:#01579b,color:#fff
    classDef handler fill:#0288d1,stroke:#01579b,color:#fff
    classDef model fill:#039be5,stroke:#01579b,color:#fff
    classDef database fill:#29b6f6,stroke:#01579b
    classDef infra fill:#ff9800,stroke:#e65100
    classDef aws fill:#616161,stroke:#212121,color:#fff
    classDef game fill:#ff5722,stroke:#bf360c,color:#fff
    classDef monitoring fill:#9c27b0,stroke:#4a148c,color:#fff
```
