# vgrem/phpspo architecture

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

- Interactive diagram: https://gitdiagram.com/vgrem/phpspo
- Repository: https://github.com/vgrem/phpspo

## Overview

##### Main Components
- Core Library & Service Client: Represent the GraphServiceClient and the higher-level service objects which act as entry points to various APIs.
- Authentication Modules: Include different authentication flows (client credential, certificate, NTLM, user credentials) located under Runtime/Auth. Indicate flows towards services such as AADTokenProvider.
- Service-Specific APIs: Break out modules for SharePoint, Teams, Outlook, OneDrive, OneNote, and Planner. Each has its own namespace under “src” (e.g., Office365\SharePoint, Office365\GraphServiceClient, Office365\Teams) which provide service-specific functionality.
- OData and HTTP Communication: Illustrate the internal handling of HTTP requests, query building, and data serialization via components under Runtime (e.g., Runtime/Http, Runtime/OData, ClientRequest, Requests, Response, etc.).
- Object Models & Data Structures: Represent the entities and collections that mirror Microsoft 365 objects (e.g., ListItem, File, DriveItem, Message, etc.) across the API’s.
- Code Generation Tools: Note the “generator” folder with builders and templates. This component automates (or assists in) generation of models and API stubs and is a critical piece for maintaining consistency.
- Examples & Tests: Include examples (demonstrating usage, such as CRUD operations, sending emails, and working with SharePoint list items) and tests directory (which covers extensive unit and integration tests).

##### Relationships and Interactions
- Authentication Dependency: The authentication modules serve as prerequisites for a secure connection with Microsoft Graph and SharePoint endpoints.

##### Architectural Patterns & Design Principles
- Layered Architecture: Separate the presentation (client usage examples) from the business logic (service APIs) and the infrastructure (HTTP, OData, authentication).
- Builder / Fluent API: Illustrate the fluent interaction where methods return modified objects or queries enabling chained method calls.
- Modularity & Namespacing: Given the long list of service-specific directories within “src,” emphasize that each service module is decoupled and adheres to clear boundaries.
- Test-Driven / Example Driven: Note that the tests and examples are used to ensure integration across the layers, guiding proper API usage.

##### Technology and Frameworks
- PHP and Composer: Mention that the library depends on Composer for autoloading and dependency management.
- OData and REST: Highlight that the communication with Microsoft 365 services is REST/OData based.
- Authentication Protocols: Acknowledge support for OAuth (AAD tokens) and other strategies like NTLM and certificate-based auth.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Application Layer
    subgraph "Application Layer"
        E["Examples"]:::app
        T["Tests"]:::app
    end

    %% API Services Layer
    subgraph "API Services"
        G["GraphServiceClient"]:::api
        SP["Service Module: SharePoint"]:::api
        OD["Service Module: OneDrive"]:::api
        OL["Service Module: Outlook"]:::api
        ON["Service Module: OneNote"]:::api
        TM["Service Module: Teams"]:::api
        PL["Service Module: Planner"]:::api
    end

    %% Core Runtime Layer
    subgraph "Core Runtime"
        AUTH["Authentication (AADTokenProvider)"]:::runtime
        HTTP["HTTP Communication"]:::runtime
        ODATA["OData Layer"]:::runtime
        OBJ["Object Models & Data Structures"]:::runtime
    end

    %% Supporting Tools
    subgraph "Supporting Tools"
        GEN["Code Generator"]:::gen
    end

    %% External Service
    M365["Microsoft 365 Services"]:::external

    %% Connections - Application to API
    E -->|"initiates"| G
    T -->|"initiates"| G

    %% API Services interactions
    G -->|"authenticates"| AUTH
    AUTH -->|"returns-token"| G
    G -->|"builds-request"| HTTP
    G -->|"builds-query"| ODATA
    G -->|"uses-objects"| OBJ

    %% Code Generator support
    GEN -->|"generates-models"| G
    GEN -->|"generates-objects"| OBJ

    %% API Service modules invoked via GraphServiceClient
    G -->|"calls-service"| SP
    G -->|"calls-service"| OD
    G -->|"calls-service"| OL
    G -->|"calls-service"| ON
    G -->|"calls-service"| TM
    G -->|"calls-service"| PL

    %% Underlying runtime communication flow to Microsoft 365
    HTTP -->|"sends-receives"| M365
    ODATA -->|"sends-receives"| M365

    %% API modules utilizing Object Models
    SP -->|"utilizes"| OBJ
    OD -->|"utilizes"| OBJ
    OL -->|"utilizes"| OBJ
    ON -->|"utilizes"| OBJ
    TM -->|"utilizes"| OBJ
    PL -->|"utilizes"| OBJ

    %% Click Events
    click G "https://github.com/vgrem/phpspo/blob/master/src/GraphServiceClient.php"
    click AUTH "https://github.com/vgrem/phpspo/blob/master/src/Runtime/Auth/AADTokenProvider.php"
    click SP "https://github.com/vgrem/phpspo/tree/master/src/SharePoint"
    click OD "https://github.com/vgrem/phpspo/tree/master/src/OneDrive"
    click OL "https://github.com/vgrem/phpspo/tree/master/src/Outlook"
    click ON "https://github.com/vgrem/phpspo/tree/master/src/OneNote"
    click TM "https://github.com/vgrem/phpspo/tree/master/src/Teams"
    click PL "https://github.com/vgrem/phpspo/tree/master/src/Planner"
    click HTTP "https://github.com/vgrem/phpspo/tree/master/src/Runtime/Http"
    click ODATA "https://github.com/vgrem/phpspo/tree/master/src/Runtime/OData"
    click OBJ "https://github.com/vgrem/phpspo/blob/master/src/Entity.php"
    click GEN "https://github.com/vgrem/phpspo/tree/master/generator"
    click E "https://github.com/vgrem/phpspo/tree/master/examples"
    click T "https://github.com/vgrem/phpspo/tree/master/tests"

    %% Style Definitions
    classDef app fill:#FFEB3B,stroke:#FDD835,stroke-width:2px;
    classDef api fill:#AED581,stroke:#7CB342,stroke-width:2px;
    classDef runtime fill:#81D4FA,stroke:#039BE5,stroke-width:2px;
    classDef gen fill:#CE93D8,stroke:#AB47BC,stroke-width:2px;
    classDef external fill:#E0E0E0,stroke:#9E9E9E,stroke-width:2px;
```
