# mlflow-oidc/mlflow-oidc-auth architecture

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

- Interactive diagram: https://gitdiagram.com/mlflow-oidc/mlflow-oidc-auth
- Repository: https://github.com/mlflow-oidc/mlflow-oidc-auth

## Overview

##### Main Components
- Backend Authentication Service:
- Mlflow_oidc_auth module as the core backend service. Within this service, include sub-components such as:
▪ App and Routing (app.py and routes.py) managing incoming HTTP requests.
▪ Authentication logic (auth.py, client.py, views) that implements OIDC flows.
▪ Session management modules (session/) handling Flask sessions with a choice of filesystem or Redis storage.
▪ Cache components (cache/) with distinct implementations like FilesystemCache and RedisCache.
▪ Database & Migration layer (db/ and migrations) using SQLAlchemy, with migration scripts for managing models and group/user permissions.
▪ Plugins (plugins/) such as the Microsoft Entra ID group detection, indicating an extensible design.
▪ Helpers (validators, utils, responses) assisting in data validation and error handling.

- Frontend Web UI:

- External Dependencies:
- Third-party dependencies such as MLflow itself (since this is a plugin for MLflow) and any other integrations noted in the configuration.

##### Component Relationships and Interactions
- The Frontend (Angular Web UI) issues calls (HTTP REST API requests) to the Backend Authentication Service, typically for login flows, permission management, and user data operations.
- The Backend Service, upon receiving authentication requests, interacts with the external OIDC provider:
- It sends users to the OIDC authorization endpoint.
- It receives callbacks and tokens from the OIDC provider via its configured redirect (OIDC_REDIRECT_URI).
- After authentication, the backend uses its session management (via Flask sessions configured with either filesystem or Redis) to maintain user state.
- The caching layer (using either FilesystemCache or RedisCache) optimizes session data and possibly token caching.
- The database layer (using SQLAlchemy and managed by Alembic migrations) records user information and permission data. This storage also supports the permission management UIs available in the Web UI.
- Optional plugins (e.g., group_detection_microsoft_entra_id) extend backend functionality to pull additional group membership or permission details from external identity providers.

##### Architectural Patterns and Design Principles
- Modular design: The backend is split into clearly defined modules – authentication, database, caching, plugins, and views – allowing independent evolution and testing.
- Separation of concerns: The Angular Web UI is decoupled from the backend business logic, communicating over well-defined API endpoints.
- Extensibility: Use of plugins for group detection shows an extensible architecture to support different OIDC providers and custom group management solutions.
- Robust session management: Configurable session storage supports scalability and reliability.
- Standardization: Following the OAuth/OIDC flows and integrating with MLflow’s plugin patterns emphasizes standardized security and interoperability practices.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Components
    Frontend["Frontend Web UI (Angular)"]:::frontend
    OIDC["OIDC Provider"]:::external
    MLflow["MLflow Server"]:::external

    %% Backend Subgraph
    subgraph "Backend Authentication Service"
        BackendCore["mlflow_oidc_auth (Backend Service)"]:::backend
        AppRouting["App & Routing (app.py, routes.py)"]:::backendComp
        AuthLogic["Authentication Logic (auth.py, client.py, views/)"]:::backendComp
        SessionMgmt["Session Management (session/)"]:::backendComp
        Cache["Caching (cache/)"]:::backendComp
        Database["Database & Migration (db/ & migrations)"]:::backendComp
        Plugin["Plugins (group detection)"]:::backendComp
        Helpers["Helper Modules (validators, utils, responses)"]:::backendComp

        BackendCore --> AppRouting
        AppRouting --> AuthLogic
        AuthLogic --> SessionMgmt
        AuthLogic --> Database
        AuthLogic --> Plugin
        AuthLogic --> Helpers
        SessionMgmt --> Cache
    end

    %% Interactions Between Components
    Frontend -->|"API_request"| AppRouting
    AuthLogic -->|"OIDC_Auth_Flow"| OIDC
    OIDC -->|"OIDC_Response"| AuthLogic
    AuthLogic -->|"MLflow_Verification"| MLflow

    %% Click Events for Backend Components
    click BackendCore "https://github.com/mlflow-oidc/mlflow-oidc-auth/tree/main/mlflow_oidc_auth"
    click AppRouting "https://github.com/mlflow-oidc/mlflow-oidc-auth/blob/main/mlflow_oidc_auth/app.py"
    click AppRouting "https://github.com/mlflow-oidc/mlflow-oidc-auth/blob/main/mlflow_oidc_auth/routes.py"
    click AuthLogic "https://github.com/mlflow-oidc/mlflow-oidc-auth/blob/main/mlflow_oidc_auth/auth.py"
    click AuthLogic "https://github.com/mlflow-oidc/mlflow-oidc-auth/blob/main/mlflow_oidc_auth/client.py"
    click AuthLogic "https://github.com/mlflow-oidc/mlflow-oidc-auth/tree/main/mlflow_oidc_auth/views/"
    click SessionMgmt "https://github.com/mlflow-oidc/mlflow-oidc-auth/tree/main/mlflow_oidc_auth/session/"
    click Cache "https://github.com/mlflow-oidc/mlflow-oidc-auth/tree/main/mlflow_oidc_auth/cache/"
    click Database "https://github.com/mlflow-oidc/mlflow-oidc-auth/tree/main/mlflow_oidc_auth/db/"
    click Database "https://github.com/mlflow-oidc/mlflow-oidc-auth/tree/main/mlflow_oidc_auth/db/migrations"
    click Plugin "https://github.com/mlflow-oidc/mlflow-oidc-auth/tree/main/mlflow_oidc_auth/plugins/"
    click Plugin "https://github.com/mlflow-oidc/mlflow-oidc-auth/tree/main/mlflow_oidc_auth/plugins/group_detection_microsoft_entra_id"
    click Helpers "https://github.com/mlflow-oidc/mlflow-oidc-auth/tree/main/mlflow_oidc_auth/validators/"
    click Helpers "https://github.com/mlflow-oidc/mlflow-oidc-auth/blob/main/mlflow_oidc_auth/utils.py"
    click Helpers "https://github.com/mlflow-oidc/mlflow-oidc-auth/tree/main/mlflow_oidc_auth/responses/"
    click Frontend "https://github.com/mlflow-oidc/mlflow-oidc-auth/tree/main/web-ui"

    %% Styles
    classDef backend fill:#FFD700,stroke:#8B8000,stroke-width:2px;
    classDef backendComp fill:#FFEFD5,stroke:#CD853F,stroke-width:1px;
    classDef frontend fill:#98FB98,stroke:#2E8B57,stroke-width:2px;
    classDef external fill:#ADD8E6,stroke:#00008B,stroke-width:2px,stroke-dasharray: 5 5;
    classDef external_db fill:#E0FFFF,stroke:#008B8B,stroke-width:2px,stroke-dasharray: 5 5;
```
