# dotnet/roslyn-analyzers architecture

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

- Interactive diagram: https://gitdiagram.com/dotnet/roslyn-analyzers
- Repository: https://github.com/dotnet/roslyn-analyzers

## Overview

This project is the “Roslyn Analyzers” repository – a large, multi-package code analysis suite that extends the Roslyn compiler platform by providing a wide range of analyzers, code fixes, refactorings, and testing utilities for .NET projects. Its primary purpose is to supply high-quality static analysis rules (such as CAxxxx rules) for code quality, performance, security, and design, and is delivered as several NuGet packages (for example, Microsoft.CodeAnalysis.NetAnalyzers).

##### Core Components & Analyzer Engines
- An “Analyzer Core” module that encapsulates the common infrastructure shared by all analyzer packages. This includes the core utilities under the “src/NetAnalyzers/Core” directory and shared analyzer metadata (like AnalyzerReleases, rule configurations, etc).
- Language-Specific Analyzers: Separate submodules for C# and Visual Basic. For instance, within “src/NetAnalyzers/CSharp” you see rules for code quality, API design, maintainability, performance, etc.; similarly, the “VisualBasic” directories contain VB–specific implementations.
- Specialized Analyzers for different target frameworks: Although the newer package consolidates most analyzers into Microsoft.CodeAnalysis.NetAnalyzers, legacy components and migration support still exist (e.g. the FxCopAnalyzers and the Microsoft.CodeQuality/NetCore/NetFramework.Analyzers components). A block for these can note target-specific behavior (bailing out when a checked API isn’t available).

##### Testing and Validation Infrastructure
- Unit Tests and Integration Tests: A large portion of the repository is dedicated to unit tests (e.g., “src/NetAnalyzers/UnitTests”) and performance tests (“src/PerformanceTests”) to validate the analyzers.
- Test Utilities and Frameworks: The “src/Test.Utilities”, “src/Utilities”, and various “FlowAnalysis” directories contain shared test code and utilities for verifying analyzer correctness.
- Code Metrics and Refactoring utilities: Components residing in “src/Utilities/Compiler”, “src/Utilities/FlowAnalysis”, and “src/Utilities/Refactoring” provide common functions that the analyzers and tests depend on.

##### Build, Automation, and CI/CD
- Build and Configuration: The repository includes several build scripts and configuration files (e.g., “build.cmd”, “Test.cmd”, “Restore.cmd”, “Directory.Build.props/targets”, and the “eng” folder with extensive cross-platform build scripts and pipeline templates). This block should show how source code is restored, compiled, and prepared for testing.

##### Packaging and Distribution
- Tools & Utilities: Under “src/Tools” you have programs for generating documentation, configuration files, and even performance diff utilities. These support both packaging and developer documentation.

##### Developer and External Interaction
- Documentation and Guidelines: The “docs” and “GuidelinesForNewRules.md” files support developer onboarding, suggesting that there is external documentation available for both users of the analyzers and contributors.

– Source code & configuration (repository “src”, “eng”, “docs”, etc.) → Build/CI processes.
– Build outputs → Generated NuGet packages → Integration with IDEs and Roslyn.
– Testing Utilities → Unit Tests running as part of CI.
- Callouts for important technologies:
– .NET SDK and Roslyn compiler platform for analyzer integration.
– CI/CD technologies (Azure Pipelines, GitHub workflows).
– NuGet as the distribution medium.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Developer and External Interaction
    subgraph "Developer and External Interaction"
        extSys["Roslyn & IDE Integration"]:::external
        doc["Documentation & Guidelines"]:::doc
    end

    %% Packaging and Distribution
    subgraph "Packaging and Distribution"
        nugetPkg["NuGet Package Project"]:::packaging
        setupPack["Setup & Packaging"]:::packaging
        toolMain["Tools"]:::tools
        perfDiff["Perf Diff Utility"]:::tools
        releaseNotes["ReleaseNotes Utility"]:::tools
    end

    %% Build, Automation, and CI/CD
    subgraph "Build, Automation, and CI/CD"
        BP["Build Process"]:::build
        buildCmd["Build.cmd"]:::build
        testCmd["Test.cmd"]:::build
        restoreCmd["Restore.cmd"]:::build
        buildSh["build.sh"]:::build
        dirBuildProps["Directory.Build.props"]:::build
        dirBuildTargets["Directory.Build.targets"]:::build
        githubWorkflows["GitHub Workflows"]:::build
        azurePipelines["Azure Pipelines"]:::build
        eng["eng Directory"]:::build
    end

    %% Testing and Validation
    subgraph "Testing and Validation"
        tests["Unit & Integration Tests"]:::testing
        perfTests["Performance Tests"]:::testing
        testUtil["Test Utilities"]:::testing
    end

    %% Core Analyzer Engine
    subgraph "Core Analyzer Engine"
        analyzerCore["Analyzer Core"]:::core
        analyzerCSharp["C# Analyzers"]:::core
        analyzerVB["Visual Basic Analyzers"]:::core
        legacy["Legacy/Specialized Analyzers"]:::core
    end

    %% Relationships within Core Analyzer Engine
    analyzerCore --> analyzerCSharp
    analyzerCore --> analyzerVB
    analyzerCore --> legacy

    %% Flow: from Core to Build Process
    analyzerCore -->|"source"| BP
    buildCmd --> BP
    testCmd --> BP
    restoreCmd --> BP
    buildSh --> BP
    dirBuildProps --> BP
    dirBuildTargets --> BP
    githubWorkflows --> BP
    azurePipelines --> BP
    eng --> BP

    %% Flow: Build Process triggers Testing and Packaging
    BP --> tests
    BP --> nugetPkg

    %% Testing group internal relationship
    testUtil --> tests

    %% Packaging tools relationship
    toolMain --> nugetPkg
    perfDiff --> toolMain
    releaseNotes --> toolMain

    %% External integration from Packaging and Documentation
    nugetPkg --> extSys
    doc --> extSys

    %% Click Events
    click analyzerCore "https://github.com/dotnet/roslyn-analyzers/tree/main/src/NetAnalyzers/Core"
    click analyzerCSharp "https://github.com/dotnet/roslyn-analyzers/tree/main/src/NetAnalyzers/CSharp"
    click analyzerVB "https://github.com/dotnet/roslyn-analyzers/tree/main/src/NetAnalyzers/VisualBasic"
    click legacy "https://github.com/dotnet/roslyn-analyzers/blob/main/src/NetAnalyzers/Core/Microsoft.NetFramework.Analyzers"
    click tests "https://github.com/dotnet/roslyn-analyzers/tree/main/src/NetAnalyzers/UnitTests"
    click perfTests "https://github.com/dotnet/roslyn-analyzers/tree/main/src/PerformanceTests"
    click testUtil "https://github.com/dotnet/roslyn-analyzers/blob/main/src/Test.Utilities"
    click buildCmd "https://github.com/dotnet/roslyn-analyzers/blob/main/Build.cmd"
    click testCmd "https://github.com/dotnet/roslyn-analyzers/blob/main/Test.cmd"
    click restoreCmd "https://github.com/dotnet/roslyn-analyzers/blob/main/Restore.cmd"
    click buildSh "https://github.com/dotnet/roslyn-analyzers/blob/main/build.sh"
    click dirBuildProps "https://github.com/dotnet/roslyn-analyzers/blob/main/Directory.Build.props"
    click dirBuildTargets "https://github.com/dotnet/roslyn-analyzers/blob/main/Directory.Build.targets"
    click githubWorkflows "https://github.com/dotnet/roslyn-analyzers/tree/main/.github/workflows"
    click azurePipelines "https://github.com/dotnet/roslyn-analyzers/blob/main/azure-pipelines*.yml"
    click eng "https://github.com/dotnet/roslyn-analyzers/tree/main/eng/"
    click nugetPkg "https://github.com/dotnet/roslyn-analyzers/blob/main/nuget/NetAnalyzers/Microsoft.CodeAnalysis.NetAnalyzers.Package.csproj"
    click setupPack "https://github.com/dotnet/roslyn-analyzers/tree/main/src/NetAnalyzers/Setup"
    click toolMain "https://github.com/dotnet/roslyn-analyzers/tree/main/src/Tools"
    click perfDiff "https://github.com/dotnet/roslyn-analyzers/tree/main/src/Tools/PerfDiff"
    click releaseNotes "https://github.com/dotnet/roslyn-analyzers/tree/main/src/Tools/ReleaseNotesUtil"
    click doc "https://github.com/dotnet/roslyn-analyzers/tree/main/docs"

    %% Styles
    classDef core fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef testing fill:#D5F5E3,stroke:#196F3D,stroke-width:2px;
    classDef build fill:#F9E79F,stroke:#B9770E,stroke-width:2px;
    classDef packaging fill:#FAD7A0,stroke:#BA4A00,stroke-width:2px;
    classDef external fill:#E8DAEF,stroke:#6C3483,stroke-width:2px;
    classDef doc fill:#D6DBDF,stroke:#566573,stroke-width:2px;
    classDef tools fill:#FDEBD0,stroke:#CB4335,stroke-width:2px;
```
