How stackotter/swift-cross-ui works
Main Components
• Core Framework Module: Represent the central SwiftCrossUI library which includes the core API for building views, managing state (e.g., State, Binding, Published), and constructing scene graphs (the view hierarchy management).
• Backend Modules: Illustrate the various backends that the framework supports. These include:
• DefaultBackend (which adapts to the target OS)
• AppKitBackend (macOS)
• UIKitBackend (iOS/tvOS)
• WinUIBackend (Windows)
• GtkBackend & Gtk3Backend (Linux, plus macOS/Windows for Gtk3)
• Other experimental/alternative backends (e.g., LVGLBackend, CursesBackend, QtBackend)
• Examples: Include an examples category which demonstrates how client applications (e.g., CounterExample, NavigationExample, etc.) make use of the framework.
• Auxiliary Modules: Note the additional support components such as code generators (GtkCodeGen), hot reloading macros, custom widgets (GtkCustomWidgets, SwiftCrossUI/ViewGraph), and tests.
Relationships & Interactions
• The Core Framework is the center of the architecture – it exposes the API for developers.
• The front-end usage by client apps (shown in Examples) will be built on top of SwiftCrossUI and use the APIs for Views, Scenes, and State management. Illustrate how an Example app (like the CounterExample) interacts with the Core Framework which in turn interfaces with the selected backend.
• Additionally, include support flows such as how hot reloading macros or code generation modules feed into the build or runtime system.
Architectural Patterns & Design Principles
• Separation of concerns: the UI logic is abstracted in the core framework while each backend encapsulates the platform-specific details.
• API resemblances to SwiftUI (using concepts such as Scenes, Views, and State) but with customization points to adapt to different platforms.
• Use of modular design by placing each backend in its own submodule, so it’s clear that adding a new backend only requires interfacing with the common API of SwiftCrossUI.
Specify Relevant Technologies
• Language: Swift (5.10+)
• Build/Dependency Tools: Swift Package Manager (as shown in Package.swift), along with scripts and Dockerfile for containerized builds.
• CI/CD & Linting: GitHub workflows for building on macOS, Linux, Windows; SwiftLint and SwiftFormat configurations.
• Integration of external libraries or system dependencies for certain backends (e.g., GTK 3/4 for GtkBackend/Gtk3Backend).
Suggested Elements
• Annotation/Notes: Optionally add brief notes next to each component to mention its purpose (e.g., “Handles view construction and state management”, “Maps APIs to native OS UI frameworks”).
• Similarly, list out the backends as separate nodes with critical dependencies (for example, showing that DefaultBackend conditionally selects a specific backend at compile-time/runtime).
– At the top/center, show the SwiftCrossUI core layer.
– Branching from it, illustrate the different backend modules.
– Connect an “Example App Layer” that shows how client applications plug into the system.
– Optionally, annotate peripheral components like CI/CD pipelines or code generation tools.