# microsoft/sbom-tool architecture

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

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

## Overview

##### Project Type and Purpose
- The SBOM Tool is a command-line and API-based utility designed to generate, validate, and redact Software Bill of Materials (SBOM) files that comply with the SPDX 2.2 standard.
- Its purpose is to scan artifacts (for example, build outputs) to detect components (using component-detection libraries) and then produce an SBOM that details the software’s components, hashing information, and associated metadata. It also integrates external services (such as the ClearlyDefined API) for license population.
- This project is comprised of multiple interlocking components, including a CLI tool (with .NET Tool support), an API library (to be consumed in other projects), adapters, parsers, targets for build integration, and extensive testing infrastructure.

##### Analyzing the File Structure
- The top-level structure shows directories for documentation (*.md files), CI/CD configurations (under .github, pipelines), Docker support, and extensive source code under the “src” directory.
- The “src” folder is further divided into sub-projects:
- Microsoft.Sbom.Api: Contains most of the business logic around configuration, component detection, file hashing, SBOM generation and validation, and output formatting.
- Microsoft.Sbom.Adapters: Implements functionality to transform component detection results into SBOM package structures.
- Microsoft.Sbom.Common: Provides shared utilities, configuration handling, and cross-cutting concerns.
- Microsoft.Sbom.Contracts: Defines interfaces and contract entities (like SBOMPackage, SBOMFile, etc.) used across the other components.
- Microsoft.Sbom.DotNetTool & Microsoft.Sbom.Tool: Implementations for the command-line interface and .NET tool entrypoints.
- Microsoft.Sbom.Extensions, Parsers, Targets, and more: Provide additional features such as dependency injection extensions, support for parsing multiple SBOM formats (SPDX 2.2, potentially newer versions), and MSBuild integration.
- The tests folder further reinforces the modular design by having dedicated test projects for nearly every component, ensuring that unit and integration tests validate functionality.

a. Main Components:
- SBOM API Layer – representing the core logic that parses input configurations, routes processing via various executors (file scanner, hash generator, manifest generator), handles exceptions, and produces SBOM outputs.
- CLI/Tool Interface – encapsulated by projects like Microsoft.Sbom.Tool and Microsoft.Sbom.DotNetTool that provide entry points to generate, validate, or redact SBOM files.
- Adapters & Component Detection – modules (such as those in Microsoft.Sbom.Adapters) are responsible for interfacing with the external component detection libraries and converting results to SBOM-compliant outputs.
- Parsers & Validators – components that read SBOM files, validate formats (via FormatValidator, SPDX parsers), and ensure compliance.
- Utility & Common Services – shared libraries that handle configuration, logging, file I/O, hash generation, and provide abstraction layers across the tool.
- External Integrations – clearly visible references to external services (e.g., ClearlyDefined API) and integration hooks to CI/CD workflows (documented pipelines, GitHub Actions configurations).

b. Relationships and Interactions:
- The CLI/Tool Interface invokes the SBOM API to start the SBOM generation workflow.
- The SBOM API, in turn, uses the Adapters to invoke component detection logic. There’s a clear flow from reading configurations (using the Configuration and Validators submodules), locating and scanning files (via file system utilities), and passing results to manifest generators.
- The Parsers and Validators interact with SBOM outputs to ensure that the produced SBOM meets SPDX 2.2 standards.
- Utility/Services support all layers by providing common operations like file handling, logging, hash code generation, and configuration sanitization.
- External services (e.g., ClearlyDefined) are used by the adapters or metadata providers to enrich component data.
- CI/CD integrations (pipelines, Dockerfile, GitHub workflows) are outside the core runtime architecture but are integral for automated testing and deployment.

c. Important Architectural Patterns and Design Principles:
- Layered Architecture – the tool is structured so that presentation (CLI), business logic (API and workflows), and infrastructure (utilities, adapters) are well separated.
- Extensibility and Dependency Injection – clear use of interfaces and dependency injection (see Microsoft.Sbom.Extensions.DependencyInjection) allows for easy extension or replacement of components.
- Modularity – each major functionality (generation, validation, redaction, parsing) is encapsulated in its dedicated module.
- Robust testing – the extensive “test” directory shows that a unit and integration testing strategy is in place.

d. Relevant Technologies, Frameworks, or Libraries:
- .NET/C# is the primary technology stack.
- Component Detection libraries (from Microsoft/component-detection) are directly referenced.
- ClearlyDefined API integration for licensing information.
- CI/CD tools (GitHub Actions, Azure DevOps pipelines) are integrated for automated builds and tests.
- The project also involves Docker for containerized builds.

##### Elements
- Clear labels for each major component (e.g., "SBOM CLI/Tool Interface", "SBOM API & Workflows", "Component Detection Adapters", "SBOM Parsers & Validators", "Common Utilities & Configurations", "External Integration Services").

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% CLI Layer
    subgraph "CLI Layer"
        CLI_Tool["SBOM CLI/Tool: Microsoft.Sbom.Tool"]:::cli
        CLI_DotNetTool["SBOM CLI/Tool: Microsoft.Sbom.DotNetTool"]:::cli
    end

    %% Business Logic
    subgraph "Business Logic"
        API["SBOM API & Workflows"]:::api
    end

    %% Adapters Layer
    subgraph "Adapters Layer"
        Adapter["Component Detection Adapters"]:::adapter
    end

    %% Parsers & Validators
    subgraph "Parsers & Validators"
        Parser22["SPDX 2.2 Parser"]:::parser
        Parser30["SPDX 3.0 Parser"]:::parser
    end

    %% Common Utilities
    subgraph "Common Utilities"
        Common["Common Services"]:::common
        Extensions["Dependency Injection & Extensions"]:::common
    end

    %% External Integrations
    subgraph "External Integrations"
        Meta["MetaData Provider"]:::external
        ExtDoc["ExternalDocReference Providers"]:::external
    end

    %% Legend
    subgraph "Legend"
        Legend1["CLI/Tool Interface"]:::cli
        Legend2["SBOM API & Workflows"]:::api
        Legend3["Component Detection Adapters"]:::adapter
        Legend4["SPDX Parsers & Validators"]:::parser
        Legend5["Common Utilities & Configurations"]:::common
        Legend6["External Integration Services"]:::external
    end

    %% Connections
    CLI_Tool -->|"invokes"| API
    CLI_DotNetTool -->|"invokes"| API
    API -->|"calls"| Adapter
    API -->|"routes to"| Parser22
    API -->|"routes to"| Parser30
    API -->|"utilizes"| Common
    API -->|"utilizes"| Extensions
    Adapter -->|"integrates"| Meta
    Adapter -->|"integrates"| ExtDoc
    Parser22 -->|"uses"| Common
    Parser30 -->|"uses"| Common

    %% Styles
    classDef cli fill:#b3e6ff,stroke:#000,stroke-width:1px;
    classDef api fill:#cce5ff,stroke:#000,stroke-width:1px;
    classDef adapter fill:#ffcc99,stroke:#000,stroke-width:1px;
    classDef parser fill:#e5ccff,stroke:#000,stroke-width:1px;
    classDef common fill:#d9d9d9,stroke:#000,stroke-width:1px;
    classDef external fill:#ff9999,stroke:#000,stroke-width:1px;

    %% Click Events
    click CLI_Tool "https://github.com/microsoft/sbom-tool/blob/main/src/Microsoft.Sbom.Tool"
    click CLI_DotNetTool "https://github.com/microsoft/sbom-tool/blob/main/src/Microsoft.Sbom.DotNetTool"
    click API "https://github.com/microsoft/sbom-tool/blob/main/src/Microsoft.Sbom.Api"
    click Adapter "https://github.com/microsoft/sbom-tool/blob/main/src/Microsoft.Sbom.Adapters"
    click Parser22 "https://github.com/microsoft/sbom-tool/blob/main/src/Microsoft.Sbom.Parsers.Spdx22SbomParser"
    click Parser30 "https://github.com/microsoft/sbom-tool/blob/main/src/Microsoft.Sbom.Parsers.Spdx30SbomParser"
    click Common "https://github.com/microsoft/sbom-tool/blob/main/src/Microsoft.Sbom.Common"
    click Extensions "https://github.com/microsoft/sbom-tool/blob/main/src/Microsoft.Sbom.Extensions"
    click Meta "https://github.com/microsoft/sbom-tool/tree/main/src/Microsoft.Sbom.Api/MetaData"
    click ExtDoc "https://github.com/microsoft/sbom-tool/tree/main/src/Microsoft.Sbom.Api/Providers/ExternalDocumentReferenceProviders"
```
