# cppcheck-opensource/cppcheck architecture

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

- Interactive diagram: https://gitdiagram.com/cppcheck-opensource/cppcheck
- Repository: https://github.com/cppcheck-opensource/cppcheck

## Overview

Cppcheck is a static analyzer for C and C++. Its main workflow accepts source files and analysis settings, processes code into tokens and symbols, runs diagnostics, then presents or serializes findings. The tree also exposes a graphical client, project-import support, optional rule/add-on analysis, and report formats. The source index confirms selected imports and references; many runtime connections are unsampled, so those links are omitted or marked unverified rather than inferred as fact.

Main entry points: [`lib/cppcheck.cpp`](https://github.com/cppcheck-opensource/cppcheck/blob/main/lib/cppcheck.cpp) (Analysis engine), [`lib/errorlogger.h`](https://github.com/cppcheck-opensource/cppcheck/blob/main/lib/errorlogger.h) (Error reporting), [`lib/symboldatabase.cpp`](https://github.com/cppcheck-opensource/cppcheck/blob/main/lib/symboldatabase.cpp) (Symbol database), [`lib/settings.h`](https://github.com/cppcheck-opensource/cppcheck/blob/main/lib/settings.h) (Analysis settings)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["User interfaces"]
  node_cli["CLI entry<br/>[main.cpp]"]
  node_cli_executor["CLI execution"]
  node_cli_parser["Option parsing<br/>[cmdlineparser.cpp]"]
  node_gui["GUI entry<br/>[main.cpp]"]
  node_gui_window["Main window<br/>[mainwindow.cpp]"]
  node_gui_threads["Check threads<br/>[threadhandler.cpp]"]
end

subgraph group_analysis["Analysis engine"]
  node_file_settings["File configuration<br/>[filesettings.h]"]
  node_settings["Analysis settings<br/>[settings.h]"]
  node_preprocessor["Preprocessing<br/>[preprocessor.cpp]"]
  node_tokenizer["Tokenization<br/>[tokenize.cpp]"]
  node_symbols[("Symbol database<br/>[symboldatabase.cpp]")]
  node_valueflow["Value flow<br/>[valueflow.cpp]"]
  node_engine["Analysis engine<br/>[cppcheck.cpp]"]
end

subgraph group_diagnostics["Diagnostics and extensions"]
  node_checks["Code checks<br/>[checkother.cpp]"]
  node_project_import["Project import<br/>[importproject.cpp]"]
  node_addons["Python add-ons"]
end

subgraph group_outputs["Results and reports"]
  node_error_types["Diagnostic types<br/>[errortypes.h]"]
  node_error_logger["Error reporting<br/>[errorlogger.h]"]
  node_xml_report["XML reports<br/>[xmlreport.cpp]"]
  node_sarif_report["SARIF reports<br/>[sarifreport.cpp]"]
  node_gui_results["GUI results<br/>[resultsview.cpp]"]
end

node_user(("Analyst"))

node_user -->|"invokes"| node_cli
node_user -->|"opens"| node_gui
node_cli -->|"starts"| node_cli_executor
node_gui -->|"starts"| node_gui_window
node_gui_threads -->|"uses"| node_gui_results
node_file_settings -->|"configures"| node_settings
node_symbols -->|"reads"| node_settings
node_symbols -->|"uses tokens"| node_tokenizer
node_checks -.->|"analyzes"| node_symbols
node_engine -.->|"processes input"| node_preprocessor
node_engine -.->|"runs checks"| node_checks
node_engine -.->|"reports findings"| node_error_logger
node_error_logger -->|"formats"| node_error_types
node_engine -.->|"uses value analysis"| node_valueflow
node_cli_executor -.->|"runs analysis"| node_engine
node_cli_parser -.->|"sets options"| node_settings
node_project_import -.->|"creates file settings"| node_file_settings
node_addons -.->|"extends analysis"| node_engine
node_error_logger -.->|"supplies findings"| node_xml_report
node_error_logger -.->|"supplies findings"| node_sarif_report
node_gui_threads -.->|"runs checks"| node_engine
node_gui_results -.->|"displays findings"| node_error_types

click node_cli "https://github.com/cppcheck-opensource/cppcheck/blob/main/cli/main.cpp"
click node_cli_executor "https://github.com/cppcheck-opensource/cppcheck/blob/main/cli/cppcheckexecutor.cpp"
click node_cli_parser "https://github.com/cppcheck-opensource/cppcheck/blob/main/cli/cmdlineparser.cpp"
click node_gui "https://github.com/cppcheck-opensource/cppcheck/blob/main/gui/main.cpp"
click node_gui_window "https://github.com/cppcheck-opensource/cppcheck/blob/main/gui/mainwindow.cpp"
click node_gui_threads "https://github.com/cppcheck-opensource/cppcheck/blob/main/gui/threadhandler.cpp"
click node_file_settings "https://github.com/cppcheck-opensource/cppcheck/blob/main/lib/filesettings.h"
click node_settings "https://github.com/cppcheck-opensource/cppcheck/blob/main/lib/settings.h"
click node_preprocessor "https://github.com/cppcheck-opensource/cppcheck/blob/main/lib/preprocessor.cpp"
click node_tokenizer "https://github.com/cppcheck-opensource/cppcheck/blob/main/lib/tokenize.cpp"
click node_symbols "https://github.com/cppcheck-opensource/cppcheck/blob/main/lib/symboldatabase.cpp"
click node_valueflow "https://github.com/cppcheck-opensource/cppcheck/blob/main/lib/valueflow.cpp"
click node_engine "https://github.com/cppcheck-opensource/cppcheck/blob/main/lib/cppcheck.cpp"
click node_checks "https://github.com/cppcheck-opensource/cppcheck/blob/main/lib/checkother.cpp"
click node_project_import "https://github.com/cppcheck-opensource/cppcheck/blob/main/lib/importproject.cpp"
click node_addons "https://github.com/cppcheck-opensource/cppcheck/tree/main/addons"
click node_error_types "https://github.com/cppcheck-opensource/cppcheck/blob/main/lib/errortypes.h"
click node_error_logger "https://github.com/cppcheck-opensource/cppcheck/blob/main/lib/errorlogger.h"
click node_xml_report "https://github.com/cppcheck-opensource/cppcheck/blob/main/gui/xmlreport.cpp"
click node_sarif_report "https://github.com/cppcheck-opensource/cppcheck/blob/main/lib/sarifreport.cpp"
click node_gui_results "https://github.com/cppcheck-opensource/cppcheck/blob/main/gui/resultsview.cpp"

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_cli_executor,node_cli_parser,node_gui,node_gui_window,node_gui_threads toneBlue
class node_file_settings,node_settings,node_preprocessor,node_tokenizer,node_symbols,node_valueflow,node_engine toneAmber
class node_checks,node_project_import,node_addons toneMint
class node_error_types,node_error_logger,node_xml_report,node_sarif_report,node_gui_results toneRose
class node_user toneIndigo
```

## Components

### User interfaces

- [CLI entry](https://github.com/cppcheck-opensource/cppcheck/blob/main/cli/main.cpp): `cli/main.cpp`
- [CLI execution](https://github.com/cppcheck-opensource/cppcheck/blob/main/cli/cppcheckexecutor.cpp): `cli/cppcheckexecutor.cpp`
- [Option parsing](https://github.com/cppcheck-opensource/cppcheck/blob/main/cli/cmdlineparser.cpp): `cli/cmdlineparser.cpp`
- [GUI entry](https://github.com/cppcheck-opensource/cppcheck/blob/main/gui/main.cpp): `gui/main.cpp`
- [Main window](https://github.com/cppcheck-opensource/cppcheck/blob/main/gui/mainwindow.cpp): `gui/mainwindow.cpp`
- [Check threads](https://github.com/cppcheck-opensource/cppcheck/blob/main/gui/threadhandler.cpp): `gui/threadhandler.cpp`

### Analysis engine

- [File configuration](https://github.com/cppcheck-opensource/cppcheck/blob/main/lib/filesettings.h): `lib/filesettings.h`
- [Analysis settings](https://github.com/cppcheck-opensource/cppcheck/blob/main/lib/settings.h): `lib/settings.h`
- [Preprocessing](https://github.com/cppcheck-opensource/cppcheck/blob/main/lib/preprocessor.cpp): `lib/preprocessor.cpp`
- [Tokenization](https://github.com/cppcheck-opensource/cppcheck/blob/main/lib/tokenize.cpp): `lib/tokenize.cpp`
- [Symbol database](https://github.com/cppcheck-opensource/cppcheck/blob/main/lib/symboldatabase.cpp): `lib/symboldatabase.cpp`
- [Value flow](https://github.com/cppcheck-opensource/cppcheck/blob/main/lib/valueflow.cpp): `lib/valueflow.cpp`
- [Analysis engine](https://github.com/cppcheck-opensource/cppcheck/blob/main/lib/cppcheck.cpp): `lib/cppcheck.cpp`

### Diagnostics and extensions

- [Code checks](https://github.com/cppcheck-opensource/cppcheck/blob/main/lib/checkother.cpp): `lib/checkother.cpp`
- [Project import](https://github.com/cppcheck-opensource/cppcheck/blob/main/lib/importproject.cpp): `lib/importproject.cpp`
- [Python add-ons](https://github.com/cppcheck-opensource/cppcheck/tree/main/addons): `addons`

### Results and reports

- [Diagnostic types](https://github.com/cppcheck-opensource/cppcheck/blob/main/lib/errortypes.h): `lib/errortypes.h`
- [Error reporting](https://github.com/cppcheck-opensource/cppcheck/blob/main/lib/errorlogger.h): `lib/errorlogger.h`
- [XML reports](https://github.com/cppcheck-opensource/cppcheck/blob/main/gui/xmlreport.cpp): `gui/xmlreport.cpp`
- [SARIF reports](https://github.com/cppcheck-opensource/cppcheck/blob/main/lib/sarifreport.cpp): `lib/sarifreport.cpp`
- [GUI results](https://github.com/cppcheck-opensource/cppcheck/blob/main/gui/resultsview.cpp): `gui/resultsview.cpp`

### Other components

- **Analyst**

## Connections

- Analyst → CLI entry: invokes
- Analyst → GUI entry: opens (evidence: `gui/main.cpp`)
- CLI entry → CLI execution: starts (evidence: `cli/main.cpp`)
- GUI entry → Main window: starts (evidence: `gui/main.cpp`)
- Check threads → GUI results: uses (evidence: `gui/threadhandler.cpp`)
- File configuration → Analysis settings: configures (evidence: `lib/filesettings.h`)
- Symbol database → Analysis settings: reads (evidence: `lib/symboldatabase.cpp`)
- Symbol database → Tokenization: uses tokens (evidence: `lib/symboldatabase.cpp`)
- Code checks → Symbol database: analyzes
- Analysis engine → Preprocessing: processes input
- Analysis engine → Code checks: runs checks
- Analysis engine → Error reporting: reports findings
- Error reporting → Diagnostic types: formats (evidence: `lib/errorlogger.h`)
- Analysis engine → Value flow: uses value analysis
- CLI execution → Analysis engine: runs analysis
- Option parsing → Analysis settings: sets options
- Project import → File configuration: creates file settings
- Python add-ons → Analysis engine: extends analysis
- Error reporting → XML reports: supplies findings
- Error reporting → SARIF reports: supplies findings
- Check threads → Analysis engine: runs checks
- GUI results → Diagnostic types: displays findings
