# kalinjul/kotlin-multiplatform-oidc architecture

> Architecture diagram of the GitHub repository kalinjul/kotlin-multiplatform-oidc, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kalinjul/kotlin-multiplatform-oidc
- Repository: https://github.com/kalinjul/kotlin-multiplatform-oidc

## Overview

##### Project Type & Purpose
- This is a Kotlin Multiplatform library suite implementing the OpenID Connect “Authorization Code Grant” flow (with PKCE), plus convenience modules (HTTP integrations, token persistence) and two application bundles (playground‐app and sample‐app) demonstrating usage on Android, iOS, Desktop, and WasmJS.

##### Top‐Level Modules & Directory Patterns
- build‐logic: custom Gradle convention plugins (build‐time only).
- oidc‐core: “commonMain” implementation of discovery, flows, types, JWT parsing.
- oidc‐crypto: multiplatform cryptographic support (PKCE challenge, hashing).
- oidc‐appsupport: platform‐specific AuthFlowFactory implementations (Android, iOS, JVM, WasmJS).
- oidc‐ktor, oidc‐okhttp4: optional HTTP‐client integrations (Ktor Auth plugin, OkHttp authenticator).
- oidc‐tokenstore: multiplatform token persistence (EncryptedPreferences, Keychain, in‐memory).
- playground‐app: a toy multiplatform app that assembles UI modules (core, data, domain, ui) using the library.
- sample‐app: a fully‐fledged sample demonstrating integration on each platform.

##### README for Insights
- Core features: discovery, PKCE, code‐auth flow, JWT parsing.
- Supported platforms & stability matrix.
- Dependencies on multiplatform settings, SQLDelight, Ktor/OkHttp.
- Sample usage patterns (DI, factory creation).

##### Main Components & Their Relationships
- oidc‐core (common logic)
- oidc‐crypto (crypto helpers)
- oidc‐appsupport (AuthFlowFactory per platform)
- oidc‐tokenstore (Settings‐based persistence per platform)
- HTTP integrations (oidc‐ktor, oidc‐okhttp4)
b. Application Bundles
- playground‐app (composed modules: core, domain, data, ui, shared)
- sample‐app (realistic Android, iOS, Desktop, WasmJS apps)
c. External Services & Libraries
- OAuth2/OIDC Provider endpoints (authorization, token, discovery)
- SQLDelight (for db‐sqldelight in playground app)
- Multiplatform Settings library (used by oidc‐tokenstore)
- Ktor / OkHttp engines

##### Dependency Flow
- oidc‐appsupport → oidc‐core → oidc‐crypto
- oidc‐ktor / oidc‐okhttp4 → oidc‐core
- oidc‐tokenstore → multiplatform‐settings
- playground‐app / sample‐app → [oidc‐appsupport, oidc‐core, oidc‐tokenstore, HTTP modules]
- playground‐app/data/db‐sqldelight → SQLDelight
- sample‐app/shared → sample‐app/platform code

##### Key Architectural Patterns
- Layered MPP: “commonMain” for platform‐agnostic code, “*Main” for platform specifics.
- Factory pattern: AuthFlowFactory produces platform flow.
- Optional plugin architecture: HTTP integrations are separate modules.
- DI‐friendly: flow factories and stores passed into client code.
- Persistence abstraction: token store interface with platform adapters.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Build-time Logic"
        BL["build-logic"]:::build
    end

    subgraph "Core Libraries"
        Core["oidc-core"]:::core
        Crypto["oidc-crypto"]:::core
    end

    subgraph "Platform & Integrations"
        AppSupport["oidc-appsupport"]:::platform
        TokenStore["oidc-tokenstore"]:::platform
        Ktor["oidc-ktor"]:::platform
        OkHttp["oidc-okhttp4"]:::platform
    end

    subgraph "Applications"
        Playground["playground-app"]:::app
        subgraph "Sample App Bundle"
            Sample["sample-app"]:::app
            Android["Android App"]:::app
            Desktop["Desktop App"]:::app
            IOS["iOS App"]:::app
            Wasm["WasmJS App"]:::app
            Shared["Shared Logic/UI"]:::app
            SettingsMod["Multiplatform Settings Module"]:::app
        end
    end

    OIDC["OIDC Provider Endpoints"]:::external
    MSP["Multiplatform Settings"]:::external
    SQLDelight["SQLDelight"]:::external

    AppSupport -->|"depends on"| Core
    Core -->|"depends on"| Crypto
    Ktor -->|"depends on"| Core
    OkHttp -->|"depends on"| Core
    TokenStore -->|"depends on"| MSP

    Playground -->|"uses"| Core
    Playground -->|"uses"| AppSupport
    Playground -->|"uses"| TokenStore
    Playground -->|"uses"| Ktor
    Playground -->|"uses"| OkHttp
    Playground -->|"uses"| SQLDelight

    Sample -->|"uses"| Core
    Sample -->|"uses"| AppSupport
    Sample -->|"uses"| TokenStore
    Sample -->|"uses"| Ktor
    Sample -->|"uses"| OkHttp
    Sample -->|"uses"| SQLDelight

    Sample --> Android
    Sample --> Desktop
    Sample --> IOS
    Sample --> Wasm
    Sample --> Shared
    Sample --> SettingsMod

    OIDC -->|"discovery/token/auth"| Core
    OIDC -->|"authorization callbacks"| AppSupport

    click BL "https://github.com/kalinjul/kotlin-multiplatform-oidc/tree/main/build-logic/"
    click Core "https://github.com/kalinjul/kotlin-multiplatform-oidc/tree/main/oidc-core/"
    click Crypto "https://github.com/kalinjul/kotlin-multiplatform-oidc/tree/main/oidc-crypto/"
    click AppSupport "https://github.com/kalinjul/kotlin-multiplatform-oidc/tree/main/oidc-appsupport/"
    click Ktor "https://github.com/kalinjul/kotlin-multiplatform-oidc/tree/main/oidc-ktor/"
    click OkHttp "https://github.com/kalinjul/kotlin-multiplatform-oidc/tree/main/oidc-okhttp4/"
    click TokenStore "https://github.com/kalinjul/kotlin-multiplatform-oidc/tree/main/oidc-tokenstore/"
    click Playground "https://github.com/kalinjul/kotlin-multiplatform-oidc/tree/main/playground-app/"
    click Sample "https://github.com/kalinjul/kotlin-multiplatform-oidc/tree/main/sample-app/"
    click Android "https://github.com/kalinjul/kotlin-multiplatform-oidc/tree/main/sample-app/android-app/"
    click Desktop "https://github.com/kalinjul/kotlin-multiplatform-oidc/tree/main/sample-app/desktop-app/"
    click IOS "https://github.com/kalinjul/kotlin-multiplatform-oidc/tree/main/sample-app/ios-app/"
    click Wasm "https://github.com/kalinjul/kotlin-multiplatform-oidc/tree/main/sample-app/wasm-js-app/"
    click Shared "https://github.com/kalinjul/kotlin-multiplatform-oidc/tree/main/sample-app/shared/"
    click SettingsMod "https://github.com/kalinjul/kotlin-multiplatform-oidc/tree/main/sample-app/settings/"

    classDef core fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef platform fill:#90EE90,stroke:#333,stroke-width:1px
    classDef app fill:#FFA500,stroke:#333,stroke-width:1px
    classDef build fill:#D3D3D3,stroke:#333,stroke-width:1px
    classDef external fill:#CCCCCC,stroke:#333,stroke-width:1px
```
