# orlandorode97/gofetch architecture

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

- Interactive diagram: https://gitdiagram.com/orlandorode97/gofetch
- Repository: https://github.com/orlandorode97/gofetch

## Overview

##### Project type and purpose
- gofetch is a command‐line (CLI) application written in Go that replicates the functionality of neofetch/screenfetch/pfetch by gathering OS and hardware information and rendering it in the terminal alongside an ASCII “gopher.”
- Its primary use case is local environment inspection—no networking, no external services.

##### File structure
- Top-level
- cmd/main.go, cmd/version.go: CLI entry point and version command
- fetch/: core orchestrator that discovers and formats the data
- pkg/: platform-specific subdirectories (linux, macos, windows) each implementing collectors for CPU, memory, GPU, uptime, shell, resolution, kernel, etc.
- pkg/time: a small helper for time formatting
- Makefile & .github/workflows: build and CI pipelines
- Patterns
- Strategy/adapter pattern in pkg/{os}: a common interface for “collectors,” implemented per OS
- Single-responsibility modules: fetch does orchestration and formatting, pkg/* does platform data gathering

##### README for additional insights
- Build steps: Makefile supports cross-compilation for linux, macOS, Windows
- Dependencies: pure Go standard library, no external services or databases

a. Main components
- CLI Entry Point (cmd/main.go)
- Fetch Orchestrator (fetch/fetcher.go + fetch/output.go)
- Platform Collectors (pkg/linux, pkg/macos, pkg/windows)
- Time Formatter (pkg/time/time.go)
- Go Runtime & Standard Library (net/http, os, fmt, runtime)
- Build & CI Pipeline (Makefile + .github/workflows)

b. Relationships & data flow
1. User runs `gofetch` in terminal →
2. cmd/main invokes fetcher.Fetch() →
3. fetcher queries runtime.GOOS, selects correct pkg/{os}.Collect() →
4. Each collector calls OS system calls or reads `/proc` (Linux) / syscalls (macOS, Windows API) →
5. Data objects (CPUInfo, MemInfo, Uptime, ShellInfo, etc.) returned to fetcher →
6. fetcher merges them, applies TimeFormatter →
8. Terminal displays output

c. Architectural patterns & design principles
- Adapter/Strategy: pkg/* platforms implement a shared collector interface
- Modular layering: separation of concerns between orchestration (fetch), data gathering (pkg/*), presentation (output)
- Cross-compilation support via Makefile abstractions
- Test coverage: each pkg/* has its own unit tests validating correct parsing

d. Key technologies
- Go modules (go.mod / go.sum)
- Go standard library (os, fmt, runtime, time)
- Makefile for builds, GitHub Actions for CI & linting

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% CLI Layer
    subgraph "CLI Entry Point"
        MainGo["cmd/main.go"]:::blue
        VersionGo["cmd/version.go"]:::blue
    end
    MainGo -->|"invokes Fetch()"| FetcherNode
    VersionGo -->|"invokes Fetch()"| FetcherNode

    %% Core Logic
    subgraph "Core Logic"
        FetcherNode["fetch/fetcher.go"]:::blue
        OutputNode["fetch/output.go"]:::orange
        TimeFmt["pkg/time/time.go"]:::blue
    end
    FetcherNode -->|"applies TimeFormatter"| TimeFmt
    FetcherNode -->|"renders via output"| OutputNode

    %% Platform Collectors
    subgraph "Platform Collectors"
        subgraph "Linux"
            LinuxInit["pkg/linux/linux.go"]:::green
            LinuxCpu["pkg/linux/cpu.go"]:::green
            LinuxMem["pkg/linux/memory.go"]:::green
            LinuxGpu["pkg/linux/gpu.go"]:::green
            LinuxUptime["pkg/linux/uptime.go"]:::green
            LinuxShell["pkg/linux/shell.go"]:::green
            LinuxRes["pkg/linux/resolution.go"]:::green
            LinuxKernel["pkg/linux/kernel.go"]:::green
            LinuxOSVer["pkg/linux/os_version.go"]:::green
            LinuxName["pkg/linux/name.go"]:::green
            LinuxPkg["pkg/linux/package.go"]:::green
            LinuxDE["pkg/linux/desk_environment.go"]:::green
            LinuxTerm["pkg/linux/terminal.go"]:::green
        end
        subgraph "macOS"
            MacInit["pkg/macos/mac_os.go"]:::green
            MacCpu["pkg/macos/cpu.go"]:::green
            MacMem["pkg/macos/memory.go"]:::green
            MacGpu["pkg/macos/gpu.go"]:::green
            MacUptime["pkg/macos/uptime.go"]:::green
            MacShell["pkg/macos/shell.go"]:::green
            MacRes["pkg/macos/resolution.go"]:::green
            MacKernel["pkg/macos/kernel.go"]:::green
            MacOSVer["pkg/macos/os_version.go"]:::green
            MacName["pkg/macos/name.go"]:::green
            MacPkg["pkg/macos/package.go"]:::green
            MacDE["pkg/macos/desk_environment.go"]:::green
            MacTerm["pkg/macos/terminal.go"]:::green
        end
        subgraph "Windows"
            WinInit["pkg/windows/windows.go"]:::green
            WinCpu["pkg/windows/cpu.go"]:::green
            WinMem["pkg/windows/memory.go"]:::green
            WinGpu["pkg/windows/gpu.go"]:::green
            WinUptime["pkg/windows/uptime.go"]:::green
            WinShell["pkg/windows/shell.go"]:::green
            WinRes["pkg/windows/resolution.go"]:::green
            WinKernel["pkg/windows/kernel.go"]:::green
            WinOSVer["pkg/windows/os_version.go"]:::green
            WinName["pkg/windows/name.go"]:::green
            WinPkg["pkg/windows/package.go"]:::green
            WinDE["pkg/windows/desk_environment.go"]:::green
            WinTerm["pkg/windows/terminal.go"]:::green
        end
    end
    FetcherNode -->|"selects based on runtime.GOOS"| LinuxInit
    FetcherNode -->|"selects based on runtime.GOOS"| MacInit
    FetcherNode -->|"selects based on runtime.GOOS"| WinInit

    %% OS Kernel and Terminal
    subgraph "External Entities"
        OSKernel["OS Kernel (syscalls, /proc)"]:::gray
        Terminal["Terminal\n(UTF-8 & ANSI)"]:::gray
    end
    LinuxInit -->|"reads syscalls"| OSKernel
    MacInit -->|"reads syscalls"| OSKernel
    WinInit -->|"reads syscalls"| OSKernel
    OutputNode -->|"renders to"| Terminal

    %% Build & CI Pipeline
    subgraph "Build & CI Pipeline"
        Make["Makefile"]:::pipeline
        CI[".github/workflows/ci.yaml"]:::pipeline
        Lint[".github/workflows/linter.yaml"]:::pipeline
    end
    Make -->|"triggers"| CI
    Make -->|"triggers"| Lint

    %% Click Events
    click MainGo "https://github.com/orlandorode97/gofetch/blob/main/cmd/main.go"
    click VersionGo "https://github.com/orlandorode97/gofetch/blob/main/cmd/version.go"
    click FetcherNode "https://github.com/orlandorode97/gofetch/blob/main/fetch/fetcher.go"
    click OutputNode "https://github.com/orlandorode97/gofetch/blob/main/fetch/output.go"
    click TimeFmt "https://github.com/orlandorode97/gofetch/blob/main/pkg/time/time.go"
    click LinuxInit "https://github.com/orlandorode97/gofetch/blob/main/pkg/linux/linux.go"
    click LinuxCpu "https://github.com/orlandorode97/gofetch/blob/main/pkg/linux/cpu.go"
    click LinuxMem "https://github.com/orlandorode97/gofetch/blob/main/pkg/linux/memory.go"
    click LinuxGpu "https://github.com/orlandorode97/gofetch/blob/main/pkg/linux/gpu.go"
    click LinuxUptime "https://github.com/orlandorode97/gofetch/blob/main/pkg/linux/uptime.go"
    click LinuxShell "https://github.com/orlandorode97/gofetch/blob/main/pkg/linux/shell.go"
    click LinuxRes "https://github.com/orlandorode97/gofetch/blob/main/pkg/linux/resolution.go"
    click LinuxKernel "https://github.com/orlandorode97/gofetch/blob/main/pkg/linux/kernel.go"
    click LinuxOSVer "https://github.com/orlandorode97/gofetch/blob/main/pkg/linux/os_version.go"
    click LinuxName "https://github.com/orlandorode97/gofetch/blob/main/pkg/linux/name.go"
    click LinuxPkg "https://github.com/orlandorode97/gofetch/blob/main/pkg/linux/package.go"
    click LinuxDE "https://github.com/orlandorode97/gofetch/blob/main/pkg/linux/desk_environment.go"
    click LinuxTerm "https://github.com/orlandorode97/gofetch/blob/main/pkg/linux/terminal.go"
    click MacInit "https://github.com/orlandorode97/gofetch/blob/main/pkg/macos/mac_os.go"
    click MacCpu "https://github.com/orlandorode97/gofetch/blob/main/pkg/macos/cpu.go"
    click MacMem "https://github.com/orlandorode97/gofetch/blob/main/pkg/macos/memory.go"
    click MacGpu "https://github.com/orlandorode97/gofetch/blob/main/pkg/macos/gpu.go"
    click MacUptime "https://github.com/orlandorode97/gofetch/blob/main/pkg/macos/uptime.go"
    click MacShell "https://github.com/orlandorode97/gofetch/blob/main/pkg/macos/shell.go"
    click MacRes "https://github.com/orlandorode97/gofetch/blob/main/pkg/macos/resolution.go"
    click MacKernel "https://github.com/orlandorode97/gofetch/blob/main/pkg/macos/kernel.go"
    click MacOSVer "https://github.com/orlandorode97/gofetch/blob/main/pkg/macos/os_version.go"
    click MacName "https://github.com/orlandorode97/gofetch/blob/main/pkg/macos/name.go"
    click MacPkg "https://github.com/orlandorode97/gofetch/blob/main/pkg/macos/package.go"
    click MacDE "https://github.com/orlandorode97/gofetch/blob/main/pkg/macos/desk_environment.go"
    click MacTerm "https://github.com/orlandorode97/gofetch/blob/main/pkg/macos/terminal.go"
    click WinInit "https://github.com/orlandorode97/gofetch/blob/main/pkg/windows/windows.go"
    click WinCpu "https://github.com/orlandorode97/gofetch/blob/main/pkg/windows/cpu.go"
    click WinMem "https://github.com/orlandorode97/gofetch/blob/main/pkg/windows/memory.go"
    click WinGpu "https://github.com/orlandorode97/gofetch/blob/main/pkg/windows/gpu.go"
    click WinUptime "https://github.com/orlandorode97/gofetch/blob/main/pkg/windows/uptime.go"
    click WinShell "https://github.com/orlandorode97/gofetch/blob/main/pkg/windows/shell.go"
    click WinRes "https://github.com/orlandorode97/gofetch/blob/main/pkg/windows/resolution.go"
    click WinKernel "https://github.com/orlandorode97/gofetch/blob/main/pkg/windows/kernel.go"
    click WinOSVer "https://github.com/orlandorode97/gofetch/blob/main/pkg/windows/os_version.go"
    click WinName "https://github.com/orlandorode97/gofetch/blob/main/pkg/windows/name.go"
    click WinPkg "https://github.com/orlandorode97/gofetch/blob/main/pkg/windows/package.go"
    click WinDE "https://github.com/orlandorode97/gofetch/blob/main/pkg/windows/desk_environment.go"
    click WinTerm "https://github.com/orlandorode97/gofetch/blob/main/pkg/windows/terminal.go"
    click Make "https://github.com/orlandorode97/gofetch/tree/main/Makefile"
    click CI "https://github.com/orlandorode97/gofetch/blob/main/.github/workflows/ci.yaml"
    click Lint "https://github.com/orlandorode97/gofetch/blob/main/.github/workflows/linter.yaml"

    %% Styles
    classDef blue fill:#D6EAF8,stroke:#21618C,color:#1B4F72
    classDef green fill:#D5F5E3,stroke:#196F3D,color:#145A32
    classDef orange fill:#FAD7A0,stroke:#B9770E,color:#7E5109
    classDef gray fill:#E5E7E9,stroke:#566573,color:#2C3E50
    classDef pipeline fill:#FCF3CF,stroke:#F39C12,color:#B9770E,stroke-dasharray: 2 2
```
