# tfourj/nickel architecture

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

- Interactive diagram: https://gitdiagram.com/tfourj/nickel
- Repository: https://github.com/tfourj/nickel

## Overview

##### Project type and purpose
- Type: Native iOS application (built with SwiftUI) plus a Share Extension.
- Purpose: Acts as a third-party client for self-hosted Cobalt API servers to download media from social platforms. It does not connect directly to social platforms—it forwards requests to a user-provided Cobalt API instance.

##### File structure
- Top level
- Nickel/… – main iOS app source code and assets
- Nickel Share Extension/… – share extension that invokes the same backend API
- Nickel.xcodeproj, build scripts, CI workflows, tests, license, README
- Within Nickel/
- SwiftUI views (ContentView, ConsoleView, DebugView, LandingPageView, MainTabView, SettingsView)
- Models and managers (DownloadManager, FileDownloader, NotificationManager, SettingsModel, AppAttest)
- Info.plist and entitlements
- Tests folder
- Patterns
- UI (SwiftUI)
- Business logic and state (SettingsModel, NotificationManager)
- Networking layer (DownloadManager, FileDownloader using URLSession)
- Persistence (FileManager storage for downloads)
- Security (AppAttest integration)

##### Extra insights from README
- Relies on external Cobalt API server; optionally integrates with Nickel-Auth for authentication.
- Targets iOS 17+ and uses Xcode 15.3+.
- Feature set: download media, auto-save, notifications.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI Layer
    subgraph "UI Layer"
        direction TB
        NickelApp["NickelApp\n(Nickel/NickelApp.swift)"]:::frontend
        ContentView["ContentView\n(Nickel/ContentView.swift)"]:::frontend
        ConsoleView["ConsoleView\n(Nickel/ConsoleView.swift)"]:::frontend
        DebugView["DebugView\n(Nickel/DebugView.swift)"]:::frontend
        LandingPageView["LandingPageView\n(Nickel/LandingPageView.swift)"]:::frontend
        MainTabView["MainTabView\n(Nickel/MainTabView.swift)"]:::frontend
        SettingsView["SettingsView\n(Nickel/SettingsView.swift)"]:::frontend
    end

    %% Core Logic
    subgraph "Core / Business Logic Layer"
        direction TB
        SettingsModel["SettingsModel\n(Nickel/SettingsModel.swift)"]:::core
        NotificationManager["NotificationManager\n(Nickel/NotificationManager.swift)"]:::core
    end

    %% Networking Layer
    subgraph "Networking Layer"
        direction TB
        DownloadManager["DownloadManager\n(Nickel/DownloadManager.swift)"]:::network
        FileDownloader["FileDownloader\n(Nickel/FileDownloader.swift)"]:::network
    end

    %% Persistence
    LocalStorage["Local Storage\n(FileManager)"]:::storage

    %% Security
    AppAttest["AppAttest\n(Nickel/AppAttest.swift)"]:::security

    %% Share Extension
    subgraph "Share Extension" 
        direction TB
        ShareViewController["ShareViewController\n(Nickel Share Extension/ShareViewController.swift)"]:::extension
        MainInterface["MainInterface.storyboard\n(Nickel Share Extension/Base.lproj/MainInterface.storyboard)"]:::extension
        ExtInfo["Info.plist\n(Nickel Share Extension/Info.plist)"]:::extension
        ExtEntitlements["Nickel Share Extension.entitlements\n(Nickel Share Extension/Nickel Share Extension.entitlements)"]:::extension
    end

    %% External Services
    subgraph "External Services"
        direction TB
        CobaltAPI["Cobalt API Server"]:::external
        NickelAuth["Nickel-Auth Server"]:::external
    end

    %% Interactions
    NickelApp -->|"binds to"| SettingsModel
    ContentView --> SettingsModel
    ConsoleView --> SettingsModel
    DebugView --> SettingsModel
    LandingPageView --> SettingsModel
    MainTabView --> SettingsModel
    SettingsView --> SettingsModel

    SettingsModel -->|injects| DownloadManager
    DownloadManager --> AppAttest
    AppAttest --> FileDownloader
    FileDownloader -->|HTTP/HTTPS| CobaltAPI
    FileDownloader --> LocalStorage
    FileDownloader --> NotificationManager
    NotificationManager -->|dispatches| UserNotification["Local Notifications"]:::external

    %% Share Extension flow
    ShareViewController --> DownloadManager
    MainInterface --> ShareViewController
    ExtInfo --> ShareViewController
    ExtEntitlements --> ShareViewController

    %% Optional Auth
    SettingsModel --> NickelAuth
    DownloadManager --> NickelAuth

    %% Click Events
    click NickelApp "https://github.com/tfourj/nickel/blob/main/Nickel/NickelApp.swift"
    click ContentView "https://github.com/tfourj/nickel/blob/main/Nickel/ContentView.swift"
    click ConsoleView "https://github.com/tfourj/nickel/blob/main/Nickel/ConsoleView.swift"
    click DebugView "https://github.com/tfourj/nickel/blob/main/Nickel/DebugView.swift"
    click LandingPageView "https://github.com/tfourj/nickel/blob/main/Nickel/LandingPageView.swift"
    click MainTabView "https://github.com/tfourj/nickel/blob/main/Nickel/MainTabView.swift"
    click SettingsView "https://github.com/tfourj/nickel/blob/main/Nickel/SettingsView.swift"
    click SettingsModel "https://github.com/tfourj/nickel/blob/main/Nickel/SettingsModel.swift"
    click NotificationManager "https://github.com/tfourj/nickel/blob/main/Nickel/NotificationManager.swift"
    click DownloadManager "https://github.com/tfourj/nickel/blob/main/Nickel/DownloadManager.swift"
    click FileDownloader "https://github.com/tfourj/nickel/blob/main/Nickel/FileDownloader.swift"
    click AppAttest "https://github.com/tfourj/nickel/blob/main/Nickel/AppAttest.swift"
    click LocalStorage "https://github.com/tfourj/nickel/blob/main/Nickel/FileDownloader.swift"
    click ShareViewController "https://github.com/tfourj/nickel/blob/main/Nickel Share Extension/ShareViewController.swift"
    click MainInterface "https://github.com/tfourj/nickel/blob/main/Nickel Share Extension/Base.lproj/MainInterface.storyboard"
    click ExtInfo "https://github.com/tfourj/nickel/blob/main/Nickel Share Extension/Info.plist"
    click ExtEntitlements "https://github.com/tfourj/nickel/blob/main/Nickel Share Extension/Nickel Share Extension.entitlements"
    click CobaltAPI "https://github.com/tfourj/nickel/tree/main/Cobalt API Server"
    click NickelAuth "https://github.com/tfourj/nickel/tree/main/Nickel-Auth Server"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#4A90E2,stroke-width:1px
    classDef core fill:#E8F5D0,stroke:#7EA92E,stroke-width:1px
    classDef network fill:#FFE8D0,stroke:#E27E1B,stroke-width:1px
    classDef storage fill:#D0FFE8,stroke:#1BE27E,stroke-width:1px,stroke-dasharray: 5 5
    classDef security fill:#F5D0E8,stroke:#A92E7E,stroke-width:1px,stroke-dasharray: 5 5
    classDef extension fill:#F0F0F0,stroke:#555,stroke-width:1px,stroke-dasharray: 2 2
    classDef external fill:#FFEFD0,stroke:#E2A91B,stroke-width:1px,shape:cloud
```
