# snmac/sykeyboard architecture

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

- Interactive diagram: https://gitdiagram.com/snmac/sykeyboard
- Repository: https://github.com/snmac/sykeyboard

## Overview

##### Project Type and Purpose
- This is an iOS application that provides a custom keyboard extension (SYKeyboard) plus two extension targets (EnglishKeyboard and HangeulKeyboard), built in Swift/SwiftUI and UIKit. Users install the SYKeyboard host app to configure settings, and then enable one or more keyboard extensions in the system keyboard settings.

##### Main Components
A. Host App (SYKeyboard)
- SwiftUI/App entry (SYKeyboardApp.swift, ContentView.swift)
- Settings screens (KeyboardSettings/*)
- Instructions tab (InstructionsTab/*)
- Preview/Test view (KeyboardTestView.swift)
- Models and Utils (SupportEmail.swift, custom view modifiers and extensions)
B. Keyboard Extension Targets
1. EnglishKeyboard
– ViewController: EnglishKeyboardViewController
– Presentation/View/Layout: EnglishKeyboardView & its protocol
– Resources: Entitlements, Info.plist, xcconfig
2. HangeulKeyboard
– ViewController: HangeulKeyboardViewController
– Presentation/View/Layout: CheonjiinKeyboardView, NaratgeulKeyboardView
– Resources: Entitlements, InfoPlist.xcstrings, Localizable.xcstrings, xcconfig
C. Common Module
- Shared code for both keyboards and host:
– FeedbackManager.swift, UserDefaultsManager.swift
– Utils (DefaultValues, OneHandedMode, UserDefaultsKeys)
– Presentation components: Buttons, Overlays, GestureControllers, Layout Views under Keyboards/Common/Presentation
D. External Services
- Firebase Analytics
- Google AdMob (via Pods/GAD)
- Meta Audience Network (Pods/FBAudienceNetwork.xcframework)
E. Persistence and Configuration
- UserDefaults (via UserDefaultsManager) for storing keyboard height, one-handed mode, repeat rate, etc.
- Build configurations via xcconfig files (Debug/Release for each target).
F. Dependency Management
- CocoaPods (Podfile, Pod targets for each extension)
- Swift Package Manager (SPM) if any non-CocoaPods dependencies

##### Relationships and Interactions
- The Host App reads/writes user settings (UserDefaults) via singleton managers.
- Keyboard extensions import the Common module; they fetch stored settings and configure UI (height, one-handed offset, key repeat) accordingly.
- UI interactions in the extension (button taps, gestures) route through GestureControllers → Button Protocols → FeedbackManager (haptic) → delegate back to the extension’s textDocumentProxy.
- Both the Host App and Extensions log events to Firebase Analytics.
- Ad components (AdMob, Meta Audience) load ads in the Host App’s BannerView.

##### Architectural Patterns & Design Principles
- MVVM-ish / Presenter-style separation:
- Views (SwiftUI + UIKit UIView subclasses) ↔ ViewControllers
- Delegate Pattern: KeyboardViewController delegates text insertion/deletion to UITextDocumentProxy.
- Singleton Pattern: FeedbackManager, UserDefaultsManager.
- Modularization: Common code is factored into a separate module/directory, imported by all targets.

##### Technologies and Frameworks to Annotate
- SwiftUI (Host App)
- UIKit (Keyboard Extensions)
- SnapKit + Then (Auto Layout DSL)
- Swift Package Manager + CocoaPods (dependency managers)
- Firebase Analytics, Google AdMob, Meta Audience Network
- UserDefaults (local storage)

##### Essential Elements Checklist
- Clear labels on each module/component
- Notes on architectural patterns (delegate, singleton) where they apply

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Host App
    subgraph "Host App (SYKeyboard)"
        direction TB
        SYApp["SYKeyboardApp.swift\nContentView.swift"]:::host
        KeyboardSettings["KeyboardSettings\n*.swift"]:::host
        InstructionsTab["InstructionsTab\n*.swift"]:::host
        KeyboardTestView["KeyboardTestView.swift"]:::host
        SupportEmail["SupportEmail.swift"]:::host
        UtilsHost["Utils (modifiers/extensions)"]:::host
        ConfigsHost["Configs (.xcconfig)"]:::host
        BannerView["BannerView.swift"]:::host
    end

    click SYApp "https://github.com/snmac/sykeyboard/blob/develop/SYKeyboard/App/SYKeyboardApp.swift"
    click SYApp "https://github.com/snmac/sykeyboard/blob/develop/SYKeyboard/ContentView.swift"
    click KeyboardSettings "https://github.com/snmac/sykeyboard/tree/develop/SYKeyboard/KeyboardSettings"
    click InstructionsTab "https://github.com/snmac/sykeyboard/tree/develop/SYKeyboard/InstructionsTab"
    click KeyboardTestView "https://github.com/snmac/sykeyboard/blob/develop/SYKeyboard/KeyboardTestView.swift"
    click SupportEmail "https://github.com/snmac/sykeyboard/blob/develop/SYKeyboard/Models/SupportEmail.swift"
    click UtilsHost "https://github.com/snmac/sykeyboard/tree/develop/SYKeyboard/Utils"
    click ConfigsHost "https://github.com/snmac/sykeyboard/tree/develop/SYKeyboard/Resources/Configs"
    click BannerView "https://github.com/snmac/sykeyboard/blob/develop/SYKeyboard/BannerView.swift"

    %% English Keyboard Extension
    subgraph "EnglishKeyboard Extension" 
        direction TB
        EngVC["EnglishKeyboardViewController.swift"]:::extension
        EngLayout["EnglishKeyboardView.swift"]:::extension
        EngProtocols["EnglishKeyboardLayout.swift"]:::extension
        EngResources["Entitlements & Info.plist"]:::extension
        EngConfigs["Configs (.xcconfig)"]:::extension
    end

    click EngVC "https://github.com/snmac/sykeyboard/blob/develop/Keyboards/EnglishKeyboard/Presentation/ViewController/EnglishKeyboardViewController.swift"
    click EngLayout "https://github.com/snmac/sykeyboard/blob/develop/Keyboards/EnglishKeyboard/Presentation/View/KeyboardLayout/EnglishKeyboardView.swift"
    click EngProtocols "https://github.com/snmac/sykeyboard/blob/develop/Keyboards/EnglishKeyboard/Presentation/View/Protocols/EnglishKeyboardLayout.swift"
    click EngResources "https://github.com/snmac/sykeyboard/blob/develop/Keyboards/EnglishKeyboard/Resources/EnglishKeyboard.entitlements"
    click EngResources "https://github.com/snmac/sykeyboard/blob/develop/Keyboards/EnglishKeyboard/Resources/Info.plist"
    click EngConfigs "https://github.com/snmac/sykeyboard/blob/develop/Keyboards/EnglishKeyboard/Resources/Configs/DebugConfig-EnglishKeyboard.xcconfig"
    click EngConfigs "https://github.com/snmac/sykeyboard/blob/develop/Keyboards/EnglishKeyboard/Resources/Configs/ReleaseConfig-EnglishKeyboard.xcconfig"

    %% Hangeul Keyboard Extension
    subgraph "HangeulKeyboard Extension"
        direction TB
        HanVC["HangeulKeyboardViewController.swift"]:::extension
        HanLayouts["Cheonjiin & Naratgeul Keyboard Views"]:::extension
        HanProtocols["HangeulKeyboardLayout.swift"]:::extension
        HanResources["Entitlements & Info.plist\nLocalizable.xcstrings"]:::extension
        HanConfigs["Configs (.xcconfig)"]:::extension
    end

    click HanVC "https://github.com/snmac/sykeyboard/blob/develop/Keyboards/HangeulKeyboard/Presentation/ViewController/HangeulKeyboardViewController.swift"
    click HanLayouts "https://github.com/snmac/sykeyboard/blob/develop/Keyboards/HangeulKeyboard/Presentation/View/KeyboardLayout/CheonjiinKeyboardView.swift"
    click HanLayouts "https://github.com/snmac/sykeyboard/blob/develop/Keyboards/HangeulKeyboard/Presentation/View/KeyboardLayout/NaratgeulKeyboardView.swift"
    click HanProtocols "https://github.com/snmac/sykeyboard/blob/develop/Keyboards/HangeulKeyboard/Presentation/View/Protocols/HangeulKeyboardLayout.swift"
    click HanResources "https://github.com/snmac/sykeyboard/blob/develop/Keyboards/HangeulKeyboard/Resources/HangeulKeyboard.entitlements"
    click HanResources "https://github.com/snmac/sykeyboard/blob/develop/Keyboards/HangeulKeyboard/Resources/Info.plist"
    click HanResources "https://github.com/snmac/sykeyboard/blob/develop/Keyboards/HangeulKeyboard/Resources/Localizable.xcstrings"
    click HanResources "https://github.com/snmac/sykeyboard/blob/develop/Keyboards/HangeulKeyboard/Resources/InfoPlist.xcstrings"
    click HanConfigs "https://github.com/snmac/sykeyboard/blob/develop/Keyboards/HangeulKeyboard/Resources/Configs/DebugConfig-HangeulKeyboard.xcconfig"
    click HanConfigs "https://github.com/snmac/sykeyboard/blob/develop/Keyboards/HangeulKeyboard/Resources/Configs/ReleaseConfig-HangeulKeyboard.xcconfig"

    %% Common Module
    subgraph "Common Module"
        direction TB
        FeedbackMgr["FeedbackManager.swift"]:::common
        UDManager["UserDefaultsManager.swift"]:::common
        UtilsCommon["Utils"]:::common
        ConfigsCommon["Configs"]:::common
        AssetsCommon["Assets.xcassets"]:::common
        CommonPres["Common Presentation"]:::common
    end

    click FeedbackMgr "https://github.com/snmac/sykeyboard/blob/develop/Common/FeedbackManager.swift"
    click UDManager "https://github.com/snmac/sykeyboard/blob/develop/Common/UserDefaultsManager.swift"
    click UtilsCommon "https://github.com/snmac/sykeyboard/tree/develop/Common/Utils"
    click ConfigsCommon "https://github.com/snmac/sykeyboard/tree/develop/Common/Configs"
    click AssetsCommon "https://github.com/snmac/sykeyboard/blob/develop/Common/Resources/Assets.xcassets"
    click CommonPres "https://github.com/snmac/sykeyboard/tree/develop/Keyboards/Common/Presentation"

    %% External Services
    subgraph "External Services"
        direction TB
        Firebase["Firebase Analytics"]:::external
        AdMob["Google AdMob"]:::external
        MetaAudience["Meta Audience Network"]:::external
    end

    click MetaAudience "https://github.com/snmac/sykeyboard/blob/develop/Pods/FBAudienceNetwork/Static/FBAudienceNetwork.xcframework"
    click AdMob "https://github.com/snmac/sykeyboard/tree/develop/Pods/Target Support Files"
    click Firebase "https://github.com/snmac/sykeyboard/tree/develop/Pods/Target Support Files/Pods-SYKeyboard"

    %% Persistence Layer
    UserDefaultsStorage[(UserDefaults)]:::storage

    %% TextDocumentProxy
    TDP["UITextDocumentProxy"]:::storage

    %% Dependencies
    Podfile["Podfile & Podfile.lock"]:::external
    XcodeProj["SYKeyboard.xcodeproj\nSYKeyboard.xcworkspace"]:::external

    %% Flows
    User["User"]:::external
    User -->|"interacts with"| SYApp
    SYApp -->|"load settings"| UDManager
    SYApp -->|"log event"| Firebase
    SYApp -->|"load ad"| AdMob
    SYApp -->|"load ad"| MetaAudience
    UDManager -->|"read/write"| UserDefaultsStorage

    EngLayout -->|"user input"| EngVC
    EngVC -->|"fetch settings"| UDManager
    EngVC -->|"send analytics"| Firebase
    EngVC -->|"send haptic"| FeedbackMgr
    EngVC -->|"delegate text"| TDP

    HanLayouts -->|"user input"| HanVC
    HanVC -->|"fetch settings"| UDManager
    HanVC -->|"send analytics"| Firebase
    HanVC -->|"send haptic"| FeedbackMgr
    HanVC -->|"delegate text"| TDP

    FeedbackMgr -->|"access settings"| UDManager

    %% Classes
    classDef host fill:#d0e7ff,stroke:#1e70bf,color:#000
    classDef extension fill:#d0ffd8,stroke:#2d8f1e,color:#000
    classDef common fill:#f0d8ff,stroke:#8e1eaf,color:#000
    classDef external fill:#ffe0b2,stroke:#bf6600,color:#000
    classDef storage fill:#fff2a8,stroke:#bf9f00,color:#000
```
