# haytham-labs/auth architecture

> Architecture diagram of the GitHub repository haytham-labs/auth, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/haytham-labs/auth
- Repository: https://github.com/haytham-labs/auth

## Overview

This is an Express OAuth 2.0 / OpenID Connect server. A client starts an authorization-code request; users sign in or register, approve requested scopes, and the client exchanges the code using PKCE. The server also provides discovery, JWKS, revocation, and logout endpoints through oidc-provider. The excerpts show server routing and persistence calls; protocol endpoint behavior is documented in the README, while several provider details are delegated to the dependency.

Main entry points: [`src/server.js`](https://github.com/haytham-labs/auth/blob/main/src/server.js) (Express and OIDC provider), [`src/database.js`](https://github.com/haytham-labs/auth/blob/main/src/database.js) (User account operations), [`src/mysql-adapter.js`](https://github.com/haytham-labs/auth/blob/main/src/mysql-adapter.js) (OIDC model adapter), [`src/security.js`](https://github.com/haytham-labs/auth/blob/main/src/security.js) (CSRF and client config)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_server["Authorization server"]
  node_server["Express and OIDC provider<br/>[server.js]"]
  node_login["Sign-in and consent<br/>[server.js]"]
  node_signing_keys["Signing keys"]
end

subgraph group_identity["User identity"]
  node_security["CSRF and client config<br/>[security.js]"]
  node_users["User account operations<br/>[database.js]"]
end

subgraph group_persistence["Persistence"]
  node_mysql_adapter["OIDC model adapter<br/>[mysql-adapter.js]"]
  node_mysql[("MySQL database<br/>[schema.sql]")]
end

node_client(("OIDC client"))

node_client -->|"requests authorization"| node_server
node_server -->|"routes interactions"| node_login
node_login -->|"validates input"| node_security
node_login -->|"reads and creates accounts"| node_users
node_server -->|"loads client config"| node_security
node_server -->|"configures adapter"| node_mysql_adapter
node_mysql_adapter -->|"reads and writes models"| node_mysql
node_users -->|"reads and writes users"| node_mysql
node_server -->|"loads JWKS"| node_signing_keys
node_server -->|"serves tokens and protocol endpoints"| node_client

click node_server "https://github.com/haytham-labs/auth/blob/main/src/server.js"
click node_login "https://github.com/haytham-labs/auth/blob/main/src/server.js"
click node_security "https://github.com/haytham-labs/auth/blob/main/src/security.js"
click node_users "https://github.com/haytham-labs/auth/blob/main/src/database.js"
click node_mysql_adapter "https://github.com/haytham-labs/auth/blob/main/src/mysql-adapter.js"
click node_mysql "https://github.com/haytham-labs/auth/blob/main/db/schema.sql"

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_server,node_login,node_signing_keys,node_client toneBlue
class node_security,node_users toneAmber
class node_mysql_adapter,node_mysql toneMint
```

## Components

### Authorization server

- [Express and OIDC provider](https://github.com/haytham-labs/auth/blob/main/src/server.js): `src/server.js`
- [Sign-in and consent](https://github.com/haytham-labs/auth/blob/main/src/server.js): `src/server.js`
- **Signing keys**

### User identity

- [CSRF and client config](https://github.com/haytham-labs/auth/blob/main/src/security.js): `src/security.js`
- [User account operations](https://github.com/haytham-labs/auth/blob/main/src/database.js): `src/database.js`

### Persistence

- [OIDC model adapter](https://github.com/haytham-labs/auth/blob/main/src/mysql-adapter.js): `src/mysql-adapter.js`
- [MySQL database](https://github.com/haytham-labs/auth/blob/main/db/schema.sql): `db/schema.sql`

### Other components

- **OIDC client**

## Connections

- OIDC client → Express and OIDC provider: requests authorization (evidence: `README.md`)
- Express and OIDC provider → Sign-in and consent: routes interactions (evidence: `src/server.js`)
- Sign-in and consent → CSRF and client config: validates input (evidence: `src/server.js`)
- Sign-in and consent → User account operations: reads and creates accounts (evidence: `src/server.js`)
- Express and OIDC provider → CSRF and client config: loads client config (evidence: `src/server.js`)
- Express and OIDC provider → OIDC model adapter: configures adapter (evidence: `src/server.js`)
- OIDC model adapter → MySQL database: reads and writes models (evidence: `src/mysql-adapter.js`)
- User account operations → MySQL database: reads and writes users (evidence: `src/database.js`)
- Express and OIDC provider → Signing keys: loads JWKS (evidence: `README.md`)
- Express and OIDC provider → OIDC client: serves tokens and protocol endpoints (evidence: `README.md`)
