# neal-c/gh-ghpm architecture

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

- Interactive diagram: https://gitdiagram.com/neal-c/gh-ghpm
- Repository: https://github.com/neal-c/gh-ghpm

## Overview

##### Main Components
a. User & Environment
- Developer machine / terminal
- Installed GitHub CLI (gh) with the gh-ghpm extension
b. gh-ghpm CLI Extension (Go application)
- Entry point: main.go
- internal/cli package:
– root.go (command setup & flags)
– thanos_snap.go (batch-private logic)
– version.go (version command)
- Configuration: staticcheck.conf, go.mod/go.sum
c. GitHub API (external service)
- Repos list endpoint
- Edit repo endpoint
d. CI/CD Pipeline (GitHub Actions)
- .github/workflows/release.yaml for automated releases

##### Relationships & Data Flows
1. User runs “gh ghpm [command]” in terminal.
2. gh invokes the extension binary.
3. The Go binary parses flags/commands via internal/cli/root.go.
4. For “thanos_snap”, it:
a. Calls GitHub API to list all user repos.
b. Filters out forks and repos with ≥1 star.
c. Sends edit-visibility requests to GitHub API for each remaining repo.
5. Responses from GitHub API are handled and output printed to the terminal.
6. CI/CD workflow triggers on new tags or commits, builds the Go binary, and publishes releases.

##### Architectural Patterns & Principles
- Single-binary CLI tool with modular internal packages (separation of concerns).
- Command-based architecture (root command + subcommands).
- External HTTP API integration with rate-limiting considerations (O(n) requests).
- CI/CD for continuous delivery.

##### Technologies, Frameworks & Libraries
- Go standard library (flag parsing, net/http)
- GitHub CLI extension mechanism
- GitHub REST API v3
- GitHub Actions for CI/CD

## Diagram (Mermaid)

```mermaid
flowchart TD
    User["User / Terminal"]:::user
    GHCLI["gh CLI"]:::user
    User --> GHCLI

    GHCLI --> Main

    subgraph "gh-ghpm Extension (Go)"
        Main["main.go"]:::core
        Root["root.go"]:::core
        Thanos["thanos_snap.go"]:::core
        Version["version.go"]:::core
        GoMod["go.mod"]:::core
        GoSum["go.sum"]:::core
        StaticConf["staticcheck.conf"]:::core
    end

    Main --> Root
    Main --> GoMod
    Main --> GoSum
    Main --> StaticConf
    Root --> Thanos
    Root --> Version

    Thanos -->|"List repos & PATCH /repos"| GitHubAPI["GitHub API"]:::external
    GitHubAPI --> Thanos

    User -->|push/tags| CI["CI/CD (GitHub Actions)\n.github/workflows/release.yaml"]:::infra
    CI -->|"build & publish release"| Releases["Releases"]:::infra

    Docs["README.md\ndocs/docs.md"]:::infra
    License["LICENSE"]:::infra

    click Main "https://github.com/neal-c/gh-ghpm/blob/main/main.go"
    click Root "https://github.com/neal-c/gh-ghpm/blob/main/internal/cli/root.go"
    click Thanos "https://github.com/neal-c/gh-ghpm/blob/main/internal/cli/thanos_snap.go"
    click Version "https://github.com/neal-c/gh-ghpm/blob/main/internal/cli/version.go"
    click GoMod "https://github.com/neal-c/gh-ghpm/blob/main/go.mod"
    click GoSum "https://github.com/neal-c/gh-ghpm/blob/main/go.sum"
    click StaticConf "https://github.com/neal-c/gh-ghpm/blob/main/staticcheck.conf"
    click CI "https://github.com/neal-c/gh-ghpm/blob/main/.github/workflows/release.yaml"
    click Docs "https://github.com/neal-c/gh-ghpm/blob/main/README.md"
    click Docs "https://github.com/neal-c/gh-ghpm/blob/main/docs/docs.md"
    click License "https://github.com/neal-c/gh-ghpm/tree/main/LICENSE"

    classDef user fill:#D0E6FF,stroke:#0275d8,color:#000
    classDef core fill:#E6F3E6,stroke:#3C763D,color:#000
    classDef external fill:#FFE6CC,stroke:#FF8C00,color:#000
    classDef infra fill:#E6E6F3,stroke:#5D5D9A,color:#000
```
