# trugamr/wol architecture

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

- Interactive diagram: https://gitdiagram.com/trugamr/wol
- Repository: https://github.com/trugamr/wol

## Overview

##### Main Components
- CLI Layer – This is represented by the "cmd" directory. Each file (list.go, send.go, serve.go, version.go, root.go) corresponds to a CLI command. These commands act as the entry points depending on user input.
- Core Business Logic – The "magicpacket" package contains the core functionality to construct and send the wake-on-LAN magic packets.
- Configuration Component – The "config" directory with config.go handles reading the YAML configuration file (from various locations or environment variable).
- Web Interface – The serve command (cmd/serve.go) along with the "cmd/templates" directory form the web component. They serve the web page (via HTTP) using HTML templates for user interactions.
- Docker & Deployment – The docker directory and associated configuration files (e.g., .goreleaser.yaml, examples) indicate how to containerize and deploy the application.
- CI/CD / Release Automation – The .github/workflows and other GitHub-specific files show integration with automated workflows.

##### Relationships and Interactions
- The main entry point (main.go) routes to the proper CLI command based on the arguments provided.
- Depending on the command invoked:
- The "send" command will use the magicpacket package to send a packet, drawing its configuration from the config component.
- The "list" command will fetch and display the information of configured machines.
- The "serve" command will initialize the web server, load templates (from cmd/templates), and expose endpoints for triggering wake-up actions via a browser.
- The web server (in the serve command) reuses the same configuration and magicpacket modules for its operations, but exposes functionality over HTTP.

##### Architectural Patterns & Design Principles
- Command Pattern – The project uses separate command files to encapsulate different operations (list, send, serve, version).
- Configuration Precedence – The configuration system is designed to look into multiple sources (current directory, user home, system-wide, or environment variable), which should be noted.
- Separation of Concerns – The concerns are split between CLI handling, business logic (sending packets), and presentation (web UI/HTML templates).

##### Relevant Technologies/Frameworks
- Go Standard Libraries and Package System – for CLI, HTTP server, and configuration parsing.
- Docker – for containerization (Dockerfile and docker-compose examples).
- GitHub Actions (.github/workflows) – for release and CI/CD integrations.
- YAML – for configuration management.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Main Application Entry Point
    subgraph "Application Entry"
        MAIN["main.go"]:::entry
        click MAIN "https://github.com/trugamr/wol/blob/main/main.go"
    end

    %% CLI Layer
    subgraph "CLI Layer"
        ROOT["root.go"]:::cli
        LIST["list.go"]:::cli
        SEND["send.go"]:::cli
        SERVE_CLI["serve.go (CLI)"]:::cli
        VERSION["version.go"]:::cli
        click ROOT "https://github.com/trugamr/wol/blob/main/cmd/root.go"
        click LIST "https://github.com/trugamr/wol/blob/main/cmd/list.go"
        click SEND "https://github.com/trugamr/wol/blob/main/cmd/send.go"
        click SERVE_CLI "https://github.com/trugamr/wol/blob/main/cmd/serve.go"
        click VERSION "https://github.com/trugamr/wol/blob/main/cmd/version.go"
    end

    %% Configuration Component
    subgraph "Configuration"
        CONFIG["config.go"]:::config
        CONFIG_EX["config.example.yaml"]:::config
        click CONFIG "https://github.com/trugamr/wol/blob/main/config/config.go"
        click CONFIG_EX "https://github.com/trugamr/wol/blob/main/config.example.yaml"
    end

    %% Core Business Logic
    subgraph "Core Business Logic"
        MAGIC["magicpacket.go"]:::core
        click MAGIC "https://github.com/trugamr/wol/blob/main/magicpacket/magicpacket.go"
    end

    %% Web Interface
    subgraph "Web Interface"
        SERVE_WEB["serve.go (Web)"]:::web
        TEMPLATES["Templates"]:::web
        click SERVE_WEB "https://github.com/trugamr/wol/blob/main/cmd/serve.go"
        click TEMPLATES "https://github.com/trugamr/wol/tree/main/cmd/templates"
        subgraph "HTML Templates"
            INDEX["index.html"]:::web
            click INDEX "https://github.com/trugamr/wol/blob/main/cmd/templates/index.html"
        end
    end

    %% Deployment & Docker
    subgraph "Deployment & Docker"
        DOCKER_DIR["docker directory"]:::deploy
        DOCKERFILE["Dockerfile"]:::deploy
        DOCKERFILE_TEMPLATE["Dockerfile.template"]:::deploy
        EXAMPLE_PROXY["reverse-proxy.yml"]:::deploy
        GORELEASER[".goreleaser.yaml"]:::deploy
        click DOCKER_DIR "https://github.com/trugamr/wol/tree/main/docker"
        click DOCKERFILE "https://github.com/trugamr/wol/tree/main/docker/Dockerfile"
        click DOCKERFILE_TEMPLATE "https://github.com/trugamr/wol/blob/main/docker/Dockerfile.template"
        click EXAMPLE_PROXY "https://github.com/trugamr/wol/blob/main/examples/reverse-proxy.yml"
        click GORELEASER "https://github.com/trugamr/wol/blob/main/.goreleaser.yaml"
    end

    %% CI/CD & Release Automation
    subgraph "CI/CD & Release"
        WORKFLOWS["Workflows Directory"]:::cicd
        RELEASE["release.yaml"]:::cicd
        click WORKFLOWS "https://github.com/trugamr/wol/tree/main/.github/workflows"
        click RELEASE "https://github.com/trugamr/wol/blob/main/.github/workflows/release.yaml"
    end

    %% Connections between Main and CLI
    MAIN -->|"routesTo"| ROOT
    ROOT -->|"subcommand"| LIST
    ROOT -->|"subcommand"| SEND
    ROOT -->|"subcommand"| SERVE_CLI
    ROOT -->|"subcommand"| VERSION

    %% CLI Commands interactions with Configuration and Core Business Logic
    SEND -->|"readsConfig"| CONFIG
    SEND -->|"usesMagic"| MAGIC
    LIST -->|"readsConfig"| CONFIG

    %% Web Interface interactions with Configuration and Core Business Logic
    SERVE_WEB -->|"readsConfig"| CONFIG
    SERVE_WEB -->|"triggersMagic"| MAGIC

    %% CLI serve command launches Web Interface
    SERVE_CLI -->|"launchesUI"| SERVE_WEB

    %% CI/CD and Deployment interrelations
    RELEASE -->|"builds"| GORELEASER
    GORELEASER -->|"buildsImage"| DOCKERFILE
    WORKFLOWS -->|"automates"| MAIN

    %% Class Definitions for styling
    classDef entry fill:#F8E0F8,stroke:#8B008B,stroke-width:2px;
    classDef cli fill:#FFE4B5,stroke:#D2691E,stroke-width:2px;
    classDef config fill:#B0E0E6,stroke:#4682B4,stroke-width:2px;
    classDef core fill:#E0FFFF,stroke:#20B2AA,stroke-width:2px;
    classDef web fill:#FFDAB9,stroke:#FF8C00,stroke-width:2px;
    classDef deploy fill:#E6E6FA,stroke:#6A5ACD,stroke-width:2px;
    classDef cicd fill:#FFFACD,stroke:#DAA520,stroke-width:2px;
```
