# microsoft/applicationinspector architecture

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

- Interactive diagram: https://gitdiagram.com/microsoft/applicationinspector
- Repository: https://github.com/microsoft/applicationinspector

## Overview

##### Project type and purpose
- This is a .NET-based open-source command-line tool (“Application Inspector”) whose purpose is to scan source code (many languages) for feature-detection by applying a large set of JSON-defined rules and emitting reports (HTML, JSON, text, SARIF).
- Key indicators:
- Multi-project .NET solution: CLI, Common, Logging, RulesEngine, AppInspector (core commands), Benchmarks, Tests
- README describes a CLI with commands: analyze, tagdiff, exporttags, verifyrules, packrules
- Rules are stored as JSON under AppInspector/rules and AppInspector.RulesEngine/Resources

##### File structure
- Top-level projects/modules:
- AppInspector.CLI – the command-line front end (argument parsing, command dispatch, Writers)
- AppInspector (or AppInspector.Commands) – core command implementations (AnalyzeCommand, ExportTagsCommand, etc.)
- AppInspector.RulesEngine – the rule-processing engine (RuleProcessor, SearchPattern, TypedRuleSet)
- AppInspector.Common – common utilities (file I/O, metadata helpers, exceptions, messaging)
- AppInspector.Logging – logging configuration and options
- AppInspector.Benchmarks – performance benchmarks against analyzers
- AppInspector.Tests – unit/integration tests
- Configuration and resources:
- JSON rule files under AppInspector/rules/default/...
- HTML templates under AppInspector.CLI/html
- .NET Build & deployment files (Directory.Build.props, publish profiles, pipelines YAML)

##### README for additional insights
- Describes architecture in prose: CLI tool with over 400 rules, outputs in multiple formats
- Usage flow: `appinspector analyze -s <path>` calls AnalyzeCommand → scans files → applies RulesEngine → writes report
- Dependencies: .NET 6 SDK, NuGet package distribution, platform-specific binaries

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Top Layer: User Interaction
    User["User"]:::external
    User -->|"runs"| CLI["CLI Front End"]:::frontend

    %% CLI Front End
    subgraph "CLI Front End"
        Program["Program.cs"]:::frontend
        CLICmdOptions["CLICmdOptions.cs"]:::frontend
    end
    CLI --> Program
    CLI --> CLICmdOptions

    %% Command Dispatcher & Handlers
    Program -->|"dispatches to"| Dispatcher["Command Dispatcher"]:::frontend
    subgraph "Command Handlers"
        AnalyzeCmd["AnalyzeCommand.cs"]:::frontend
        ExportTagsCmd["ExportTagsCommand.cs"]:::frontend
        PackRulesCmd["PackRulesCommand.cs"]:::frontend
        TagDiffCmd["TagDiffCommand.cs"]:::frontend
        VerifyRulesCmd["VerifyRulesCommand.cs"]:::frontend
    end
    Dispatcher --> AnalyzeCmd
    Dispatcher --> ExportTagsCmd
    Dispatcher --> PackRulesCmd
    Dispatcher --> TagDiffCmd
    Dispatcher --> VerifyRulesCmd

    %% Application Core Library
    subgraph "Core Application Library"
        CoreProj["AppInspector.Commands.csproj"]:::domain
        FileRecord["FileRecord.cs"]:::domain
        MetaDataHelper["MetaDataHelper.cs"]:::domain
        Result["Result.cs"]:::domain
        RuleSetUtils["RuleSetUtils.cs"]:::domain
        MetricTagCounter["MetricTagCounter.cs"]:::domain
        GitInformation["GitInformation.cs"]:::domain
        MetaData["MetaData.cs"]:::domain
    end
    AnalyzeCmd --> CoreProj
    ExportTagsCmd --> CoreProj
    PackRulesCmd --> CoreProj
    TagDiffCmd --> CoreProj
    VerifyRulesCmd --> CoreProj
    CoreProj --> FileRecord
    CoreProj --> MetaDataHelper
    CoreProj --> Result
    CoreProj --> RuleSetUtils
    CoreProj --> MetricTagCounter
    CoreProj --> GitInformation
    CoreProj --> MetaData

    %% Common Utilities
    subgraph "Common Utilities"
        Utils["Utils.cs"]:::domain
        OpException["OpException.cs"]:::domain
        MsgHelp["MsgHelp.cs"]:::domain
    end
    CoreProj --> Utils
    CoreProj --> OpException
    CoreProj --> MsgHelp

    %% Rules Engine Domain
    subgraph "Rules Engine"
        RuleLoader["AbstractRuleSet.cs"]:::domain
        RuleProcessor["RuleProcessor.cs"]:::domain
        SearchPattern["SearchPattern.cs"]:::domain
        TypedRuleSet["TypedRuleSet.cs"]:::domain
        OtherRE["(other .cs files)"]:::domain
    end
    CoreProj --> RuleLoader
    CoreProj --> RuleProcessor
    CoreProj --> SearchPattern
    CoreProj --> TypedRuleSet
    CoreProj --> OtherRE

    %% Infrastructure: File System & Logging
    FileSystem["File System Scanner"]:::infra
    RuleStore["JSON Rule Store"]:::external
    Logging["Logging Infrastructure"]:::infra

    Program --> FileSystem
    RuleLoader --> RuleStore
    CLI --> Logging
    CoreProj --> Logging
    RuleProcessor --> Logging

    %% Writers
    subgraph "Writers"
        AnalyzeHtml["AnalyzeHtmlWriter.cs"]:::writer
        AnalyzeJson["AnalyzeJsonWriter.cs"]:::writer
        AnalyzeSarif["AnalyzeSarifWriter.cs"]:::writer
        AnalyzeText["AnalyzeTextWriter.cs"]:::writer
        CmdResults["CmdResultsWriter.cs"]:::writer
        ExportTagsText["ExportTagsTextWriter.cs"]:::writer
        JsonWriter["JsonWriter.cs"]:::writer
        TagDiffText["TagDiffTextWriter.cs"]:::writer
        VerifyRulesText["VerifyRulesTextWriter.cs"]:::writer
        WriterFactory["WriterFactory.cs"]:::writer
    end
    CoreProj --> WriterFactory
    WriterFactory --> AnalyzeHtml
    WriterFactory --> AnalyzeJson
    WriterFactory --> AnalyzeSarif
    WriterFactory --> AnalyzeText
    WriterFactory --> CmdResults
    WriterFactory --> ExportTagsText
    WriterFactory --> JsonWriter
    WriterFactory --> TagDiffText
    WriterFactory --> VerifyRulesText

    %% HTML Templates & Assets
    HTMLTemplates["HTML Templates & Assets"]:::external
    AnalyzeHtml --> HTMLTemplates

    %% Output Reports
    Reports["Output Reports (HTML/JSON/Text/SARIF)"]:::external
    AnalyzeHtml --> Reports
    AnalyzeJson --> Reports
    AnalyzeSarif --> Reports
    AnalyzeText --> Reports

    %% Benchmarks & Tests (Orthogonal Modules)
    subgraph "Benchmarks Module"
        BenchProgram["Program.cs"]:::tests
        AnalyzeBench["AnalyzeBenchmark.cs"]:::tests
        DistinctBench["DistinctBenchmarks.cs"]:::tests
        WriterBench["WriterBench.cs"]:::tests
    end
    BenchProgram --> AnalyzeBench
    BenchProgram --> DistinctBench
    BenchProgram --> WriterBench

    subgraph "Test Suite"
        Tests["AppInspector.Tests/**"]:::tests
    end

    %% Styling
    classDef frontend fill:#D0E8FF,stroke:#0366d6,color:#0366d6;
    classDef domain fill:#DFF2BF,stroke:#4F8A10,color:#4F8A10;
    classDef infra fill:#FFF2CC,stroke:#B89F4A,color:#B89F4A;
    classDef writer fill:#E6DAF1,stroke:#6F42C1,color:#6F42C1;
    classDef external fill:#F0F0F0,stroke:#AAAAAA,color:#666666,stroke-dasharray: 5 5;
    classDef tests fill:#FEE2E2,stroke:#E53E3E,color:#E53E3E;

    %% Click Events
    click Program "https://github.com/microsoft/applicationinspector/blob/main/AppInspector.CLI/Program.cs"
    click CLICmdOptions "https://github.com/microsoft/applicationinspector/blob/main/AppInspector.CLI/CLICmdOptions.cs"
    click AnalyzeCmd "https://github.com/microsoft/applicationinspector/blob/main/AppInspector/Commands/AnalyzeCommand.cs"
    click ExportTagsCmd "https://github.com/microsoft/applicationinspector/blob/main/AppInspector/Commands/ExportTagsCommand.cs"
    click PackRulesCmd "https://github.com/microsoft/applicationinspector/blob/main/AppInspector/Commands/PackRulesCommand.cs"
    click TagDiffCmd "https://github.com/microsoft/applicationinspector/blob/main/AppInspector/Commands/TagDiffCommand.cs"
    click VerifyRulesCmd "https://github.com/microsoft/applicationinspector/blob/main/AppInspector/Commands/VerifyRulesCommand.cs"
    click CoreProj "https://github.com/microsoft/applicationinspector/blob/main/AppInspector/AppInspector.Commands.csproj"
    click FileRecord "https://github.com/microsoft/applicationinspector/blob/main/AppInspector/FileRecord.cs"
    click MetaDataHelper "https://github.com/microsoft/applicationinspector/blob/main/AppInspector/MetaDataHelper.cs"
    click Result "https://github.com/microsoft/applicationinspector/blob/main/AppInspector/Result.cs"
    click RuleSetUtils "https://github.com/microsoft/applicationinspector/blob/main/AppInspector/RuleSetUtils.cs"
    click MetricTagCounter "https://github.com/microsoft/applicationinspector/blob/main/AppInspector/MetricTagCounter.cs"
    click GitInformation "https://github.com/microsoft/applicationinspector/blob/main/AppInspector/GitInformation.cs"
    click MetaData "https://github.com/microsoft/applicationinspector/blob/main/AppInspector/MetaData.cs"
    click Utils "https://github.com/microsoft/applicationinspector/blob/main/AppInspector.Common/Utils.cs"
    click OpException "https://github.com/microsoft/applicationinspector/blob/main/AppInspector.Common/OpException.cs"
    click MsgHelp "https://github.com/microsoft/applicationinspector/blob/main/AppInspector.Common/MsgHelp.cs"
    click RuleLoader "https://github.com/microsoft/applicationinspector/blob/main/AppInspector.RulesEngine/AbstractRuleSet.cs"
    click RuleProcessor "https://github.com/microsoft/applicationinspector/blob/main/AppInspector.RulesEngine/RuleProcessor.cs"
    click SearchPattern "https://github.com/microsoft/applicationinspector/blob/main/AppInspector.RulesEngine/SearchPattern.cs"
    click TypedRuleSet "https://github.com/microsoft/applicationinspector/blob/main/AppInspector.RulesEngine/TypedRuleSet.cs"
    click OtherRE "https://github.com/microsoft/applicationinspector/tree/main/AppInspector.RulesEngine/"
    click Logging "https://github.com/microsoft/applicationinspector/blob/main/AppInspector.Logging/LogOptions.cs"
    click AnalyzeHtml "https://github.com/microsoft/applicationinspector/blob/main/AppInspector.CLI/Writers/AnalyzeHtmlWriter.cs"
    click AnalyzeJson "https://github.com/microsoft/applicationinspector/blob/main/AppInspector.CLI/Writers/AnalyzeJsonWriter.cs"
    click AnalyzeSarif "https://github.com/microsoft/applicationinspector/blob/main/AppInspector.CLI/Writers/AnalyzeSarifWriter.cs"
    click AnalyzeText "https://github.com/microsoft/applicationinspector/blob/main/AppInspector.CLI/Writers/AnalyzeTextWriter.cs"
    click CmdResults "https://github.com/microsoft/applicationinspector/blob/main/AppInspector.CLI/Writers/CmdResultsWriter.cs"
    click ExportTagsText "https://github.com/microsoft/applicationinspector/blob/main/AppInspector.CLI/Writers/ExportTagsTextWriter.cs"
    click JsonWriter "https://github.com/microsoft/applicationinspector/blob/main/AppInspector.CLI/Writers/JsonWriter.cs"
    click TagDiffText "https://github.com/microsoft/applicationinspector/blob/main/AppInspector.CLI/Writers/TagDiffTextWriter.cs"
    click VerifyRulesText "https://github.com/microsoft/applicationinspector/blob/main/AppInspector.CLI/Writers/VerifyRulesTextWriter.cs"
    click HTMLTemplates "https://github.com/microsoft/applicationinspector/tree/main/AppInspector.CLI/html"
    click RuleStore "https://github.com/microsoft/applicationinspector/tree/main/AppInspector/rules/default/"
    click BenchProgram "https://github.com/microsoft/applicationinspector/blob/main/AppInspector.Benchmarks/Program.cs"
    click AnalyzeBench "https://github.com/microsoft/applicationinspector/blob/main/AppInspector.Benchmarks/AnalyzeBenchmark.cs"
    click DistinctBench "https://github.com/microsoft/applicationinspector/blob/main/AppInspector.Benchmarks/DistinctBenchmarks.cs"
    click WriterBench "https://github.com/microsoft/applicationinspector/blob/main/AppInspector.Benchmarks/WriterBench.cs"
    click Tests "https://github.com/microsoft/applicationinspector/tree/main/AppInspector.Tests/"
```
