# bazel-contrib/rules_dotnet architecture

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

- Interactive diagram: https://gitdiagram.com/bazel-contrib/rules_dotnet
- Repository: https://github.com/bazel-contrib/rules_dotnet

## Overview

##### Main Components
- Build System Integration Component: At the heart of the project is Bazel. Represent the Bazel engine along with its configuration files (e.g., .bazelrc, BUILD.bazel, MODULE.bazel). This shows the overall orchestration.
- Dependency Resolution & Packaging: Highlight how Paket (and the related tools in the “paket” directories) integrates with Bazel, as well as the role of NuGet-related build rules (in dotnet/private/rules/nuget). This component manages external dependencies and package versions.
- Test and Verification Modules: Illustrate the extensive testing setup (inside dotnet/private/tests and e2e). These tests cover a range of scenarios such as dependency resolution, source generation, and publishing scenarios. Clearly show how these tests validate the build rules.
- Development & CI/CD Configuration: Show support files and directories, including:
- CI configuration (.bazelci, .github/workflows) to integrate with BuildKite and GitHub actions.
- Development environment configuration (.devcontainer for containerized dev setups).
- Documentation and Examples: Include the docs and examples directories. These illustrate the end-user integration with the rules and provide guidance for adopting the system.

##### Relationships and Data Flow
- Testing components as a separate validation layer that feeds back into ensuring the integrity of the csharp, fsharp, and packaging rules.
- Link the CI/CD components with the build system to represent automated testing and release pipelines.

##### Architectural Patterns and Key Design Principles
- Modularity: The project splits responsibilities into discrete packages (e.g., rules for C#, rules for F#, dependency resolution) which can be independently maintained and updated.
- Extensibility: The presence of extension points (for NuGet, for toolkit resolution, and for source generation) suggests that the design anticipates future feature additions and support for more platform-specific optimizations.
- Layered Abstraction: There is a clear separation between the build orchestration (Bazel), rule definitions (dotnet/private/rules), SDK/toolchain integration (dotnet/private/sdk), and the testing/validation infrastructure.

## Diagram (Mermaid)

```mermaid
flowchart TD
    CI_CD["CI/CD & Development Environments"]:::ci
    Docs["Documentation & Examples"]:::docs

    BazelEngine["Bazel Engine/Orchestrator"]:::core
    NETRulesC[".NET Rules (C#)"]:::rules
    NETRulesF[".NET Rules (F#)"]:::rules
    Dependency["Dependency Resolution (NuGet,Paket)"]:::dep
    SDKIntegration["SDK & Toolchain Integration"]:::sdk
    Testing["Testing & Validation Suite"]:::testing

    CI_CD -->|"automated_builds"| BazelEngine
    BazelEngine -->|"invokes"| NETRulesC
    BazelEngine -->|"invokes"| NETRulesF
    Dependency -->|"provides_dependencies"| NETRulesC
    Dependency -->|"provides_dependencies"| NETRulesF
    SDKIntegration -->|"provides_tools"| NETRulesC
    SDKIntegration -->|"provides_tools"| NETRulesF
    NETRulesC -->|"validated_by"| Testing
    NETRulesF -->|"validated_by"| Testing
    Testing -->|"feedback"| BazelEngine
    BazelEngine -->|"documented_by"| Docs

    click BazelEngine "https://github.com/bazel-contrib/rules_dotnet/blob/master/.bazelrc"
    click NETRulesC "https://github.com/bazel-contrib/rules_dotnet/tree/master/dotnet/private/rules/csharp"
    click NETRulesF "https://github.com/bazel-contrib/rules_dotnet/tree/master/dotnet/private/rules/fsharp"
    click Dependency "https://github.com/bazel-contrib/rules_dotnet/tree/master/dotnet/private/rules/nuget"
    click SDKIntegration "https://github.com/bazel-contrib/rules_dotnet/tree/master/dotnet/private/sdk"
    click Testing "https://github.com/bazel-contrib/rules_dotnet/tree/master/dotnet/private/tests"
    click CI_CD "https://github.com/bazel-contrib/rules_dotnet/blob/master/.bazelci"
    click Docs "https://github.com/bazel-contrib/rules_dotnet/tree/master/docs"

    classDef core fill:#bbdefb,stroke:#1e88e5,stroke-width:2px;
    classDef rules fill:#c8e6c9,stroke:#43a047,stroke-width:2px;
    classDef dep fill:#ffe0b2,stroke:#fb8c00,stroke-width:2px;
    classDef sdk fill:#d1c4e9,stroke:#7e57c2,stroke-width:2px;
    classDef testing fill:#ffccbc,stroke:#e64a19,stroke-width:2px;
    classDef ci fill:#cfd8dc,stroke:#546e7a,stroke-width:2px;
    classDef docs fill:#fff9c4,stroke:#fdd835,stroke-width:2px;
```
