# quangtrinh1612/powerbi-api architecture

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

- Interactive diagram: https://gitdiagram.com/quangtrinh1612/powerbi-api
- Repository: https://github.com/quangtrinh1612/powerbi-api

## Overview

##### Project Type & Purpose
- This is a Python client library designed to interact with Microsoft Power BI REST APIs.
- Its purpose is to provide an object-oriented interface that encapsulates operations for handling dashboards, datasets, reports, dataflows, workspaces, and users in Power BI.
- It emphasizes modularity (with dedicated service modules for each entity), token-based authentication, centralized logging, and robust session management.

##### Analyzing the File Structure
- Key top-level files:
- main.py: The entry point for running the application.
- README.md & requirements.txt: Documentation and dependency management.
- config/: Contains configuration files such as logging.yaml.
- The “powerbi” directory is the heart of the project:
- Contains modules like auth.py, client.py, logger.py, session.py, config.py, enums.py, and utils.py.
- The “services” subdirectory encapsulates entity-specific operations (e.g., datasets, dashboards, reports, etc.) and clearly defines boundaries for each function.
- Testing and scripting directories indicate support for automated unit tests (test/) and additional utility scripts (script/).

##### Core Components
a. Main Application & Entry Point:
- main.py: Initiates the application and ties together configuration, authentication, and session management.
b. API Client & Session Management:
- client.py: Acts as the primary interface with Power BI REST API.
- session.py: Handles HTTP requests and manages session state, including token injection.
c. Authentication & Security:
- auth.py: Implements token-based authentication with Power BI’s API.
d. Configuration & Logging:
- config.py & config/logging.yaml: Manage API endpoints, credentials, and logging settings.
- logger.py: Centralizes logging configuration and sends logs to both console and files.
e. Modular Services (Business Logic Components):
- The services folder: Contains distinct modules such as datasets.py, dashboards.py, reports.py, etc.
- These modules are loosely coupled and focus on a specific aspect of Power BI management.
f. Utility & Enum Definitions:
- utils.py: Houses helper functions.
- enums.py: Defines enumerations for Power BI entities, ensuring consistency across the modules.
g. External Dependencies:
- Microsoft Power BI REST APIs: All client operations ultimately call these external endpoints.

- Application Layer (main.py): The entry point.
- Core Library Layer (powerbi package): Include a central block for the API client and session/auth handling.
- Service Modules (inside the services subdirectory): Individual blocks for datasets, dashboards, reports, etc.
- Supporting configurations (config and environment variables) and logging utilities.
- Relationships and data flows:
- That the client uses session management to interact with the Power BI REST API.
- That each service module depends on the client for its operations.
- Configuration (config.py and logging.yaml) to both the client and logger modules.
- Integrations (e.g., token injection from auth.py to session.py; logging output directed to external log files and console).

##### Architectural Patterns & Design Principles
- Modularization: Separation of distinct functionalities into dedicated modules (authentication, API calling, specific service operations).
- Separation of Concerns: Configurations, logging, and session management are clearly separated, enhancing maintainability.
- Extensibility: The clear directory layout for services allows new modules (e.g., additional data management features) to be added easily.
- Encapsulation: The client abstracts complexities (e.g., HTTP session, token management) from individual service modules.

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Application Layer
    subgraph "Application Layer"
        M["Main (main.py)"]:::main
    end

    %% Core Library Layer
    subgraph "Core Library Layer"
        AC["API Client (client.py)"]:::core
        SM["Session Management (session.py)"]:::core
        AU["Authentication (auth.py)"]:::core
        C["Configuration (config.py)"]:::core
        LC["Logging Config (logging.yaml)"]:::core
        LG["Logger (logger.py)"]:::core
        EA["External API (Microsoft Power BI REST)"]:::external
    end

    %% Service Modules
    subgraph "Service Modules"
        SV["Service Modules (powerbi/services)"]:::service
    end

    %% Supporting Modules
    subgraph "Supporting Modules"
        UT["Utility Functions (utils.py)"]:::support
        EN["Enumeration Definitions (enums.py)"]:::support
    end

    %% Relationships
    M -->|"initiates"| AC
    M -->|"loads"| C
    M -->|"loads"| LC

    AC -->|"manages"| SM
    AC -->|"uses"| AU
    AC -->|"reads"| C
    AC -->|"logsTo"| LG
    AC -->|"calls"| EA
    AC -->|"utilizes"| UT
    AC -->|"utilizes"| EN

    AU -->|"injectsToken"| SM

    SV -->|"dependsOn"| AC
    SV -->|"utilizes"| UT
    SV -->|"utilizes"| EN

    %% Legend
    subgraph Legend["Legend"]
        L1["Main: Light Blue\nCore Modules: Light Green\nService Modules: Light Orange\nSupporting Modules: Light Salmon\nExternal API: Light Purple"]:::legend
    end

    %% Click Events
    click M "https://github.com/quangtrinh1612/powerbi-api/blob/main/main.py"
    click AC "https://github.com/quangtrinh1612/powerbi-api/blob/main/powerbi/client.py"
    click SM "https://github.com/quangtrinh1612/powerbi-api/blob/main/powerbi/session.py"
    click AU "https://github.com/quangtrinh1612/powerbi-api/blob/main/powerbi/auth.py"
    click C "https://github.com/quangtrinh1612/powerbi-api/blob/main/powerbi/config.py"
    click LC "https://github.com/quangtrinh1612/powerbi-api/blob/main/config/logging.yaml"
    click LG "https://github.com/quangtrinh1612/powerbi-api/blob/main/powerbi/logger.py"
    click SV "https://github.com/quangtrinh1612/powerbi-api/tree/main/powerbi/services"
    click UT "https://github.com/quangtrinh1612/powerbi-api/blob/main/powerbi/utils.py"
    click EN "https://github.com/quangtrinh1612/powerbi-api/blob/main/powerbi/enums.py"

    %% Styling
    classDef main fill:#B3E5FC,stroke:#000,stroke-width:1px;
    classDef core fill:#C8E6C9,stroke:#000,stroke-width:1px;
    classDef service fill:#FFECB3,stroke:#000,stroke-width:1px;
    classDef support fill:#FFE0B2,stroke:#000,stroke-width:1px;
    classDef external fill:#D1C4E9,stroke:#000,stroke-width:1px;
    classDef legend fill:#E0E0E0,stroke:#000,stroke-width:1px, font-size:10px;
```
