# jamf/jamfsync architecture

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

- Interactive diagram: https://gitdiagram.com/jamf/jamfsync
- Repository: https://github.com/jamf/jamfsync

## Overview

##### Main Components
- JamfSyncApp & UI: The entry point is “JamfSyncApp” (in JamfSync/UI) which initializes the SwiftUI ContentView and related views. This layer encapsulates all user interactions. Within UI, separate views (e.g., AboutView, SettingsView, PackageListView, etc.) allow configuration, display, and progress updates.
- Model Layer: Contains the primary domain objects that drive the business logic. Key classes include DataModel, DistributionPoint, and its subclasses (FileShareDp, Jcds2Dp, FolderDp). The Model also includes types for handling files and checksums (e.g., DpFile, Checksums, and associated utility functions). The “ViewModels” sub-group works as an intermediary between the Model and UI, ensuring that UI state is updated via @Published properties.
- CoreData & Persistence: The CoreData directory stores user settings and other persistent entities (StoredSettings.xcdatamodeld). This layer handles storage for non-sensitive data while secure credentials are stored in the keychain.
- Utility Components: This module consists of helper classes (e.g., ArgumentParser for command line processing, FileHash, FileShare handling, KeychainHelper for secure credential storage, and others that support file operations and network communication).
- External Interactions: Components involved in interacting with external Jamf Pro servers via JamfPro APIs (JamfProPackageApi, JamfProPackageClassicApi, etc.) and additional networking components like CloudSessionDelegate. Also, note the command line interface support for scripted operations.
- Testing: Separate modules (JamfSyncTests and JamfSyncUITests) provide unit testing and UI testing to ensure functionality across modules.

##### Relationships and Interactions
- The user (or a script via command line) starts the application. The UI layer (rooted in JamfSyncApp) receives user input, which then updates the ViewModels.
- ViewModels observe and communicate changes to the DataModel.
- The DataModel interacts with persistence (CoreData for user settings) and with secure storage (using KeychainHelper) for credentials.
- When a synchronization is triggered (through UI or command line parameters), the DataModel and DistributionPoint objects coordinate:
- They use the copyFiles function to initiate file transfers between the selected source and destination.
- Depending on what type of distribution point is used (FileShareDp, Jcds2Dp, FolderDp), different implementations of file transfer logic are invoked in the Model layer.
- Utility classes (e.g., FileHash for checksums, FileShare for mounting fileshares) are employed to ensure the integrity of file operations.
- APIs (like JamfProPackageApi) are contacted when working with Jamf Pro servers.
- The UI continuously updates (via @Published properties in ViewModels) to reflect the current synchronization status and logs from the LogViewModel.

##### Architectural Patterns and Design Principles
- Separation of Concerns: The project is partitioned into clear layers (UI, Model, Utility, Persistence) that handle distinct responsibilities.
- MVVM Pattern: With view models residing alongside the Model and communicating directly with the UI (SwiftUI), the MVVM pattern is strongly in use.
- Modularization: Each module (such as Utility or DistributionPoint subtypes) encapsulates specific core functionality and can be extended (for example, to support additional cloud distribution points like AWS or Akamai later).
- Secure Data Handling: Sensitive data is managed via the keychain and Core Data for non-sensitive items.
- Command Line Integration: The application also has a headless mode via ArgumentParser, meaning the design must account for both interactive UI and CLI-driven workflows.

## Diagram (Mermaid)

```mermaid
graph TD
    %% User Initiation
    UserCLI["User (CLI)"]:::external

    %% UI Layer
    subgraph "UI Layer"
        UI1["JamfSyncApp"]:::ui
        UI2["ContentView"]:::ui
        UI3["AboutView/SettingsView/PackageListView"]:::ui
        UI1 -->|"loads"| UI2
        UI2 -->|"navigates"| UI3
    end

    %% Model Layer
    subgraph "Model Layer"
        M6["ViewModels"]:::model
        M1["DataModel"]:::model
        M2["DistributionPoint"]:::model
        M3["FileShareDp"]:::model
        M4["FolderDp"]:::model
        M5["Jcds2Dp"]:::model
        M6 -->|"updates"| M1
        M1 -->|"coordinates with"| M2
        M2 -->|"invokes subtype"| M3
        M2 -->|"invokes subtype"| M4
        M2 -->|"invokes subtype"| M5
    end

    %% Persistence
    subgraph "Persistence"
        P1["CoreData (StoredSettings & DataManager)"]:::persistence
    end

    %% Utility Layer
    subgraph "Utility"
        U1["ArgumentParser"]:::utility
        U2["FileHash"]:::utility
        U3["FileShare"]:::utility
        U4["KeychainHelper"]:::utility
        U5["CloudSessionDelegate"]:::utility
    end

    %% External Interfaces
    subgraph "External Interfaces"
        E1["JamfProPackageApi"]:::external
        E2["JamfProPackageClassicApi"]:::external
        E3["JamfProPackageUApi"]:::external
    end

    %% Testing Modules
    subgraph "Testing"
        T1["JamfSyncTests"]:::testing
        T2["JamfSyncUITests"]:::testing
    end

    %% Inter-layer Connections
    UI1 -->|"triggers"| M6
    M1 -->|"persists data"| P1
    M1 -->|"initiates sync"| M2
    M2 -->|"uses"| U2
    M2 -->|"uses"| U3
    M1 -->|"secure-access"| U4
    M2 -->|"calls API"| E1
    M2 -->|"calls API"| E2
    M2 -->|"calls API"| E3
    UserCLI -->|"parses args via"| U1
    U1 -->|"updates"| M1

    %% Styles
    classDef ui fill:#f9c74f,stroke:#000,stroke-width:1px;
    classDef model fill:#90be6d,stroke:#000,stroke-width:1px;
    classDef persistence fill:#f9844a,stroke:#000,stroke-width:1px;
    classDef utility fill:#577590,stroke:#000,stroke-width:1px;
    classDef external fill:#f94144,stroke:#000,stroke-width:1px;
    classDef testing fill:#277da1,stroke:#000,stroke-width:1px;

    %% Click Events - UI Layer
    click UI1 "https://github.com/jamf/jamfsync/blob/main/JamfSync/UI/JamfSyncApp.swift"
    click UI2 "https://github.com/jamf/jamfsync/blob/main/JamfSync/UI/ContentView.swift"

    %% Click Events - Model Layer
    click M1 "https://github.com/jamf/jamfsync/blob/main/JamfSync/Model/DataModel.swift"
    click M2 "https://github.com/jamf/jamfsync/blob/main/JamfSync/Model/DistributionPoint.swift"
    click M3 "https://github.com/jamf/jamfsync/blob/main/JamfSync/Model/FileShareDp.swift"
    click M4 "https://github.com/jamf/jamfsync/blob/main/JamfSync/Model/FolderDp.swift"
    click M5 "https://github.com/jamf/jamfsync/blob/main/JamfSync/Model/Jcds2Dp.swift"
    click M6 "https://github.com/jamf/jamfsync/tree/main/JamfSync/Model/ViewModels"

    %% Click Events - Persistence
    click P1 "https://github.com/jamf/jamfsync/tree/main/CoreData"

    %% Click Events - Utility Layer
    click U1 "https://github.com/jamf/jamfsync/blob/main/JamfSync/Utility/ArgumentParser.swift"
    click U2 "https://github.com/jamf/jamfsync/blob/main/JamfSync/Utility/FileHash.swift"
    click U3 "https://github.com/jamf/jamfsync/blob/main/JamfSync/Utility/FileShare.swift"
    click U4 "https://github.com/jamf/jamfsync/blob/main/JamfSync/Utility/KeychainHelper.swift"
    click U5 "https://github.com/jamf/jamfsync/blob/main/JamfSync/Utility/CloudSessionDelegate.swift"

    %% Click Events - External Interfaces
    click E1 "https://github.com/jamf/jamfsync/blob/main/JamfSync/Model/JamfProPackageApi.swift"
    click E2 "https://github.com/jamf/jamfsync/blob/main/JamfSync/Model/JamfProPackageClassicApi.swift"
    click E3 "https://github.com/jamf/jamfsync/blob/main/JamfSync/Model/JamfProPackageUApi.swift"

    %% Click Events - Testing
    click T1 "https://github.com/jamf/jamfsync/tree/main/JamfSyncTests"
    click T2 "https://github.com/jamf/jamfsync/tree/main/JamfSyncUITests"
```
