# mshddev/sonacli architecture

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

- Interactive diagram: https://gitdiagram.com/mshddev/sonacli
- Repository: https://github.com/mshddev/sonacli

## Overview

1. **What this repo is**
   - `sonacli` is a Go-based command-line client for **SonarQube Community Build** only.
   - It runs locally on **Linux and macOS** and talks to a remote SonarQube server over HTTP.

2. **Top-level runtime shape**
   - The binary entrypoint is `main.go`.
   - `internal/cli` is the primary presentation layer: it defines the root command and subcommands, parses flags/args, and routes execution.
   - The command surface is organized around `auth`, `issue`, `project`, `star`, `skill`, `update`, and `version`.

3. **Configuration and auth boundary**
   - `internal/config` owns local persisted settings, especially the SonarQube server URL and user token established by `sonacli auth setup`.
   - `auth status` reads that local state back out, so the boundary is: user machine state in config, SonarQube credentials only used to reach the server.
   - This makes authentication a local bootstrap step rather than a long-lived service.

4. **SonarQube API integration**
   - `internal/sonarqube/client.go` is the HTTP client layer for SonarQube.
   - All server-facing features flow through this client: project listing, issue listing/showing, starring/un-starring, and any metadata lookups needed by the CLI.
   - The architectural boundary is clear: `internal/cli` handles UX and argument normalization; `internal/sonarqube` handles remote API calls and response handling.

5. **Issue and project workflows**
   - `issue` and `project` commands are the main read paths for consuming analysis results.
   - The CLI supports both direct issue keys and SonarQube issue URLs, so command handlers likely include parsing/normalization before calling the API client.
   - The `--pretty` style output in the README suggests formatting concerns are kept in the CLI layer rather than in the API client.

6. **Star operations**
   - `internal/cli/star.go` plus the SonarQube client provide a small mutation workflow for starring projects.
   - This is a separate command family from read-only listing, but it uses the same server/auth/config plumbing.

7. **Skill packaging subsystem**
   - `internal/agentskill` is a distinct subsystem for installing and uninstalling a packaged “skill” bundle.
   - The bundle is stored under `internal/agentskill/assets`, including `SKILL.md` and agent configuration such as `agents/openai.yaml`.
   - Architecturally, this is a filesystem distribution feature: the CLI ships assets with the binary and manages their placement on the user’s machine.

8. **Self-update and release distribution**
   - `internal/selfupdate` updates the installed binary in place by fetching a newer GitHub release.
   - The separate `install.sh` bootstrap script downloads the correct release archive for the user’s OS/CPU, verifies `checksums.txt`, and installs the binary.
   - That creates two related but distinct delivery paths: initial install via GitHub Releases, then in-app update via the updater subsystem.

9. **Documentation and demo/sample data**
   - `docs/` contains the command reference and a demo script/tape for showcasing flows.
   - `docs/_demo-source` and `tests/fixtures/sample-basic` are synthetic Go projects with `sonar-project.properties`, used to generate predictable SonarQube analysis data for demos and tests.
   - These directories are not runtime dependencies; they support documentation and reproducible examples.

10. **Testing and quality gates**
   - The repo mixes Go unit tests (`*_test.go`) with scenario-style markdown tests under `tests/`.
   - `tests/bin`, `tests/results`, and `tests/fixtures` indicate a harness that exercises the CLI end-to-end against controlled inputs and captures output.
   - This is important architecturally because the CLI behavior is driven by command output formatting, URL parsing, and remote API interactions.

11. **Build, CI, and release pipeline**
   - `Makefile` and GitHub Actions workflows (`ci.yml`, `release.yml`) orchestrate builds, tests, and releases.
   - Release artifacts are likely version-stamped from Git tags or `git describe`, matching the README’s note about `make build`.
   - The release pipeline matters because both the installer and self-update features depend on consistent GitHub release artifacts and checksums.

Main entry points: [`internal/cli/root.go`](https://github.com/mshddev/sonacli/blob/main/internal/cli/root.go) (Root cmd), [`internal/sonarqube/client.go`](https://github.com/mshddev/sonacli/blob/main/internal/sonarqube/client.go) (API client), [`internal/config/config.go`](https://github.com/mshddev/sonacli/blob/main/internal/config/config.go) (Config), [`tests/README.md`](https://github.com/mshddev/sonacli/blob/main/tests/README.md) (Scenario tests)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["CLI Runtime"]
  node_main(("main<br/>entrypoint<br/>[main.go]"))
  node_rootcmd["Root cmd<br/>command router<br/>[root.go]"]
  node_authcmd["Auth<br/>command<br/>[auth.go]"]
  node_issuecmd["Issue<br/>command<br/>[issue.go]"]
  node_projectcmd["Project<br/>command<br/>[project.go]"]
  node_starcmd["Star<br/>command<br/>[star.go]"]
  node_skillcmd["Skill<br/>command<br/>[skill.go]"]
  node_updatecmd["Update<br/>command<br/>[update.go]"]
  node_versioncmd["Version<br/>command<br/>[version.go]"]
end

subgraph group_server["SonarQube Integration"]
  node_sqclient["API client<br/>http client<br/>[client.go]"]
end

subgraph group_delivery["Delivery"]
  node_config[("Config<br/>local state<br/>[config.go]")]
  node_skillmgr["Skill mgr<br/>bundle manager<br/>[manager.go]"]
  node_skillassets["Skill assets<br/>packaged assets<br/>[assets.go]"]
  node_updater["Updater<br/>[updater.go]"]
  node_installer["Install script<br/>bootstrap script<br/>[install.sh]"]
end

subgraph group_support["Support"]
  node_docs["Docs<br/>documentation<br/>[cli.md]"]
  node_sampleapp["Sample app<br/>fixture project<br/>[auth.go]"]
  node_tests["Scenario tests<br/>test harness<br/>[README.md]"]
end

node_main -->|"starts"| node_rootcmd
node_rootcmd -->|"subcommand"| node_authcmd
node_rootcmd -->|"subcommand"| node_issuecmd
node_rootcmd -->|"subcommand"| node_projectcmd
node_rootcmd -->|"subcommand"| node_starcmd
node_rootcmd -->|"subcommand"| node_skillcmd
node_rootcmd -->|"subcommand"| node_updatecmd
node_rootcmd -->|"subcommand"| node_versioncmd
node_authcmd -->|"reads/writes"| node_config
node_issuecmd -->|"reads"| node_config
node_projectcmd -->|"reads"| node_config
node_starcmd -->|"reads"| node_config
node_issuecmd -->|"calls"| node_sqclient
node_projectcmd -->|"calls"| node_sqclient
node_starcmd -->|"calls"| node_sqclient
node_skillcmd -->|"uses"| node_skillmgr
node_skillmgr -->|"reads"| node_skillassets
node_updatecmd -->|"uses"| node_updater
node_installer -.->|"complements"| node_updater
node_docs -.->|"demonstrates"| node_sampleapp
node_tests -.->|"exercises"| node_rootcmd
node_tests -.->|"exercises"| node_sqclient
node_tests -.->|"exercises"| node_installer

click node_main "https://github.com/mshddev/sonacli/blob/main/main.go"
click node_rootcmd "https://github.com/mshddev/sonacli/blob/main/internal/cli/root.go"
click node_authcmd "https://github.com/mshddev/sonacli/blob/main/internal/cli/auth.go"
click node_issuecmd "https://github.com/mshddev/sonacli/blob/main/internal/cli/issue.go"
click node_projectcmd "https://github.com/mshddev/sonacli/blob/main/internal/cli/project.go"
click node_starcmd "https://github.com/mshddev/sonacli/blob/main/internal/cli/star.go"
click node_skillcmd "https://github.com/mshddev/sonacli/blob/main/internal/cli/skill.go"
click node_updatecmd "https://github.com/mshddev/sonacli/blob/main/internal/cli/update.go"
click node_versioncmd "https://github.com/mshddev/sonacli/blob/main/internal/cli/version.go"
click node_config "https://github.com/mshddev/sonacli/blob/main/internal/config/config.go"
click node_sqclient "https://github.com/mshddev/sonacli/blob/main/internal/sonarqube/client.go"
click node_skillmgr "https://github.com/mshddev/sonacli/blob/main/internal/agentskill/manager.go"
click node_skillassets "https://github.com/mshddev/sonacli/blob/main/internal/agentskill/assets.go"
click node_updater "https://github.com/mshddev/sonacli/blob/main/internal/selfupdate/updater.go"
click node_installer "https://github.com/mshddev/sonacli/blob/main/install.sh"
click node_docs "https://github.com/mshddev/sonacli/blob/main/docs/cli.md"
click node_sampleapp "https://github.com/mshddev/sonacli/blob/main/docs/_demo-source/src/auth.go"
click node_tests "https://github.com/mshddev/sonacli/blob/main/tests/README.md"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_rootcmd,node_authcmd,node_issuecmd,node_projectcmd,node_starcmd,node_skillcmd,node_updatecmd,node_versioncmd toneBlue
class node_sqclient toneAmber
class node_config,node_skillmgr,node_skillassets,node_updater,node_installer toneMint
class node_docs,node_sampleapp,node_tests toneRose
```

## Components

### CLI Runtime

Command parsing and user-facing execution

- [main](https://github.com/mshddev/sonacli/blob/main/main.go): entrypoint · CLI binary entrypoint · `main.go`
- [Root cmd](https://github.com/mshddev/sonacli/blob/main/internal/cli/root.go): command router · Top-level command wiring · `internal/cli/root.go`
- [Auth](https://github.com/mshddev/sonacli/blob/main/internal/cli/auth.go): command · Local server-token setup and status · `internal/cli/auth.go`
- [Issue](https://github.com/mshddev/sonacli/blob/main/internal/cli/issue.go): command · Issue lookup and listing flows · `internal/cli/issue.go`
- [Project](https://github.com/mshddev/sonacli/blob/main/internal/cli/project.go): command · Project listing and related views · `internal/cli/project.go`
- [Star](https://github.com/mshddev/sonacli/blob/main/internal/cli/star.go): command · Project starring actions · `internal/cli/star.go`
- [Skill](https://github.com/mshddev/sonacli/blob/main/internal/cli/skill.go): command · Skill install and uninstall UX · `internal/cli/skill.go`
- [Update](https://github.com/mshddev/sonacli/blob/main/internal/cli/update.go): command · In-app self-update command · `internal/cli/update.go`
- [Version](https://github.com/mshddev/sonacli/blob/main/internal/cli/version.go): command · Build and release version display · `internal/cli/version.go`

### SonarQube Integration

Remote API access and server workflows

- [API client](https://github.com/mshddev/sonacli/blob/main/internal/sonarqube/client.go): http client · SonarQube server API wrapper · `internal/sonarqube/client.go`

### Delivery

Install, update, and packaged skill assets

- [Config](https://github.com/mshddev/sonacli/blob/main/internal/config/config.go): local state · Persisted server URL and token · `internal/config/config.go`
- [Skill mgr](https://github.com/mshddev/sonacli/blob/main/internal/agentskill/manager.go): bundle manager · Installs packaged agent skill assets · `internal/agentskill/manager.go`
- [Skill assets](https://github.com/mshddev/sonacli/blob/main/internal/agentskill/assets.go): packaged assets · Embedded SKILL.md and agent config · `internal/agentskill/assets.go`
- [Updater](https://github.com/mshddev/sonacli/blob/main/internal/selfupdate/updater.go): release updater · Fetches and installs newer release binaries · `internal/selfupdate/updater.go`
- [Install script](https://github.com/mshddev/sonacli/blob/main/install.sh): bootstrap script · Downloads release archive and verifies checksums · `install.sh`

### Support

Docs, samples, and release tooling

- [Docs](https://github.com/mshddev/sonacli/blob/main/docs/cli.md): documentation · Command reference and demo tape · `docs/cli.md`
- [Sample app](https://github.com/mshddev/sonacli/blob/main/docs/_demo-source/src/auth.go): fixture project · Synthetic Go project for demos and tests · `docs/_demo-source/src/auth.go`
- [Scenario tests](https://github.com/mshddev/sonacli/blob/main/tests/README.md): test harness · Markdown scenarios and captured outputs · `tests/README.md`

## Connections

- main → Root cmd: starts · Binary initializes the command tree
- Root cmd → Auth: subcommand · Routes auth commands
- Root cmd → Issue: subcommand · Routes issue commands
- Root cmd → Project: subcommand · Routes project commands
- Root cmd → Star: subcommand · Routes starring commands
- Root cmd → Skill: subcommand · Routes skill management commands
- Root cmd → Update: subcommand · Routes update commands
- Root cmd → Version: subcommand · Routes version command
- Auth → Config: reads/writes · Persists and loads local SonarQube connection state
- Issue → Config: reads · Uses stored credentials for server access
- Project → Config: reads · Uses stored credentials for server access
- Star → Config: reads · Uses stored credentials for server access
- Issue → API client: calls · Fetches issues and resolves issue references
- Project → API client: calls · Fetches project data
- Star → API client: calls · Stars and unstars projects
- Skill → Skill mgr: uses · Installs or removes the skill bundle
- Skill mgr → Skill assets: reads · Uses embedded files as the install source
- Update → Updater: uses · Triggers in-place binary update
- Install script → Updater: complements · Initial install and in-app update form one delivery path
- Docs → Sample app: demonstrates · Docs and demo flows use a synthetic project
- Scenario tests → Root cmd: exercises · Scenario tests validate command behavior
- Scenario tests → API client: exercises · End-to-end tests cover remote API-driven flows
- Scenario tests → Install script: exercises · Install-script scenario coverage
