# esn-hungary/esnscope architecture

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

- Interactive diagram: https://gitdiagram.com/esn-hungary/esnscope
- Repository: https://github.com/esn-hungary/esnscope

## Overview

ESNscope is a Cloudflare Worker OAuth exploration client. A browser reaches the Worker’s home/login pages, starts a PKCE authorization request to ESNaccount, returns to the callback, exchanges the code and fetches userinfo, then views profile, roles, and token metadata. The graph separates request routing, OAuth orchestration, provider communication, and presentation. Source excerpts support the shown calls; external-provider interactions are visible in the ESNaccount client, while broader configuration details are documented in the README.

Main entry points: [`src/oauth.ts`](https://github.com/esn-hungary/esnscope/blob/main/src/oauth.ts) (OAuth orchestration), [`src/esnaccount.ts`](https://github.com/esn-hungary/esnscope/blob/main/src/esnaccount.ts) (Provider client), [`src/html.ts`](https://github.com/esn-hungary/esnscope/blob/main/src/html.ts) (Page rendering), [`src/index.ts`](https://github.com/esn-hungary/esnscope/blob/main/src/index.ts) (HTTP router)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_worker["Worker routing"]
  node_router["HTTP router<br/>[index.ts]"]
end

subgraph group_oauth["OAuth flow"]
  node_oauth_flow["OAuth orchestration<br/>[oauth.ts]"]
  node_config["OAuth configuration<br/>[config.ts]"]
  node_oauth_types["OAuth data types<br/>[types.ts]"]
end

subgraph group_provider["ESNaccount API"]
  node_esn_api["Provider client<br/>[esnaccount.ts]"]
end

subgraph group_presentation["Profile explorer"]
  node_pages["Page rendering<br/>[html.ts]"]
  node_role_parser["Role extraction<br/>[roles.ts]"]
  node_styles["Page styles<br/>[styles.ts]"]
end

node_browser(("Browser"))
node_esnaccount["ESNaccount"]

node_browser -->|"sends requests"| node_router
node_router -->|"renders pages"| node_pages
node_router -->|"dispatches OAuth"| node_oauth_flow
node_oauth_flow -->|"reads settings"| node_config
node_oauth_flow -->|"requests tokens and profile"| node_esn_api
node_oauth_flow -->|"renders callback result"| node_pages
node_esn_api -->|"calls authorization endpoint"| node_esnaccount
node_esn_api -->|"posts code exchange"| node_esnaccount
node_esn_api -->|"gets userinfo"| node_esnaccount
node_pages -->|"extracts roles"| node_role_parser
node_pages -->|"embeds styles"| node_styles

click node_router "https://github.com/esn-hungary/esnscope/blob/main/src/index.ts"
click node_oauth_flow "https://github.com/esn-hungary/esnscope/blob/main/src/oauth.ts"
click node_config "https://github.com/esn-hungary/esnscope/blob/main/src/config.ts"
click node_oauth_types "https://github.com/esn-hungary/esnscope/blob/main/src/types.ts"
click node_esn_api "https://github.com/esn-hungary/esnscope/blob/main/src/esnaccount.ts"
click node_pages "https://github.com/esn-hungary/esnscope/blob/main/src/html.ts"
click node_role_parser "https://github.com/esn-hungary/esnscope/blob/main/src/roles.ts"
click node_styles "https://github.com/esn-hungary/esnscope/blob/main/src/styles.ts"

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_router,node_browser toneBlue
class node_oauth_flow,node_config,node_oauth_types toneAmber
class node_esn_api toneMint
class node_pages,node_role_parser,node_styles toneRose
class node_esnaccount toneIndigo
```

## Components

### Worker routing

- [HTTP router](https://github.com/esn-hungary/esnscope/blob/main/src/index.ts): `src/index.ts`

### OAuth flow

- [OAuth orchestration](https://github.com/esn-hungary/esnscope/blob/main/src/oauth.ts): `src/oauth.ts`
- [OAuth configuration](https://github.com/esn-hungary/esnscope/blob/main/src/config.ts): `src/config.ts`
- [OAuth data types](https://github.com/esn-hungary/esnscope/blob/main/src/types.ts): `src/types.ts`

### ESNaccount API

- [Provider client](https://github.com/esn-hungary/esnscope/blob/main/src/esnaccount.ts): `src/esnaccount.ts`

### Profile explorer

- [Page rendering](https://github.com/esn-hungary/esnscope/blob/main/src/html.ts): `src/html.ts`
- [Role extraction](https://github.com/esn-hungary/esnscope/blob/main/src/roles.ts): `src/roles.ts`
- [Page styles](https://github.com/esn-hungary/esnscope/blob/main/src/styles.ts): `src/styles.ts`

### Other components

- **Browser**
- **ESNaccount**

## Connections

- Browser → HTTP router: sends requests (evidence: `README.md`)
- HTTP router → Page rendering: renders pages (evidence: `src/index.ts`)
- HTTP router → OAuth orchestration: dispatches OAuth (evidence: `src/index.ts`)
- OAuth orchestration → OAuth configuration: reads settings (evidence: `src/oauth.ts`)
- OAuth orchestration → Provider client: requests tokens and profile (evidence: `src/oauth.ts`)
- OAuth orchestration → Page rendering: renders callback result (evidence: `src/oauth.ts`)
- Provider client → ESNaccount: calls authorization endpoint (evidence: `README.md`)
- Provider client → ESNaccount: posts code exchange (evidence: `src/esnaccount.ts`)
- Provider client → ESNaccount: gets userinfo (evidence: `src/esnaccount.ts`)
- Page rendering → Role extraction: extracts roles (evidence: `src/html.ts`)
- Page rendering → Page styles: embeds styles (evidence: `src/html.ts`)
