# thephpleague/oauth2-server-bundle architecture

> Architecture diagram of the GitHub repository thephpleague/oauth2-server-bundle, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/thephpleague/oauth2-server-bundle
- Repository: https://github.com/thephpleague/oauth2-server-bundle

## Overview

OAuth2ServerBundle integrates League’s OAuth2 server with Symfony: clients initiate authorization, device-code, or token requests; the server validates and completes them, while bundle repositories and managers provide persistence. Symfony security authenticates resulting OAuth2 tokens and checks scopes. Client administration and key-management commands are additional product capabilities. The graph reflects the shown authorization and persistence calls plus README and service-configuration evidence; some controller and integration internals are represented only at their documented or configured boundaries.

Main entry points: [`src/Controller/AuthorizationController.php`](https://github.com/thephpleague/oauth2-server-bundle/blob/2.x/src/Controller/AuthorizationController.php) (Authorization Flow), [`src/Manager`](https://github.com/thephpleague/oauth2-server-bundle/tree/2.x/src/Manager) (Token and Client Managers), [`src/Manager/Doctrine/ClientManager.php`](https://github.com/thephpleague/oauth2-server-bundle/blob/2.x/src/Manager/Doctrine/ClientManager.php) (Client Manager), [`src/Command`](https://github.com/thephpleague/oauth2-server-bundle/tree/2.x/src/Command) (Client Commands)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_protocol["OAuth2 Protocol"]
  node_authorization["Authorization Flow"]
  node_device["Device Flow"]
  node_token["Token Endpoint"]
  node_league["League OAuth Server"]
  node_resolve["Authorization Resolution"]
  node_userconvert["User Conversion"]
end

subgraph group_persistence["Persistence"]
  node_oauthrepos["OAuth Repositories"]
  node_authcode["Authorization Code Repository"]
  node_devicerepo["Device Code Repository"]
  node_managers["Token and Client Managers"]
  node_doctrinemgr["Doctrine Managers"]
  node_memorymgr["In-Memory Managers"]
  node_database[("Doctrine Store")]
  node_clientmgr["Client Manager<br/>[ClientManager.php]"]
end

subgraph group_security["Symfony Security"]
  node_securityauth["OAuth2 Authenticator"]
  node_scopecheck["Scope Checks"]
end

subgraph group_admin["Client Administration"]
  node_clientcmd["Client Commands"]
  node_keycmd["Key Generation"]
  node_clientmodel["Client Model<br/>[AbstractClient.php]"]
  node_events["Client Save Event"]
end

node_client(("OAuth Client"))

node_client -->|"requests authorization"| node_authorization
node_authorization -->|"validates and completes"| node_league
node_authorization -->|"dispatches resolution"| node_resolve
node_authorization -->|"converts user"| node_userconvert
node_client -.->|"requests device code"| node_device
node_client -.->|"requests token"| node_token
node_token -.->|"handles token request"| node_league
node_league -.->|"uses repositories"| node_oauthrepos
node_league -.->|"uses code repository"| node_authcode
node_authcode -->|"reads and saves codes"| node_managers
node_devicerepo -->|"uses code managers"| node_managers
node_managers -.->|"implemented by"| node_doctrinemgr
node_managers -.->|"implemented by"| node_memorymgr
node_doctrinemgr -.->|"persists entities"| node_database
node_securityauth -.->|"checks scopes"| node_scopecheck
node_clientcmd -->|"creates and manages"| node_clientmgr
node_clientcmd -->|"builds client"| node_clientmodel
node_clientmgr -->|"dispatches before save"| node_events
node_clientmgr -->|"persists clients"| node_database
node_keycmd -.->|"generates server keys"| node_client

click node_authorization "https://github.com/thephpleague/oauth2-server-bundle/blob/2.x/src/Controller/AuthorizationController.php"
click node_device "https://github.com/thephpleague/oauth2-server-bundle/blob/2.x/src/Controller/DeviceCodeController.php"
click node_token "https://github.com/thephpleague/oauth2-server-bundle/blob/2.x/src/Controller/TokenController.php"
click node_resolve "https://github.com/thephpleague/oauth2-server-bundle/blob/2.x/src/Event/AuthorizationRequestResolveEventFactory.php"
click node_userconvert "https://github.com/thephpleague/oauth2-server-bundle/blob/2.x/src/Converter/UserConverterInterface.php"
click node_oauthrepos "https://github.com/thephpleague/oauth2-server-bundle/tree/2.x/src/Repository"
click node_authcode "https://github.com/thephpleague/oauth2-server-bundle/blob/2.x/src/Repository/AuthCodeRepository.php"
click node_devicerepo "https://github.com/thephpleague/oauth2-server-bundle/blob/2.x/src/Repository/DeviceCodeRepository.php"
click node_managers "https://github.com/thephpleague/oauth2-server-bundle/tree/2.x/src/Manager"
click node_doctrinemgr "https://github.com/thephpleague/oauth2-server-bundle/tree/2.x/src/Manager/Doctrine"
click node_memorymgr "https://github.com/thephpleague/oauth2-server-bundle/tree/2.x/src/Manager/InMemory"
click node_securityauth "https://github.com/thephpleague/oauth2-server-bundle/blob/2.x/src/Security/Authenticator/OAuth2Authenticator.php"
click node_scopecheck "https://github.com/thephpleague/oauth2-server-bundle/blob/2.x/src/Security/EventListener/CheckScopeListener.php"
click node_clientcmd "https://github.com/thephpleague/oauth2-server-bundle/tree/2.x/src/Command"
click node_keycmd "https://github.com/thephpleague/oauth2-server-bundle/blob/2.x/src/Command/GenerateKeyPairCommand.php"
click node_clientmodel "https://github.com/thephpleague/oauth2-server-bundle/blob/2.x/src/Model/AbstractClient.php"
click node_clientmgr "https://github.com/thephpleague/oauth2-server-bundle/blob/2.x/src/Manager/Doctrine/ClientManager.php"
click node_events "https://github.com/thephpleague/oauth2-server-bundle/blob/2.x/src/Event/PreSaveClientEvent.php"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_authorization,node_device,node_token,node_league,node_resolve,node_userconvert,node_client toneBlue
class node_oauthrepos,node_authcode,node_devicerepo,node_managers,node_doctrinemgr,node_memorymgr,node_database,node_clientmgr toneAmber
class node_securityauth,node_scopecheck toneMint
class node_clientcmd,node_keycmd,node_clientmodel,node_events toneRose
```

## Components

### OAuth2 Protocol

- [Authorization Flow](https://github.com/thephpleague/oauth2-server-bundle/blob/2.x/src/Controller/AuthorizationController.php): `src/Controller/AuthorizationController.php`
- [Device Flow](https://github.com/thephpleague/oauth2-server-bundle/blob/2.x/src/Controller/DeviceCodeController.php): `src/Controller/DeviceCodeController.php`
- [Token Endpoint](https://github.com/thephpleague/oauth2-server-bundle/blob/2.x/src/Controller/TokenController.php): `src/Controller/TokenController.php`
- **League OAuth Server**
- [Authorization Resolution](https://github.com/thephpleague/oauth2-server-bundle/blob/2.x/src/Event/AuthorizationRequestResolveEventFactory.php): `src/Event/AuthorizationRequestResolveEventFactory.php`
- [User Conversion](https://github.com/thephpleague/oauth2-server-bundle/blob/2.x/src/Converter/UserConverterInterface.php): `src/Converter/UserConverterInterface.php`

### Persistence

- [OAuth Repositories](https://github.com/thephpleague/oauth2-server-bundle/tree/2.x/src/Repository): `src/Repository`
- [Authorization Code Repository](https://github.com/thephpleague/oauth2-server-bundle/blob/2.x/src/Repository/AuthCodeRepository.php): `src/Repository/AuthCodeRepository.php`
- [Device Code Repository](https://github.com/thephpleague/oauth2-server-bundle/blob/2.x/src/Repository/DeviceCodeRepository.php): `src/Repository/DeviceCodeRepository.php`
- [Token and Client Managers](https://github.com/thephpleague/oauth2-server-bundle/tree/2.x/src/Manager): `src/Manager`
- [Doctrine Managers](https://github.com/thephpleague/oauth2-server-bundle/tree/2.x/src/Manager/Doctrine): `src/Manager/Doctrine`
- [In-Memory Managers](https://github.com/thephpleague/oauth2-server-bundle/tree/2.x/src/Manager/InMemory): `src/Manager/InMemory`
- **Doctrine Store**
- [Client Manager](https://github.com/thephpleague/oauth2-server-bundle/blob/2.x/src/Manager/Doctrine/ClientManager.php): `src/Manager/Doctrine/ClientManager.php`

### Symfony Security

- [OAuth2 Authenticator](https://github.com/thephpleague/oauth2-server-bundle/blob/2.x/src/Security/Authenticator/OAuth2Authenticator.php): `src/Security/Authenticator/OAuth2Authenticator.php`
- [Scope Checks](https://github.com/thephpleague/oauth2-server-bundle/blob/2.x/src/Security/EventListener/CheckScopeListener.php): `src/Security/EventListener/CheckScopeListener.php`

### Client Administration

- [Client Commands](https://github.com/thephpleague/oauth2-server-bundle/tree/2.x/src/Command): `src/Command`
- [Key Generation](https://github.com/thephpleague/oauth2-server-bundle/blob/2.x/src/Command/GenerateKeyPairCommand.php): `src/Command/GenerateKeyPairCommand.php`
- [Client Model](https://github.com/thephpleague/oauth2-server-bundle/blob/2.x/src/Model/AbstractClient.php): `src/Model/AbstractClient.php`
- [Client Save Event](https://github.com/thephpleague/oauth2-server-bundle/blob/2.x/src/Event/PreSaveClientEvent.php): `src/Event/PreSaveClientEvent.php`

### Other components

- **OAuth Client**

## Connections

- OAuth Client → Authorization Flow: requests authorization (evidence: `src/Controller/AuthorizationController.php`)
- Authorization Flow → League OAuth Server: validates and completes (evidence: `src/Controller/AuthorizationController.php`)
- Authorization Flow → Authorization Resolution: dispatches resolution (evidence: `src/Controller/AuthorizationController.php`)
- Authorization Flow → User Conversion: converts user (evidence: `src/Controller/AuthorizationController.php`)
- OAuth Client → Device Flow: requests device code
- OAuth Client → Token Endpoint: requests token
- Token Endpoint → League OAuth Server: handles token request
- League OAuth Server → OAuth Repositories: uses repositories
- League OAuth Server → Authorization Code Repository: uses code repository
- Authorization Code Repository → Token and Client Managers: reads and saves codes (evidence: `src/Repository/AuthCodeRepository.php`)
- Device Code Repository → Token and Client Managers: uses code managers (evidence: `src/Repository/DeviceCodeRepository.php`)
- Token and Client Managers → Doctrine Managers: implemented by (evidence: `src/Manager/Doctrine/ClientManager.php`)
- Token and Client Managers → In-Memory Managers: implemented by (evidence: `config/services.php`)
- Doctrine Managers → Doctrine Store: persists entities
- OAuth2 Authenticator → Scope Checks: checks scopes
- Client Commands → Client Manager: creates and manages (evidence: `src/Command/CreateClientCommand.php`)
- Client Commands → Client Model: builds client (evidence: `src/Command/CreateClientCommand.php`)
- Client Manager → Client Save Event: dispatches before save (evidence: `src/Manager/Doctrine/ClientManager.php`)
- Client Manager → Doctrine Store: persists clients (evidence: `src/Manager/Doctrine/ClientManager.php`)
- Key Generation → OAuth Client: generates server keys
