# wordpress/wporg-two-factor architecture

> Architecture diagram of the GitHub repository wordpress/wporg-two-factor, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/wordpress/wporg-two-factor
- Repository: https://github.com/wordpress/wporg-two-factor

## Overview

##### Main System Components

a) WordPress Core Integration Layer
- How the plugin integrates with WordPress Multisite
- MU-plugins integration points
- BbPress integration for user management

b) Authentication Components
- Two-Factor Authentication Providers:
- WebAuthn Provider
- Encrypted TOTP Provider
- Integration with external Two-Factor plugin

c) Frontend Architecture
- React-based Settings Interface
- REST API Integration
- User Management Screens

##### Key Relationships to Highlight

a) Data Flow
- WordPress authentication hooks → Two-Factor providers
- REST API endpoints ↔ React components
- User settings ↔ Authentication providers

b) Component Integration
- How the settings UI communicates with the backend
- Authentication flow between providers
- Revalidation process flow

##### Specific Implementation Details

- Blue rectangles: Core WordPress components
- Green rectangles: Custom plugin components
- Yellow diamonds: Authentication providers
- Purple rectangles: Frontend React components
- Red lines: Security-critical paths
- Gray lines: Standard data flow

##### Architectural Layers (top to bottom)

**[Frontend Layer]**
- React Components (settings/src/components/)
- User Interface Elements
- WebAuthn Integration

**[API Layer]**
- REST API Endpoints (settings/rest-api.php)
- WordPress Hooks Integration

**[Authentication Layer]**
- Two-Factor Providers
- Encrypted TOTP
- WebAuthn Provider

**[WordPress Core Integration]**
- Multisite Support
- bbPress Integration
- MU-Plugin Hooks

##### Important Elements

- Clear separation between frontend and backend components
- Integration points with WordPress core
- Testing infrastructure connections
- Build and deployment workflow connections

##### Technical Stack Indicators

- WordPress
- React
- PHP
- JavaScript
- WebAuthn
- TOTP
- Composer
- npm/Yarn

##### Development Workflow

A separate section for:
- GitHub Actions workflows
- Testing infrastructure
- Build processes
- Environment setup

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Frontend
        RC[React Components]
        WC[WebAuthn Components]
        TC[TOTP Components]
        FT[First Time Setup]
        UM[User Management]
        FU[Frontend Utilities]
    end

    subgraph API
        REST[REST API]
        SA[Settings API]
        WPH[WordPress Hooks]
    end

    subgraph Authentication
        direction TB
        WA[WebAuthn Provider]
        TP[TOTP Provider]
        EXT[External 2FA Plugin]
    end

    subgraph "WordPress Integration"
        direction TB
        MU[MU-Plugin]
        MS[Multisite]
        BB[bbPress]
        PE[Plugin Entry]
    end

    subgraph "Development Infrastructure"
        direction TB
        CI[CI/CD Workflows]
        TI[Testing Infrastructure]
        RV[Revalidation System]
    end

    %% Frontend Connections
    RC --> REST
    WC --> REST
    TC --> REST
    FT --> REST
    UM --> REST

    %% API Connections
    REST --> WPH
    SA --> WPH
    WPH --> Authentication

    %% Authentication Connections
    WA --> WPH
    TP --> WPH
    EXT --> WPH

    %% WordPress Integration Connections
    WPH --> MU
    WPH --> MS
    WPH --> BB
    PE --> WPH

    %% Development Infrastructure Connections
    CI --> PE
    TI --> PE
    RV --> WPH

    %% Styling
    classDef frontend fill:#purple,stroke:#333,stroke-width:2px
    classDef api fill:#green,stroke:#333,stroke-width:2px
    classDef auth fill:#yellow,stroke:#333,stroke-width:2px
    classDef wp fill:#blue,stroke:#333,stroke-width:2px
    classDef infra fill:#gray,stroke:#333,stroke-width:2px

    class RC,WC,TC,FT,UM,FU frontend
    class REST,SA,WPH api
    class WA,TP,EXT auth
    class MU,MS,BB,PE wp
    class CI,TI,RV infra

    %% Click Events
    click WA "https://github.com/wordpress/wporg-two-factor/blob/trunk/class-wporg-webauthn-provider.php"
    click TP "https://github.com/wordpress/wporg-two-factor/blob/trunk/class-encrypted-totp-provider.php"
    click RC "https://github.com/wordpress/wporg-two-factor/tree/trunk/settings/src/components/"
    click REST "https://github.com/wordpress/wporg-two-factor/blob/trunk/settings/rest-api.php"
    click WC "https://github.com/wordpress/wporg-two-factor/tree/trunk/settings/src/components/webauthn/"
    click TC "https://github.com/wordpress/wporg-two-factor/blob/trunk/settings/src/components/totp.js"
    click UM "https://github.com/wordpress/wporg-two-factor/blob/trunk/settings/src/hooks/useUser.js"
    click MU "https://github.com/wordpress/wporg-two-factor/blob/trunk/.wp-env/mu-plugin.php"
    click PE "https://github.com/wordpress/wporg-two-factor/blob/trunk/wporg-two-factor.php"
    click RV "https://github.com/wordpress/wporg-two-factor/tree/trunk/revalidation/"
    click TI "https://github.com/wordpress/wporg-two-factor/tree/trunk/tests/"
    click CI "https://github.com/wordpress/wporg-two-factor/tree/trunk/.github/workflows/"
    click SA "https://github.com/wordpress/wporg-two-factor/blob/trunk/settings/settings.php"
    click FU "https://github.com/wordpress/wporg-two-factor/tree/trunk/settings/src/utilities/"
    click FT "https://github.com/wordpress/wporg-two-factor/tree/trunk/settings/src/components/first-time/"
```
