# muxy-app/muxy architecture

> Architecture diagram of the GitHub repository muxy-app/muxy, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/muxy-app/muxy
- Repository: https://github.com/muxy-app/muxy

## Overview

Muxy is a multi-target Swift repository centered on a macOS SwiftUI app, with a companion iOS client, a remote server layer, a shared protocol/DTO package, and a small C wrapper around Ghostty’s terminal engine.

1. **Top-level product boundaries**
   - **Muxy**: the main macOS app.
   - **MuxyMobile**: iOS companion app for remote connection.
   - **MuxyServer**: remote server implementation that exposes workspace/VCS data and actions to the mobile client.
   - **MuxyShared**: transport types and protocol messages shared by desktop and mobile.
   - **GhosttyKit**: C module map + wrapper used to bridge Swift to `libghostty`.

2. **Desktop app shell**
   - The macOS app is a SwiftUI application rooted at `MuxyApp.swift`, with the primary UI assembled in `Views/MainWindow.swift`, `Sidebar`, `Workspace`, `Terminal`, `VCS`, `Editor`, `Settings`, and `NotificationPanel`.
   - The app is strongly state-driven: views consume model objects and services rather than talking directly to the filesystem, Git, or Ghostty.

3. **Workspace as the core domain**
   - The central UX concept is a **project-based workspace** that persists tabs, splits, focus, and pane layout per project.
   - Core state types include `AppState`, `WorkspaceSnapshot`, `Project`, `Worktree`, `TerminalTab`, `VCSTabState`, `EditorTabState`, `DiffViewerTabState`, `SplitNode`, `TabArea`, and `ViewportState`.
   - Reducer-style logic under `Models/WorkspaceReducer` governs workspace mutation, focus changes, tab/split operations, and project lifecycle events.

4. **Terminal subsystem**
   - Terminal rendering and interaction are backed by **Ghostty/libghostty** via `GhosttyKit`, with `GhosttyService` and `GhosttyRuntimeEventAdapter` translating engine events into app state.
   - The UI layer for this is in `Views/Terminal` and `Models/TerminalPaneState`, `TerminalSearchState`, `TextBackingStore`, and `TerminalViewRegistry`.
   - This subsystem is responsible for shell sessions, search within terminal output, and pane ownership/attachment inside the workspace layout.

5. **Git/VCS subsystem**
   - Git functionality is isolated under `Services/Git` and includes process execution, status parsing, diff parsing, commit log parsing, PR parsing, metadata caching, and repository/worktree management.
   - The UI for this lives in `Views/VCS`, including commit history, diff viewer, split/unified diff rendering, branch creation, and PR creation.
   - The architecture keeps Git as a service boundary: Git commands are run and parsed into models, then surfaced through tab state and view-specific DTOs.

6. **File tree, editor, and project management**
   - File navigation and editing are separate from terminal and Git: `FileTreeService`, `FileSystemOperations`, `FileSearchService`, and `ProjectOpenService` feed the sidebar, file tree, and editor views.
   - The editor is a native SwiftUI/AppKit bridge (`CodeEditorRepresentable`, `EditorPane`) paired with `EditorSettings`.
   - Projects and worktrees are persisted and presented through `ProjectStore`, `WorktreeStore`, `ProjectPersistence`, `WorktreePersistence`, and related models, making project selection a first-class architectural layer.

7. **Persistence and local stores**
   - The app uses lightweight persistence services rather than a single database: `CodableFileStore`, `JSONFilePersistence`, `WorkspacePersistence`, `KeyBindingPersistence`, `NotificationStore`, `PaneOwnershipStore`, `ProjectLogoStorage`, and `ApprovedDevicesStore`.
   - These stores back user preferences, workspace layout, key bindings, notification history, and remote-device trust decisions.
   - The result is a set of small, bounded local state stores aligned with the app’s domain objects.

8. **Input, commands, and keyboard customization**
   - Shortcut handling is a dedicated subsystem: `KeyBinding`, `KeyCombo`, `ShortcutContext`, `ShortcutActionDispatcher`, and the `Commands` package define command routing and conflict-aware key mapping.
   - Views under `Settings/KeyboardShortcutsSettingsView` and supporting components provide user-facing configuration.
   - Modifier-key monitoring and view helpers indicate the app maps global and context-sensitive shortcuts into workspace actions rather than relying on standard menu-only flows.

9. **Themes, appearance, and app chrome**
   - Theme selection is centralized in `ThemeService`, with bundled Ghostty theme assets and a `ThemePicker`.
   - UI appearance settings are separated into settings views and shared theme/model types.
   - The architecture treats theming as a cross-cutting concern that affects terminal rendering and general UI presentation.

10. **Notifications and automation hooks**
   - Notifications are modeled explicitly (`MuxyNotification`, `NotificationSettings`, `NotificationNavigator`) and can be delivered through `NotificationSocketServer`.
   - `MuxyNotificationHooks` and bundled scripts under `Resources/scripts` support automation/integration with external AI/tooling workflows.
   - This sits adjacent to the core workspace model so notifications can reference project/worktree context.

11. **Remote access architecture**
   - The mobile story is not just a second UI; it is a remote control/client-server subsystem.
   - `MuxyServer` exposes workspace, VCS, and notification state over a custom protocol implemented in `MuxyShared` (`MuxyMessage`, `MuxyProtocol`, DTOs for projects, workspaces, VCS status, worktrees, notifications).
   - `MuxyMobile` includes connection management, device credentials, workspace/project pickers, and screens for remote terminal/VCS/worktree interaction.
   - `PairingRequestCoordinator`, `RemoteServerDelegate`, `MobileServerService`, and `NotificationSocketServer` suggest a trust/pairing model for device access.

12. **External integrations and operational tooling**
   - `UpdateService` indicates Sparkle-based auto-update support.
   - `AIProviderIntegration`, `Providers/ClaudeCodeProvider.swift`, `Providers/OpenCodeProvider.swift`, and the repo scripts point to optional AI-tool integration, but these are secondary to the core terminal/workspace architecture.
   - CI/CD and release workflows exist under `.github/workflows`, reflecting separate release paths for desktop and iOS targets.

13. **How data flows through the app**
   - User input enters through SwiftUI views and shortcut dispatch.
   - Commands mutate workspace reducers and local stores.
   - Services perform side effects: shell/Ghostty sessions, Git commands, filesystem queries, persistence writes, or remote protocol I/O.
   - Parsed results are converted into shared models/state and rendered back through tabbed workspace views, terminal panes, editor panes, and VCS screens.

14. **Key architectural takeaway**
   - Muxy is organized around a **stateful workspace core** with clearly separated service boundaries for terminal, Git, filesystem, persistence, and remote connectivity.
   - The macOS app is the source of truth; the iOS app is a controlled client over a shared protocol; and most subsystems are modeled as independently testable services feeding a reducer-driven UI.

Main entry points: [`Muxy/Views/Workspace/Workspace.swift`](https://github.com/muxy-app/muxy/blob/main/Muxy/Views/Workspace/Workspace.swift) (Workspace UI), [`Muxy/Models/WorkspaceReducer.swift`](https://github.com/muxy-app/muxy/blob/main/Muxy/Models/WorkspaceReducer.swift) (Workspace Reducer), [`Muxy/Views/Terminal/TerminalPane.swift`](https://github.com/muxy-app/muxy/blob/main/Muxy/Views/Terminal/TerminalPane.swift) (Terminal UI), [`Muxy/Models/AppState.swift`](https://github.com/muxy-app/muxy/blob/main/Muxy/Models/AppState.swift) (App State)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_desktop["Muxy Desktop"]
  node_muxy_app["App Shell<br/>SwiftUI app<br/>[MuxyApp.swift]"]
  node_main_window["Main Window<br/>UI composition<br/>[MainWindow.swift]"]
  node_workspace_ui["Workspace UI<br/>layout views<br/>[Workspace.swift]"]
  node_workspace_reducer{{"Workspace Reducer<br/>state reducer"}}
  node_app_state[("App State<br/>workspace model<br/>[AppState.swift]")]
  node_terminal_ui["Terminal UI<br/>pane views<br/>[TerminalPane.swift]"]
  node_terminal_service{{"Ghostty Service<br/>terminal service"}}
  node_git_service{{"Git Service<br/>vcs service"}}
  node_vcs_ui["VCS Views<br/>vcs ui<br/>[VCSTabView.swift]"]
  node_file_tree{{"File Tree<br/>filesystem service"}}
  node_editor_ui["Editor<br/>[EditorPane.swift]"]
  node_project_store[("Project Store<br/>project persistence<br/>[ProjectStore.swift]")]
  node_persistence[("Local Stores<br/>persistence layer")]
  node_shortcuts{{"Shortcuts<br/>command routing"}}
  node_theme{{"Theme Service<br/>appearance service<br/>[ThemeService.swift]"}}
  node_notification{{"Notifications<br/>notification system"}}
end

subgraph group_remote["Remote Access"]
  node_muxy_server["Server"]
  node_server_conn["Client Conn<br/>server connection"]
  node_mobile_app["Mobile App<br/>iOS client"]
  node_mobile_conn{{"Connection Manager<br/>client networking"}}
end

subgraph group_shared["Shared Protocol"]
  node_muxy_shared["Shared Types<br/>protocol DTOs<br/>[MuxyProtocol.swift]"]
end

subgraph group_bridge["Terminal Bridge"]
  node_ghosttykit["GhosttyKit<br/>C bridge<br/>[GhosttyKit.c]"]
end

node_muxy_app -->|"builds"| node_main_window
node_main_window -->|"hosts"| node_workspace_ui
node_workspace_ui -->|"reads state"| node_workspace_reducer
node_workspace_reducer -->|"mutates"| node_app_state
node_workspace_ui -->|"shows"| node_terminal_ui
node_terminal_ui -->|"drives"| node_terminal_service
node_terminal_service -->|"bridges"| node_ghosttykit
node_workspace_ui -->|"shows"| node_vcs_ui
node_vcs_ui -->|"queries"| node_git_service
node_workspace_ui -->|"shows"| node_editor_ui
node_editor_ui -->|"opens files"| node_file_tree
node_file_tree -->|"uses"| node_project_store
node_project_store -->|"persists"| node_persistence
node_workspace_reducer -->|"invoked by"| node_shortcuts
node_shortcuts -->|"dispatches"| node_app_state
node_theme -->|"styles"| node_terminal_ui
node_notification -->|"stores"| node_persistence
node_muxy_server -->|"accepts"| node_server_conn
node_mobile_app -->|"uses"| node_mobile_conn
node_mobile_conn -->|"encodes"| node_muxy_shared
node_server_conn -->|"decodes"| node_muxy_shared
node_muxy_server -->|"reflects"| node_app_state
node_notification -.->|"shares"| node_muxy_shared

click node_muxy_app "https://github.com/muxy-app/muxy/blob/main/Muxy/MuxyApp.swift"
click node_main_window "https://github.com/muxy-app/muxy/blob/main/Muxy/Views/MainWindow.swift"
click node_workspace_ui "https://github.com/muxy-app/muxy/blob/main/Muxy/Views/Workspace/Workspace.swift"
click node_workspace_reducer "https://github.com/muxy-app/muxy/blob/main/Muxy/Models/WorkspaceReducer.swift"
click node_app_state "https://github.com/muxy-app/muxy/blob/main/Muxy/Models/AppState.swift"
click node_terminal_ui "https://github.com/muxy-app/muxy/blob/main/Muxy/Views/Terminal/TerminalPane.swift"
click node_terminal_service "https://github.com/muxy-app/muxy/blob/main/Muxy/Services/GhosttyService.swift"
click node_git_service "https://github.com/muxy-app/muxy/blob/main/Muxy/Services/Git/GitRepositoryService.swift"
click node_vcs_ui "https://github.com/muxy-app/muxy/blob/main/Muxy/Views/VCS/VCSTabView.swift"
click node_file_tree "https://github.com/muxy-app/muxy/blob/main/Muxy/Services/FileTreeService.swift"
click node_editor_ui "https://github.com/muxy-app/muxy/blob/main/Muxy/Views/Editor/EditorPane.swift"
click node_project_store "https://github.com/muxy-app/muxy/blob/main/Muxy/Services/ProjectStore.swift"
click node_persistence "https://github.com/muxy-app/muxy/blob/main/Muxy/Services/WorkspacePersistence.swift"
click node_shortcuts "https://github.com/muxy-app/muxy/blob/main/Muxy/Services/ShortcutActionDispatcher.swift"
click node_theme "https://github.com/muxy-app/muxy/blob/main/Muxy/Services/ThemeService.swift"
click node_notification "https://github.com/muxy-app/muxy/blob/main/Muxy/Services/NotificationStore.swift"
click node_ghosttykit "https://github.com/muxy-app/muxy/blob/main/GhosttyKit/GhosttyKit.c"
click node_muxy_server "https://github.com/muxy-app/muxy/blob/main/MuxyServer/MuxyRemoteServer.swift"
click node_server_conn "https://github.com/muxy-app/muxy/blob/main/MuxyServer/ClientConnection.swift"
click node_mobile_app "https://github.com/muxy-app/muxy/blob/main/MuxyMobile/MuxyMobileApp.swift"
click node_mobile_conn "https://github.com/muxy-app/muxy/blob/main/MuxyMobile/ConnectionManager.swift"
click node_muxy_shared "https://github.com/muxy-app/muxy/blob/main/MuxyShared/MuxyProtocol.swift"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_muxy_app,node_main_window,node_workspace_ui,node_workspace_reducer,node_app_state,node_terminal_ui,node_terminal_service,node_git_service,node_vcs_ui,node_file_tree,node_editor_ui,node_project_store,node_persistence,node_shortcuts,node_theme,node_notification toneBlue
class node_muxy_server,node_server_conn,node_mobile_app,node_mobile_conn toneAmber
class node_muxy_shared toneMint
class node_ghosttykit toneRose
```

## Components

### Muxy Desktop

macOS SwiftUI app with workspace, terminal, Git, editor, and local persistence.

- [App Shell](https://github.com/muxy-app/muxy/blob/main/Muxy/MuxyApp.swift): SwiftUI app · Entry point and top-level app wiring for the macOS client. · `Muxy/MuxyApp.swift`
- [Main Window](https://github.com/muxy-app/muxy/blob/main/Muxy/Views/MainWindow.swift): UI composition · Primary desktop window that assembles the workspace chrome and panes. · `Muxy/Views/MainWindow.swift`
- [Workspace UI](https://github.com/muxy-app/muxy/blob/main/Muxy/Views/Workspace/Workspace.swift): layout views · Workspace shell, split containers, tab areas, and drag/drop handling. · `Muxy/Views/Workspace/Workspace.swift`
- [Workspace Reducer](https://github.com/muxy-app/muxy/blob/main/Muxy/Models/WorkspaceReducer.swift): state reducer · Reducer-style mutation logic for workspace, focus, tabs, splits, and project lifecycle. · `Muxy/Models/WorkspaceReducer.swift`
- [App State](https://github.com/muxy-app/muxy/blob/main/Muxy/Models/AppState.swift): workspace model · Core application and workspace state container used across the desktop app. · `Muxy/Models/AppState.swift`
- [Terminal UI](https://github.com/muxy-app/muxy/blob/main/Muxy/Views/Terminal/TerminalPane.swift): pane views · Terminal pane views and registry for rendering shell sessions inside the workspace. · `Muxy/Views/Terminal/TerminalPane.swift`
- [Ghostty Service](https://github.com/muxy-app/muxy/blob/main/Muxy/Services/GhosttyService.swift): terminal service · Coordinates Ghostty runtime events and terminal session attachment in app state. · `Muxy/Services/GhosttyService.swift`
- [Git Service](https://github.com/muxy-app/muxy/blob/main/Muxy/Services/Git/GitRepositoryService.swift): vcs service · Git process execution, parsing, repository state, diff loading, and worktree management. · `Muxy/Services/Git/GitRepositoryService.swift`
- [VCS Views](https://github.com/muxy-app/muxy/blob/main/Muxy/Views/VCS/VCSTabView.swift): vcs ui · Commit history, diff viewer, branch creation, and pull request UI. · `Muxy/Views/VCS/VCSTabView.swift`
- [File Tree](https://github.com/muxy-app/muxy/blob/main/Muxy/Services/FileTreeService.swift): filesystem service · File navigation, search, clipboard, and project-opening services feeding the sidebar and editor. · `Muxy/Services/FileTreeService.swift`
- [Editor](https://github.com/muxy-app/muxy/blob/main/Muxy/Views/Editor/EditorPane.swift): editor views · Native editor bridge and editor pane used for file editing inside the app. · `Muxy/Views/Editor/EditorPane.swift`
- [Project Store](https://github.com/muxy-app/muxy/blob/main/Muxy/Services/ProjectStore.swift): project persistence · Project and worktree persistence, selection, and setup support for the workspace model. · `Muxy/Services/ProjectStore.swift`
- [Local Stores](https://github.com/muxy-app/muxy/blob/main/Muxy/Services/WorkspacePersistence.swift): persistence layer · Small file-backed stores for workspace layout, key bindings, notifications, device trust, and related state. · `Muxy/Services/WorkspacePersistence.swift`
- [Shortcuts](https://github.com/muxy-app/muxy/blob/main/Muxy/Services/ShortcutActionDispatcher.swift): command routing · Key binding models, shortcut context, and command dispatch into workspace actions. · `Muxy/Services/ShortcutActionDispatcher.swift`
- [Theme Service](https://github.com/muxy-app/muxy/blob/main/Muxy/Services/ThemeService.swift): appearance service · Theme selection and app-wide appearance coordination, including terminal styling. · `Muxy/Services/ThemeService.swift`
- [Notifications](https://github.com/muxy-app/muxy/blob/main/Muxy/Services/NotificationStore.swift): notification system · Notification models, navigator, hooks, and socket server for workspace-adjacent alerts and automation. · `Muxy/Services/NotificationStore.swift`

### Remote Access

iOS client and server pair for workspace and VCS access over a custom protocol.

- [Server](https://github.com/muxy-app/muxy/blob/main/MuxyServer/MuxyRemoteServer.swift): remote server · Remote server process that exposes workspace and VCS state to mobile clients. · `MuxyServer/MuxyRemoteServer.swift`
- [Client Conn](https://github.com/muxy-app/muxy/blob/main/MuxyServer/ClientConnection.swift): server connection · Per-client connection handling and routing for the remote server. · `MuxyServer/ClientConnection.swift`
- [Mobile App](https://github.com/muxy-app/muxy/blob/main/MuxyMobile/MuxyMobileApp.swift): iOS client · Companion iOS app for remote workspace, terminal, VCS, and project control. · `MuxyMobile/MuxyMobileApp.swift`
- [Connection Manager](https://github.com/muxy-app/muxy/blob/main/MuxyMobile/ConnectionManager.swift): client networking · Handles pairing, device credentials, and remote workspace/VCS communication from iOS. · `MuxyMobile/ConnectionManager.swift`

### Shared Protocol

DTOs and message types shared between desktop, server, and mobile targets.

- [Shared Types](https://github.com/muxy-app/muxy/blob/main/MuxyShared/MuxyProtocol.swift): protocol DTOs · Messages, protocol params, and DTOs shared across desktop, server, and mobile targets. · `MuxyShared/MuxyProtocol.swift`

### Terminal Bridge

C wrapper around Ghostty’s engine used by the desktop terminal subsystem.

- [GhosttyKit](https://github.com/muxy-app/muxy/blob/main/GhosttyKit/GhosttyKit.c): C bridge · Module map and C wrapper that expose libghostty to Swift. · `GhosttyKit/GhosttyKit.c`

## Connections

- App Shell → Main Window: builds · The app entry point constructs the main desktop window.
- Main Window → Workspace UI: hosts · Main window embeds the workspace shell and its panes.
- Workspace UI → Workspace Reducer: reads state · Workspace views render and react to reducer-managed state.
- Workspace Reducer → App State: mutates · Reducer logic updates the core app/workspace state.
- Workspace UI → Terminal UI: shows · Workspace layout contains terminal panes and tab areas.
- Terminal UI → Ghostty Service: drives · Terminal views delegate engine/session work to the terminal service.
- Ghostty Service → GhosttyKit: bridges · Service talks to the Ghostty C wrapper and runtime events.
- Workspace UI → VCS Views: shows · Workspace hosts VCS tabs and diff views.
- VCS Views → Git Service: queries · VCS views consume Git-derived models and diff data.
- Workspace UI → Editor: shows · Workspace includes editor panes for file editing.
- Editor → File Tree: opens files · Editor and sidebar source file navigation from the file tree service.
- File Tree → Project Store: uses · File and project operations are scoped by project/worktree state.
- Project Store → Local Stores: persists · Project and worktree state is stored through local file-backed persistence.
- Workspace Reducer → Shortcuts: invoked by · Shortcut actions dispatch into workspace mutations and navigation.
- Shortcuts → App State: dispatches · Key bindings and commands map to app/workspace actions.
- Theme Service → Terminal UI: styles · Theme selection affects terminal rendering and app appearance.
- Notifications → Local Stores: stores · Notification history and trust decisions are persisted locally.
- Server → Client Conn: accepts · The remote server manages client connections and request routing.
- Mobile App → Connection Manager: uses · The iOS app communicates through its connection manager.
- Connection Manager → Shared Types: encodes · Mobile client sends and receives shared protocol messages.
- Client Conn → Shared Types: decodes · Server connections interpret the shared protocol and DTOs.
- Server → App State: reflects · Remote server exposes workspace/VCS state derived from the desktop domain model.
- Notifications → Shared Types: shares · Notifications also flow through shared DTOs for remote transport.
