# microsoftgraph/msgraph-training-python architecture

> Architecture diagram of the GitHub repository microsoftgraph/msgraph-training-python, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/microsoftgraph/msgraph-training-python
- Repository: https://github.com/microsoftgraph/msgraph-training-python

## Overview

##### Project type and purpose
- This repository is a set of Python sample applications demonstrating how to call Microsoft Graph from Python.
- It contains two independent console-style samples:
a. Delegated user authentication sample under `user-auth/`
b. App-only (daemon) authentication sample under `app-auth/`
- Each sample authenticates against Azure AD, acquires an access token, and uses the Microsoft Graph SDK to call Graph endpoints in Microsoft 365.

##### File structure
- Top‐level:
- `.github/`, CI workflows, codelinting.
- `README.md`, license, security, code of conduct.
- `app-auth/` – App-only auth sample
- `user-auth/` – Delegated user auth sample
- `app-auth/graphapponlytutorial/` and `user-auth/graphtutorial/` each contain:
- `config.cfg` – holds tenant/app/client-ID settings
- `main.py` – orchestrates auth and Graph calls
- `graph.py` – contains wrapper functions for Graph API operations
- `requirements*.txt`, `pylintrc` for lint/deps
- PowerShell scripts to register Azure AD app.

##### README for additional insights
- Describes running two distinct samples.
- Points to Microsoft Graph tutorials for detailed steps.
- No built-in database or UI: pure Python console app + external Graph service.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Developer Workstation
    Dev["Developer Workstation / CLI"]:::cli

    %% App-only Sample Application
    subgraph "Python Sample App (App-only / Daemon Flow)"
        direction TB
        AO_Config["config.cfg"]:::local
        AO_Auth["Auth Module (Client Credentials)"]:::local
        AO_Graph["Graph Client Module"]:::local
        AO_Main["Main Orchestrator"]:::local
        AO_Deps["requirements.in / requirements.txt"]:::local
        AO_Lint["pylintrc"]:::local
        AO_PS["RegisterAppForAppOnlyAuth.ps1"]:::script
        AO_Readme["README.md"]:::doc
    end

    %% Delegated Flow Sample Application
    subgraph "Python Sample App (Delegated User Flow)"
        direction TB
        DU_Config["config.cfg"]:::local
        DU_Auth["Auth Module (Device Code / Interactive)"]:::local
        DU_Graph["Graph Client Module"]:::local
        DU_Main["Main Orchestrator"]:::local
        DU_Deps["requirements.in / requirements.txt"]:::local
        DU_Lint["pylintrc"]:::local
        DU_PS["RegisterAppForUserAuth.ps1"]:::script
        DU_Readme["README.md"]:::doc
    end

    %% External Services
    subgraph External
        direction TB
        AzureAD["Azure AD / Identity Platform"]:::identity
        GraphAPI["Microsoft Graph API"]:::cloud
        M365["Microsoft 365 Services"]:::cloud
    end

    %% Root docs and governance
    subgraph "Repository Root"
        direction TB
        Root_Readme["README.md"]:::doc
        CodeConduct["CODE_OF_CONDUCT.md"]:::doc
        License["LICENSE"]:::doc
        Security["SECURITY.md"]:::doc
        CI_Pylint[".github/workflows/pylint.yml"]:::ci
        CI_Merge[".github/workflows/auto-merge-dependabot.yml"]:::ci
    end

    %% Data Flows for App-only
    Dev --> AO_Main
    AO_Main -->|"reads config"| AO_Config
    AO_Main -->|"invokes Auth Module"| AO_Auth
    AO_Auth -->|"OAuth2 token request"| AzureAD
    AzureAD -->|"Access Token"| AO_Auth
    AO_Main -->|"uses token"| AO_Graph
    AO_Graph -->|"HTTPS Graph calls (SDK)"| GraphAPI
    GraphAPI -->|"Service operations"| M365

    %% Data Flows for Delegated
    Dev --> DU_Main
    DU_Main -->|"reads config"| DU_Config
    DU_Main -->|"invokes Auth Module"| DU_Auth
    DU_Auth -->|"OAuth2 token request"| AzureAD
    AzureAD -->|"Access Token"| DU_Auth
    DU_Main -->|"uses token"| DU_Graph
    DU_Graph -->|"HTTPS Graph calls (SDK)"| GraphAPI
    GraphAPI -->|"Service operations"| M365

    %% Click Events - App-only
    click AO_Config "https://github.com/microsoftgraph/msgraph-training-python/blob/main/app-auth/graphapponlytutorial/config.cfg"
    click AO_Auth "https://github.com/microsoftgraph/msgraph-training-python/blob/main/app-auth/graphapponlytutorial/graph.py"
    click AO_Graph "https://github.com/microsoftgraph/msgraph-training-python/blob/main/app-auth/graphapponlytutorial/graph.py"
    click AO_Main "https://github.com/microsoftgraph/msgraph-training-python/blob/main/app-auth/graphapponlytutorial/main.py"
    click AO_Deps "https://github.com/microsoftgraph/msgraph-training-python/blob/main/app-auth/graphapponlytutorial/requirements.in"
    click AO_Lint "https://github.com/microsoftgraph/msgraph-training-python/tree/main/app-auth/graphapponlytutorial/pylintrc"
    click AO_PS "https://github.com/microsoftgraph/msgraph-training-python/blob/main/app-auth/RegisterAppForAppOnlyAuth.ps1"
    click AO_Readme "https://github.com/microsoftgraph/msgraph-training-python/blob/main/app-auth/README.md"

    %% Click Events - Delegated
    click DU_Config "https://github.com/microsoftgraph/msgraph-training-python/blob/main/user-auth/graphtutorial/config.cfg"
    click DU_Auth "https://github.com/microsoftgraph/msgraph-training-python/blob/main/user-auth/graphtutorial/graph.py"
    click DU_Graph "https://github.com/microsoftgraph/msgraph-training-python/blob/main/user-auth/graphtutorial/graph.py"
    click DU_Main "https://github.com/microsoftgraph/msgraph-training-python/blob/main/user-auth/graphtutorial/main.py"
    click DU_Deps "https://github.com/microsoftgraph/msgraph-training-python/blob/main/user-auth/graphtutorial/requirements.in"
    click DU_Lint "https://github.com/microsoftgraph/msgraph-training-python/tree/main/user-auth/graphtutorial/pylintrc"
    click DU_PS "https://github.com/microsoftgraph/msgraph-training-python/blob/main/user-auth/RegisterAppForUserAuth.ps1"
    click DU_Readme "https://github.com/microsoftgraph/msgraph-training-python/blob/main/user-auth/README.md"

    %% Click Events - Root
    click CI_Pylint "https://github.com/microsoftgraph/msgraph-training-python/blob/main/.github/workflows/pylint.yml"
    click CI_Merge "https://github.com/microsoftgraph/msgraph-training-python/blob/main/.github/workflows/auto-merge-dependabot.yml"
    click Root_Readme "https://github.com/microsoftgraph/msgraph-training-python/blob/main/README.md"
    click CodeConduct "https://github.com/microsoftgraph/msgraph-training-python/blob/main/CODE_OF_CONDUCT.md"
    click License "https://github.com/microsoftgraph/msgraph-training-python/tree/main/LICENSE"
    click Security "https://github.com/microsoftgraph/msgraph-training-python/blob/main/SECURITY.md"

    %% Styles
    classDef local fill:#cce5ff,stroke:#004085,stroke-width:1px
    classDef identity fill:#d4edda,stroke:#155724,stroke-width:1px
    classDef cloud fill:#fff3cd,stroke:#856404,stroke-width:1px
    classDef cli fill:#e2e3e5,stroke:#6c757d,stroke-width:1px
    classDef script fill:#f8d7da,stroke:#721c24,stroke-width:1px
    classDef doc fill:#d1ecf1,stroke:#0c5460,stroke-width:1px
    classDef ci fill:#f0f0f0,stroke:#888888,stroke-width:1px
```
