# gwan-son/linkclip architecture

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

- Interactive diagram: https://gitdiagram.com/gwan-son/linkclip
- Repository: https://github.com/gwan-son/linkclip

## Overview

##### Project Type and Purpose
- Project type: Native iOS application with a Share Extension
- Purpose: Let users save and organize web links (LinkClip), both from within the app and via the iOS share sheet.

##### Main Components
a. Host App (“LinkClip”)
– SwiftUI-based UI modules:
- MainView (HomeView, EditView, OnboardingView, LinkRowView, NothingView)
- CategoryView (AddCategoryView, CategoryManagementView, CategoryView)
- SettingView (SettingView, MailView)
- Shared SwiftUI views (ShareView.swift used in both host and extension)
– ViewModel: MainViewModel (MVVM)
– Model / Data Layer:
- SwiftDataContainer.swift (encapsulates persistence)
- Entities: Category, LinkItem, SearchScope, SortOption
– Utilities: ToastModifier, ShareError
– Assets: AppIcon, AccentColor, BackgroundColor, MainColor, SettingImage

b. Share Extension (“ShareViewController”)
– UIKit UIViewController (ShareViewController.swift)
– Uses same SwiftDataContainer via App Group entitlement
– Presents minimal UI to name/link and save into the host app’s store

c. Persistence & Data Flow
– SwiftData (or Core Data under the hood) storing LinkItem & Category objects
– App Group container for sharing the persistent store between host and extension
– Entitlements files: LinkClip.entitlements & ShareViewController.entitlements

d. External / System Services
– iOS Share Sheet API
– File system (App Group directory)
– Mail composer (in SettingView)

##### Architectural Patterns & Design Principles
- MVVM: Views ↔ ViewModel ↔ Model
- Single Data Container: SwiftDataContainer acts as the façade for all persistence operations
- Separation of Concerns:
– UI modules (MainView, CategoryView, SettingView) do not perform direct store access; they call into ViewModel → SwiftDataContainer
– Share extension isolated in its own target, shares code but has separate entitlements
- Reusable Components: Category.swift, LinkItem.swift, ToastModifier.swift, ShareView.swift

##### Relationships & Data Flows
1. User taps “Add Link” in Host App
→ MainViewModel receives action
→ Calls SwiftDataContainer.save(linkItem)
→ SwiftDataContainer writes to persistent store in App Group
→ MainViewModel publishes updated list → MainView updates UI

2. User invokes Share Extension from Safari
→ iOS launches ShareViewController
→ User enters category or link details in ShareView (SwiftUI hosted)
→ ShareViewController calls SwiftDataContainer.save(…) over the App Group store
→ Dismiss extension → Host App sees new item on next launch

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Host App Layer
    subgraph "Host App (LinkClip)"
        direction TB
        subgraph "UI Layer" 
            direction TB
            MainView["MainView"]:::hostUI
            HomeView["HomeView"]:::hostUI
            EditView["EditView"]:::hostUI
            OnboardingView["OnboardingView"]:::hostUI
            LinkRowView["LinkRowView"]:::hostUI
            NothingView["NothingView"]:::hostUI
            CategoryViewUI["CategoryView"]:::hostUI
            AddCategoryView["AddCategoryView"]:::hostUI
            CategoryManagementView["CategoryManagementView"]:::hostUI
            SettingView["SettingView"]:::hostUI
            MailView["MailView"]:::hostUI
        end
        MainView -->|uses| HomeView
        MainView -->|uses| EditView
        MainView -->|uses| OnboardingView
        MainView -->|uses| LinkRowView
        MainView -->|uses| NothingView
        MainView -->|uses| CategoryViewUI
        MainView -->|uses| SettingView
        CategoryViewUI -->|navigates| AddCategoryView
        CategoryViewUI -->|navigates| CategoryManagementView

        MainVM["MainViewModel"]:::hostVM
        MainView -->|"binds to"| MainVM
        UI_Views(("UI Layers")):::hostUI
    end

    %% Share Extension Layer
    subgraph "Share Extension"
        direction TB
        ShareVC["ShareViewController"]:::ext
        ShareUI["ShareView (SwiftUI)"]:::ext
        ShareVC -->|"embeds"| ShareUI
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        SwiftDataContainer["SwiftDataContainer"]:::data
        CategoryEntity["Category"]:::data
        LinkItemEntity["LinkItem"]:::data
        SearchScope["SearchScope"]:::data
        SortOption["SortOption"]:::data
        ToastModifier["ToastModifier"]:::data
        ShareError["ShareError"]:::data
        Store["Persistent Store\n(CoreData/SQLite)"]:::data
        SwiftDataContainer -->|manages| CategoryEntity
        SwiftDataContainer -->|manages| LinkItemEntity
        SwiftDataContainer -->|manages| SearchScope
        SwiftDataContainer -->|manages| SortOption
        SwiftDataContainer -->|uses| Store
    end

    %% System Services
    subgraph "System / External Services"
        direction TB
        ShareSheet["iOS Share Sheet API"]:::sys
        FileSystem["App Group File System"]:::sys
        MailCompose["MFMailComposeViewController"]:::sys
    end

    %% Interactions
    MainVM -->|"saveLink() / fetchLinks()"| SwiftDataContainer
    ShareVC -->|"saveLink()"| SwiftDataContainer
    SwiftDataContainer -->|writes to| Store
    Store -->|stored in| FileSystem
    ShareSheet -->|invokes| ShareVC
    SettingView -->|opens| MailCompose

    %% Click Events
    click MainView "https://github.com/gwan-son/linkclip/blob/main/LinkClip/MainView/MainView.swift"
    click HomeView "https://github.com/gwan-son/linkclip/blob/main/LinkClip/MainView/HomeView.swift"
    click EditView "https://github.com/gwan-son/linkclip/blob/main/LinkClip/MainView/EditView.swift"
    click OnboardingView "https://github.com/gwan-son/linkclip/blob/main/LinkClip/MainView/OnboardingView.swift"
    click LinkRowView "https://github.com/gwan-son/linkclip/blob/main/LinkClip/MainView/LinkRowView.swift"
    click NothingView "https://github.com/gwan-son/linkclip/blob/main/LinkClip/MainView/NothingView.swift"
    click CategoryViewUI "https://github.com/gwan-son/linkclip/blob/main/LinkClip/CategoryView/CategoryView.swift"
    click AddCategoryView "https://github.com/gwan-son/linkclip/blob/main/LinkClip/CategoryView/AddCategoryView.swift"
    click CategoryManagementView "https://github.com/gwan-son/linkclip/blob/main/LinkClip/CategoryView/CategoryManagementView.swift"
    click SettingView "https://github.com/gwan-son/linkclip/blob/main/LinkClip/SettingView/SettingView.swift"
    click MailView "https://github.com/gwan-son/linkclip/blob/main/LinkClip/SettingView/MailView.swift"
    click ShareUI "https://github.com/gwan-son/linkclip/blob/main/LinkClip/Shared/ShareView.swift"
    click MainVM "https://github.com/gwan-son/linkclip/blob/main/LinkClip/MainView/MainViewModel.swift"
    click SwiftDataContainer "https://github.com/gwan-son/linkclip/blob/main/LinkClip/Shared/SwiftDataContainer.swift"
    click CategoryEntity "https://github.com/gwan-son/linkclip/blob/main/LinkClip/Components/Category.swift"
    click LinkItemEntity "https://github.com/gwan-son/linkclip/blob/main/LinkClip/Components/LinkItem.swift"
    click SearchScope "https://github.com/gwan-son/linkclip/blob/main/LinkClip/Components/SearchScope.swift"
    click SortOption "https://github.com/gwan-son/linkclip/blob/main/LinkClip/Components/SortOption.swift"
    click ToastModifier "https://github.com/gwan-son/linkclip/blob/main/LinkClip/Components/ToastModifier.swift"
    click ShareError "https://github.com/gwan-son/linkclip/blob/main/LinkClip/Shared/ShareError.swift"
    click Store "https://github.com/gwan-son/linkclip/blob/main/LinkClip/LinkClip.entitlements"
    click ShareVC "https://github.com/gwan-son/linkclip/blob/main/ShareViewController/ShareViewController.swift"
    click FileSystem "https://github.com/gwan-son/linkclip/blob/main/ShareViewController/ShareViewController.entitlements"

    %% Styles
    classDef hostUI fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef hostVM fill:#1E90FF,stroke:#000,stroke-width:1px
    classDef data fill:#FFA500,stroke:#000,stroke-width:1px
    classDef ext fill:#90EE90,stroke:#000,stroke-width:1px
    classDef sys fill:#D3D3D3,stroke:#000,stroke-width:1px
```
