# saiupadhyayula/spring-security-oauth2-keycloak-demo architecture

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

- Interactive diagram: https://gitdiagram.com/saiupadhyayula/spring-security-oauth2-keycloak-demo
- Repository: https://github.com/saiupadhyayula/spring-security-oauth2-keycloak-demo

## Overview

This repository is a set of three Spring Security/Keycloak OAuth2 demos: Authorization Code, PKCE Authorization Code, and Client Credentials. The clearest end-to-end path is the PKCE Angular client configuring OAuth, requesting a protected API response, and displaying it. README documentation establishes the three grant types and realm-import capability; several implementation details, especially Client Credentials, are not shown in the excerpts, so their internal links are omitted. The map excludes build and test machinery.

Main entry points: [`oauth2-pkce-demo/src/main/resources/frontend/src/app/app.component.ts`](https://github.com/saiupadhyayula/spring-security-oauth2-keycloak-demo/blob/master/oauth2-pkce-demo/src/main/resources/frontend/src/app/app.component.ts) (Login and Display), [`oauth2-pkce-demo/src/main/resources/frontend/src/app/app.module.ts`](https://github.com/saiupadhyayula/spring-security-oauth2-keycloak-demo/blob/master/oauth2-pkce-demo/src/main/resources/frontend/src/app/app.module.ts) (Angular Module), [`oauth2-pkce-demo/src/main/resources/frontend/src/main.ts`](https://github.com/saiupadhyayula/spring-security-oauth2-keycloak-demo/blob/master/oauth2-pkce-demo/src/main/resources/frontend/src/main.ts) (Angular Bootstrap), [`oauth2-authorization-code-demo/src/main/java/com/programming/techie/authcode/controller/HomeController.java`](https://github.com/saiupadhyayula/spring-security-oauth2-keycloak-demo/blob/master/oauth2-authorization-code-demo/src/main/java/com/programming/techie/authcode/controller/HomeController.java) (Home Page Route)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_authcode["Authorization Code Demo"]
  node_auth_entry["Application Entry"]
  node_auth_page["Home Page Route"]
  node_auth_template["Home Template<br/>[home.html]"]
  node_auth_api["Hello Endpoint"]
end

subgraph group_pkce["PKCE Demo"]
  node_pkce_entry["Application Entry"]
  node_pkce_security["Security Configuration"]
  node_angular_bootstrap["Angular Bootstrap<br/>[main.ts]"]
  node_angular_module["Angular Module<br/>[app.module.ts]"]
  node_angular_routes["Route Setup"]
  node_angular_app["Login and Display<br/>[app.component.ts]"]
  node_oauth_config["OAuth Settings<br/>[auth.config.ts]"]
  node_angular_service["API Client<br/>[app.service.ts]"]
  node_angular_env["Environment Settings<br/>[environment.ts]"]
  node_pkce_api["Home API"]
end

subgraph group_clientcreds["Client Credentials Demo"]
  node_client_entry["Application Entry"]
  node_client_security["Security Configuration"]
  node_client_api["Service Endpoint<br/>[Controller1.java]"]
end

subgraph group_keycloak["Identity Provider"]
  node_keycloak_service[("Keycloak Server")]
  node_realm_export["Realm Configuration<br/>[realm-export.json]"]
end

node_user(("User"))

node_user -->|"opens page"| node_auth_page
node_auth_page -->|"returns view"| node_auth_template
node_user -->|"requests hello"| node_auth_api
node_angular_bootstrap -->|"bootstraps"| node_angular_module
node_angular_bootstrap -->|"reads settings"| node_angular_env
node_angular_module -->|"bootstraps"| node_angular_app
node_angular_module -->|"registers routes"| node_angular_routes
node_angular_app -->|"configures OAuth"| node_oauth_config
node_angular_app -->|"calls API client"| node_angular_service
node_angular_service -->|"requests response"| node_pkce_api
node_user -.->|"uses client"| node_angular_app
node_angular_app -.->|"starts login"| node_keycloak_service
node_realm_export -->|"imports realm"| node_keycloak_service
node_client_api -.->|"uses OAuth"| node_keycloak_service

click node_auth_entry "https://github.com/saiupadhyayula/spring-security-oauth2-keycloak-demo/blob/master/oauth2-authorization-code-demo/src/main/java/com/programming/techie/authcode/DemoApplication.java"
click node_auth_page "https://github.com/saiupadhyayula/spring-security-oauth2-keycloak-demo/blob/master/oauth2-authorization-code-demo/src/main/java/com/programming/techie/authcode/controller/HomeController.java"
click node_auth_template "https://github.com/saiupadhyayula/spring-security-oauth2-keycloak-demo/blob/master/oauth2-authorization-code-demo/src/main/resources/templates/home.html"
click node_auth_api "https://github.com/saiupadhyayula/spring-security-oauth2-keycloak-demo/blob/master/oauth2-authorization-code-demo/src/main/java/com/programming/techie/authcode/controller/HomeRestController.java"
click node_pkce_entry "https://github.com/saiupadhyayula/spring-security-oauth2-keycloak-demo/blob/master/oauth2-pkce-demo/src/main/java/com/programming/techie/pkce/Oauth2PKCEDemoApplication.java"
click node_pkce_security "https://github.com/saiupadhyayula/spring-security-oauth2-keycloak-demo/blob/master/oauth2-pkce-demo/src/main/java/com/programming/techie/pkce/config/SecurityConfig.java"
click node_angular_bootstrap "https://github.com/saiupadhyayula/spring-security-oauth2-keycloak-demo/blob/master/oauth2-pkce-demo/src/main/resources/frontend/src/main.ts"
click node_angular_module "https://github.com/saiupadhyayula/spring-security-oauth2-keycloak-demo/blob/master/oauth2-pkce-demo/src/main/resources/frontend/src/app/app.module.ts"
click node_angular_routes "https://github.com/saiupadhyayula/spring-security-oauth2-keycloak-demo/blob/master/oauth2-pkce-demo/src/main/resources/frontend/src/app/app-routing.module.ts"
click node_angular_app "https://github.com/saiupadhyayula/spring-security-oauth2-keycloak-demo/blob/master/oauth2-pkce-demo/src/main/resources/frontend/src/app/app.component.ts"
click node_oauth_config "https://github.com/saiupadhyayula/spring-security-oauth2-keycloak-demo/blob/master/oauth2-pkce-demo/src/main/resources/frontend/src/app/auth.config.ts"
click node_angular_service "https://github.com/saiupadhyayula/spring-security-oauth2-keycloak-demo/blob/master/oauth2-pkce-demo/src/main/resources/frontend/src/app/app.service.ts"
click node_angular_env "https://github.com/saiupadhyayula/spring-security-oauth2-keycloak-demo/blob/master/oauth2-pkce-demo/src/main/resources/frontend/src/environments/environment.ts"
click node_pkce_api "https://github.com/saiupadhyayula/spring-security-oauth2-keycloak-demo/blob/master/oauth2-pkce-demo/src/main/java/com/programming/techie/pkce/controller/HomeRestController.java"
click node_client_entry "https://github.com/saiupadhyayula/spring-security-oauth2-keycloak-demo/blob/master/oauth2-client-credentials-demo/microservice-1/src/main/java/com/programming/techie/microservice1/Microservice1Application.java"
click node_client_security "https://github.com/saiupadhyayula/spring-security-oauth2-keycloak-demo/blob/master/oauth2-client-credentials-demo/microservice-1/src/main/java/com/programming/techie/microservice1/config/SecurityConfig.java"
click node_client_api "https://github.com/saiupadhyayula/spring-security-oauth2-keycloak-demo/blob/master/oauth2-client-credentials-demo/microservice-1/src/main/java/com/programming/techie/microservice1/controller/Controller1.java"
click node_realm_export "https://github.com/saiupadhyayula/spring-security-oauth2-keycloak-demo/blob/master/realm-export.json"

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_auth_entry,node_auth_page,node_auth_template,node_auth_api,node_user toneBlue
class node_pkce_entry,node_pkce_security,node_angular_bootstrap,node_angular_module,node_angular_routes,node_angular_app,node_oauth_config,node_angular_service,node_angular_env,node_pkce_api toneAmber
class node_client_entry,node_client_security,node_client_api toneMint
class node_keycloak_service,node_realm_export toneRose
```

## Components

### Authorization Code Demo

- [Application Entry](https://github.com/saiupadhyayula/spring-security-oauth2-keycloak-demo/blob/master/oauth2-authorization-code-demo/src/main/java/com/programming/techie/authcode/DemoApplication.java): `oauth2-authorization-code-demo/src/main/java/com/programming/techie/authcode/DemoApplication.java`
- [Home Page Route](https://github.com/saiupadhyayula/spring-security-oauth2-keycloak-demo/blob/master/oauth2-authorization-code-demo/src/main/java/com/programming/techie/authcode/controller/HomeController.java): `oauth2-authorization-code-demo/src/main/java/com/programming/techie/authcode/controller/HomeController.java`
- [Home Template](https://github.com/saiupadhyayula/spring-security-oauth2-keycloak-demo/blob/master/oauth2-authorization-code-demo/src/main/resources/templates/home.html): `oauth2-authorization-code-demo/src/main/resources/templates/home.html`
- [Hello Endpoint](https://github.com/saiupadhyayula/spring-security-oauth2-keycloak-demo/blob/master/oauth2-authorization-code-demo/src/main/java/com/programming/techie/authcode/controller/HomeRestController.java): `oauth2-authorization-code-demo/src/main/java/com/programming/techie/authcode/controller/HomeRestController.java`

### PKCE Demo

- [Application Entry](https://github.com/saiupadhyayula/spring-security-oauth2-keycloak-demo/blob/master/oauth2-pkce-demo/src/main/java/com/programming/techie/pkce/Oauth2PKCEDemoApplication.java): `oauth2-pkce-demo/src/main/java/com/programming/techie/pkce/Oauth2PKCEDemoApplication.java`
- [Security Configuration](https://github.com/saiupadhyayula/spring-security-oauth2-keycloak-demo/blob/master/oauth2-pkce-demo/src/main/java/com/programming/techie/pkce/config/SecurityConfig.java): `oauth2-pkce-demo/src/main/java/com/programming/techie/pkce/config/SecurityConfig.java`
- [Angular Bootstrap](https://github.com/saiupadhyayula/spring-security-oauth2-keycloak-demo/blob/master/oauth2-pkce-demo/src/main/resources/frontend/src/main.ts): `oauth2-pkce-demo/src/main/resources/frontend/src/main.ts`
- [Angular Module](https://github.com/saiupadhyayula/spring-security-oauth2-keycloak-demo/blob/master/oauth2-pkce-demo/src/main/resources/frontend/src/app/app.module.ts): `oauth2-pkce-demo/src/main/resources/frontend/src/app/app.module.ts`
- [Route Setup](https://github.com/saiupadhyayula/spring-security-oauth2-keycloak-demo/blob/master/oauth2-pkce-demo/src/main/resources/frontend/src/app/app-routing.module.ts): `oauth2-pkce-demo/src/main/resources/frontend/src/app/app-routing.module.ts`
- [Login and Display](https://github.com/saiupadhyayula/spring-security-oauth2-keycloak-demo/blob/master/oauth2-pkce-demo/src/main/resources/frontend/src/app/app.component.ts): `oauth2-pkce-demo/src/main/resources/frontend/src/app/app.component.ts`
- [OAuth Settings](https://github.com/saiupadhyayula/spring-security-oauth2-keycloak-demo/blob/master/oauth2-pkce-demo/src/main/resources/frontend/src/app/auth.config.ts): `oauth2-pkce-demo/src/main/resources/frontend/src/app/auth.config.ts`
- [API Client](https://github.com/saiupadhyayula/spring-security-oauth2-keycloak-demo/blob/master/oauth2-pkce-demo/src/main/resources/frontend/src/app/app.service.ts): `oauth2-pkce-demo/src/main/resources/frontend/src/app/app.service.ts`
- [Environment Settings](https://github.com/saiupadhyayula/spring-security-oauth2-keycloak-demo/blob/master/oauth2-pkce-demo/src/main/resources/frontend/src/environments/environment.ts): `oauth2-pkce-demo/src/main/resources/frontend/src/environments/environment.ts`
- [Home API](https://github.com/saiupadhyayula/spring-security-oauth2-keycloak-demo/blob/master/oauth2-pkce-demo/src/main/java/com/programming/techie/pkce/controller/HomeRestController.java): `oauth2-pkce-demo/src/main/java/com/programming/techie/pkce/controller/HomeRestController.java`

### Client Credentials Demo

- [Application Entry](https://github.com/saiupadhyayula/spring-security-oauth2-keycloak-demo/blob/master/oauth2-client-credentials-demo/microservice-1/src/main/java/com/programming/techie/microservice1/Microservice1Application.java): `oauth2-client-credentials-demo/microservice-1/src/main/java/com/programming/techie/microservice1/Microservice1Application.java`
- [Security Configuration](https://github.com/saiupadhyayula/spring-security-oauth2-keycloak-demo/blob/master/oauth2-client-credentials-demo/microservice-1/src/main/java/com/programming/techie/microservice1/config/SecurityConfig.java): `oauth2-client-credentials-demo/microservice-1/src/main/java/com/programming/techie/microservice1/config/SecurityConfig.java`
- [Service Endpoint](https://github.com/saiupadhyayula/spring-security-oauth2-keycloak-demo/blob/master/oauth2-client-credentials-demo/microservice-1/src/main/java/com/programming/techie/microservice1/controller/Controller1.java): `oauth2-client-credentials-demo/microservice-1/src/main/java/com/programming/techie/microservice1/controller/Controller1.java`

### Identity Provider

- **Keycloak Server**
- [Realm Configuration](https://github.com/saiupadhyayula/spring-security-oauth2-keycloak-demo/blob/master/realm-export.json): `realm-export.json`

### Other components

- **User**

## Connections

- User → Home Page Route: opens page (evidence: `oauth2-authorization-code-demo/src/main/java/com/programming/techie/authcode/controller/HomeController.java`)
- Home Page Route → Home Template: returns view (evidence: `oauth2-authorization-code-demo/src/main/java/com/programming/techie/authcode/controller/HomeController.java`)
- User → Hello Endpoint: requests hello (evidence: `oauth2-authorization-code-demo/src/main/java/com/programming/techie/authcode/controller/HomeRestController.java`)
- Angular Bootstrap → Angular Module: bootstraps (evidence: `oauth2-pkce-demo/src/main/resources/frontend/src/main.ts`)
- Angular Bootstrap → Environment Settings: reads settings (evidence: `oauth2-pkce-demo/src/main/resources/frontend/src/main.ts`)
- Angular Module → Login and Display: bootstraps (evidence: `oauth2-pkce-demo/src/main/resources/frontend/src/app/app.module.ts`)
- Angular Module → Route Setup: registers routes (evidence: `oauth2-pkce-demo/src/main/resources/frontend/src/app/app.module.ts`)
- Login and Display → OAuth Settings: configures OAuth (evidence: `oauth2-pkce-demo/src/main/resources/frontend/src/app/app.component.ts`)
- Login and Display → API Client: calls API client (evidence: `oauth2-pkce-demo/src/main/resources/frontend/src/app/app.component.ts`)
- API Client → Home API: requests response (evidence: `oauth2-pkce-demo/src/main/resources/frontend/src/app/app.service.ts`)
- User → Login and Display: uses client
- Login and Display → Keycloak Server: starts login
- Realm Configuration → Keycloak Server: imports realm (evidence: `README.md`)
- Service Endpoint → Keycloak Server: uses OAuth
