# stytchauth/stytch-ios architecture

> Architecture diagram of the GitHub repository stytchauth/stytch-ios, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/stytchauth/stytch-ios
- Repository: https://github.com/stytchauth/stytch-ios

## Overview

##### High-Level Components

a) Core SDK Layer (StytchCore):
- Components:
- Authentication Clients (Consumer & B2B)
- Networking Layer
- Storage Systems (Keychain, UserDefaults)
- Crypto Operations
- Session Management

b) UI Layer (StytchUI):
- Above Core SDK
- Separate into:
- Consumer UI Components
- B2B UI Components
- Shared UI Elements

c) Integration Layer:
- Top-level showing how apps integrate
- Demo Applications
- Configuration Flow

##### Component Relationships

a) Data Flow:
**App Integration → StytchUI → StytchCore → Backend Services**

b) Authentication Flows:
- OAuth
- Magic Links
- OTP
- Passwords
- Biometrics
- SSO (B2B)

##### Detailed Component Breakdown

For each major component, include:

a) StytchCore:
- Client Management
- Consumer Client
- B2B Client
- Authentication Methods
- OAuth
- Magic Links
- OTP
- Others...
- Networking
- Request Handler
- Response Processing
- Storage
- Keychain
- User Defaults

b) StytchUI:
- View Controllers
- Auth Flows
- User Management
- Components
- Input Fields
- Buttons
- Theme Management

##### Technical Details

Annotations for:
- Minimum iOS/macOS versions
- Swift Package Manager integration
- Async/await support with alternatives
- Security features

##### Implementation Notes

Callouts for:
- Configuration requirements
- Error handling flows
- Session management
- Authentication state transitions

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef core fill:#e1f5fe,stroke:#01579b
    classDef ui fill:#f3e5f5,stroke:#4a148c
    classDef integration fill:#e8f5e9,stroke:#1b5e20
    classDef storage fill:#fff3e0,stroke:#e65100
    classDef networking fill:#f3e5f5,stroke:#4a148c
    classDef auth fill:#e3f2fd,stroke:#0d47a1

    %% Integration Layer
    subgraph Integration
        DemoApps["Demo Applications"]
        Config["Configuration Flow"]
    end

    %% UI Layer
    subgraph UILayer["UI Layer"]
        ConsumerUI["Consumer UI Components"]
        B2BUI["B2B UI Components"]
        SharedUI["Shared UI Elements"]
    end

    %% Core SDK Layer
    subgraph CoreSDK["Core SDK Layer"]
        subgraph AuthClients["Authentication Clients"]
            ConsumerClient["Consumer Client"]
            B2BClient["B2B Client"]
        end

        subgraph Network["Networking"]
            RequestHandler["Request Handler"]
            ResponseProcess["Response Processing"]
        end

        subgraph Storage["Storage Systems"]
            Keychain["Keychain"]
            UserDefaults["User Defaults"]
        end

        CryptoOps["Crypto Operations"]
        SessionMgmt["Session Management"]

        subgraph AuthMethods["Authentication Methods"]
            OAuth["OAuth"]
            MagicLinks["Magic Links"]
            OTP["OTP"]
            Passwords["Passwords"]
            Biometrics["Biometrics"]
            SSO["SSO (B2B)"]
        end
    end

    %% Relationships
    DemoApps --> ConsumerUI & B2BUI
    Config --> ConsumerUI & B2BUI
    ConsumerUI --> ConsumerClient
    B2BUI --> B2BClient
    SharedUI --> ConsumerUI & B2BUI
    ConsumerClient & B2BClient --> Network
    ConsumerClient & B2BClient --> Storage
    ConsumerClient & B2BClient --> CryptoOps
    ConsumerClient & B2BClient --> SessionMgmt
    ConsumerClient & B2BClient --> AuthMethods

    %% Click Events
    click DemoApps "https://github.com/stytchauth/stytch-ios/tree/main/Stytch/DemoApps"
    click Config "https://github.com/stytchauth/stytch-ios/blob/main/Sources/StytchUI/StytchUIClient/StytchUIClient+Configuration.swift"
    click ConsumerUI "https://github.com/stytchauth/stytch-ios/tree/main/Sources/StytchUI/StytchUIClient"
    click B2BUI "https://github.com/stytchauth/stytch-ios/tree/main/Sources/StytchUI/StytchB2BUIClient"
    click SharedUI "https://github.com/stytchauth/stytch-ios/tree/main/Sources/StytchUI/Shared"
    click ConsumerClient "https://github.com/stytchauth/stytch-ios/tree/main/Sources/StytchCore/StytchClient"
    click B2BClient "https://github.com/stytchauth/stytch-ios/tree/main/Sources/StytchCore/StytchB2BClient"
    click Network "https://github.com/stytchauth/stytch-ios/tree/main/Sources/StytchCore/Networking"
    click Keychain "https://github.com/stytchauth/stytch-ios/tree/main/Sources/StytchCore/KeychainClient"
    click CryptoOps "https://github.com/stytchauth/stytch-ios/tree/main/Sources/StytchCore/CryptoClient"
    click SessionMgmt "https://github.com/stytchauth/stytch-ios/blob/main/Sources/StytchCore/SessionManager.swift"

    %% Style Applications
    class DemoApps,Config integration
    class ConsumerUI,B2BUI,SharedUI ui
    class ConsumerClient,B2BClient,AuthMethods auth
    class Network,RequestHandler,ResponseProcess networking
    class Storage,Keychain,UserDefaults storage
    class CryptoOps,SessionMgmt core
```
