# jamf/jamf-switcher architecture

> Architecture diagram of the GitHub repository jamf/jamf-switcher, 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/jamf-switcher
- Repository: https://github.com/jamf/jamf-switcher

## Overview

##### Main Components
- User Interface (UI) Layer:
- This includes the storyboard (Main.storyboard), AppDelegate.swift, ViewController.swift, and any other UI-specific assets.
- It handles user interactions, such as selecting bookmarks, search queries (CMD + F), and double-clicking to trigger app selection.
- API/Logic Layer:
- Resolve functionality provided in the JamfAPI directory. Within JamfAPI, separate concerns are evident:
▪ API: Handles calls to Jamf API endpoints (CallAPI.swift, JamfAPI.swift).
▪ Logic: Encapsulated business logic for Jamf operations (JamfLogic.swift).
▪ Models: Data structures that represent Jamf information (Structures.swift).
▪ Service: Implements service layer tasks (JamfService.swift).
- Self Service & Bookmark Processing:
- JamfSelfServiceParser.swift parses self-service bookmark data that is configured within Jamf Pro.
- System Integration & Keychain:
- KeychainService.swift likely handles secure storage or retrieval of credentials/settings.
- Configuration & External Interactions:
- The app makes changes to the system’s ~/Library/Preferences/com.jamfsoftware.jss.plist based on user actions.
- There’s logic in PolicyLogic.swift (under Jamf Switcher/Logic) that might deal with decision-making and policy operations.

##### Out Relationships and Interactions
- The UI Layer presents the list of Jamf bookmarks to the user and captures actions (e.g., selecting a bookmark or executing a search).
- On user action, the UI layer delegates work to the Business Logic/Policy layer (PolicyLogic.swift) and to the API/Service layer for handling network requests or local updates.
- The API/Logic Layer processes user requests by calling APIs, managing models, and executing business logic.
- When the target Jamf Pro application needs to be launched, the app accesses external applications (e.g., checking for /Applications/Jamf Pro/ folder) and modifies configuration files accordingly.
- The KeychainService may be used by various layers to securely store or fetch credentials if needed.

##### Architectural Patterns and Design Principles
- Separation of Concerns: The project neatly divides the UI (Storyboards, controllers) from business logic (JamfAPI’s subdirectories) and from system integration (Keychain, Preference modifications).
- Modular Design: The use of directories like API, Logic, Models, and Service indicates a modular structure that helps extensibility and maintenance.

##### Relevant Technologies, Frameworks, and Tools
- Swift as the primary programming language and Xcode as the development environment.
- Cocoa frameworks for macOS user interface components.
- Xcode project configuration files (Jamf Switcher.xcodeproj) that outline the build and project settings.
- External dependencies: Although not explicitly mentioned as third-party libraries in the file tree, note that self-service bookmark configuration and the system preference file integration imply usage of macOS system APIs.

##### Elements
- Each Component Label:
- “UI Layer” – Main.storyboard, ViewController, AppDelegate.
- “Business Logic” – PolicyLogic, JamfAPI’s Logic and Models.
- “API/Service Layer” – JamfAPI/API, JamfService.
- “System Integration” – KeychainService, Preference updates at ~/Library/Preferences/com.jamfsoftware.jss.plist.
- Data flow: UI actions → Business Logic → Service/API calls → System-level actions.
- Differentiation of Components:

##### Detail and Structure
- Even though the project isn’t vast in component count, decompose it enough to see clear boundaries between functionality. This separation helps when revisiting integration points (like how the Jamf Self Service bookmarks feed into the app logic or trigger external actions).

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% UI Layer
    subgraph "UI Layer"
        UI1["Main.storyboard"]
        UI2["AppDelegate.swift"]
        UI3["ViewController.swift"]
    end

    %% Business Logic Layer
    subgraph "Business Logic"
        BL1["PolicyLogic.swift"]
    end

    %% Self Service Processing
    subgraph "Self Service Processing"
        SSP["JamfSelfServiceParser.swift"]
    end

    %% API/Service Layer
    subgraph "API/Service Layer"
        APIC1["CallAPI.swift"]
        APIC2["JamfAPI.swift"]
        APIL["JamfLogic.swift"]
        APIM["Structures.swift"]
        APIS["JamfService.swift"]
    end

    %% System Integration
    subgraph "System Integration"
        SI1["KeychainService.swift"]
        SI2["Configuration File Update"]
    end

    %% Connections
    UI1 -->|"user interaction"| BL1
    UI2 -->|"user interaction"| BL1
    UI3 -->|"user interaction"| BL1
    SSP -->|"parses bookmarks"| BL1

    BL1 -->|"invokes service"| APIS
    APIS -->|"calls API"| APIC1
    APIS -->|"calls API"| APIC2
    APIS -->|"processes logic"| APIL
    APIS -->|"manages data"| APIM

    BL1 -->|"triggers"| SI1
    BL1 -->|"updates"| SI2

    %% Click Events - UI Layer
    click UI1 "https://github.com/jamf/jamf-switcher/blob/master/Jamf Switcher/Base.lproj/Main.storyboard"
    click UI2 "https://github.com/jamf/jamf-switcher/blob/master/Jamf Switcher/AppDelegate.swift"
    click UI3 "https://github.com/jamf/jamf-switcher/blob/master/Jamf Switcher/ViewController.swift"

    %% Click Events - API Layer
    click APIC1 "https://github.com/jamf/jamf-switcher/blob/master/Jamf Switcher/JamfAPI/API/CallAPI.swift"
    click APIC2 "https://github.com/jamf/jamf-switcher/blob/master/Jamf Switcher/JamfAPI/API/JamfAPI.swift"
    click APIL "https://github.com/jamf/jamf-switcher/blob/master/Jamf Switcher/JamfAPI/Logic/JamfLogic.swift"
    click APIM "https://github.com/jamf/jamf-switcher/blob/master/Jamf Switcher/JamfAPI/Models/Structures.swift"
    click APIS "https://github.com/jamf/jamf-switcher/blob/master/Jamf Switcher/JamfAPI/Service/JamfService.swift"

    %% Click Event - Self Service Processing
    click SSP "https://github.com/jamf/jamf-switcher/blob/master/Jamf Switcher/JamfSelfServiceParser.swift"

    %% Click Events - System Integration and Business Logic
    click SI1 "https://github.com/jamf/jamf-switcher/blob/master/Jamf Switcher/KeychainService.swift"
    click BL1 "https://github.com/jamf/jamf-switcher/blob/master/Jamf Switcher/Logic/PolicyLogic.swift"

    %% Styles
    class UI1,UI2,UI3,SSP blue
    class BL1,APIL,APIS,APIC1,APIC2,APIM,SI1,SI2 yellow

    %% Additional styling for subgraphs (using linkStyle as placeholder for better clarity)
    linkStyle default fill:#f9f,stroke:#333,stroke-width:2px
    style UI1 fill:#AED6F1,stroke:#1B4F72,stroke-width:2px
    style UI2 fill:#AED6F1,stroke:#1B4F72,stroke-width:2px
    style UI3 fill:#AED6F1,stroke:#1B4F72,stroke-width:2px
    style BL1 fill:#F9E79F,stroke:#B9770E,stroke-width:2px
    style SSP fill:#AED6F1,stroke:#1B4F72,stroke-width:2px
    style APIC1 fill:#A3E4D7,stroke:#117864,stroke-width:2px
    style APIC2 fill:#A3E4D7,stroke:#117864,stroke-width:2px
    style APIL fill:#A3E4D7,stroke:#117864,stroke-width:2px
    style APIM fill:#A3E4D7,stroke:#117864,stroke-width:2px
    style APIS fill:#A3E4D7,stroke:#117864,stroke-width:2px
    style SI1 fill:#F5B7B1,stroke:#922B21,stroke-width:2px
    style SI2 fill:#F5B7B1,stroke:#922B21,stroke-width:2px
```
