How huynguyencong/swiftui-mvvm-c works
Main Components
• App Bootstrapping & Lifecycle: Include the AppDelegate.swift and SceneDelegate.swift which set up the application lifecycle and entry points.
• Views (UI): Represented by SwiftUI views such as ContentView.swift, the storyboard for the launch screen (LaunchScreen.storyboard), and specific UI components in Modules (like Profile/ProfileView.swift, RepoListView.swift, RepoDetailsView.swift) plus shared views (e.g., EmptyNavigationLink.swift in CommonShared/Views).
• ViewModels: Each UI component has a corresponding ViewModel ― for example, ProfileViewModel.swift, RepoListViewModel.swift, RepoDetailsViewModel.swift.
• Coordinators: These are used for handling navigation logic outside the views. You have specific coordinator files for each module (e.g., ProfileCoordinator.swift, RepoListCoordinator.swift) that promote separation of concerns.
• Models: Found within the Shared/Models directory (e.g., User.swift, Repo.swift), which represent the data.
• Networking: There are two clear networking layers:
• CommonShared/Networking (with NetworkProvider, NetworkClient, NetworkUtils) abstracts the general network handling.
• Shared/Networking (with GithubNetworkProvider.swift and GithubRouter.swift) is specific to interfacing with the GitHub API.
• Utilities & Extensions: The project has various extensions (in CommonShared/Extensions) and other utility classes (like Container.swift) which help with dependency injection, data binding, and other supporting functionality.
• Unit Testing: Although not part of the live app’s architecture per se, the SwiftUI-MVVM-CTests directory shows that there is a dedicated structure for unit testing the network calls, ViewModel logic, and so on.
Architectural Relationships and Interactions
• The View (SwiftUI Views) binds to the ViewModel using SwiftUI’s data-binding supported by Combine.
• The ViewModel processes business logic and interacts with the Networking layer to fetch data from the GitHub API.
• The Coordinator decouples navigation logic from the View and ViewModel, handling transitions between modules like RepoList and Profile.
• The Models represent the underlying data that travels from the network layer (via GithubNetworkProvider/GithubRouter) through the ViewModels to update the views.
• Views → ViewModels (denoting binding and event triggers).
• ViewModels → Networking (for API calls), and vice versa for callback/Combine publishers.
• Coordinators → Views (for navigation-triggered presentation).
Architectural Patterns and Design Principles
• Dependency Management: Note the presence of dependency injection as seen with utility files like Container.swift.
• Reactive Programming: Show that Combine is used to propagate events and network responses from the networking layer to update the UI reactively.
Putting It All Together
• A “RepoList” module containing RepoListView, RepoListViewModel, RepoListCoordinator, and related details (RepoDetails as a submodule).
• A “Profile” module similarly structured with its view, viewmodel, and coordinator.
• In parallel, detail the supporting layers:
• Networking: Two parts—generic network provider under CommonShared/Networking, and GitHub-specific implementations under Shared/Networking.
• Shared Models and Utility functions that underpin all modules.
• Extensions that enhance functionality across the app.
• Don’t forget to include the testing suite illustrating that MockData and MockNetworkClient facilitate unit tests.