# abanoubha/gobrew architecture

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

- Interactive diagram: https://gitdiagram.com/abanoubha/gobrew
- Repository: https://github.com/abanoubha/gobrew

## Overview

##### Main architectural layers & components
a. Presentation (CLI) Layer
– Component: gobrew CLI (main.go)
– Responsibilities: parse command-line flags, dispatch commands (`-l`, `-b`, `-s`, `-d`, etc.)
b. Application / Service Layer
– Component: Command Dispatcher
- Maps each sub-command to a service function
– Component: Language/Build-System Service
- Orchestrates data fetch + parsing + aggregation
c. Domain / Business-Logic Layer
– Component: DataFetcher
- Fetches Homebrew Core formulae JSON (via GitHub API or raw Git)
– Component: FormulaParser
- Parses each formula’s metadata, extracts language, build-system, deps
– Component: Analyzer
- Aggregates counts by language, versions, build systems, dependencies
d. Infrastructure / Integration Layer
– External Service: GitHub / Homebrew Core repository
– External Service: Snap Store (for distribution)
– Packaging: snap/snapcraft.yaml → Snapcraft build pipeline

##### Relationships & data flow
– User invokes `gobrew` CLI → CLI Layer
– CLI Layer → Command Dispatcher (flags → service method)
– Dispatcher → Language/Build-System Service
– Service → DataFetcher → HTTP GETs to GitHub/Homebrew
– DataFetcher → returns raw formula JSON/data
– FormulaParser → transforms raw data into structured records
– Analyzer → computes counts, filters, sorts
– Service → OutputFormatter → prints results to stdout
– User sees results in terminal
– Snapcraft packaging → takes built binary → publishes to Snap Store

##### Architectural patterns & design principles
– Layered Architecture: clear separation of CLI, services, domain logic, infra
– Single-binary modular design: all modules compile into one executable
– Dependency Injection (via function parameters) for testability
– Use of Go Modules (go.mod) for dependency management
– Snap packaging keeps runtime isolated (confined Snap)

##### Important technologies & libraries
– Go standard library: `flag` (CLI), `net/http` (data fetch), `encoding/json` (parse)
– Go Modules: go.mod / go.sum
– Snapcraft: snap/snapcraft.yaml for packaging & publishing
– Homebrew Core repository (GitHub) as data source

##### Detail without over-splitting
– Show sub-components only if they have distinct responsibilities

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Layers
    subgraph "User & CLI Layer"
        direction TB
        User("User"):::external
        gobrewCLI("gobrew CLI\n(main.go)"):::internal
    end

    subgraph "Application / Service Layer"
        direction TB
        cmdDispatcher("Command\nDispatcher"):::internal
        langService("Language/Build-System\nService"):::internal
        outputFormatter("OutputFormatter"):::internal
    end

    subgraph "Domain / Business-Logic Layer"
        direction TB
        dataFetcher("DataFetcher"):::internal
        formulaParser("FormulaParser"):::internal
        analyzer("Analyzer"):::internal
    end

    subgraph "Infrastructure / External Services & Packaging"
        direction TB
        GitHub("GitHub API\nHomebrew Core"):::external
        stdout("Stdout"):::external
        SnapStore("Snap Store"):::external
        snapPackaging("Snapcraft Build\n(snap/snapcraft.yaml)"):::packaging
    end

    subgraph "Project Artifacts"
        direction TB
        goMod("go.mod"):::internal
        goSum("go.sum"):::internal
        readme("readme.md"):::internal
        changelog("CHANGELOG.md"):::internal
        contrib("CONTRIBUTING.md"):::internal
    end

    %% Connections
    User --> gobrewCLI
    gobrewCLI --> cmdDispatcher
    cmdDispatcher --> langService
    langService --> dataFetcher
    dataFetcher -->|HTTP GET / JSON| GitHub
    GitHub -->|JSON data| dataFetcher
    dataFetcher --> formulaParser
    formulaParser --> analyzer
    analyzer --> outputFormatter
    outputFormatter --> stdout

    snapPackaging --> SnapStore

    %% Click Events
    click gobrewCLI "https://github.com/abanoubha/gobrew/blob/main/main.go"
    click goMod "https://github.com/abanoubha/gobrew/blob/main/go.mod"
    click goSum "https://github.com/abanoubha/gobrew/blob/main/go.sum"
    click snapPackaging "https://github.com/abanoubha/gobrew/blob/main/snap/snapcraft.yaml"
    click readme "https://github.com/abanoubha/gobrew/blob/main/readme.md"
    click changelog "https://github.com/abanoubha/gobrew/blob/main/CHANGELOG.md"
    click contrib "https://github.com/abanoubha/gobrew/blob/main/CONTRIBUTING.md"

    %% Styles
    classDef internal fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef external fill:#90EE90,stroke:#000,stroke-width:1px
    classDef packaging fill:#FFA500,stroke:#000,stroke-width:1px
```
