# khanhnam-nathan/pyneat architecture

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

- Interactive diagram: https://gitdiagram.com/khanhnam-nathan/pyneat
- Repository: https://github.com/khanhnam-nathan/pyneat

## Overview

1. **Repository shape**
   This is a multi-language code analysis and cleanup platform centered on a Python package (`pyneat/`) with an optional Rust accelerator (`pyneat-rs/`). Around that core are IDE integrations, CLI entrypoints, security tooling, benchmarks, tests, and CI/CD workflows.

2. **Primary product boundary: Python package**
   The main user-facing engine lives in `pyneat/`. It exposes the CLI (`pyneat/cli.py`, `pyneat/__main__.py`), configuration loading (`config.py`, `config_loader.py`), the rule engine (`core/engine.py`), and the rule catalog under `pyneat/rules/`. This is the default runtime for scan/clean operations and the Python API.

3. **Core processing pipeline**
   The key flow is: source file or code string → parsing/normalization in `pyneat/core` and `pyneat/scanner` → rule evaluation from `pyneat/rules` → issue reporting and optional autofix → manifest/report export or in-place rewrite. The `core` package contains transformation safety boundaries such as atomic updates, scope/semantic guards, cleanup of markers, and type-related protections.

4. **Rule system architecture**
   Rules are organized by concern, not by language alone. `pyneat/rules/safe.py`, `conservative.py`, `destructive.py`, `quality.py`, `security.py`, and the language-specific subpackages (`go/`, `java/`, `javascript/`, `php/`, `ruby/`, `rust/`, `csharp/`, `multilang/`) define the scanning and fixing logic. Supporting files like `registry.py` and `security_registry.py` indicate centralized discovery/selection of rules and security severities.

5. **Security scanning as a first-class subsystem**
   Security functionality is not a thin addon; it is a parallel subsystem with its own rule packs (`security_pack/`), taint analysis (`taint_analysis.py`), secret classification, advisory integration, and vulnerability scanners under `pyneat/tools/security/`. The tests under `tests/test_security/` show coverage for common OWASP-style issues plus AI-specific risks.

6. **Reporting and export boundary**
   Output is standardized for downstream tools through report/manifest generation. The README references JSON, SARIF, HTML, Code Climate, and JUnit exports, while the repo includes manifest/export and marker cleanup support in `pyneat/core/manifest.py` and `marker_cleanup.py`. This boundary is what lets CI, GitHub code scanning, and editor integrations consume results consistently.

7. **Rust backend (`pyneat-rs`)**
   The Rust crate is a performance-oriented alternate engine that mirrors the Python product domain. It contains its own scanner, rule engine, fixer, SARIF writer, and LSP server. Important architectural pieces include tree-sitter parsing, an LN-AST abstraction (`ln_ast.rs`, `ln_ast_converter.rs`), multi-language scanners under `src/scanner/`, and language-specific rule sets under `src/rules/`.

8. **Cross-language scanning model in Rust**
   `pyneat-rs` is structured around language adapters for Python, JavaScript, TypeScript, Go, Java, PHP, Ruby, Rust, C#, and a multilang layer. Each adapter owns parsing and rule application for its language, while shared infrastructure in `scanner/base.rs`, `rules/base.rs`, and `scanner/multilang.rs` enables common behavior across languages.

9. **Editor and IDE integrations**
   There are three separate integration surfaces: a VSCode/Cursor extension under `vscode-extension/`, a JetBrains plugin under `jetbrains-plugin/`, and a Neovim LSP client wrapper under `nvim-lsp/`. These do not implement analysis themselves; they call into the backend, render diagnostics, offer quick fixes, and expose context actions. The VSCode extension also includes a wrapper around the CLI/backend and a sidebar/context-provider model.

10. **External integrations and ecosystem connectors**
   The Rust backend includes native integrations for GitHub, GitLab, and SonarQube under `pyneat-rs/src/integrations/`. The Python side also has security-oriented tooling under `pyneat/tools/` for SBOM generation, OSV advisory lookup, dependency scanning, and GitHub fuzzing. These pieces sit at the edges of the system and feed security intelligence into scans or reports.

11. **Validation, testing, and quality gates**
   The repo is heavily test-driven: Python tests cover engine behavior, rule behavior, integrations, fuzzing, marker cleanup, manifest export, multilang support, and security cases; Rust has integration tests and benches. Benchmarks exist on both sides, which matters architecturally because performance is a tracked feature, not just an implementation detail.

12. **Build, release, and governance layer**
   GitHub Actions and GitLab CI workflows handle build, publish, security scans, benchmarks, and releases. The presence of pre-commit hooks, packaging files, changelog/release docs, and dual Python/Rust build artifacts shows a distribution architecture that supports both library use and installed CLI/editor tooling.

13. **How the pieces fit together**
   The main architectural boundary is between “analysis logic” and “consumers.” Analysis logic lives in Python and Rust engines; consumers are CLI, Python API, IDE plugins, and CI integrations. Data typically enters as source text or files, is parsed into language-aware structures, transformed into findings/fixes, then emitted as patches, diagnostics, or standardized reports.

Main entry points: [`pyneat/core/engine.py`](https://github.com/khanhnam-nathan/pyneat/blob/main/pyneat/core/engine.py) (Engine), [`pyneat-rs/src/scanner`](https://github.com/khanhnam-nathan/pyneat/tree/main/pyneat-rs/src/scanner) (Rust scanner), [`.github/workflows/ci.yml`](https://github.com/khanhnam-nathan/pyneat/blob/main/.github/workflows/ci.yml) (CI/CD), [`tests`](https://github.com/khanhnam-nathan/pyneat/tree/main/tests) (Tests)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_python["Python package"]
  node_py_cli["CLI<br/>entrypoint<br/>[cli.py]"]
  node_py_config["Config<br/>[config.py]"]
  node_py_engine{{"Engine<br/>analysis core<br/>[engine.py]"}}
  node_py_core_guards["Guards<br/>safety layer"]
  node_py_manifest["Reports<br/>export<br/>[manifest.py]"]
  node_py_scanner["Scanner<br/>parser layer"]
  node_py_rules["Rules<br/>rule catalog"]
  node_py_security["Security<br/>[taint_analysis.py]"]
  node_py_plugins["Plugins<br/>extension api"]
  node_py_tools["Tools<br/>security tooling"]
end

subgraph group_group_rust["Rust accelerator"]
  node_rs_main["Rust CLI<br/>entrypoint<br/>[main.rs]"]
  node_rs_scanner{{"Rust scanner<br/>analysis core"}}
  node_rs_rules["Rust rules<br/>rule engine"]
  node_rs_fixer["Fixer<br/>rewrite engine"]
  node_rs_sarif["SARIF<br/>export"]
  node_rs_integrations["Integrations<br/>connectors"]
end

subgraph group_group_integrations["Integrations"]
  node_ide_vscode["VS Code<br/>editor extension<br/>[extension.ts]"]
  node_ide_jetbrains["JetBrains<br/>IDE plugin"]
  node_ide_nvim["Neovim<br/>LSP client<br/>[pyneat_lsp.lua]"]
end

subgraph group_group_quality["Quality gate"]
  node_qa_tests["Tests<br/>verification"]
  node_qa_bench["Benchmarks<br/>performance"]
  node_qa_ci["CI/CD<br/>delivery<br/>[ci.yml]"]
end

node_py_cli -->|"loads"| node_py_config
node_py_cli -->|"invokes"| node_py_engine
node_py_engine -->|"parses"| node_py_scanner
node_py_engine -->|"evaluates"| node_py_rules
node_py_engine -->|"protects"| node_py_core_guards
node_py_engine -->|"emits"| node_py_manifest
node_py_rules -->|"includes"| node_py_security
node_py_rules -->|"extends"| node_py_plugins
node_py_security -->|"feeds"| node_py_tools
node_rs_main -->|"drives"| node_rs_scanner
node_rs_scanner -->|"applies"| node_rs_rules
node_rs_scanner -->|"rewrites"| node_rs_fixer
node_rs_rules -->|"exports"| node_rs_sarif
node_rs_rules -->|"publishes"| node_rs_integrations
node_ide_vscode -->|"wraps"| node_py_cli
node_ide_vscode -->|"reads"| node_py_manifest
node_ide_jetbrains -->|"calls"| node_py_engine
node_ide_nvim -->|"connects"| node_py_cli
node_qa_tests -->|"verifies"| node_py_engine
node_qa_tests -->|"verifies"| node_py_security
node_qa_tests -->|"verifies"| node_rs_scanner
node_qa_bench -->|"measures"| node_py_engine
node_qa_bench -->|"measures"| node_rs_scanner
node_qa_ci -->|"runs"| node_qa_tests
node_qa_ci -->|"tracks"| node_qa_bench
node_qa_ci -->|"packages"| node_ide_vscode
node_qa_ci -->|"builds"| node_rs_main

click node_py_cli "https://github.com/khanhnam-nathan/pyneat/blob/main/pyneat/cli.py"
click node_py_config "https://github.com/khanhnam-nathan/pyneat/blob/main/pyneat/config.py"
click node_py_engine "https://github.com/khanhnam-nathan/pyneat/blob/main/pyneat/core/engine.py"
click node_py_core_guards "https://github.com/khanhnam-nathan/pyneat/tree/main/pyneat/core"
click node_py_manifest "https://github.com/khanhnam-nathan/pyneat/blob/main/pyneat/core/manifest.py"
click node_py_scanner "https://github.com/khanhnam-nathan/pyneat/tree/main/pyneat/scanner"
click node_py_rules "https://github.com/khanhnam-nathan/pyneat/tree/main/pyneat/rules"
click node_py_security "https://github.com/khanhnam-nathan/pyneat/blob/main/pyneat/rules/taint_analysis.py"
click node_py_plugins "https://github.com/khanhnam-nathan/pyneat/tree/main/pyneat/plugins"
click node_py_tools "https://github.com/khanhnam-nathan/pyneat/tree/main/pyneat/tools"
click node_rs_main "https://github.com/khanhnam-nathan/pyneat/blob/main/pyneat-rs/src/main.rs"
click node_rs_scanner "https://github.com/khanhnam-nathan/pyneat/tree/main/pyneat-rs/src/scanner"
click node_rs_rules "https://github.com/khanhnam-nathan/pyneat/tree/main/pyneat-rs/src/rules"
click node_rs_fixer "https://github.com/khanhnam-nathan/pyneat/tree/main/pyneat-rs/src/fixer"
click node_rs_sarif "https://github.com/khanhnam-nathan/pyneat/tree/main/pyneat-rs/src/sarif"
click node_rs_integrations "https://github.com/khanhnam-nathan/pyneat/tree/main/pyneat-rs/src/integrations"
click node_ide_vscode "https://github.com/khanhnam-nathan/pyneat/blob/main/vscode-extension/src/extension.ts"
click node_ide_jetbrains "https://github.com/khanhnam-nathan/pyneat/blob/main/jetbrains-plugin/src/main/kotlin/dev/pyneat/PyNEATInspection.kt"
click node_ide_nvim "https://github.com/khanhnam-nathan/pyneat/blob/main/nvim-lsp/pyneat_lsp.lua"
click node_qa_tests "https://github.com/khanhnam-nathan/pyneat/tree/main/tests"
click node_qa_bench "https://github.com/khanhnam-nathan/pyneat/tree/main/benchmarks"
click node_qa_ci "https://github.com/khanhnam-nathan/pyneat/blob/main/.github/workflows/ci.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_py_cli,node_py_config,node_py_engine,node_py_core_guards,node_py_manifest,node_py_scanner,node_py_rules,node_py_security,node_py_plugins,node_py_tools toneBlue
class node_rs_main,node_rs_scanner,node_rs_rules,node_rs_fixer,node_rs_sarif,node_rs_integrations toneAmber
class node_ide_vscode,node_ide_jetbrains,node_ide_nvim toneMint
class node_qa_tests,node_qa_bench,node_qa_ci toneRose
```

## Components

### Python package

Primary analysis engine, rules, scanners, and tools exposed to users and automation.

- [CLI](https://github.com/khanhnam-nathan/pyneat/blob/main/pyneat/cli.py): entrypoint · Command-line entrypoint and package launcher for scan/clean workflows. · `pyneat/cli.py`
- [Config](https://github.com/khanhnam-nathan/pyneat/blob/main/pyneat/config.py): config · Loads and normalizes runtime configuration and options. · `pyneat/config.py`
- [Engine](https://github.com/khanhnam-nathan/pyneat/blob/main/pyneat/core/engine.py): analysis core · Coordinates parsing, rule evaluation, fixes, and output generation. · `pyneat/core/engine.py`
- [Guards](https://github.com/khanhnam-nathan/pyneat/tree/main/pyneat/core): safety layer · Atomic updates, scope/semantic protections, type shielding, and marker cleanup. · `pyneat/core`
- [Reports](https://github.com/khanhnam-nathan/pyneat/blob/main/pyneat/core/manifest.py): export · Manifest and standardized report emission for downstream tools. · `pyneat/core/manifest.py`
- [Scanner](https://github.com/khanhnam-nathan/pyneat/tree/main/pyneat/scanner): parser layer · Python-side scanner adapter and language-aware preprocessing. · `pyneat/scanner`
- [Rules](https://github.com/khanhnam-nathan/pyneat/tree/main/pyneat/rules): rule catalog · Central rule registry plus quality, security, and language-specific rule packs. · `pyneat/rules`
- [Security](https://github.com/khanhnam-nathan/pyneat/blob/main/pyneat/rules/taint_analysis.py): security subsystem · Taint analysis, secret classification, advisory lookup, and vulnerability tooling. · `pyneat/rules/taint_analysis.py`
- [Plugins](https://github.com/khanhnam-nathan/pyneat/tree/main/pyneat/plugins): extension api · Builtin plugin surface for extending or customizing analysis behavior. · `pyneat/plugins`
- [Tools](https://github.com/khanhnam-nathan/pyneat/tree/main/pyneat/tools): security tooling · SBOM, OSV, dependency scanning, and GitHub fuzzing helpers. · `pyneat/tools`

### Rust accelerator

Optional high-performance backend mirroring the analysis domain in Rust.

- [Rust CLI](https://github.com/khanhnam-nathan/pyneat/blob/main/pyneat-rs/src/main.rs): entrypoint · Rust crate entrypoint for the accelerator and standalone usage. · `pyneat-rs/src/main.rs`
- [Rust scanner](https://github.com/khanhnam-nathan/pyneat/tree/main/pyneat-rs/src/scanner): analysis core · Tree-sitter-based scanning pipeline with LN-AST conversion and multilang adapters. · `pyneat-rs/src/scanner`
- [Rust rules](https://github.com/khanhnam-nathan/pyneat/tree/main/pyneat-rs/src/rules): rule engine · Shared Rust rule engine plus language and security rule sets. · `pyneat-rs/src/rules`
- [Fixer](https://github.com/khanhnam-nathan/pyneat/tree/main/pyneat-rs/src/fixer): rewrite engine · Applies fixes and computes diffs for rewritten source. · `pyneat-rs/src/fixer`
- [SARIF](https://github.com/khanhnam-nathan/pyneat/tree/main/pyneat-rs/src/sarif): export · Produces standardized SARIF output from Rust analysis results. · `pyneat-rs/src/sarif`
- [Integrations](https://github.com/khanhnam-nathan/pyneat/tree/main/pyneat-rs/src/integrations): connectors · GitHub, GitLab, and SonarQube integration layer. · `pyneat-rs/src/integrations`

### Integrations

Editor, IDE, and LSP entrypoints that consume analysis results.

- [VS Code](https://github.com/khanhnam-nathan/pyneat/blob/main/vscode-extension/src/extension.ts): editor extension · Extension UI, diagnostics, fixes, and backend wrapper for VS Code/Cursor. · `vscode-extension/src/extension.ts`
- [JetBrains](https://github.com/khanhnam-nathan/pyneat/blob/main/jetbrains-plugin/src/main/kotlin/dev/pyneat/PyNEATInspection.kt): IDE plugin · Kotlin plugin providing inspections, dialogs, actions, and window integration. · `jetbrains-plugin/src/main/kotlin/dev/pyneat/PyNEATInspection.kt`
- [Neovim](https://github.com/khanhnam-nathan/pyneat/blob/main/nvim-lsp/pyneat_lsp.lua): LSP client · Neovim wrapper that connects to the backend over LSP. · `nvim-lsp/pyneat_lsp.lua`

### Quality gate

Tests, benchmarks, and CI/release workflows that validate and ship the platform.

- [Tests](https://github.com/khanhnam-nathan/pyneat/tree/main/tests): verification · Python and Rust test suites covering engine, rules, security, multilang, and integration behavior. · `tests`
- [Benchmarks](https://github.com/khanhnam-nathan/pyneat/tree/main/benchmarks): performance · Benchmark suites tracking parsing, batch processing, scanner, and rule performance. · `benchmarks`
- [CI/CD](https://github.com/khanhnam-nathan/pyneat/blob/main/.github/workflows/ci.yml): delivery · GitHub Actions, GitLab, pre-commit, and release workflows. · `.github/workflows/ci.yml`

## Connections

- CLI → Config: loads · CLI initializes runtime options and settings.
- CLI → Engine: invokes · CLI drives the main analysis pipeline.
- Engine → Scanner: parses · Engine delegates source intake and normalization to scanner layers.
- Engine → Rules: evaluates · Engine applies the rule catalog to discovered code patterns.
- Engine → Guards: protects · Core safety boundaries guard rewrites and transformations.
- Engine → Reports: emits · Engine exports standardized findings and manifests.
- Rules → Security: includes · Security pack is a first-class subset of the rule system.
- Rules → Plugins: extends · Plugin layer can add or adapt rule behavior.
- Security → Tools: feeds · Security tooling enriches scanning with advisories and dependency intelligence.
- Rust CLI → Rust scanner: drives · Rust entrypoint starts the parsing and scanning pipeline.
- Rust scanner → Rust rules: applies · Scanner evaluates rules over parsed language structures.
- Rust scanner → Fixer: rewrites · Findings can be turned into automated fixes and diffs.
- Rust rules → SARIF: exports · Rust results can be serialized to SARIF.
- Rust rules → Integrations: publishes · Integration layer consumes results for external platforms.
- VS Code → CLI: wraps · VS Code extension shells out to or coordinates with the Python backend.
- VS Code → Reports: reads · Extension consumes standardized diagnostics and outputs.
- JetBrains → Engine: calls · JetBrains plugin uses backend analysis for inspections and actions.
- Neovim → CLI: connects · Neovim client talks to the backend through LSP-facing entrypoints.
- Tests → Engine: verifies · Tests cover core engine behavior and rule application.
- Tests → Security: verifies · Security suites validate taint, secrets, and vulnerability rules.
- Tests → Rust scanner: verifies · Rust and Python tests exercise scanner parity and behavior.
- Benchmarks → Engine: measures · Benchmarks track Python-side processing performance.
- Benchmarks → Rust scanner: measures · Benchmarks track Rust-side parsing and scanning throughput.
- CI/CD → Tests: runs · CI executes validation gates before release.
- CI/CD → Benchmarks: tracks · Performance workflows monitor regressions.
- CI/CD → VS Code: packages · Release workflows build editor artifacts.
- CI/CD → Rust CLI: builds · CI produces Rust binaries and release artifacts.
