# 3l-d1abl0/gomon architecture

> Architecture diagram of the GitHub repository 3l-d1abl0/gomon, 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/3l-d1abl0/gomon
- Repository: https://github.com/3l-d1abl0/gomon

## Overview

##### Main Components
- API Layer: Represented by the “api” directory (api/api.go) where the HTTP endpoints are defined. This is the entry point for incoming requests.
- Middlewares: Shown in the “middlewares” directory with middleware components like logger and header processing (headers.go, logger.go). They intercept requests before reaching the core handlers.
- System Information Module: Located in “sysinfo” (sysinfo/sysinfo.go and sysinfo_test.go). This module is responsible for gathering system metrics from the OS, leveraging gopsutil.
- Common Data Module: In the “commonData” directory (commonData/common.go), likely used to share common routines, structures, constants, or helper functions across various parts of the system.
- Main Application Logic: The “main.go” file, which is the starting point of the application where the setup of routes, middleware, and server initiation occurs.
- Testing: Files like “main_test.go” and “sysinfo/sysinfo_test.go” that indicate testing strategies and components.

##### Flow and Relationships
- Next, capture the “API Layer” (using Gin) that receives these HTTP requests.
- Within the API layer, incoming requests pass through the “Middlewares” (logger, headers) which modify or log requests before routing.
- The API endpoints, once processed, invoke the “System Information Module” (sysinfo) to collect and return the appropriate system metrics.
- The “Common Data Module” supports these layers, providing shared utilities or data structures.
- The Main function acts as the coordinator that initializes all these components and starts the HTTP server.

##### Architectural Patterns and Design Principles
- Use a layered architecture where the API layer (presentation) is separated from business logic (sysinfo) and common utilities (commonData).
- Dependency injection where possible, so that the middleware and system info components can be easily maintained and tested.
- The use of a microkernel or modular approach is visible here with clear separation of concerns: middleware handling, system data processing, and API endpoints.

- Use rectangles for infrastructure (API server, main application).

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["Main Application (main.go)"]:::mainApp
    B["Client (External Scraper)"]:::client

    subgraph "API Server (Gin)"
        D["Logger Middleware (middlewares/logger.go)"]:::middleware
        E["Header Middleware (middlewares/headers.go)"]:::middleware
        F["API Endpoints (api/api.go)"]:::api
    end

    G["System Info Module (gopsutil) (sysinfo/sysinfo.go)"]:::sysinfo
    H["Common Data Utility (commonData/common.go)"]:::commonData

    I["Main Test (main_test.go)"]:::test
    J["SysInfo Test (sysinfo/sysinfo_test.go)"]:::test

    A -->|"initializes"| D
    B -->|"sends_request"| D
    D -->|"passes"| E
    E -->|"routes_to"| F
    F -->|"invokes"| G
    F ---|"uses"| H
    G ---|"uses"| H

    A ---|"tested_by"| I
    G ---|"tested_by"| J

    click A "https://github.com/3l-d1abl0/gomon/blob/trunk/main.go"
    click D "https://github.com/3l-d1abl0/gomon/blob/trunk/middlewares/logger.go"
    click E "https://github.com/3l-d1abl0/gomon/blob/trunk/middlewares/headers.go"
    click F "https://github.com/3l-d1abl0/gomon/blob/trunk/api/api.go"
    click G "https://github.com/3l-d1abl0/gomon/blob/trunk/sysinfo/sysinfo.go"
    click H "https://github.com/3l-d1abl0/gomon/blob/trunk/commonData/common.go"
    click I "https://github.com/3l-d1abl0/gomon/blob/trunk/main_test.go"
    click J "https://github.com/3l-d1abl0/gomon/blob/trunk/sysinfo/sysinfo_test.go"

    classDef mainApp fill:#FFD700,stroke:#DAA520,stroke-width:2px;
    classDef client fill:#87CEEB,stroke:#4682B4,stroke-width:2px;
    classDef middleware fill:#90EE90,stroke:#32CD32,stroke-width:2px;
    classDef api fill:#AFEEEE,stroke:#40E0D0,stroke-width:2px;
    classDef sysinfo fill:#FFB6C1,stroke:#FF69B4,stroke-width:2px;
    classDef commonData fill:#E6E6FA,stroke:#9370DB,stroke-width:2px;
    classDef test fill:#D3D3D3,stroke:#A9A9A9,stroke-width:2px;
```
