# wp-graphql/wp-graphql-jwt-authentication architecture

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

- Interactive diagram: https://gitdiagram.com/wp-graphql/wp-graphql-jwt-authentication
- Repository: https://github.com/wp-graphql/wp-graphql-jwt-authentication

## Overview

##### Main Components
- WordPress Core – This is the hosting environment where the plugin is installed.
- WPGraphQL Plugin – Represents the GraphQL layer that provides the schema and query/mutation execution.
- WPGraphQL JWT Authentication Plugin – The plugin itself, which adds new mutations (login, registerUser, refreshJwtAuthToken) and includes the PHP classes (found in the src directory: Auth.php, Login.php, ManageTokens.php, RefreshToken.php) that encapsulate the authentication logic.
- External Services & Libraries – JWT libraries for encoding/decoding tokens, and Composer for dependency management.
- HTTP Layer – The client is expected to send the HTTP_AUTHORIZATION header, so include a component that represents the HTTP request/response cycle with proper handling of headers.
- Testing Suite – Represent the testing framework (PHPUnit, Codeception, wpunit tests) and supporting helper components (tests/_support/Helper/*.php files) that simulate various scenarios.

##### Relationships & Interactions
- The WordPress Core loads WPGraphQL, which in turn integrates your JWT Authentication plugin.
- Incoming authentication requests (Login, RegisterUser, RefreshToken).
- Outgoing token creation or validation responses.
- That the secret key (configured via constants or filters) is used for encoding/decoding JWT tokens.

##### Architectural Patterns & Design Principles
- The plugin follows a modular design by separating authentication logic into classes within the src directory.
- Use of filters (to customize secret key and expiration time) as an extensibility point.
- The separation between business logic (JWT management and mutations) and testing is clearly visible from the file structure: tests (functional, wpunit) and src.
- Use of dependency management via Composer suggests adherence to standard PHP practices.

##### Relevant Technologies, Frameworks, and Libraries
- PHP – The primary language, with the code organized in src.
- WordPress & WPGraphQL – The framework and GraphQL schema provider.
- JWT (JSON Web Token) standards – RFC 7519.
- Testing Tools – PHPUnit, Codeception, wpunit.
- Configuration Files – Note files such as .env.dist, composer.json, and codeception/ PHPUnit configurations.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client["Client (GraphQL Request)"] 
    HTTPLayer["HTTP Layer (HTTP_AUTHORIZATION)"]
    WPCore["WordPress Core"]
    WPGraphQL["WPGraphQL Plugin"]
    JWTPlugin["WPGraphQL JWT Authentication Plugin"]
    
    subgraph "Authentication Logic Classes"
        Auth["Auth"]
        Login["Login"]
        ManageTokens["Manage Tokens"]
        RefreshToken["Refresh Token"]
    end

    ExternalLib["External Services & Libraries"]
    TestingSuite["Testing Suite"]

    Client -->|"sendsRequest"| HTTPLayer
    HTTPLayer -->|"forwardsHeader"| WPGraphQL
    WPCore -->|"loads"| WPGraphQL
    WPGraphQL -->|"integrates"| JWTPlugin
    JWTPlugin -->|"executes"| Auth
    JWTPlugin -->|"executes"| Login
    JWTPlugin -->|"executes"| ManageTokens
    JWTPlugin -->|"executes"| RefreshToken
    Auth -->|"usesLibrary"| ExternalLib
    Login -->|"usesLibrary"| ExternalLib
    ManageTokens -->|"usesLibrary"| ExternalLib
    RefreshToken -->|"usesLibrary"| ExternalLib
    TestingSuite -->|"simulatesCalls"| WPGraphQL

    click JWTPlugin "https://github.com/wp-graphql/wp-graphql-jwt-authentication/blob/develop/wp-graphql-jwt-authentication.php"
    click Auth "https://github.com/wp-graphql/wp-graphql-jwt-authentication/blob/develop/src/Auth.php"
    click Login "https://github.com/wp-graphql/wp-graphql-jwt-authentication/blob/develop/src/Login.php"
    click ManageTokens "https://github.com/wp-graphql/wp-graphql-jwt-authentication/blob/develop/src/ManageTokens.php"
    click RefreshToken "https://github.com/wp-graphql/wp-graphql-jwt-authentication/blob/develop/src/RefreshToken.php"
    click ExternalLib "https://github.com/wp-graphql/wp-graphql-jwt-authentication/blob/develop/composer.json"
    click TestingSuite "https://github.com/wp-graphql/wp-graphql-jwt-authentication/tree/develop/tests"

    classDef wordpress fill:#f8f9fa,stroke:#343a40,stroke-width:2px;
    classDef plugin fill:#d1e7dd,stroke:#0f5132,stroke-width:2px;
    classDef auth fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;
    classDef http fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef external fill:#cfe2ff,stroke:#084298,stroke-width:2px;
    classDef testing fill:#f8d7da,stroke:#842029,stroke-width:2px;

    class WPCore,WPGraphQL wordpress;
    class JWTPlugin plugin;
    class Auth,Login,ManageTokens,RefreshToken auth;
    class HTTPLayer,Client http;
    class ExternalLib external;
    class TestingSuite testing;
```
