# paugp/heimdall architecture

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

- Interactive diagram: https://gitdiagram.com/paugp/heimdall
- Repository: https://github.com/paugp/heimdall

## Overview

##### Main Components

a. Core Components:
- Heimdall Core (Main wrapper)
- Security Framework (iOS)
- CommonCrypto Module
- Keychain Storage
- RSA Cryptography Module
- AES Cryptography Module

b. Integration Points:
- Public API Interface
- Application Integration Layer

**┌─ Application Layer ─────────────────────────┐**

- iOS Application Integration         │

- ┤

- Heimdall Public API             │

- ┤

- Heimdall Core Logic             │

- ┬────────────────┬──────────┤

- RSA Module   │   AES Module   │ Keychain │

- ┴────────────────┴──────────┤

- CommonCrypto Module             │

- ┤

- iOS Security Framework           │

- ┘

##### Key Interactions to Highlight

a. Encryption Flow:
- How data flows from the application through Heimdall's encryption process
- Hybrid encryption system (RSA + AES)
- Storage in Keychain

b. Decryption Flow:
- Reverse process of decryption
- Retrieval from Keychain
- Separation of encrypted key and data

##### Implementation Details

- The wrapper nature of the framework
- The security boundary between application and system frameworks
- The modularity of the cryptographic operations
- The key management system

- Keep the focus on the security aspects and data flow
- Separation of concerns
- Clear boundaries between system and application code
- Version compatibility information
- Swift language requirement

- Layer-based organization
- Clear component boundaries
- Professional-looking connections
- Export to high-resolution formats

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles and classes
    classDef application fill:#f5f5f5,stroke:#333
    classDef heimdall fill:#b3d9ff,stroke:#333
    classDef security fill:#ffe6b3,stroke:#333
    classDef system fill:#b3ffb3,stroke:#333
    classDef integration fill:#e6e6e6,stroke:#333

    %% Application Layer
    subgraph AppLayer["Application Layer"]
        AppIntegration["iOS Application Integration"]:::integration
        ExampleApp["Example Application"]:::integration
    end
    click ExampleApp "https://github.com/paugp/Heimdall/tree/master/Example/HeimdallExample/"
    click AppIntegration "https://github.com/paugp/Heimdall/tree/master/Example/HeimdallExample/"

    %% Heimdall Public API Layer
    subgraph APILayer["Public API Layer"]
        PublicAPI["Heimdall Public API"]:::heimdall
    end
    click PublicAPI "https://github.com/paugp/Heimdall/blob/master/Heimdall/Heimdall.h"

    %% Heimdall Core Layer
    subgraph CoreLayer["Heimdall Core Layer"]
        HeimdallCore["Heimdall Core Logic"]:::heimdall
        IntegrationTests["Integration Tests"]:::heimdall
    end
    click HeimdallCore "https://github.com/paugp/Heimdall/blob/master/Heimdall/Heimdall.swift"
    click IntegrationTests "https://github.com/paugp/Heimdall/blob/master/HeimdallTests/HeimdallTests.swift"

    %% Cryptographic Modules Layer
    subgraph CryptoLayer["Cryptographic Modules"]
        RSAModule["RSA Module"]:::security
        AESModule["AES Module"]:::security
        KeychainStorage["Keychain Storage"]:::security
    end

    %% Common Crypto Layer
    subgraph CommonLayer["Common Crypto Layer"]
        CommonCrypto["CommonCrypto Module"]:::system
        iOSImpl["iOS Implementation"]:::system
        iOSSimulator["iOS Simulator"]:::system
        tvOSImpl["tvOS Implementation"]:::system
        tvOSSimulator["tvOS Simulator"]:::system
    end
    click CommonCrypto "https://github.com/paugp/Heimdall/tree/master/CommonCrypto/"
    click iOSImpl "https://github.com/paugp/Heimdall/blob/master/CommonCrypto/iphoneos.modulemap"
    click iOSSimulator "https://github.com/paugp/Heimdall/blob/master/CommonCrypto/iphonesimulator.modulemap"
    click tvOSImpl "https://github.com/paugp/Heimdall/blob/master/CommonCrypto/appletvos.modulemap"
    click tvOSSimulator "https://github.com/paugp/Heimdall/blob/master/CommonCrypto/appletvsimulator.modulemap"

    %% System Framework Layer
    subgraph SystemLayer["System Framework Layer"]
        SecurityFramework["iOS Security Framework"]:::system
    end

    %% Connections
    AppIntegration --> PublicAPI
    ExampleApp --> PublicAPI
    PublicAPI --> HeimdallCore
    HeimdallCore --> IntegrationTests
    HeimdallCore --> RSAModule
    HeimdallCore --> AESModule
    HeimdallCore --> KeychainStorage
    RSAModule --> CommonCrypto
    AESModule --> CommonCrypto
    KeychainStorage --> SecurityFramework
    CommonCrypto --> SecurityFramework
    CommonCrypto --> iOSImpl & iOSSimulator & tvOSImpl & tvOSSimulator

    %% Legend
    subgraph Legend
        L1["Application Components"]:::application
        L2["Heimdall Components"]:::heimdall
        L3["Security Components"]:::security
        L4["System Components"]:::system
        L5["Integration Components"]:::integration
    end
```
