# brandon7cc/mac-wheres-my-bootstrap architecture

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

- Interactive diagram: https://gitdiagram.com/brandon7cc/mac-wheres-my-bootstrap
- Repository: https://github.com/brandon7cc/mac-wheres-my-bootstrap

## Overview

##### Main Components
- XPC2Proc Host Application – This is the main macOS app. It is where all the modules are integrated and run. Mark this as the container for the other internal components.
- Detection Module – Found under the Detection directory with files like CodeSigning.swift and DetectionEngine.swift. This module is responsible for validating code signing and detecting exploitation attempts.
- Endpoint Security (ES) Module – Under the Endpoint Security directory (ESClient.swift and EventModel.swift), which handles reception and basic parsing of macOS Endpoint Security events such as XPC_CONNECT events.
- SwiftLaunchCtl Module – Contains logic for resolving service names to program paths as well as interfacing with launchd. Files such as LaunchCtl.swift, DomainsAndTargets.swift, and entry.swift exemplify how the app programmatically queries and tests launchd responses.
- UI Module – Found under the UI directory (with files like ContentView.swift, ConnectionsTable.swift, etc.). This provides the front-end for user interaction and displays output, including potential alerts regarding detected exploits.
- Resources & Assets – This includes visual assets (AppIcon, AccentColor) and any other resource files that support the user interface.
- Test Suite – Located in the tests folder. It contains build scripts and C source files for testing XPC connections (e.g., xpc_connection_tester.c).

##### Relationships and Data Flows
- The UI component interacts with the underlying detection logic. For example, user actions in the UI trigger operations in the Detection module.
- The Detection engine collaborates with the Endpoint Security module to listen for and parse XPC-related events.
- The SwiftLaunchCtl module bridges communication between the application and macOS launchd services. It is used both in the main app and in the tests to resolve and validate service paths dynamically.
- Data flows are often directional: events are received from macOS’s Endpoint Security, then passed to the Detection engine, which in turn may leverage SwiftLaunchCtl to interrogate service details and present results via the UI.

##### Architectural Patterns & Design Principles
- Modular Organization: The separation of concerns is evident—each folder/module (Detection, Endpoint Security, SwiftLaunchCtl, UI) represents a distinct aspect of the system.
- Integration of System-Level APIs: The project uses macOS system frameworks (for Endpoint Security and launchd) and exemplifies bridging between Swift and lower-level system functionalities (evident via the bridging header).
- Programmatic Resolution and Testing: Through the SwiftLaunchCtl module, the project demonstrates dynamic resolution of service targets, reflecting a real-time, exploratory design that interacts with system services.

##### Content
- Interaction flows:
- The user starts the app (UI) → triggers a detection process.
- Detection module receives event data from Endpoint Security → validates code signing via its internal logic.
- In parallel, SwiftLaunchCtl is called to resolve the program path of the involved XPC service.
- Architectural elements such as the programmatic API interactions detailed in the README, along with any configuration or entitlements indicated by files like XPC2Proc.entitlements and the bridging header.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Main Container
    subgraph "XPC2Proc Host Application"
        direction TB
        UI["User Interface (UI Module)"]:::module
        DET["Detection Module"]:::module
        ES["Endpoint Security Module"]:::module
        SLC["SwiftLaunchCtl Module"]:::module
        RES["Resources & Assets"]:::resource
    end

    %% External System Services
    ESYS["macOS Endpoint Security"]:::external
    LCH["launchd Service"]:::external

    %% Test Environment
    TEST["Test Suite"]:::test

    %% Data Flow Relationships
    UI -->|"triggersDetection"| DET
    ESYS -->|"sendsEvents"| ES
    ES -->|"forwardsParsedEvents"| DET
    DET -->|"callsResolver"| SLC
    SLC -->|"queriesService"| LCH
    SLC -->|"returnsResolvedPath"| UI
    RES -->|"suppliesAssetsTo"| UI
    TEST -->|"simulatesResolution"| SLC

    %% Click Events for Components
    click UI "https://github.com/brandon7cc/mac-wheres-my-bootstrap/tree/main/XPC2Proc/XPC2Proc/UI"
    click DET "https://github.com/brandon7cc/mac-wheres-my-bootstrap/tree/main/XPC2Proc/XPC2Proc/Detection"
    click ES "https://github.com/brandon7cc/mac-wheres-my-bootstrap/tree/main/XPC2Proc/XPC2Proc/Endpoint Security"
    click SLC "https://github.com/brandon7cc/mac-wheres-my-bootstrap/tree/main/XPC2Proc/XPC2Proc/SwiftLaunchCtl"
    click RES "https://github.com/brandon7cc/mac-wheres-my-bootstrap/blob/main/XPC2Proc/XPC2Proc/Assets.xcassets"
    click TEST "https://github.com/brandon7cc/mac-wheres-my-bootstrap/tree/main/tests"
    click XPC2ProcHost "https://github.com/brandon7cc/mac-wheres-my-bootstrap/blob/main/XPC2Proc/XPC2Proc/XPC2ProcApp.swift"

    %% Invisible node for host app click event to attach to container label
    XPC2ProcHost["XPC2Proc Host Application"]:::host
    XPC2ProcHost --- UI

    %% Styles
    classDef host fill:#e0f7fa,stroke:#006064,stroke-width:2px;
    classDef module fill:#fff3e0,stroke:#e65100,stroke-width:2px;
    classDef external fill:#fce4ec,stroke:#880e4f,stroke-width:2px;
    classDef resource fill:#e8f5e9,stroke:#2e7d32,stroke-width:2px;
    classDef test fill:#f3e5f5,stroke:#6a1b9a,stroke-width:2px;
```
