# microsoft/partner-center-dotnet-samples architecture

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

- Interactive diagram: https://gitdiagram.com/microsoft/partner-center-dotnet-samples
- Repository: https://github.com/microsoft/partner-center-dotnet-samples

## Overview

##### Project type and purpose
- This repository is a collection of .NET sample applications and tools demonstrating how to interact with the Microsoft Partner Center SDK and how to implement the Secure App Model using Azure Key Vault.
- It includes:
- Two command-line tools (MCARefreshBulkAttestationCLITool and NCEBulkMigrationTool)
- A suite of console “sdk” samples covering Partner Center SDK scenarios
- A “secure-app-model” section with three projects (CPVApplication, CSPApplication, PartnerConsent web app) showing Key Vault integration and OAuth flows

##### File structure
- Top-level folders:
- MCARefreshBulkAttestationCLITool (CLI tool for bulk customer re-attestation)
- nce-bulk-migration-tool (CLI for New Commerce bulk migration)
- sdk (console apps grouped by scenario/category under SdkSamples)
- secure-app-model (Key Vault samples: CPV, CSP, ASP.NET MVC partner consent app)
- Common sub-structures in each console/web project:
- Interfaces (ICustomerProvider, ITokenProvider, IFileProvider)
- Providers (implementations: CsvProvider, TokenProvider, CustomerProvider)
- Http folder (extension methods for HttpClient)
- Models (DTOs for Partner Center request/responses)
- AppSettings/Configuration files (appsettings.json, App.config)
- Build/deployment files:
- .csproj and .sln for each project
- Azure Pipelines YAML for CI/CD
- Scripts to install or update tools

##### README for additional insights
- The root README splits the repository into two main scenario sets: “SDK Samples” (console scenarios using Partner Center .NET SDK) and “Secure App Model” (demonstrates best practices for CPV/CSP apps using Key Vault).

a. Main components (grouped into logical layers)
- Presentation/CLI layer
- MCARefreshBulkAttestationCLITool
- NCEBulkMigrationTool
- SdkSamples console app
- PartnerConsent ASP.NET MVC web app
- Business/Provider layer
- ITokenProvider + TokenProvider
- ICustomerProvider + CustomerProvider
- IFileProvider + CsvProvider
- INewCommerceMigrationProvider, ISubscriptionProvider, etc.
- HttpClient extensions (McaHttpClientExtensions)
- SDK/Service layer
- Partner Center .NET SDK (NuGet packages)
- Azure Key Vault client libraries (for secure-app-model projects)
- External services
- Partner Center REST API (PartnerCenter endpoint)
- Azure Active Directory (OAuth token issuance)
- Azure Key Vault (secret storage)
- Local file system (CSV import/export)
b. Relationships and data flows
- CLI/Console apps → TokenProvider → AAD → partner center SDK → Partner Center API
- CSVProvider reads local CSV → constructs domain model → CustomerProvider calls SDK
- Secure-app projects → KeyVaultProvider → Azure Key Vault → retrieve client secrets → AuthorizationUtilities → obtain AAD token → call Partner Center
- PartnerConsent web app uses MVC controllers to present UI, triggers calls through AuthorizationUtilities and KeyVaultProvider before delegating to Partner Center SDK
c. Architectural patterns and design principles
- Dependency Injection (Interfaces decoupled from Implements)
- Layered architecture (Presentation → Business → SDK / External)
- Single Responsibility (each Provider has one concern: token, file, customer, migration)
- Extension Methods for configuring HttpClient consistency
- MVC pattern in the ASP.NET PartnerConsent app
d. Key technologies, frameworks, libraries
- .NET Core / .NET Framework console & web projects
- Partner Center .NET SDK (PartnerCenter NuGet)
- Azure.Identity or ADAL/MSAL for authentication
- Microsoft.Azure.KeyVault or Azure.Security.KeyVault.*
- ASP.NET MVC (PartnerConsent web app)
- CsvHelper or custom CSVProvider for file I/O

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "CLI Tools"
        direction TB
        MCA["MCARefreshBulkAttestationCLITool"]:::cli
        NCE["NCEBulkMigrationTool"]:::cli
    end

    subgraph "SDK Samples"
        direction TB
        SDK["SdkSamples Console Apps"]:::cli
        Config["App.config & Configuration"]:::config
    end

    subgraph "Secure App Model"
        direction TB
        CPV["CPVApplication (Console)"]:::cli
        CSP["CSPApplication (Console)"]:::cli
        PC["PartnerConsent (ASP.NET MVC)"]:::web
    end

    %% Business / Provider Layer
    subgraph "Business / Provider Layer"
        direction TB
        IToken["ITokenProvider / TokenProvider"]:::bus
        ICustomer["ICustomerProvider / CustomerProvider"]:::bus
        IFile["IFileProvider / CsvProvider"]:::bus
        INCM["INewCommerceMigrationProvider / NewCommerceMigrationProvider"]:::bus
        ISub["ISubscriptionProvider / SubscriptionProvider"]:::bus
        Ext["McaHttpClientExtensions"]:::bus
        AuthUtil["AuthorizationUtilities / KeyVaultProvider"]:::bus
    end

    %% SDK / Service Layer
    subgraph "SDK / Service Layer"
        direction TB
        PCSDK["Partner Center SDK"]:::service
        KVClient["Azure Key Vault SDK"]:::service
    end

    %% External Services
    subgraph "External Services"
        direction TB
        AAD["Azure Active Directory"]:::external
        PCAPI["Partner Center REST API"]:::external
        KV["Azure Key Vault"]:::external
        FS["Local File System"]:::external
    end

    %% Connections - CLI Tools
    MCA -->|uses| IToken
    MCA -->|uses| ICustomer
    MCA -->|uses| IFile
    MCA -->|calls| Ext

    NCE -->|uses| IToken
    NCE -->|uses| ICustomer
    NCE -->|uses| INCM
    NCE -->|uses| ISub

    %% Connections - SDK Samples
    SDK -->|configured by| Config
    SDK -->|uses| IToken
    SDK -->|uses| ICustomer
    SDK -->|uses| IFile

    %% Connections - Secure App Model
    CPV -->|uses| AuthUtil
    CPV -->|uses| IToken
    CSP -->|uses| AuthUtil
    CSP -->|uses| IToken

    PC -->|MVC controllers call| AuthUtil
    PC -->|MVC controllers call| IToken

    %% Business to SDK/Service
    IToken -->|authenticates via| PCSDK
    IToken -->|authenticates via| KVClient
    ICustomer -->|calls| PCSDK
    INCM -->|calls| PCSDK
    ISub -->|calls| PCSDK
    IFile -->|reads/writes| FS
    Ext -->|extends| PCSDK
    AuthUtil -->|fetches secrets from| KVClient

    %% SDK/Service to External
    PCSDK -->|requests| PCAPI
    KVClient -->|requests| KV
    IToken -->|requests| AAD
    AuthUtil -->|requests| AAD

    %% Click Events
    click MCA "https://github.com/microsoft/partner-center-dotnet-samples/tree/master/MCARefreshBulkAttestationCLITool/"
    click Ext "https://github.com/microsoft/partner-center-dotnet-samples/blob/master/MCARefreshBulkAttestationCLITool/Http/McaHttpClientExtensions.cs"
    click IToken "https://github.com/microsoft/partner-center-dotnet-samples/tree/master/MCARefreshBulkAttestationCLITool/Interfaces/"
    click ICustomer "https://github.com/microsoft/partner-center-dotnet-samples/tree/master/MCARefreshBulkAttestationCLITool/Providers/"
    click NCE "https://github.com/microsoft/partner-center-dotnet-samples/tree/master/nce-bulk-migration-tool/NCEBulkMigrationTool/"
    click SDK "https://github.com/microsoft/partner-center-dotnet-samples/tree/master/sdk/SdkSamples/"
    click Config "https://github.com/microsoft/partner-center-dotnet-samples/blob/master/sdk/SdkSamples/App.config"
    click Config "https://github.com/microsoft/partner-center-dotnet-samples/tree/master/sdk/SdkSamples/Configuration/"
    click CPV "https://github.com/microsoft/partner-center-dotnet-samples/tree/master/secure-app-model/keyvault/CPVApplication/"
    click AuthUtil "https://github.com/microsoft/partner-center-dotnet-samples/tree/master/secure-app-model/keyvault/CPVApplication/Utilities/"
    click CSP "https://github.com/microsoft/partner-center-dotnet-samples/tree/master/secure-app-model/keyvault/CSPApplication/"
    click AuthUtil "https://github.com/microsoft/partner-center-dotnet-samples/tree/master/secure-app-model/keyvault/CSPApplication/Utilities/"
    click PC "https://github.com/microsoft/partner-center-dotnet-samples/tree/master/secure-app-model/keyvault/PartnerConsent/"
    click PC_Ctrl "https://github.com/microsoft/partner-center-dotnet-samples/tree/master/secure-app-model/keyvault/PartnerConsent/Controllers/"
    click PC_Util "https://github.com/microsoft/partner-center-dotnet-samples/tree/master/secure-app-model/keyvault/PartnerConsent/Utilities/"
    click PC_V "https://github.com/microsoft/partner-center-dotnet-samples/tree/master/secure-app-model/keyvault/PartnerConsent/Views/"
    click PC_AS "https://github.com/microsoft/partner-center-dotnet-samples/tree/master/secure-app-model/keyvault/PartnerConsent/App_Start/"

    %% Styles
    classDef cli fill:#D6E9FE,stroke:#4A90E2
    classDef web fill:#DFF0D8,stroke:#3C763D
    classDef bus fill:#FCF8E3,stroke:#8A6D3B
    classDef service fill:#F2DEDE,stroke:#A94442
    classDef external fill:#E0E0E0,stroke:#333
    classDef config fill:#F5F5F5,stroke:#CCC
```
