# dotnet/cli-lab architecture

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

- Interactive diagram: https://gitdiagram.com/dotnet/cli-lab
- Repository: https://github.com/dotnet/cli-lab

## Overview

##### Project Type and Purpose
- This project is a command line tool (CLI) for uninstalling .NET Core SDKs, Runtimes, ASP.NET Core Runtimes, and Hosting Bundles.
- Its primary goal is to enable users to remove specific dotnet installations safely and reliably, while managing the complications of being used on different platforms (Windows, macOS, etc.).

##### Analyzing the File Structure (focusing on dotnet-core-uninstall)
- The dotnet-core-uninstall source is located in the “src/dotnet-core-uninstall” directory.
- Key folders inside include:
– Root files (e.g., Program.cs) which contain the entry point and overall application orchestration.
– A “Shared” directory that contains several submodules:
▪ Commands – Implementations for various uninstall commands (e.g., List, Uninstall, DryRun).
▪ Configs – Command line argument parsing/configuration and option handling.
▪ BundleInfo – Logic to represent and manage information about bundles (the components being uninstalled), including versioning details.
▪ Exceptions – Custom exception types that deal with error conditions like invalid inputs or conflicting versions.
▪ Filterers – Components that filter out bundles depending on options (e.g., filtering out all but the latest version).
▪ Utils – Utility functions (for regex processing, runtime information extraction, etc.).
▪ VSVersioning – Possibly handling Visual Studio version compatibility or extraction.
– Platform-Specific Directories (e.g., “MacOs” and “Windows”) that likely contain code tailored to OS-specific uninstall procedures.

##### Main Components
a. CLI Entry Point:
- Represented by the main Program.cs which initializes the tool.
- It gathers command line inputs and dispatches them to the appropriate command handlers.
b. Command Dispatcher & Parser:
- Module(s) within “Shared/Configs” that parse input arguments and configuration options.
c. Command Implementations:
- From “Shared/Commands”, illustrate how each command (like UninstallCommand, ListCommand, etc.) is implemented.
- That commands internally call into shared components to perform operations.
d. Bundle Processing Logic:
- The “Shared/BundleInfo” modules encapsulate how bundles are defined, versioned, and managed.
- The “Filterers” interact with BundleInfo to decide which bundles are eligible for uninstallation.
e. Error Handling:
- The “Shared/Exceptions” module where errors (e.g., invalid inputs, version conflicts) are processed.
f. Utility Functions:
- “Shared/Utils” and “Shared/VSVersioning” provide supporting functionality accessible to multiple commands.
g. Platform-Specific Layers:
- Separate modules (under “MacOs” and “Windows”) show the abstraction layer that handles OS-specific operations such as registry queries or file system interactions.
h. Build/Localization:

##### Relationships and Interactions
- The CLI entry point receives input and passes it to the configuration parser.
- Parsed commands are routed to the appropriate command handler, which then orchestrates:
– Querying the BundleInfo (with data provided by Filterers and Utils).
– Handling errors using custom Exceptions.
– Delegating OS-specific tasks to the platform-specific modules.
- How shared logic (commands, bundle processing, utilities) decouples the core business logic from platform nuances.

##### Architectural Patterns and Design Principles
- Modular design: Separation of concerns is evident from various “Shared” submodules. It enables easy maintenance and testing.
- Extensibility: The design supports adding new commands or filters without affecting the base structure.
- Platform Abstraction: Encapsulation of OS-specific implementations (in MacOs and Windows subdirectories) allows the tool to operate cross-platform.
- Clear error handling via custom Exceptions, facilitating graceful failures and user feedback.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Core CLI"
        A["CLI Entry Point (Program.cs)"]:::cli
    end

    subgraph "Configuration"
        B["Command Dispatcher & Parser (Configs)"]:::config
    end

    subgraph "Commands"
        C["Command Implementations (Commands)"]:::commands
    end

    subgraph "Business Logic"
        D["Bundle Processing (BundleInfo)"]:::bundle
        E["Filterers (Filterers)"]:::filterers
    end

    subgraph "Utilities"
        F["General Utils (Utils)"]:::utils
        G["Visual Studio Versioning (VSVersioning)"]:::utils
    end

    subgraph "Error Handling"
        H["Error Handling (Exceptions)"]:::errors
    end

    subgraph "Platform Specific"
        I["macOS Operations (MacOs)"]:::platform
        J["Windows Operations (Windows)"]:::platform
    end

    subgraph "Localization/Build"
        K["Localization Resources (xlf)"]:::build
    end

    %% Data Flow
    A -->|"gathers input"| B
    B -->|"dispatches commands"| C
    C -->|"orchestrates bundles"| D
    D -->|"applies filtering"| E
    C -->|"delegates OS tasks"| I
    C -->|"delegates OS tasks"| J
    C -->|"utilizes"| F
    C -->|"utilizes"| G
    C -->|"handles errors"| H

    %% Click Events
    click A "https://github.com/dotnet/cli-lab/blob/main/src/dotnet-core-uninstall/Program.cs"
    click B "https://github.com/dotnet/cli-lab/tree/main/src/dotnet-core-uninstall/Shared/Configs"
    click C "https://github.com/dotnet/cli-lab/tree/main/src/dotnet-core-uninstall/Shared/Commands"
    click D "https://github.com/dotnet/cli-lab/tree/main/src/dotnet-core-uninstall/Shared/BundleInfo"
    click E "https://github.com/dotnet/cli-lab/tree/main/src/dotnet-core-uninstall/Shared/Filterers"
    click F "https://github.com/dotnet/cli-lab/tree/main/src/dotnet-core-uninstall/Shared/Utils"
    click G "https://github.com/dotnet/cli-lab/tree/main/src/dotnet-core-uninstall/Shared/VSVersioning"
    click H "https://github.com/dotnet/cli-lab/tree/main/src/dotnet-core-uninstall/Shared/Exceptions"
    click I "https://github.com/dotnet/cli-lab/tree/main/src/dotnet-core-uninstall/MacOs"
    click J "https://github.com/dotnet/cli-lab/tree/main/src/dotnet-core-uninstall/Windows"
    click K "https://github.com/dotnet/cli-lab/tree/main/src/dotnet-core-uninstall/xlf"

    %% Styles
    classDef cli fill:#ffdead,stroke:#b22222,stroke-width:2px;
    classDef config fill:#e0ffff,stroke:#008b8b,stroke-width:2px;
    classDef commands fill:#ffd700,stroke:#b8860b,stroke-width:2px;
    classDef bundle fill:#d8bfd8,stroke:#9932cc,stroke-width:2px;
    classDef filterers fill:#dda0dd,stroke:#8a2be2,stroke-width:2px;
    classDef utils fill:#98fb98,stroke:#2e8b57,stroke-width:2px;
    classDef errors fill:#ffb6c1,stroke:#d2691e,stroke-width:2px;
    classDef platform fill:#add8e6,stroke:#00008b,stroke-width:2px;
    classDef build fill:#f0e68c,stroke:#b8860b,stroke-width:2px;
```
