How hicozyty/callkitassistant works
1. Product shape and runtime
- This is a watchOS SwiftUI VoIP client built in Xcode, not a server or a generic app.
- The app’s execution boundary is the watch device: UI, call control, audio capture/playback, encryption, and UDP transport all happen locally on-device.
2. Top-level app entry
- callkitAssistantApp.swift is the @main entry point that wires the app together.
- The app is organized as a small set of managers rather than a deep view hierarchy, so the architecture is centered on service objects.
3. UI and user-facing state
- ContentView.swift is the main UI surface for enrollment, call start/stop, server status, and debug actions.
- It is the only obvious presentation layer; it delegates almost all real work to managers instead of containing call or networking logic.
4. Call orchestration boundary
- CallManager.swift owns CallKit integration via CXProvider and CXCallController.
- Its role is to translate user actions and call lifecycle events into system call behavior, especially audio session activation (didActivate) and call state changes.
5. Audio pipeline
- AudioStreamManager.swift is the media subsystem: it manages AVAudioEngine, voice-processing I/O, playback, and capture.
- It also handles Voice Activity Detection using SoundAnalysis, plus the pre-roll buffer and hangover timer that prevent clipping at speech boundaries.
- This is where raw audio becomes encoded frames and where decrypted frames become speaker output.
6. Codec and media flow
- The app uses Opus through the swift-opus package for low-latency speech compression.
- The audio flow is: microphone input → VAD gate → Opus encode → encryption → UDP send; inbound packets reverse that path → decrypt → Opus decode → playback.
7. Security and device identity
- SecurityManager.swift is the security subsystem and the most important trust boundary.
- It handles device enrollment, Secure Enclave-backed key generation, CSR creation, certificate storage, and mTLS setup for authenticated connections.
- It also manages session key establishment and AES-GCM encryption/decryption of audio payloads, so the transport layer never sees plaintext audio.
8. Transport layer
- UDPManager.swift owns the network data plane using NWConnection over UDP.
- It is responsible for sending/receiving audio packets, heartbeat traffic, and connection viability monitoring.
- This is separate from the call UI and separate from the encryption logic; it simply moves authenticated encrypted frames between device and server.
9. Configuration and environment
- AppConfig.swift centralizes server addressing and debug-time overrides.
- The README indicates the app reads values such as serverURL, localHostname, and enrollSecret from test-Watch-App-Info.plist, which is effectively the environment/config boundary for server discovery and enrollment.
10. Data models and app-wide extensions
- Models.swift contains Codable request/response types used for server enrollment and related API responses.
- Extensions.swift appears to hold shared utility extensions, likely including notification names used to coordinate managers without tight coupling.
11. External services and trust assumptions
- The app talks to a Bun-based server for enrollment and call/media signaling support.
- Enrollment is a one-time provisioning flow: device generates a key in Secure Enclave, sends a CSR plus shared secret to /enroll, and receives a signed client certificate for future mTLS sessions.
- The committed ca.crt is used to verify the server’s certificate chain.
12. System integrations and platform constraints
- The project depends heavily on CallKit, AVFoundation, SoundAnalysis, Network, SwiftUI, and Apple’s certificate/crypto packages.
- The Info.plist/build settings enable watch-specific behaviors like local network access, microphone access, Bonjour discovery, and voip background mode, which materially shape the app’s runtime model.
13. Operational modes and debugging
- The README calls out a simulator mode that bypasses CallKit and exercises audio directly, so the audio pipeline can be tested independently of system calling behavior.
- There is also a debug hostname override and a “reset enrollment” path, which indicate the app is designed to be re-provisioned and tested against changing servers.
14. Overall architecture to diagram
- The clearest diagram is a layered flow: SwiftUI UI → CallKit controller → audio engine → security/encryption → UDP transport → remote server.
- The key architectural boundary is that call control, media processing, and secure transport are separate subsystems, coupled only through manager interfaces and shared state/events.
Main entry points: SecurityManager.swift Security manager · AudioStreamManager.swift Audio stream · CallManager.swift Call manager · callkitAssistantApp.swift App entry
Components 17
App shell
Watch app entry, UI, and shared app state
- App entry · Main app bootstrap and dependency wiring
callkitAssistant App/callkitAssistantApp.swift - Main UI · Enrollment, call controls, status, and debug actions
callkitAssistant App/ContentView.swift - Call manager · Translates UI intent and call lifecycle into system call behavior
callkitAssistant App/CallManager.swift - App config · Server addressing and debug-time overrides
callkitAssistant App/AppConfig.swift - Models · Enrollment and response request/response models
callkitAssistant App/Models.swift - Extensions · Cross-cutting utilities and app coordination helpers
callkitAssistant App/Extensions.swift - Env plist · Server URL, hostname, and enrollment secret source
test-Watch-App-Info.plist
Media pipeline
Call media capture, encoding, and playback
- Audio stream · Capture, playback, VAD gating, pre-roll, and hangover logic
callkitAssistant App/AudioStreamManager.swift
Security
Provisioning, identity, and payload protection
- Security manager · Enrollment, mTLS, session keys, and AES-GCM protection
callkitAssistant App/SecurityManager.swift - CA cert · Server certificate chain verification root
callkitAssistant App/ca.crt
Transport
UDP packet movement and heartbeat
- UDP manager · Sends and receives encrypted audio packets and heartbeats
callkitAssistant App/UDPManager.swift
Platform
Apple frameworks and external server boundary
- Opus codec · Low-latency speech compression and decompression
- CallKit · System call control and audio session activation
- AVFoundation · Audio engine, I/O, and playback APIs
- SoundAnalysis · Voice activity detection support
- Network · UDP connections and viability monitoring
- Bun server · Enrollment and media/signaling backend
Connections 22
- App entry → Main UI: hosts · Bootstraps the main SwiftUI surface
- App entry → Call manager: wires · Creates and shares call orchestration state
- App entry → Security manager: wires · Initializes device identity and trust services
- App entry → UDP manager: wires · Connects transport layer services
- Main UI → Call manager: controls · Start/stop and enrollment actions flow through call control
- Main UI → Security manager: enrolls · Triggers provisioning and reset actions
- Call manager → CallKit: uses · Owns provider/controller integration and call lifecycle
- Call manager → Audio stream: activates · Coordinates audio session activation and call audio state
- Audio stream → AVFoundation: uses · Captures and renders audio through the engine
- Audio stream → SoundAnalysis: detects · Uses VAD to gate speech frames
- Audio stream → Opus codec: encodes/decodes · Compresses outbound audio and expands inbound frames
- Audio stream → Security manager: protects · Passes encoded frames for encryption and receives decrypted frames
- Security manager → Bun server: enrolls with · Creates CSR and provisions device certificate
- Security manager → CA cert: verifies · Uses CA certificate to validate server chain
- Security manager → UDP manager: secures · Provides session keys and payload protection for transport
- UDP manager → Network: sends · Implements UDP data plane over NWConnection
- UDP manager → Bun server: exchanges · Moves encrypted audio packets and heartbeats
- App config → Env plist: reads · Derives server and debug environment values
- Models → Bun server: shapes · Defines enrollment and response payloads
- Extensions → Main UI: supports · Shared coordination helpers used across managers
- Extensions → Call manager: supports · Cross-cutting utilities and notification wiring
- Extensions → Security manager: supports · Shared helper methods and app-wide events