# ktaffy/gophercheck architecture

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

- Interactive diagram: https://gitdiagram.com/ktaffy/gophercheck
- Repository: https://github.com/ktaffy/gophercheck

## Overview

Gophercheck is a Go static performance-analysis CLI. Its main workflow loads configuration, collects Go files, parses and analyzes them with enabled detectors, then formats issues and a performance score for console/JSON or a file. Watch mode is a second entry path: filesystem events are filtered and debounced before the CLI reruns analysis. README capabilities are retained at detector level; the excerpts do not expose every detector’s internals or all analysis/report wiring.

Main entry points: [`internal/analyzer/ast_walker.go`](https://github.com/ktaffy/gophercheck/blob/master/internal/analyzer/ast_walker.go) (Analyzer engine), [`cmd/root.go`](https://github.com/ktaffy/gophercheck/blob/master/cmd/root.go) (CLI commands), [`internal/watcher/file_watcher.go`](https://github.com/ktaffy/gophercheck/blob/master/internal/watcher/file_watcher.go) (File watcher), [`main.go`](https://github.com/ktaffy/gophercheck/blob/master/main.go) (Program entry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["CLI workflow"]
  node_entry["Program entry<br/>[main.go]"]
  node_commands["CLI commands<br/>[root.go]"]
  node_config["Configuration<br/>[config.go]"]
  node_files["Go file collection<br/>[root.go]"]
end

subgraph group_analysis["Static analysis"]
  node_engine["Analyzer engine<br/>[ast_walker.go]"]
  node_context["Analysis context"]
  node_complexity["Complexity checks<br/>[complexity.go]"]
  node_function["Function length<br/>[function_length.go]"]
  node_loops["Nested-loop checks<br/>[nested_loops.go]"]
  node_strings["String concatenation<br/>[string_concat.go]"]
  node_memory["Memory allocation<br/>[memory_alloc.go]"]
  node_slice["Slice growth<br/>[slice_growth.go]"]
  node_structures["Data structures<br/>[data_structure.go]"]
  node_cycles["Import cycles<br/>[import_cycle.go]"]
end

subgraph group_results["Issues and reports"]
  node_issues["Issue results<br/>[issue.go]"]
  node_report["Report generator<br/>[report.go]"]
end

subgraph group_watch["Watch mode"]
  node_watcher["File watcher<br/>[file_watcher.go]"]
  node_debouncer["Event debouncer<br/>[debouncer.go]"]
end

node_user(("CLI user"))
node_output(("Report destination"))
node_filesystem(("Watched filesystem"))

node_user -->|"invokes"| node_entry
node_entry -->|"dispatches"| node_commands
node_commands -->|"loads"| node_config
node_commands -->|"collects"| node_files
node_commands -->|"runs analysis"| node_engine
node_commands -->|"generates report"| node_report
node_files -->|"provides files"| node_engine
node_engine -->|"uses context"| node_context
node_engine -->|"dispatches"| node_complexity
node_engine -->|"dispatches"| node_function
node_engine -->|"dispatches"| node_loops
node_engine -->|"dispatches"| node_strings
node_engine -->|"dispatches"| node_memory
node_engine -->|"dispatches"| node_slice
node_engine -->|"dispatches"| node_structures
node_engine -->|"dispatches"| node_cycles
node_engine -->|"accumulates"| node_issues
node_report -->|"reads"| node_issues
node_commands -->|"writes report"| node_output
node_commands -->|"starts watch"| node_watcher
node_filesystem -->|"emits changes"| node_watcher
node_watcher -->|"queues events"| node_debouncer
node_debouncer -->|"calls change handler"| node_commands

click node_entry "https://github.com/ktaffy/gophercheck/blob/master/main.go"
click node_commands "https://github.com/ktaffy/gophercheck/blob/master/cmd/root.go"
click node_config "https://github.com/ktaffy/gophercheck/blob/master/internal/config/config.go"
click node_files "https://github.com/ktaffy/gophercheck/blob/master/cmd/root.go"
click node_engine "https://github.com/ktaffy/gophercheck/blob/master/internal/analyzer/ast_walker.go"
click node_context "https://github.com/ktaffy/gophercheck/blob/master/internal/context/analysis_context.go"
click node_complexity "https://github.com/ktaffy/gophercheck/blob/master/internal/analyzer/detectors/complexity.go"
click node_function "https://github.com/ktaffy/gophercheck/blob/master/internal/analyzer/detectors/function_length.go"
click node_loops "https://github.com/ktaffy/gophercheck/blob/master/internal/analyzer/detectors/nested_loops.go"
click node_strings "https://github.com/ktaffy/gophercheck/blob/master/internal/analyzer/detectors/string_concat.go"
click node_memory "https://github.com/ktaffy/gophercheck/blob/master/internal/analyzer/detectors/memory_alloc.go"
click node_slice "https://github.com/ktaffy/gophercheck/blob/master/internal/analyzer/detectors/slice_growth.go"
click node_structures "https://github.com/ktaffy/gophercheck/blob/master/internal/analyzer/detectors/data_structure.go"
click node_cycles "https://github.com/ktaffy/gophercheck/blob/master/internal/analyzer/detectors/import_cycle.go"
click node_issues "https://github.com/ktaffy/gophercheck/blob/master/internal/models/issue.go"
click node_report "https://github.com/ktaffy/gophercheck/blob/master/internal/analyzer/report.go"
click node_watcher "https://github.com/ktaffy/gophercheck/blob/master/internal/watcher/file_watcher.go"
click node_debouncer "https://github.com/ktaffy/gophercheck/blob/master/internal/watcher/debouncer.go"

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_entry,node_commands,node_config,node_files,node_user toneBlue
class node_engine,node_context,node_complexity,node_function,node_loops,node_strings,node_memory,node_slice,node_structures,node_cycles toneAmber
class node_issues,node_report toneMint
class node_watcher,node_debouncer toneRose
class node_output,node_filesystem toneIndigo
```

## Components

### CLI workflow

- [Program entry](https://github.com/ktaffy/gophercheck/blob/master/main.go): `main.go`
- [CLI commands](https://github.com/ktaffy/gophercheck/blob/master/cmd/root.go): `cmd/root.go`
- [Configuration](https://github.com/ktaffy/gophercheck/blob/master/internal/config/config.go): `internal/config/config.go`
- [Go file collection](https://github.com/ktaffy/gophercheck/blob/master/cmd/root.go): `cmd/root.go`

### Static analysis

- [Analyzer engine](https://github.com/ktaffy/gophercheck/blob/master/internal/analyzer/ast_walker.go): `internal/analyzer/ast_walker.go`
- [Analysis context](https://github.com/ktaffy/gophercheck/blob/master/internal/context/analysis_context.go): `internal/context/analysis_context.go`
- [Complexity checks](https://github.com/ktaffy/gophercheck/blob/master/internal/analyzer/detectors/complexity.go): `internal/analyzer/detectors/complexity.go`
- [Function length](https://github.com/ktaffy/gophercheck/blob/master/internal/analyzer/detectors/function_length.go): `internal/analyzer/detectors/function_length.go`
- [Nested-loop checks](https://github.com/ktaffy/gophercheck/blob/master/internal/analyzer/detectors/nested_loops.go): `internal/analyzer/detectors/nested_loops.go`
- [String concatenation](https://github.com/ktaffy/gophercheck/blob/master/internal/analyzer/detectors/string_concat.go): `internal/analyzer/detectors/string_concat.go`
- [Memory allocation](https://github.com/ktaffy/gophercheck/blob/master/internal/analyzer/detectors/memory_alloc.go): `internal/analyzer/detectors/memory_alloc.go`
- [Slice growth](https://github.com/ktaffy/gophercheck/blob/master/internal/analyzer/detectors/slice_growth.go): `internal/analyzer/detectors/slice_growth.go`
- [Data structures](https://github.com/ktaffy/gophercheck/blob/master/internal/analyzer/detectors/data_structure.go): `internal/analyzer/detectors/data_structure.go`
- [Import cycles](https://github.com/ktaffy/gophercheck/blob/master/internal/analyzer/detectors/import_cycle.go): `internal/analyzer/detectors/import_cycle.go`

### Issues and reports

- [Issue results](https://github.com/ktaffy/gophercheck/blob/master/internal/models/issue.go): `internal/models/issue.go`
- [Report generator](https://github.com/ktaffy/gophercheck/blob/master/internal/analyzer/report.go): `internal/analyzer/report.go`

### Watch mode

- [File watcher](https://github.com/ktaffy/gophercheck/blob/master/internal/watcher/file_watcher.go): `internal/watcher/file_watcher.go`
- [Event debouncer](https://github.com/ktaffy/gophercheck/blob/master/internal/watcher/debouncer.go): `internal/watcher/debouncer.go`

### Other components

- **CLI user**
- **Report destination**
- **Watched filesystem**

## Connections

- CLI user → Program entry: invokes
- Program entry → CLI commands: dispatches
- CLI commands → Configuration: loads
- CLI commands → Go file collection: collects
- CLI commands → Analyzer engine: runs analysis
- CLI commands → Report generator: generates report
- Go file collection → Analyzer engine: provides files
- Analyzer engine → Analysis context: uses context
- Analyzer engine → Complexity checks: dispatches
- Analyzer engine → Function length: dispatches
- Analyzer engine → Nested-loop checks: dispatches
- Analyzer engine → String concatenation: dispatches
- Analyzer engine → Memory allocation: dispatches
- Analyzer engine → Slice growth: dispatches
- Analyzer engine → Data structures: dispatches
- Analyzer engine → Import cycles: dispatches
- Analyzer engine → Issue results: accumulates
- Report generator → Issue results: reads
- CLI commands → Report destination: writes report
- CLI commands → File watcher: starts watch
- Watched filesystem → File watcher: emits changes
- File watcher → Event debouncer: queues events
- Event debouncer → CLI commands: calls change handler
