# ketsuryo/mlkit_swift architecture

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

- Interactive diagram: https://gitdiagram.com/ketsuryo/mlkit_swift
- Repository: https://github.com/ketsuryo/mlkit_swift

## Overview

##### Project Type and Purpose
- Type: Native iOS application.
- Purpose: Perform on-device image scanning/annotation using Google’s ML Kit, present results in a UI, and allow users to review scanned content.

##### File Structure
- Top-level artifacts:
– Podfile: declares MLKit and other CocoaPods dependencies
– Xcode project/workspace (ScanAway.xcodeproj, .xcworkspace)
– ScanAway/ folder: all Swift source files, storyboards, assets, and configuration
- Code organization:
– UI layer: ViewControllers (HomeViewController.swift, ScannedViewController.swift) and Storyboards (Main.storyboard, LaunchScreen.storyboard)
– App lifecycle: AppDelegate.swift, SceneDelegate.swift
– Scanning logic: ImageScan.swift wraps MLKit camera/image capture
– Annotation logic: AnnotationUtil.swift, EntityAnnotationPlus.swift handle drawing and overlaying scan results

##### README for Additional Insights
- Very terse: “MLkit_Swift_” — confirms the core dependency on ML Kit and that this is a Swift project.

##### Main Components
a. Mobile Device (iPhone/iPad)
b. iOS Application
– UI Layer
· Home Screen (HomeViewController + Main.storyboard)
· Scanned Results Screen (ScannedViewController)
– App/Core Services
· Camera Capture & Frame Provider (ImageScan)
· ML Processing Engine (ML Kit SDK via CocoaPods)
· Annotation Engine (AnnotationUtil + EntityAnnotationPlus)
– Data/Models
· ScanResult entities (implicit Swift structs or classes returned by ML Kit)
c. External Services
– ML Kit on-device models (barcode/text/object detection)

##### Relationships & Interactions
1. User taps “Start Scan” → HomeViewController invokes ImageScan
2. ImageScan opens camera session (AVFoundation under the hood) and streams frames
3. Each frame sent to ML Kit SDK for processing
5. Annotation layer composed over live camera feed in UI
6. When scan complete, pass results to ScannedViewController for review

##### Architectural Patterns & Principles
- MVC (ViewControllers + Storyboards = View; Swift classes = Controller; ScanResult models = Model)
- Separation of Concerns:
– ImageScan exclusively manages camera/session
– AnnotationUtil exclusively handles drawing logic
– ViewControllers coordinate between UI and services
- Dependency Management via CocoaPods (Podfile)

##### Technologies & Frameworks
- Swift, UIKit, AVFoundation
- Google ML Kit (CocoaPods) for on-device vision APIs
- Xcode build system, Storyboard files for UI

##### Final Checklist
– Notes on architectural patterns (MVC, separation of concerns).
– Callouts for key frameworks (UIKit, AVFoundation, ML Kit).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI Layer
    subgraph "UI Layer"
        direction TB
        HomeVC["HomeViewController"]:::ui
        MainSB["Main.storyboard"]:::ui
        ScannedVC["ScannedViewController"]:::ui
        LaunchSB["LaunchScreen.storyboard"]:::ui
    end

    %% App Lifecycle
    subgraph "App Lifecycle"
        direction TB
        AppDelegate["AppDelegate.swift"]:::service
        SceneDelegate["SceneDelegate.swift"]:::service
    end

    %% Core Services
    subgraph "Core Services"
        direction TB
        ImageScan["ImageScan.swift"]:::service
        AnnotationUtil["AnnotationUtil.swift"]:::service
        EntityAnnotation["EntityAnnotationPlus.swift"]:::service
    end

    %% External Dependencies
    subgraph "External Dependencies"
        direction TB
        MLKit["ML Kit SDK"]:::external
        PodfileDecl["Podfile"]:::external
    end

    %% Configuration & Assets
    subgraph "Config & Assets"
        direction TB
        InfoPlist["Info.plist"]:::config
        Assets["Assets.xcassets"]:::config
    end

    %% Data Flow
    HomeVC -->|"tap Start Scan"| ImageScan
    ImageScan -->|"camera frame"| MLKit
    MLKit -->|"DetectionResult"| AnnotationUtil
    AnnotationUtil -->|"AnnotatedImage"| HomeVC
    HomeVC -->|"scan complete"| ScannedVC

    %% App Lifecycle to UI
    AppDelegate --> SceneDelegate
    SceneDelegate --> HomeVC

    %% Dependencies
    PodfileDecl --> MLKit
    InfoPlist --> HomeVC
    Assets --> HomeVC

    %% Click Events
    click HomeVC "https://github.com/ketsuryo/mlkit_swift/blob/main/ScanAway/HomeViewController.swift"
    click MainSB "https://github.com/ketsuryo/mlkit_swift/blob/main/ScanAway/Base.lproj/Main.storyboard"
    click ScannedVC "https://github.com/ketsuryo/mlkit_swift/blob/main/ScanAway/ScannedViewController.swift"
    click LaunchSB "https://github.com/ketsuryo/mlkit_swift/blob/main/ScanAway/Base.lproj/LaunchScreen.storyboard"
    click AppDelegate "https://github.com/ketsuryo/mlkit_swift/blob/main/ScanAway/AppDelegate.swift"
    click SceneDelegate "https://github.com/ketsuryo/mlkit_swift/blob/main/ScanAway/SceneDelegate.swift"
    click ImageScan "https://github.com/ketsuryo/mlkit_swift/blob/main/ScanAway/ImageScan.swift"
    click AnnotationUtil "https://github.com/ketsuryo/mlkit_swift/blob/main/ScanAway/AnnotationUtil.swift"
    click EntityAnnotation "https://github.com/ketsuryo/mlkit_swift/blob/main/ScanAway/EntityAnnotationPlus.swift"
    click PodfileDecl "https://github.com/ketsuryo/mlkit_swift/tree/main/Podfile"
    click Assets "https://github.com/ketsuryo/mlkit_swift/blob/main/ScanAway/Assets.xcassets"
    click InfoPlist "https://github.com/ketsuryo/mlkit_swift/blob/main/ScanAway/Info.plist"

    %% Styles
    classDef ui fill:#D0E6FF,stroke:#0366D6,color:#0366D6
    classDef service fill:#E6FFEA,stroke:#28A745,color:#28A745
    classDef external fill:#FFEFD0,stroke:#E69500,color:#E69500
    classDef config fill:#F0F0F0,stroke:#636363,color:#636363
```
