# liuzhanpeng/hyperf-auth-guard architecture

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

- Interactive diagram: https://gitdiagram.com/liuzhanpeng/hyperf-auth-guard
- Repository: https://github.com/liuzhanpeng/hyperf-auth-guard

## Overview

##### File structure
- Top-level files:
- .gitignore – Git excludes
- LICENSE – License text
- README.md – Project description
- Although the provided tree doesn’t show code directories, a typical Hyperf library would include:
- src/ – the PHP source code (Guards, Middleware, Config)
- config/ – default configuration files
- tests/ – unit and integration tests
- composer.json – dependency and autoload definitions
- publishable assets – e.g. config/auth.php

##### Key elements to capture
- Auth Guard as a middleware in the pipeline
- Pluggable drivers (JWT, session) as subcomponents
- User Provider interface and concrete implementations
- Token Manager/service boundaries
- Dependency Injection container wiring
- Configuration file publication path

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client
    Client["Client (Browser/API)"]:::external

    %% Hyperf Framework
    subgraph "Hyperf Framework"
        direction TB
        HTTP["HTTP Server"]:::framework
        Middleware["Middleware Stack"]:::framework
        DI["Dependency Injection Container"]:::framework
        Controller["Application Controllers"]:::framework
    end

    %% Auth Library
    subgraph "Auth Guard Library" 
        direction TB
        Config["config/auth.php"]:::config
        AuthGuard["Authentication Guard Middleware"]:::library
        subgraph "Guard Drivers"
            direction TB
            JWT["JWT Driver"]:::library
            Session["Session Driver"]:::library
        end
        TokenMgr["Token Manager"]:::library
        ProviderIntf["User Provider Interface"]:::library
    end

    %% External Systems
    DB["User Database"]:::external
    Cache["Cache Layer"]:::external
    Logger["Logger / Event Dispatcher"]:::external

    %% Flow
    Client -->|"HTTP Request"| HTTP
    HTTP --> Middleware
    Middleware --> AuthGuard
    AuthGuard -->|"reads config"| Config
    AuthGuard -->|"validateToken()"| TokenMgr
    TokenMgr -->|"uses driver"| JWT
    TokenMgr -->|"uses driver"| Session
    TokenMgr -->|"cache token"| Cache
    AuthGuard -->|"fetchUser()"| ProviderIntf
    ProviderIntf -->|"query user"| DB
    AuthGuard -->|"attach user"| Controller
    Controller -->|"business logic"| Logger
    Controller -->|"HTTP Response"| Client

    %% Styles
    classDef framework fill:#d0e7ff,stroke:#3399ff,color:#000;
    classDef library fill:#e0ffe0,stroke:#00aa00,color:#000;
    classDef external fill:#ffe0b3,stroke:#ff9900,color:#000;
    classDef config fill:#fff0b3,stroke:#e6b800,color:#000;
```
