# securego/gosec architecture

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

- Interactive diagram: https://gitdiagram.com/securego/gosec
- Repository: https://github.com/securego/gosec

## Overview

gosec is a Go security scanner: users invoke its CLI on Go packages, configure rules and exclusions, and receive findings in a selected report format. The runtime combines pattern-based AST rules with SSA analyzers and taint analysis; findings are represented as issues and can optionally receive AI-generated fix suggestions. A separate Go analysis adapter exposes scanning through the standard analysis framework. The CLI and report routing are visible in excerpts; some scanner wiring is only documented or indexed, so uncertain links are omitted or marked unverified.

Main entry points: [`issue/issue.go`](https://github.com/securego/gosec/blob/master/issue/issue.go) (Issue model), [`report/formatter.go`](https://github.com/securego/gosec/blob/master/report/formatter.go) (Report router), [`analyzer.go`](https://github.com/securego/gosec/blob/master/analyzer.go) (Scan engine), [`rules/rulelist.go`](https://github.com/securego/gosec/blob/master/rules/rulelist.go) (Rule catalog)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry points"]
  node_cli["gosec CLI<br/>[main.go]"]
end

subgraph group_scan["Scanning"]
  node_engine["Scan engine<br/>[analyzer.go]"]
  node_rule_framework["Rule framework<br/>[rule.go]"]
end

subgraph group_checks["Security checks"]
  node_rule_catalog["Rule catalog<br/>[rulelist.go]"]
  node_sql_rule["SQL rules<br/>[sql.go]"]
  node_file_rule["File rules<br/>[readfile.go]"]
  node_tls_rule["TLS rules<br/>[tls.go]"]
  node_other_rules["Other AST rules"]
  node_analyzer_catalog["Analyzer catalog<br/>[analyzerslist.go]"]
  node_ssa_checks["SSA analyzers"]
  node_context_check["Context analysis"]
  node_slice_check["Slice bounds<br/>[slice_bounds.go]"]
  node_range_check["Range analysis<br/>[range_analyzer.go]"]
  node_taint["Taint analysis<br/>[taint.go]"]
end

subgraph group_results["Findings and output"]
  node_finding["Issue model<br/>[issue.go]"]
  node_report_router["Report router<br/>[formatter.go]"]
  node_sarif["SARIF output<br/>[formatter.go]"]
  node_text_output["Text output<br/>[writer.go]"]
  node_sonar_output["Sonar output<br/>[formatter.go]"]
  node_junit_output["JUnit output<br/>[formatter.go]"]
  node_other_outputs["Other formats"]
end

subgraph group_integration["Integrations"]
  node_autofix["AI fix suggestions<br/>[ai.go]"]
  node_goanalysis["Go analysis adapter<br/>[analyzer.go]"]
end

node_user(("Scanner user"))

node_user -->|"invokes"| node_cli
node_cli -.->|"runs scan"| node_engine
node_engine -.->|"uses"| node_rule_framework
node_engine -.->|"loads analyzers"| node_analyzer_catalog
node_engine -->|"records findings"| node_finding
node_rule_catalog -.->|"registers"| node_sql_rule
node_rule_catalog -.->|"registers"| node_file_rule
node_rule_catalog -.->|"registers"| node_tls_rule
node_rule_catalog -.->|"registers"| node_other_rules
node_sql_rule -->|"creates issue"| node_finding
node_file_rule -->|"creates issue"| node_finding
node_tls_rule -->|"creates issue"| node_finding
node_analyzer_catalog -.->|"registers"| node_ssa_checks
node_ssa_checks -.->|"includes"| node_context_check
node_ssa_checks -.->|"includes"| node_slice_check
node_ssa_checks -.->|"includes"| node_range_check
node_context_check -->|"creates issue"| node_finding
node_slice_check -->|"creates issue"| node_finding
node_taint -->|"creates issue"| node_finding
node_cli -->|"routes report"| node_report_router
node_report_router -->|"writes SARIF"| node_sarif
node_report_router -->|"writes text"| node_text_output
node_report_router -->|"writes Sonar"| node_sonar_output
node_report_router -->|"writes JUnit"| node_junit_output
node_report_router -->|"writes formats"| node_other_outputs
node_finding -->|"formats findings"| node_sarif
node_finding -->|"formats findings"| node_sonar_output
node_finding -->|"formats findings"| node_junit_output
node_finding -->|"formats findings"| node_text_output
node_cli -.->|"requests fixes"| node_autofix
node_goanalysis -->|"runs analysis"| node_engine

click node_cli "https://github.com/securego/gosec/blob/master/cmd/gosec/main.go"
click node_engine "https://github.com/securego/gosec/blob/master/analyzer.go"
click node_rule_framework "https://github.com/securego/gosec/blob/master/rule.go"
click node_rule_catalog "https://github.com/securego/gosec/blob/master/rules/rulelist.go"
click node_sql_rule "https://github.com/securego/gosec/blob/master/rules/sql.go"
click node_file_rule "https://github.com/securego/gosec/blob/master/rules/readfile.go"
click node_tls_rule "https://github.com/securego/gosec/blob/master/rules/tls.go"
click node_other_rules "https://github.com/securego/gosec/tree/master/rules"
click node_analyzer_catalog "https://github.com/securego/gosec/blob/master/analyzers/analyzerslist.go"
click node_ssa_checks "https://github.com/securego/gosec/tree/master/analyzers"
click node_context_check "https://github.com/securego/gosec/blob/master/analyzers/context_propagation.go"
click node_slice_check "https://github.com/securego/gosec/blob/master/analyzers/slice_bounds.go"
click node_range_check "https://github.com/securego/gosec/blob/master/analyzers/range_analyzer.go"
click node_taint "https://github.com/securego/gosec/blob/master/taint/taint.go"
click node_finding "https://github.com/securego/gosec/blob/master/issue/issue.go"
click node_report_router "https://github.com/securego/gosec/blob/master/report/formatter.go"
click node_sarif "https://github.com/securego/gosec/blob/master/report/sarif/formatter.go"
click node_text_output "https://github.com/securego/gosec/blob/master/report/text/writer.go"
click node_sonar_output "https://github.com/securego/gosec/blob/master/report/sonar/formatter.go"
click node_junit_output "https://github.com/securego/gosec/blob/master/report/junit/formatter.go"
click node_other_outputs "https://github.com/securego/gosec/tree/master/report"
click node_autofix "https://github.com/securego/gosec/blob/master/autofix/ai.go"
click node_goanalysis "https://github.com/securego/gosec/blob/master/goanalysis/analyzer.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_cli,node_user toneBlue
class node_engine,node_rule_framework toneAmber
class node_rule_catalog,node_sql_rule,node_file_rule,node_tls_rule,node_other_rules,node_analyzer_catalog,node_ssa_checks,node_context_check,node_slice_check,node_range_check,node_taint toneMint
class node_finding,node_report_router,node_sarif,node_text_output,node_sonar_output,node_junit_output,node_other_outputs toneRose
class node_autofix,node_goanalysis toneIndigo
```

## Components

### Entry points

- [gosec CLI](https://github.com/securego/gosec/blob/master/cmd/gosec/main.go): `cmd/gosec/main.go`

### Scanning

- [Scan engine](https://github.com/securego/gosec/blob/master/analyzer.go): `analyzer.go`
- [Rule framework](https://github.com/securego/gosec/blob/master/rule.go): `rule.go`

### Security checks

- [Rule catalog](https://github.com/securego/gosec/blob/master/rules/rulelist.go): `rules/rulelist.go`
- [SQL rules](https://github.com/securego/gosec/blob/master/rules/sql.go): `rules/sql.go`
- [File rules](https://github.com/securego/gosec/blob/master/rules/readfile.go): `rules/readfile.go`
- [TLS rules](https://github.com/securego/gosec/blob/master/rules/tls.go): `rules/tls.go`
- [Other AST rules](https://github.com/securego/gosec/tree/master/rules): `rules`
- [Analyzer catalog](https://github.com/securego/gosec/blob/master/analyzers/analyzerslist.go): `analyzers/analyzerslist.go`
- [SSA analyzers](https://github.com/securego/gosec/tree/master/analyzers): `analyzers`
- [Context analysis](https://github.com/securego/gosec/blob/master/analyzers/context_propagation.go): `analyzers/context_propagation.go`
- [Slice bounds](https://github.com/securego/gosec/blob/master/analyzers/slice_bounds.go): `analyzers/slice_bounds.go`
- [Range analysis](https://github.com/securego/gosec/blob/master/analyzers/range_analyzer.go): `analyzers/range_analyzer.go`
- [Taint analysis](https://github.com/securego/gosec/blob/master/taint/taint.go): `taint/taint.go`

### Findings and output

- [Issue model](https://github.com/securego/gosec/blob/master/issue/issue.go): `issue/issue.go`
- [Report router](https://github.com/securego/gosec/blob/master/report/formatter.go): `report/formatter.go`
- [SARIF output](https://github.com/securego/gosec/blob/master/report/sarif/formatter.go): `report/sarif/formatter.go`
- [Text output](https://github.com/securego/gosec/blob/master/report/text/writer.go): `report/text/writer.go`
- [Sonar output](https://github.com/securego/gosec/blob/master/report/sonar/formatter.go): `report/sonar/formatter.go`
- [JUnit output](https://github.com/securego/gosec/blob/master/report/junit/formatter.go): `report/junit/formatter.go`
- [Other formats](https://github.com/securego/gosec/tree/master/report): `report`

### Integrations

- [AI fix suggestions](https://github.com/securego/gosec/blob/master/autofix/ai.go): `autofix/ai.go`
- [Go analysis adapter](https://github.com/securego/gosec/blob/master/goanalysis/analyzer.go): `goanalysis/analyzer.go`

### Other components

- **Scanner user**

## Connections

- Scanner user → gosec CLI: invokes
- gosec CLI → Scan engine: runs scan
- Scan engine → Rule framework: uses
- Scan engine → Analyzer catalog: loads analyzers (evidence: `analyzer.go`)
- Scan engine → Issue model: records findings (evidence: `analyzer.go`)
- Rule catalog → SQL rules: registers
- Rule catalog → File rules: registers
- Rule catalog → TLS rules: registers
- Rule catalog → Other AST rules: registers
- SQL rules → Issue model: creates issue (evidence: `rules/sql.go`)
- File rules → Issue model: creates issue (evidence: `rules/readfile.go`)
- TLS rules → Issue model: creates issue (evidence: `rules/tls.go`)
- Analyzer catalog → SSA analyzers: registers
- SSA analyzers → Context analysis: includes
- SSA analyzers → Slice bounds: includes
- SSA analyzers → Range analysis: includes
- Context analysis → Issue model: creates issue (evidence: `analyzers/context_propagation.go`)
- Slice bounds → Issue model: creates issue (evidence: `analyzers/slice_bounds.go`)
- Taint analysis → Issue model: creates issue
- gosec CLI → Report router: routes report (evidence: `cmd/gosec/main.go`)
- Report router → SARIF output: writes SARIF (evidence: `report/formatter.go`)
- Report router → Text output: writes text (evidence: `report/formatter.go`)
- Report router → Sonar output: writes Sonar (evidence: `report/formatter.go`)
- Report router → JUnit output: writes JUnit (evidence: `report/formatter.go`)
- Report router → Other formats: writes formats (evidence: `report/formatter.go`)
- Issue model → SARIF output: formats findings (evidence: `report/sarif/formatter.go`)
- Issue model → Sonar output: formats findings (evidence: `report/sonar/formatter.go`)
- Issue model → JUnit output: formats findings (evidence: `report/junit/formatter.go`)
- Issue model → Text output: formats findings (evidence: `report/text/writer.go`)
- gosec CLI → AI fix suggestions: requests fixes
- Go analysis adapter → Scan engine: runs analysis (evidence: `goanalysis/analyzer.go`)
