# panndabea/gosherpa architecture

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

- Interactive diagram: https://gitdiagram.com/panndabea/gosherpa
- Repository: https://github.com/panndabea/gosherpa

## Overview

#### Purpose and Runtime

GoSherpa is a Go 1.24 CLI for local, deterministic structural intelligence over Go modules/workspaces. It answers repository, symbol, call-graph, interface, impact, test, and pre-edit agent-context questions; it is not a hosted service. Primary executable entry point: `cmd/gosherpa/main.go`.

#### CLI Orchestration and Output Contract

Command registration, flag handling, dispatch, and terminal/JSON rendering are centralized in `cmd/gosherpa/command_registry.go`, `cmd/gosherpa/command_handlers.go`, and `cmd/gosherpa/cli_json.go`. The CLI exposes human-readable tables plus stable JSON envelopes for automation. Command-specific orchestration covers analysis, agent workflows, PR summaries, snapshots, and initialization in `cmd/gosherpa/analyze.go`, `cmd/gosherpa/agent.go`, and `cmd/gosherpa/pr.go`.

#### Repository Discovery and Semantic Analysis

The core analysis layer discovers repository roots, module/workspace layout, Go source, packages, symbols, references, calls, dependencies, tests, entrypoints, architecture, and risk. Its central repository model and scan/parse pipeline live in `internal/sherpa/repository.go`, `internal/sherpa/scan.go`, and `internal/sherpa/parse.go`. Semantic repository loading and caching form a boundary around Go-aware analysis in `internal/semantics/repository.go` and `internal/semantics/repository_cache.go`.

#### Symbol and Relationship Graph

Symbol indexing provides reusable symbol and relationship records, while Sherpa queries derive callers, callees, references, paths, dependencies, interfaces, and implementations. Key graph-facing components are `internal/symbolindex/index.go`, `internal/symbolindex/relationship.go`, and `internal/sherpa/relationship_records.go`; query implementations include `internal/sherpa/call.go`, `internal/sherpa/reference.go`, and `internal/sherpa/dependency.go`. This is the main boundary supplying structured facts to higher-level context and impact stages.

#### Snapshot and Configuration Layer

`init` persists repository settings and a reusable bounded inventory under `.gosherpa`; later commands may reuse it but must fall back to live analysis when missing, stale, invalid, or insufficient. Configuration and snapshot persistence are implemented in `internal/config/config.go`, `internal/snapshot/snapshot.go`, and wired by `cmd/gosherpa/init.go` and `cmd/gosherpa/snapshot_reuse.go`. Snapshot reuse is an optimization, not the source of truth.

#### Context, Impact, and Test Planning

Higher-level workflows convert analysis and Git diffs into bounded, ordered guidance for agents and developers. Agent-context reporting, byte limits, semantic reading order, and diff/file/package reports live in `internal/agentcontext/report.go`, `internal/agentcontext/semantic.go`, and `internal/agentcontext/diff_report.go`. Impact traversal and relationship evidence are in `internal/impact/report.go`, `internal/impact/diff.go`, and `internal/impact/snapshot_relationships.go`. Test inventory/planning is built in `internal/sherpa/test_inventory.go` and `internal/sherpa/test_plan.go`.

#### Git and GitHub Action Boundary

Local Git integration resolves base refs and changed files for diff-based context, impact, affected tests, and PR summaries via `internal/git/base.go` and `internal/git/diff.go`. GitHub is optional infrastructure: the composite action in `action.yml` runs the CLI against PR bases, produces step summaries, and uploads JSON artifacts. CI and GitHub Pages workflows reside in `.github/workflows/ci.yml` and `.github/workflows/pages.yml`.

Main entry points: [`internal/sherpa/relationship_records.go`](https://github.com/panndabea/gosherpa/blob/main/internal/sherpa/relationship_records.go) (Relationship queries), [`internal/sherpa/repository.go`](https://github.com/panndabea/gosherpa/blob/main/internal/sherpa/repository.go) (Repository scan and parse), [`cmd/gosherpa/agent.go`](https://github.com/panndabea/gosherpa/blob/main/cmd/gosherpa/agent.go) (Agent, analysis, and PR commands), [`cmd/gosherpa/command_handlers.go`](https://github.com/panndabea/gosherpa/blob/main/cmd/gosherpa/command_handlers.go) (Command handlers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["CLI Runtime"]
  node_main{{"gosherpa executable<br/>Go entrypoint<br/>[main.go]"}}
  node_command_registry["Command dispatch<br/>CLI registry"]
  node_command_handlers["Command handlers<br/>CLI orchestration"]
  node_output["Terminal and JSON output<br/>output contract<br/>[cli_json.go]"]
  node_workflow_commands["Agent, analysis, and PR commands<br/>command workflows<br/>[agent.go]"]
  node_init["Init and snapshot reuse<br/>persistence orchestration<br/>[init.go]"]
end

subgraph group_analysis["Analysis Core"]
  node_repo_scan["Repository scan and parse<br/>analysis pipeline<br/>[repository.go]"]
  node_semantic_repository["Go semantic loader<br/>semantic boundary<br/>[repository.go]"]
  node_symbol_index[("Symbol relationship index<br/>fact graph<br/>[index.go]")]
  node_relationship_queries["Relationship queries<br/>query layer"]
  node_test_planning["Test inventory and plan<br/>test analysis<br/>[test_inventory.go]"]
end

subgraph group_workflows["Guidance Workflows"]
  node_agent_context["Agent context reports<br/>context workflow<br/>[report.go]"]
  node_impact["Impact analysis<br/>impact workflow<br/>[report.go]"]
  node_git["Local Git diff<br/>VCS boundary<br/>[diff.go]"]
end

subgraph group_persistence["Local Persistence"]
  node_config["Repository settings<br/>local config<br/>[config.go]"]
  node_snapshot[("Reusable inventory snapshot<br/>local cache<br/>[snapshot.go]")]
end

subgraph group_integration["GitHub Integration"]
  node_github_action["GitHub composite action<br/>optional automation<br/>[action.yml]"]
  node_ci["CI workflow<br/>GitHub workflow<br/>[ci.yml]"]
  node_pages["Pages workflow<br/>GitHub workflow<br/>[pages.yml]"]
end

node_main -->|"starts"| node_command_registry
node_command_registry -->|"dispatches"| node_command_handlers
node_command_handlers -->|"renders through"| node_output
node_command_handlers -->|"requests analysis"| node_repo_scan
node_repo_scan -->|"loads Go semantics"| node_semantic_repository
node_semantic_repository -->|"supplies semantic facts"| node_symbol_index
node_repo_scan -->|"indexes discovered code"| node_symbol_index
node_symbol_index -->|"backs"| node_relationship_queries
node_relationship_queries -->|"informs"| node_test_planning
node_workflow_commands -->|"runs"| node_agent_context
node_workflow_commands -->|"runs"| node_impact
node_workflow_commands -->|"requests"| node_test_planning
node_git -->|"changed files"| node_agent_context
node_git -->|"diff input"| node_impact
node_relationship_queries -->|"structural context"| node_agent_context
node_relationship_queries -->|"relationship evidence"| node_impact
node_init -->|"writes settings"| node_config
node_init -->|"persists inventory"| node_snapshot
node_snapshot -.->|"reused when valid"| node_repo_scan
node_github_action -->|"invokes CLI"| node_main
node_ci -.->|"automation context"| node_github_action
node_pages -.->|"publishing context"| node_github_action

click node_main "https://github.com/panndabea/gosherpa/blob/main/cmd/gosherpa/main.go"
click node_command_registry "https://github.com/panndabea/gosherpa/blob/main/cmd/gosherpa/command_registry.go"
click node_command_handlers "https://github.com/panndabea/gosherpa/blob/main/cmd/gosherpa/command_handlers.go"
click node_output "https://github.com/panndabea/gosherpa/blob/main/cmd/gosherpa/cli_json.go"
click node_repo_scan "https://github.com/panndabea/gosherpa/blob/main/internal/sherpa/repository.go"
click node_semantic_repository "https://github.com/panndabea/gosherpa/blob/main/internal/semantics/repository.go"
click node_symbol_index "https://github.com/panndabea/gosherpa/blob/main/internal/symbolindex/index.go"
click node_relationship_queries "https://github.com/panndabea/gosherpa/blob/main/internal/sherpa/relationship_records.go"
click node_test_planning "https://github.com/panndabea/gosherpa/blob/main/internal/sherpa/test_inventory.go"
click node_agent_context "https://github.com/panndabea/gosherpa/blob/main/internal/agentcontext/report.go"
click node_impact "https://github.com/panndabea/gosherpa/blob/main/internal/impact/report.go"
click node_git "https://github.com/panndabea/gosherpa/blob/main/internal/git/diff.go"
click node_workflow_commands "https://github.com/panndabea/gosherpa/blob/main/cmd/gosherpa/agent.go"
click node_config "https://github.com/panndabea/gosherpa/blob/main/internal/config/config.go"
click node_snapshot "https://github.com/panndabea/gosherpa/blob/main/internal/snapshot/snapshot.go"
click node_init "https://github.com/panndabea/gosherpa/blob/main/cmd/gosherpa/init.go"
click node_github_action "https://github.com/panndabea/gosherpa/blob/main/action.yml"
click node_ci "https://github.com/panndabea/gosherpa/blob/main/.github/workflows/ci.yml"
click node_pages "https://github.com/panndabea/gosherpa/blob/main/.github/workflows/pages.yml"

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_command_registry,node_command_handlers,node_output,node_workflow_commands,node_init toneBlue
class node_repo_scan,node_semantic_repository,node_symbol_index,node_relationship_queries,node_test_planning toneAmber
class node_agent_context,node_impact,node_git toneMint
class node_config,node_snapshot toneRose
class node_github_action,node_ci,node_pages toneIndigo
```

## Components

### CLI Runtime

- [gosherpa executable](https://github.com/panndabea/gosherpa/blob/main/cmd/gosherpa/main.go): Go entrypoint · `cmd/gosherpa/main.go`
- [Command dispatch](https://github.com/panndabea/gosherpa/blob/main/cmd/gosherpa/command_registry.go): CLI registry · Registers commands, flags, handlers, and renderers. · `cmd/gosherpa/command_registry.go`
- [Command handlers](https://github.com/panndabea/gosherpa/blob/main/cmd/gosherpa/command_handlers.go): CLI orchestration · `cmd/gosherpa/command_handlers.go`
- [Terminal and JSON output](https://github.com/panndabea/gosherpa/blob/main/cmd/gosherpa/cli_json.go): output contract · Provides tables and stable JSON envelopes. · `cmd/gosherpa/cli_json.go`
- [Agent, analysis, and PR commands](https://github.com/panndabea/gosherpa/blob/main/cmd/gosherpa/agent.go): command workflows · `cmd/gosherpa/agent.go`
- [Init and snapshot reuse](https://github.com/panndabea/gosherpa/blob/main/cmd/gosherpa/init.go): persistence orchestration · Persists settings and reuses valid bounded inventories. · `cmd/gosherpa/init.go`

### Analysis Core

- [Repository scan and parse](https://github.com/panndabea/gosherpa/blob/main/internal/sherpa/repository.go): analysis pipeline · Discovers layout, source, packages, symbols, tests, and structural facts. · `internal/sherpa/repository.go`
- [Go semantic loader](https://github.com/panndabea/gosherpa/blob/main/internal/semantics/repository.go): semantic boundary · Loads and caches Go-aware repository semantics. · `internal/semantics/repository.go`
- [Symbol relationship index](https://github.com/panndabea/gosherpa/blob/main/internal/symbolindex/index.go): fact graph · Reusable symbols and relationship records for structural queries. · `internal/symbolindex/index.go`
- [Relationship queries](https://github.com/panndabea/gosherpa/blob/main/internal/sherpa/relationship_records.go): query layer · Derives calls, references, paths, dependencies, and implementations. · `internal/sherpa/relationship_records.go`
- [Test inventory and plan](https://github.com/panndabea/gosherpa/blob/main/internal/sherpa/test_inventory.go): test analysis · `internal/sherpa/test_inventory.go`

### Guidance Workflows

- [Agent context reports](https://github.com/panndabea/gosherpa/blob/main/internal/agentcontext/report.go): context workflow · Produces bounded semantic reading order and diff guidance. · `internal/agentcontext/report.go`
- [Impact analysis](https://github.com/panndabea/gosherpa/blob/main/internal/impact/report.go): impact workflow · Traverses relationship evidence for changed code. · `internal/impact/report.go`
- [Local Git diff](https://github.com/panndabea/gosherpa/blob/main/internal/git/diff.go): VCS boundary · Resolves base refs and changed files. · `internal/git/diff.go`

### Local Persistence

- [Repository settings](https://github.com/panndabea/gosherpa/blob/main/internal/config/config.go): local config · `internal/config/config.go`
- [Reusable inventory snapshot](https://github.com/panndabea/gosherpa/blob/main/internal/snapshot/snapshot.go): local cache · Optimization only; live analysis remains authoritative. · `internal/snapshot/snapshot.go`

### GitHub Integration

- [GitHub composite action](https://github.com/panndabea/gosherpa/blob/main/action.yml): optional automation · Runs CLI for PRs, summaries, and JSON artifacts. · `action.yml`
- [CI workflow](https://github.com/panndabea/gosherpa/blob/main/.github/workflows/ci.yml): GitHub workflow · `.github/workflows/ci.yml`
- [Pages workflow](https://github.com/panndabea/gosherpa/blob/main/.github/workflows/pages.yml): GitHub workflow · `.github/workflows/pages.yml`

## Connections

- gosherpa executable → Command dispatch: starts
- Command dispatch → Command handlers: dispatches
- Command handlers → Terminal and JSON output: renders through
- Command handlers → Repository scan and parse: requests analysis
- Repository scan and parse → Go semantic loader: loads Go semantics
- Go semantic loader → Symbol relationship index: supplies semantic facts
- Repository scan and parse → Symbol relationship index: indexes discovered code
- Symbol relationship index → Relationship queries: backs
- Relationship queries → Test inventory and plan: informs
- Agent, analysis, and PR commands → Agent context reports: runs
- Agent, analysis, and PR commands → Impact analysis: runs
- Agent, analysis, and PR commands → Test inventory and plan: requests
- Local Git diff → Agent context reports: changed files
- Local Git diff → Impact analysis: diff input
- Relationship queries → Agent context reports: structural context
- Relationship queries → Impact analysis: relationship evidence
- Init and snapshot reuse → Repository settings: writes settings
- Init and snapshot reuse → Reusable inventory snapshot: persists inventory
- Reusable inventory snapshot → Repository scan and parse: reused when valid
- GitHub composite action → gosherpa executable: invokes CLI
- CI workflow → GitHub composite action: automation context
- Pages workflow → GitHub composite action: publishing context
