# redbyte1337/graphspy architecture

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

- Interactive diagram: https://gitdiagram.com/redbyte1337/graphspy
- Repository: https://github.com/redbyte1337/graphspy

## Overview

##### Project type and purpose
- This is a full-stack Python web application (GraphSpy) built on Flask. It provides a browser-based GUI to explore and manipulate Microsoft 365 resources via the Microsoft Graph API, handling OAuth2 device-code flows, token storage, and a variety of Graph operations (OneDrive, SharePoint, Outlook, Teams, etc.).

##### File structure
- Top-level:
- GraphSpy/ – the Python package
– GraphSpy.py – main Flask application entry point
– static/ – CSS and JS assets (style.css, functions.js, theme.js)
– templates/ – Jinja2 HTML templates for each feature page
– __init__.py, version.txt
- setup.py, requirements.txt – packaging & dependencies
- README.md, LICENSE, MANIFEST.in
- There is no separate “frontend” folder; the Flask app serves both backend and frontend.
- No microservices: monolithic server that handles routing, business logic, data persistence, and external API calls.

##### README for additional insights
- Confirms Flask server runs on localhost:5000 by default.
- Uses multiple database back-ends (likely SQLite via SQLAlchemy or similar).
- Provides features organized by modules: tokens, device codes, MFA, files/SharePoint, Outlook, Teams, search, custom requests, Entra ID.
- JavaScript is used for client-side interactivity (e.g., token side-bar, dynamic tables).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI Layer
    UserBrowser["User's Web Browser"]:::ui

    %% Application Layer
    subgraph "Flask Server (GraphSpy)" 
        direction TB
        GraphSpyApp["Flask App"]:::server

        subgraph "Service Modules"
            direction TB
            AuthManager["Authentication Manager"]:::service
            TokenStore["Token Store Manager"]:::service
            DeviceCodeMgr["Device Code Manager"]:::service
            MFAModule["MFA Module"]:::service
            FileExplorer["File Explorer Module"]:::service
            OutlookModule["Outlook Module"]:::service
            TeamsModule["Teams Module"]:::service
            SearchModule["Graph Search Module"]:::service
            CustomReq["Custom Request Engine"]:::service
            EntraID["Entra ID Module"]:::service
        end

        DataLayer["Data Access Layer (ORM)"]:::server
        TemplateRenderer["Template Renderer (Jinja2)"]:::server

        subgraph "Static Assets"
            direction TB
            StyleCSS["style.css"]:::static
            FuncJS["functions.js"]:::static
            ThemeJS["theme.js"]:::static
        end
    end

    %% Persistence Layer
    DB["Local Database"]:::db

    %% External Services
    MSGraph["Microsoft Graph API"]:::external

    %% Connections
    UserBrowser -->|HTTP/HTTPS Requests| GraphSpyApp
    GraphSpyApp -->|renders HTML/CSS/JS| UserBrowser
    UserBrowser -->|loads assets| StyleCSS
    UserBrowser -->|loads assets| FuncJS
    UserBrowser -->|loads assets| ThemeJS

    GraphSpyApp --> DataLayer
    DataLayer -->|CRUD| DB

    GraphSpyApp --> TemplateRenderer
    TemplateRenderer -->|renders views| UserBrowser

    GraphSpyApp --> MSGraph
    FileExplorer -->|API Calls| MSGraph
    AuthManager -->|OAuth2 Flows| MSGraph
    TokenStore -->|Token Validation| MSGraph
    DeviceCodeMgr -->|Device Code Flow| MSGraph
    MFAModule -->|MFA Operations| MSGraph
    OutlookModule -->|Mail API| MSGraph
    TeamsModule -->|Teams API| MSGraph
    SearchModule -->|Search API| MSGraph
    CustomReq -->|Custom Requests| MSGraph
    EntraID -->|User & Directory API| MSGraph

    GraphSpyApp --> AuthManager
    GraphSpyApp --> TokenStore
    GraphSpyApp --> DeviceCodeMgr
    GraphSpyApp --> MFAModule
    GraphSpyApp --> FileExplorer
    GraphSpyApp --> OutlookModule
    GraphSpyApp --> TeamsModule
    GraphSpyApp --> SearchModule
    GraphSpyApp --> CustomReq
    GraphSpyApp --> EntraID

    %% Click Events
    click GraphSpyApp "https://github.com/redbyte1337/graphspy/blob/master/GraphSpy/GraphSpy.py"
    click AuthManager "https://github.com/redbyte1337/graphspy/blob/master/GraphSpy/GraphSpy.py"
    click TokenStore "https://github.com/redbyte1337/graphspy/blob/master/GraphSpy/GraphSpy.py"
    click DeviceCodeMgr "https://github.com/redbyte1337/graphspy/blob/master/GraphSpy/GraphSpy.py"
    click MFAModule "https://github.com/redbyte1337/graphspy/blob/master/GraphSpy/GraphSpy.py"
    click FileExplorer "https://github.com/redbyte1337/graphspy/blob/master/GraphSpy/GraphSpy.py"
    click OutlookModule "https://github.com/redbyte1337/graphspy/blob/master/GraphSpy/GraphSpy.py"
    click TeamsModule "https://github.com/redbyte1337/graphspy/blob/master/GraphSpy/GraphSpy.py"
    click SearchModule "https://github.com/redbyte1337/graphspy/blob/master/GraphSpy/GraphSpy.py"
    click CustomReq "https://github.com/redbyte1337/graphspy/blob/master/GraphSpy/GraphSpy.py"
    click EntraID "https://github.com/redbyte1337/graphspy/blob/master/GraphSpy/GraphSpy.py"
    click StyleCSS "https://github.com/redbyte1337/graphspy/blob/master/GraphSpy/static/css/style.css"
    click FuncJS "https://github.com/redbyte1337/graphspy/blob/master/GraphSpy/static/js/functions.js"
    click ThemeJS "https://github.com/redbyte1337/graphspy/blob/master/GraphSpy/static/js/theme.js"
    click TemplateRenderer "https://github.com/redbyte1337/graphspy/blob/master/GraphSpy/templates/layout.html"
    click TemplateRenderer "https://github.com/redbyte1337/graphspy/blob/master/GraphSpy/templates/index.html"

    %% Styles
    classDef ui fill:#ADD8E6,stroke:#000;
    classDef server fill:#D3D3D3,stroke:#000;
    classDef service fill:#A9A9A9,stroke:#000;
    classDef db fill:#F5DEB3,stroke:#000,shape:cylinder;
    classDef external fill:#98FB98,stroke:#000,shape:cloud;
    classDef static fill:#FFEFD5,stroke:#000;
```
