# frahz/sugoi architecture

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

- Interactive diagram: https://gitdiagram.com/frahz/sugoi
- Repository: https://github.com/frahz/sugoi

## Overview

##### Project Type Analysis
This is a specialized web server application written in Rust, with a frontend component using Tailwind CSS for styling. It's designed to manage the power state of another server through wake-on-LAN and sleep commands.

##### Main Components

a) Web Server Layer:
- Two main components inside:
- HTTP Server (Rust-based)
- Template Engine (handling HTML templates)

b) Core Functionality:
- Two sub-components:
- Wake-on-LAN Handler
- Sleep Command Handler

c) Status Management:
- A "Status Module" component
- A "Status Buffer" sub-component (noting the TODO for implementing a ring buffer)

d) Frontend Components:
- Include:
- Static Assets (CSS)
- HTML Templates
- Status Display Components

##### Component Relationships

- Client Browser → Web Server (HTTP requests)
- Web Server → Template Engine (rendering responses)
- Web Server → Power Management Module (wake/sleep commands)
- Web Server → Status Module (status updates/queries)
- Status Module → Template Engine (status data for display)

##### Technical Details

Annotations for:
- Rust as the primary implementation language
- Tailwind CSS for styling
- Template system for HTML rendering
- Target platform (Raspberry Pi Zero W)

Use the following visual elements:
- Blue containers for server-side components
- Green containers for frontend components
- Yellow containers for power management functionality

##### File Structure Integration

Following files to components:
- src/api.rs → API endpoints
- src/status.rs → Status management
- src/main.rs → Server core
- templates/* → Template components
- assets/* → Frontend assets

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        Browser["Web Browser"]:::client
    end

    subgraph "Sugoi Web Server"
        WebCore["Web Server Core"]:::server
        APIEndpoints["API Endpoints"]:::server
        TemplateEngine["Template Engine"]:::server
    end

    subgraph "Power Management"
        WoLHandler["Wake-on-LAN Handler"]:::power
        SleepHandler["Sleep Command Handler"]:::power
    end

    subgraph "Status Management"
        StatusMgr["Status Module"]:::status
        StatusBuffer["Status Buffer<br>(TODO: Ring Buffer)"]:::status-todo
    end

    subgraph "Frontend Layer"
        StaticAssets["Static Assets"]:::frontend
        HTMLTemplates["HTML Templates"]:::frontend
        StatusDisplay["Status Display<br>Components"]:::frontend
    end

    subgraph "Target Server"
        ManagedServer["Managed Server"]:::target
    end

    %% Relationships
    Browser -->|HTTP Requests| WebCore
    WebCore -->|Process Requests| APIEndpoints
    WebCore -->|Render| TemplateEngine
    APIEndpoints -->|Commands| WoLHandler
    APIEndpoints -->|Commands| SleepHandler
    APIEndpoints -->|Updates| StatusMgr
    StatusMgr -->|Data| StatusBuffer
    StatusMgr -->|Status Data| TemplateEngine
    TemplateEngine -->|Uses| HTMLTemplates
    TemplateEngine -->|Uses| StaticAssets
    TemplateEngine -->|Renders| StatusDisplay
    WoLHandler -->|Wake Command| ManagedServer
    SleepHandler -->|Sleep Command| ManagedServer

    %% Click Events
    click WebCore "https://github.com/frahz/sugoi/blob/main/src/main.rs"
    click APIEndpoints "https://github.com/frahz/sugoi/blob/main/src/api.rs"
    click StatusMgr "https://github.com/frahz/sugoi/blob/main/src/status.rs"
    click StaticAssets "https://github.com/frahz/sugoi/tree/main/assets"
    click HTMLTemplates "https://github.com/frahz/sugoi/tree/main/templates"
    click StatusDisplay "https://github.com/frahz/sugoi/tree/main/templates/status"

    %% Styles
    classDef server fill:#3b82f6,color:white
    classDef power fill:#eab308,color:black
    classDef status fill:#22c55e,color:white
    classDef status-todo fill:#22c55e,color:white,stroke-dasharray: 5 5
    classDef frontend fill:#8b5cf6,color:white
    classDef client fill:#gray,color:black
    classDef target fill:#ef4444,color:white

    %% Legend
    subgraph Legend
        L1["Server Components"]:::server
        L2["Power Management"]:::power
        L3["Status Components"]:::status
        L4["Frontend Components"]:::frontend
        L5["Target Server"]:::target
    end
```
