# frankhassanabad/oauth2orizerecipes architecture

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

- Interactive diagram: https://gitdiagram.com/frankhassanabad/oauth2orizerecipes
- Repository: https://github.com/frankhassanabad/oauth2orizerecipes

## Overview

##### Main Components
- Authorization Server: This is the core component responsible for authenticating clients and users, issuing tokens, and enforcing OAuth2 rules. Its code is primarily in the “authorization-server” directory. Note its use of Express (via app.js), token management (token.js, oauth2.js), various OAuth2 flows, client credential management (db/clients.js), and extensive testing.
- Resource Server: Housed in the “resource-server” folder, this component protects resources and makes sure only validated tokens give access. It is similar in structure to the authorization server (with its own app.js, auth.js, and supporting resources like SSO management) but specialized for serving requests and handling resource access.
- Web Client: Found in “web-client,” it is the frontend part (likely serving as a demonstration client) that interacts with the authorization server. It handles presentation (views, HTML pages) and includes client certificates for secure operations.
- Databases: Both the authorization-server and resource-server include a “db” directory for data handling (storing access tokens, refresh tokens, authorization codes, clients, and users). Even though full tokens aren’t stored (only token IDs) due to JWT implementation, this is still an important component.
- Testing and curl Scripts: Although they are not part of the runtime system architecture, noting the separation of unit and integration tests (in “test” directories) and the headless testing via the curl folder can be helpful for completeness in your overall design documentation.

##### Relationships and Data Flows
- How the Web Client communicates with the Authorization Server to initiate authentication, obtain tokens, and perform SSO.
- Communication between the Resource Server and the Authorization Server—for token validation (e.g., the REST tokeninfo endpoint) and token revocation.
- How each server uses secure communication (SSL/TLS) by pointing to the certificates folder present in each.

##### Architectural Patterns and Design Principles
- A separation of concerns is evident: each component is isolated by its purpose (authorization, resource protection, client-facing UI).
- The pattern of using JWT for stateless token management is a key design decision. Show that token verification happens without heavy DB reliance beyond token metadata.
- The project leverages middleware-like structures (e.g., Express.js app.js) to manage incoming requests, authentication, and routing.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        WC["Web Client UI"]:::frontend
        WC_Certs["Web Client Certificates"]:::security
    end

    %% Backend Layer
    subgraph "Backend Layer"
        AS["Authorization Server"]:::backend
        AS_Certs["Authorization Server Certificates"]:::security
        RS["Resource Server"]:::backend
        RS_Certs["Resource Server Certificates"]:::security
    end

    %% Databases
    subgraph "Databases"
        AS_DB["Authorization DB (Tokens, Codes, Users)"]:::db
        RS_DB["Resource DB (Tokens)"]:::db
    end

    %% Auxiliary Components
    subgraph "Auxiliary Tools"
        AS_Test["Authorization Server Testing Scripts"]:::aux
        AS_Curl["Authorization Server Curl Scripts"]:::aux
    end

    %% Data Flow Connections
    WC -->|"login/token-request"| AS
    AS -->|"issues/tokens"| WC
    AS -->|"token-validation"| RS
    RS -->|"validate token with"| AS
    AS -->|"DB operations"| AS_DB
    RS -->|"DB operations"| RS_DB
    AS ---|"SSL/TLS"| AS_Certs
    RS ---|"SSL/TLS"| RS_Certs
    WC ---|"SSL/TLS"| WC_Certs
    AS ---|"associated with"| AS_Test
    AS ---|"associated with"| AS_Curl

    %% Click Events
    click WC "https://github.com/frankhassanabad/oauth2orizerecipes/tree/master/web-client"
    click WC_Certs "https://github.com/frankhassanabad/oauth2orizerecipes/tree/master/web-client/certs"
    click AS "https://github.com/frankhassanabad/oauth2orizerecipes/tree/master/authorization-server"
    click AS_Certs "https://github.com/frankhassanabad/oauth2orizerecipes/tree/master/authorization-server/certs"
    click RS "https://github.com/frankhassanabad/oauth2orizerecipes/tree/master/resource-server"
    click RS_Certs "https://github.com/frankhassanabad/oauth2orizerecipes/tree/master/resource-server/certs"
    click AS_DB "https://github.com/frankhassanabad/oauth2orizerecipes/tree/master/authorization-server/db"
    click RS_DB "https://github.com/frankhassanabad/oauth2orizerecipes/tree/master/resource-server/db"
    click AS_Test "https://github.com/frankhassanabad/oauth2orizerecipes/tree/master/authorization-server/test"
    click AS_Curl "https://github.com/frankhassanabad/oauth2orizerecipes/tree/master/authorization-server/curl"

    %% Styles
    classDef frontend fill:#ffcc00,stroke:#333,stroke-width:2px;
    classDef backend fill:#99ccff,stroke:#333,stroke-width:2px;
    classDef db fill:#ffe6cc,stroke:#333,stroke-width:2px;
    classDef security fill:#ccffcc,stroke:#333,stroke-width:2px;
    classDef aux fill:#e6ccff,stroke:#333,stroke-width:2px;
```
