# microsoft/powerbi-csharp architecture

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

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

## Overview

##### Main Components (Top Level)

a. Client Application Layer
- External applications that consume the SDK
- A "PowerBIClient" as the main entry point

b. SDK Core Layer
- Main operation groups (visible in the Source folder):
- Reports Operations
- Datasets Operations
- Groups Operations
- Admin Operations
- Embed Token Operations

c. Models Layer
- Below the core layer
- Related models together (e.g., Report-related, Dataset-related)

d. Power BI REST API Layer
- At the bottom
- External Power BI service

##### Component Relationships

- Client Application → PowerBIClient
- PowerBIClient → Operation Groups
- Operation Groups → Models
- Operation Groups → Power BI REST API
- Models ↔ Power BI REST API (serialization/deserialization)

##### Key Architectural Elements

a. Authentication Flow
- Azure AD integration
- Credentials flow to PowerBIClient

b. Extension Points
- Extensions folder components
- How they extend core functionality
- Use a distinctive border style for extensibility points

##### Implementation Details

Important subsystems:
- Credential Management
- Token Generation
- Error Handling
- Model Serialization

##### Notes

Important callouts for:
- Required permissions
- Capacity dependencies
- API version compatibility
- Common integration patterns

- The SDK's role as a client-side library
- Clear separation between operations and models
- Authentication and security flow
- Extension points for customization
- Integration patterns with Power BI service

Remember to include version information and any backward compatibility notes, as indicated by the BackwardCompatibility.md file in the repository.

This architecture should clearly show how the SDK serves as a bridge between client applications and the Power BI REST API, while highlighting its security, extensibility, and integration capabilities.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client["Client Application Layer"]
        App[Client Application]:::client
    end

    subgraph Core["SDK Core Layer"]
        PBIClient["PowerBIClient"]:::core
        IPBIClient["IPowerBIClient Interface"]:::core
    end

    subgraph OpGroups["Operation Groups Layer"]
        Reports["ReportsOperations"]:::operations
        Datasets["DatasetsOperations"]:::operations
        Groups["GroupsOperations"]:::operations
        EmbedToken["EmbedTokenOperations"]:::operations
        Admin["AdminOperations"]:::operations
    end

    subgraph OpInterfaces["Operation Interfaces"]
        IReports["IReportsOperations"]:::interface
        IDatasets["IDatasetsOperations"]:::interface
        IGroups["IGroupsOperations"]:::interface
        IEmbedToken["IEmbedTokenOperations"]:::interface
        IAdmin["IAdminOperations"]:::interface
    end

    subgraph Models["Models Layer"]
        ReportModels["Report Models"]:::models
        DatasetModels["Dataset Models"]:::models
        AuthModels["Authentication Models"]:::models
        AdminModels["Admin Models"]:::models
    end

    subgraph Extensions["Extension Layer"]
        ClientExt["PowerBIClient Extensions"]:::extension
        ReportExt["Reports Extensions"]:::extension
        DatasetExt["Datasets Extensions"]:::extension
        GroupExt["Groups Extensions"]:::extension
    end

    subgraph Auth["Authentication Components"]
        AuthEnc["Authenticated Encryption"]:::auth
        AsymKey["Asymmetric Key Encryptor"]:::auth
        Creds["Credentials"]:::auth
    end

    subgraph External["External Systems"]
        PBIAPI["Power BI REST API"]:::external
        AzureAD["Azure AD"]:::external
    end

    App --> PBIClient
    PBIClient --> IPBIClient
    
    PBIClient --> Reports
    PBIClient --> Datasets
    PBIClient --> Groups
    PBIClient --> EmbedToken
    PBIClient --> Admin

    Reports --> IReports
    Datasets --> IDatasets
    Groups --> IGroups
    EmbedToken --> IEmbedToken
    Admin --> IAdmin

    Reports --> ReportModels
    Datasets --> DatasetModels
    Groups --> AuthModels
    Admin --> AdminModels

    PBIClient --> AuthEnc
    AuthEnc --> AsymKey
    AuthEnc --> Creds

    ClientExt --> PBIClient
    ReportExt --> Reports
    DatasetExt --> Datasets
    GroupExt --> Groups

    Reports --> PBIAPI
    Datasets --> PBIAPI
    Groups --> PBIAPI
    EmbedToken --> PBIAPI
    Admin --> PBIAPI

    PBIClient --> AzureAD

    %% Click events
    click PBIClient "https://github.com/microsoft/PowerBI-CSharp/blob/master/sdk/PowerBI.Api/Source/PowerBIClient.cs"
    click IPBIClient "https://github.com/microsoft/PowerBI-CSharp/blob/master/sdk/PowerBI.Api/Source/IPowerBIClient.cs"
    click Reports "https://github.com/microsoft/PowerBI-CSharp/blob/master/sdk/PowerBI.Api/Source/ReportsOperations.cs"
    click Datasets "https://github.com/microsoft/PowerBI-CSharp/blob/master/sdk/PowerBI.Api/Source/DatasetsOperations.cs"
    click Groups "https://github.com/microsoft/PowerBI-CSharp/blob/master/sdk/PowerBI.Api/Source/GroupsOperations.cs"
    click EmbedToken "https://github.com/microsoft/PowerBI-CSharp/blob/master/sdk/PowerBI.Api/Source/EmbedTokenOperations.cs"
    click Admin "https://github.com/microsoft/PowerBI-CSharp/blob/master/sdk/PowerBI.Api/Source/Admin.cs"
    click Models "https://github.com/microsoft/PowerBI-CSharp/tree/master/sdk/PowerBI.Api/Source/Models/"
    click AuthEnc "https://github.com/microsoft/PowerBI-CSharp/blob/master/sdk/PowerBI.Api/Extensions/AuthenticatedEncryption.cs"
    click AsymKey "https://github.com/microsoft/PowerBI-CSharp/blob/master/sdk/PowerBI.Api/Extensions/AsymmetricKeyEncryptor.cs"
    click Creds "https://github.com/microsoft/PowerBI-CSharp/tree/master/sdk/PowerBI.Api/Extensions/Models/Credentials/"
    click ClientExt "https://github.com/microsoft/PowerBI-CSharp/blob/master/sdk/PowerBI.Api/Extensions/PowerBIClientExtension.cs"
    click ReportExt "https://github.com/microsoft/PowerBI-CSharp/blob/master/sdk/PowerBI.Api/Extensions/ReportsOperationsExtensions.cs"
    click DatasetExt "https://github.com/microsoft/PowerBI-CSharp/blob/master/sdk/PowerBI.Api/Extensions/DatasetsOperationsExtensions.cs"
    click GroupExt "https://github.com/microsoft/PowerBI-CSharp/blob/master/sdk/PowerBI.Api/Extensions/GroupsOperationsExtensions.cs"
    click IReports "https://github.com/microsoft/PowerBI-CSharp/blob/master/sdk/PowerBI.Api/Source/IReportsOperations.cs"
    click IDatasets "https://github.com/microsoft/PowerBI-CSharp/blob/master/sdk/PowerBI.Api/Source/IDatasetsOperations.cs"
    click IGroups "https://github.com/microsoft/PowerBI-CSharp/blob/master/sdk/PowerBI.Api/Source/IGroupsOperations.cs"
    click IEmbedToken "https://github.com/microsoft/PowerBI-CSharp/blob/master/sdk/PowerBI.Api/Source/IEmbedTokenOperations.cs"
    click IAdmin "https://github.com/microsoft/PowerBI-CSharp/blob/master/sdk/PowerBI.Api/Source/IAdmin.cs"

    %% Styles
    classDef client fill:#fff,stroke:#333
    classDef core fill:#2196F3,stroke:#1565C0,color:#fff
    classDef operations fill:#4CAF50,stroke:#388E3C,color:#fff
    classDef models fill:#FFC107,stroke:#FFA000
    classDef extension fill:#9C27B0,stroke:#7B1FA2,color:#fff
    classDef auth fill:#FF5722,stroke:#E64A19,color:#fff
    classDef external fill:#9E9E9E,stroke:#616161,color:#fff
    classDef interface fill:#00BCD4,stroke:#0097A7,color:#fff

    %% Legend
    subgraph Legend
        L1[Client]:::client
        L2[Core SDK]:::core
        L3[Operations]:::operations
        L4[Models]:::models
        L5[Extensions]:::extension
        L6[Auth Components]:::auth
        L7[External Systems]:::external
        L8[Interfaces]:::interface
    end
```
