# jeffrey-p-mcateer/sonarqube-rust-sensor architecture

> Architecture diagram of the GitHub repository jeffrey-p-mcateer/sonarqube-rust-sensor, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jeffrey-p-mcateer/sonarqube-rust-sensor
- Repository: https://github.com/jeffrey-p-mcateer/sonarqube-rust-sensor

## Overview

The project is a SonarQube language plugin that adds Rust support to the SonarQube ecosystem. In essence, it lets SonarQube analyze Rust code and report issues using Clippy lint rules. The repository contains both Java-based core plugin code (within the sonarqube-rust-sensor directory) and several support scripts in Python to compile the sensor and perform scans. It also includes sample Rust code and configuration files to demonstrate the plugin’s functionality.

##### Main Components
- SonarQube Server (External Dependency): This is the platform where the sensor/plugin is deployed.
- SonarQube Rust Sensor Plugin: The core component found under the “sonarqube-rust-sensor” directory. This Java-based plugin integrates with the SonarQube server, defining rules, quality profiles, and the sensor logic for Rust.
- Within this directory, you see key Java classes:
○ RustSensorPlugin.java – Bootstraps the plugin.
○ RustSensor.java – Implements the sensor that performs code analysis.
○ RustRulesDefinition.java and RustQualityProfile.java – Define rules and quality profile configurations.
○ Other helper classes (e.g., ReadAllClippyRules, ReadReportedClippyLintsJson) to read and process Clippy lint data.
- Rust Code Under Analysis: The “example_rust_code” folder serves as sample input for scanning.
- Python Scripts and Utilities:
○ compile_scanner_and_scan_folder.py – A script that builds the sensor and initiates a scan.
○ run_sonarqube_server.py – Likely used for starting a test SonarQube server instance.
○ system_test.py – Holds system-level tests.
○ download_stable_clippy_lints_to_json.py – A utility to fetch Clippy lint rule definitions.
- Build and Deployment Tools:
○ pom.xml in the sensor’s directory for building the Java artifact (the plugin JAR).
○ Cargo.toml and Cargo.lock in the example Rust code, for building Rust projects that will be analyzed.
- External Tools:
○ sonar-scanner (on the client) is used to send analysis results to the SonarQube server.
○ Java 8+ is required at runtime.
○ Dependencies for development (like uv, python, container tools) that support development and testing pipelines.

##### Diagramming the Relationships and Interactions
- “sonar-scanner” as an external client that sends code analysis data to the server.
- Python scripts as auxiliary components used to build and deploy the plugin:
- “compile_scanner_and_scan_folder.py” acts as a build and scan orchestrator.
- “run_sonarqube_server.py” helps in testing by starting a local SonarQube server container.
- External dependencies, for example, the Clippy lint definitions:
- The plugin fetches or reads from a json file (clippy-rules.json) under the resources that contains lint rules, which may have been downloaded via “download_stable_clippy_lints_to_json.py.”

##### Important Architectural Patterns and Design Principles
- Separation of Concerns: The architecture separates:
- The analysis logic embedded in the plugin,
- The build and deployment automation scripts,
- The sample code used for test analysis.
- Data Flow Direction: Data flow starts at the source code level (Rust files), is processed by the sonar-scanner (possibly invoking the sensor logic within the plugin) and then integrated into the SonarQube server for reporting.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Python Scripts
    P1["compile_scanner_and_scan_folder.py"]:::dev
    P2["run_sonarqube_server.py"]:::dev
    P3["download_stable_clippy_lints_to_json.py"]:::dev
    P4["system_test.py"]:::dev

    %% Sample Rust Code and Analysis Client
    ERC["Example Rust Code"]:::data
    SS["sonar-scanner"]:::runtime

    %% SonarQube Ecosystem Subgraph
    subgraph "SonarQube Ecosystem"
        direction TB
        SRSP["SonarQube Rust Sensor Plugin"]:::runtime
        subgraph "Plugin Components"
            direction TB
            PC["Plugin Core (Java)"]:::runtime
            CR["Clippy Rules JSON"]:::runtime
            BC["Build Config (pom.xml)"]:::runtime
        end
        SQS["SonarQube Server"]:::runtime
    end

    %% Relationships between Python Scripts, Plugin and Server
    P1 -->|"build&scan"| PC
    P2 -->|"start"| SQS
    P3 -->|"update rules"| CR
    P4 -->|"test"| SQS

    %% Data flow from Rust Code to Analysis and Reporting
    ERC -->|"source"| SS
    SS -->|"report"| SQS

    %% Plugin Registration and Internal Build Flow
    SRSP -->|"register_sensor"| SQS
    BC -->|"compile"| PC
    PC -->|"load_rules"| CR

    %% Click Events
    click SRSP "https://github.com/jeffrey-p-mcateer/sonarqube-rust-sensor/tree/master/sonarqube-rust-sensor/"
    click PC "https://github.com/jeffrey-p-mcateer/sonarqube-rust-sensor/tree/master/sonarqube-rust-sensor/src/main/java/com/jmcateer/sonarqube_rust_sensor/"
    click CR "https://github.com/jeffrey-p-mcateer/sonarqube-rust-sensor/blob/master/sonarqube-rust-sensor/src/main/resources/com/jmcateer/sonarqube_rust_sensor/clippy-rules.json"
    click BC "https://github.com/jeffrey-p-mcateer/sonarqube-rust-sensor/blob/master/sonarqube-rust-sensor/pom.xml"
    click P1 "https://github.com/jeffrey-p-mcateer/sonarqube-rust-sensor/blob/master/compile_scanner_and_scan_folder.py"
    click P2 "https://github.com/jeffrey-p-mcateer/sonarqube-rust-sensor/blob/master/run_sonarqube_server.py"
    click P3 "https://github.com/jeffrey-p-mcateer/sonarqube-rust-sensor/blob/master/download_stable_clippy_lints_to_json.py"
    click P4 "https://github.com/jeffrey-p-mcateer/sonarqube-rust-sensor/blob/master/system_test.py"
    click ERC "https://github.com/jeffrey-p-mcateer/sonarqube-rust-sensor/tree/master/example_rust_code/"

    %% Styles
    classDef runtime fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef dev fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef data fill:#FFFACD,stroke:#000,stroke-width:2px;
```
