Skip to content

Directory and Module Boundaries

星冉 edited this page Aug 3, 2026 · 1 revision

Directory and Module Boundaries

中文

Current layout and problem

The Xcode Screen-Remote group and the Screen-Remote/ directory currently contain most application sources side by side. Several files combine unrelated responsibilities: DeviceManagementViews.swift, NativeScrcpySession.swift, Models.swift, SettingsView.swift, ScreenSessionManager.swift, VirtualDevices.swift, and others are large. This is a known structure to migrate, not a reason to use extensions in the same file as a cosmetic split.

Target ownership map

Target location Owns Must not own
App/ app entry, dependency environment, root navigation feature operations or protocol parsing
Core/ stable models, semantic UI tokens, localization, logging, utilities feature-specific ADB commands
Platform/ macOS availability wrappers, windows, menu bar, panels device business rules
Services/ADB/ ADB client, target, errors, helper runtime SwiftUI screens
Services/Scrcpy/ protocol, server/session lifecycle, media, control transport feature navigation
Features/<Feature>/ feature views, view models, feature services and models shared transport duplication
Resources/ assets, Localizable.xcstrings, bundled resources Swift source

First migration slices

  • Split DeviceManagementViews.swift into Management/Files, Processes, PortForwarding, and DeviceActions; move shared ADB process execution into Services/ADB.
  • Keep NativeScrcpySession as a thin orchestrator; extract server launch, ordered socket connector, metadata/headers, H264 decoder, audio pipeline, control channel, and session state machine.
  • Split Models.swift by Device, Session, Settings, Apps, and VirtualDevice models; split design tokens/components/modifiers instead of growing DesignSystem.swift.

Migration constraints

Move files and Xcode references together; a virtual Xcode group while files remain flat is not complete. The initial move must preserve behavior and access control. Do feature changes in a separate change after compilation and path checks prove the relocation is sound.

Size guard

Swift files are preferably at most 400 lines. At 500 lines, review whether responsibilities have mixed. At 700 lines, split before adding ordinary functionality; any exception needs an explicit, documented allowlist reason.

Clone this wiki locally