# betogrun/lean-microsoft-graph architecture

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

- Interactive diagram: https://gitdiagram.com/betogrun/lean-microsoft-graph
- Repository: https://github.com/betogrun/lean-microsoft-graph

## Overview

##### Project Type Analysis
This is a Ruby gem (library) that serves as a wrapper/client for Microsoft Graph API, specifically designed to work with Faraday version 1. The architecture should focus on showing the interaction flow between the client application, this gem, and Microsoft Graph API.

##### Main Components

a. Client Application Layer:
- How external applications integrate with the gem
- Entry point through LeanMicrosoftGraph::Client

b. Authentication Layer:
- Credentials management
- Token retrieval and handling
- Interaction with Microsoft Azure AD

c. Resource Layer:
- Resource handlers (Users, Tokens)
- Model objects (User, Token)

d. External Services:
- Microsoft Graph API
- Azure Active Directory

**┌─ External Application Layer ─┐**
- Client Application        │
- ┬─────────────────┘
- ↓
**┌─ LeanMicrosoftGraph Gem ────────────────────┐**
- ┌─ Client Layer ─┐                         │
- Client Class   │                         │
- ┬────────┘                         │
- ↓                                  │
- ┌─ Authentication Layer ─┐                 │
- Credentials         │                 │
- TokenRetriever      │                 │
- ┬──────────────┘                 │
- ↓                                  │
- ┌─ Resource Layer ──────┐                 │
- TokenResource       │                 │
- UsersResource       │                 │
- ┬──────────────┘                 │
- ┼──────────────────────────────────┘
- ↓
**┌─ External Services ──────┐**
- Microsoft Graph API   │
- Azure Active Directory│
- ┘

##### Important Details

a. Authentication Flow:
- Credential flow from Client → Credentials → TokenRetriever
- Token caching and renewal process

b. Resource Handling:
- Demonstrate how Resource classes interact with the Client
- Relationship between resource handlers and their models

c. External Communication:
- API endpoints
- Authentication token flow

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef external fill:#6495ED,stroke:#333,stroke-width:2px
    classDef gem fill:#98FB98,stroke:#333,stroke-width:2px
    classDef auth fill:#FFA500,stroke:#333,stroke-width:2px
    classDef resource fill:#DDA0DD,stroke:#333,stroke-width:2px
    classDef service fill:#FF69B4,stroke:#333,stroke-width:2px

    %% Client Application Layer
    ClientApp[Client Application]:::external

    %% LeanMicrosoftGraph Gem Layer
    subgraph GemLayer["LeanMicrosoftGraph Gem"]
        Entry["Main Entry Point"]:::gem
        Client["Client Interface"]:::gem
        Error["Error Handler"]:::gem
        Version["Version Manager"]:::gem

        %% Authentication Layer
        subgraph AuthLayer["Authentication Layer"]
            Credentials["Credentials Manager"]:::auth
            TokenRetriever["Token Retriever"]:::auth
        end

        %% Resource Layer
        subgraph ResourceLayer["Resource Layer"]
            BaseResource["Base Resource"]:::resource
            TokenResource["Token Resource"]:::resource
            TokenModel["Token Model"]:::resource
            UsersResource["Users Resource"]:::resource
            UserModel["User Model"]:::resource
            UsersCollection["Users Collection"]:::resource
        end
    end

    %% External Services
    MSGraph["Microsoft Graph API"]:::service
    AzureAD["Azure Active Directory"]:::service

    %% Relationships
    ClientApp --> Entry
    Entry --> Client
    Client --> Error
    Client --> Credentials
    Credentials --> TokenRetriever
    TokenRetriever --> AzureAD
    Client --> BaseResource
    BaseResource --> TokenResource
    BaseResource --> UsersResource
    TokenResource --> TokenModel
    UsersResource --> UserModel
    UsersResource --> UsersCollection
    TokenResource --> MSGraph
    UsersResource --> MSGraph

    %% Click Events
    click Entry "https://github.com/betogrun/lean-microsoft-graph/blob/main/lib/lean_microsoft_graph.rb"
    click Client "https://github.com/betogrun/lean-microsoft-graph/blob/main/lib/lean_microsoft_graph/client.rb"
    click Error "https://github.com/betogrun/lean-microsoft-graph/blob/main/lib/lean_microsoft_graph/error.rb"
    click Version "https://github.com/betogrun/lean-microsoft-graph/blob/main/lib/lean_microsoft_graph/version.rb"
    click Credentials "https://github.com/betogrun/lean-microsoft-graph/blob/main/lib/lean_microsoft_graph/authentication/credentials.rb"
    click TokenRetriever "https://github.com/betogrun/lean-microsoft-graph/blob/main/lib/lean_microsoft_graph/authentication/token_retriever.rb"
    click BaseResource "https://github.com/betogrun/lean-microsoft-graph/blob/main/lib/lean_microsoft_graph/resource.rb"
    click TokenResource "https://github.com/betogrun/lean-microsoft-graph/blob/main/lib/lean_microsoft_graph/resources/token_resource.rb"
    click TokenModel "https://github.com/betogrun/lean-microsoft-graph/blob/main/lib/lean_microsoft_graph/resources/token_resource/token.rb"
    click UsersResource "https://github.com/betogrun/lean-microsoft-graph/blob/main/lib/lean_microsoft_graph/resources/users_resource.rb"
    click UserModel "https://github.com/betogrun/lean-microsoft-graph/blob/main/lib/lean_microsoft_graph/resources/users_resource/user.rb"
    click UsersCollection "https://github.com/betogrun/lean-microsoft-graph/blob/main/lib/lean_microsoft_graph/resources/users_resource/users.rb"

    %% Legend
    subgraph Legend
        L1[External Component]:::external
        L2[Gem Component]:::gem
        L3[Auth Component]:::auth
        L4[Resource Component]:::resource
        L5[External Service]:::service
    end
```
