# fa-fifi/keycloak_wrapper architecture

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

- Interactive diagram: https://gitdiagram.com/fa-fifi/keycloak_wrapper
- Repository: https://github.com/fa-fifi/keycloak_wrapper

## Overview

##### Main Components

a. Client Application Layer:
- Flutter Application (represented as the top-level component)
- KeycloakWrapper Instance (core package component)
- Authentication Stream Controller

b. Security Layer:
- Flutter Secure Storage (for token management)
- Token Handlers (Access, ID, and Refresh tokens)

c. Authentication Layer:
- AppAuth SDK Integration
- OAuth 2.0 / OpenID Connect Flow
- Keycloak Server Connection

d. Platform-Specific Components:
- iOS/macOS URL Scheme Handler
- Android Manifest Integration

##### Component Relationships

- User Interaction → Flutter App → KeycloakWrapper
- KeycloakWrapper → AppAuth SDK → Keycloak Server
- KeycloakWrapper ↔ Flutter Secure Storage
- Authentication Stream → Flutter App State Management

##### Specific Implementation Details

- Blue rectangles for core components (KeycloakWrapper, AppAuth)
- Green rectangles for storage components (Flutter Secure Storage)
- Yellow diamonds for authentication decision points
- Red rectangles for security-sensitive areas
- Purple rectangles for platform-specific implementations

##### Key Flows to Highlight

a. Authentication Flow:
**User → App → KeycloakWrapper → AppAuth → Keycloak Server**
- ↓
- Token Storage → Auth Stream

b. Token Management Flow:
**Secure Storage ↔ KeycloakWrapper ↔ App**

##### Important Elements

- Configuration block showing KeycloakConfig parameters
- Token storage mechanism
- Authentication state stream flow
- Platform-specific redirect URI handlers
- Error handling pathways

##### Technical Details to Note

- Required platform configurations
- Bundle identifier requirements
- Security considerations
- AndroidX requirements
- HTTP/HTTPS handling

##### Architecture Patterns

Emphasize:
- Observer pattern (authentication stream)
- Facade pattern (wrapper implementation)
- Repository pattern (token storage)
- Bridge pattern (platform integration)

Remember to highlight the three main operational modes:
##### Token Management

This will help developers understand both the implementation requirements and the security considerations of the package.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client["Client Application Layer"]
        FlutterApp["Flutter Application"]
        KW["KeycloakWrapper Instance"]:::core
        AuthStream["Authentication Stream Controller"]
    end

    subgraph Security["Security Layer"]
        Storage["Flutter Secure Storage"]:::storage
        TokenMgmt["Token Management"]:::jwt
        Config["Configuration Handler"]:::config
    end

    subgraph Auth["Authentication Layer"]
        AppAuth["AppAuth SDK"]
        OAuth["OAuth 2.0 / OpenID Connect"]
        Keycloak["Keycloak Server"]
    end

    subgraph Platform["Platform-Specific Layer"]
        direction TB
        iOS["iOS/macOS URL Handler"]:::ios
        Android["Android Manifest Handler"]:::android
    end

    %% Relationships
    FlutterApp --> KW
    KW --> AppAuth
    AppAuth --> OAuth
    OAuth --> Keycloak
    KW --> TokenMgmt
    TokenMgmt --> Storage
    KW --> Config
    AuthStream --> FlutterApp
    KW --> AuthStream
    AppAuth --> iOS
    AppAuth --> Android

    %% Click Events
    click KW "https://github.com/fa-fifi/keycloak_wrapper/blob/main/lib/keycloak_wrapper.dart"
    click TokenMgmt "https://github.com/fa-fifi/keycloak_wrapper/blob/main/lib/src/jwt.dart"
    click Config "https://github.com/fa-fifi/keycloak_wrapper/blob/main/lib/src/config.dart"
    click iOS "https://github.com/fa-fifi/keycloak_wrapper/blob/main/example/ios/Runner/AppDelegate.swift"
    click Android "https://github.com/fa-fifi/keycloak_wrapper/blob/main/example/android/app/src/main/AndroidManifest.xml"

    %% Styles
    classDef core fill:#3498db,stroke:#2980b9,color:white
    classDef storage fill:#2ecc71,stroke:#27ae60,color:white
    classDef jwt fill:#e74c3c,stroke:#c0392b,color:white
    classDef config fill:#f1c40f,stroke:#f39c12,color:white
    classDef ios fill:#9b59b6,stroke:#8e44ad,color:white
    classDef android fill:#9b59b6,stroke:#8e44ad,color:white

    %% Legend
    subgraph Legend
        CoreComp["Core Component"]:::core
        StorageComp["Storage Component"]:::storage
        SecurityComp["Security Component"]:::jwt
        ConfigComp["Configuration Component"]:::config
        PlatformComp["Platform Integration"]:::ios
    end
```
