# huynguyencong/swiftui-mvvm-c architecture

> Architecture diagram of the GitHub repository huynguyencong/swiftui-mvvm-c, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/huynguyencong/swiftui-mvvm-c
- Repository: https://github.com/huynguyencong/swiftui-mvvm-c

## Overview

##### 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.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% App Bootstrapping & Lifecycle
    subgraph "App Bootstrapping"
        A("AppDelegate.swift"):::bootstrap
        B("SceneDelegate.swift"):::bootstrap
    end

    %% UI Layer
    subgraph "UI Layer"
        V("ContentView.swift"):::view
        L("LaunchScreen.storyboard"):::view
        E("Empty Navigation Link"):::view

        subgraph "Profile Module"
            PV("Profile View"):::view
            PVM("Profile ViewModel"):::viewModel
            PC("Profile Coordinator"):::coordinator
        end

        subgraph "RepoList Module"
            RV("RepoList View"):::view
            RVM("RepoList ViewModel"):::viewModel
            RC("RepoList Coordinator"):::coordinator
            RDV("RepoDetails View"):::view
            RDVM("RepoDetails ViewModel"):::viewModel
        end
    end

    %% Networking Layer
    subgraph "Networking"
        subgraph "Common Networking"
            NC("Network Client"):::networking
            NP("Network Provider"):::networking
            NU("Network Utils"):::networking
        end
        subgraph "GitHub Networking"
            GNP("GithubNetworkProvider"):::networking
            GR("GithubRouter"):::networking
        end
    end

    %% Models
    subgraph "Models"
        Rep("Repo Model"):::model
        User("User Model"):::model
    end

    %% Utilities & Extensions
    subgraph "Utilities & Extensions"
        BE("Binding+Utils"):::utility
        PE("Publisher+Utils"):::utility
        VE("View+Utils"):::utility
        DI("Container"):::utility
    end

    %% Unit Testing
    subgraph "Unit Testing"
        UT("Unit Tests"):::testing
    end

    %% Relationships
    A -->|"initializes"| V
    B -->|"initializes"| V
    V -->|"triggers"| PV
    V -->|"triggers"| RV
    PV -->|"bindsTo"| PVM
    RV -->|"bindsTo"| RVM
    RDV -->|"bindsTo"| RDVM

    PC -->|"navigatesTo"| PV
    RC -->|"navigatesTo"| RV
    RC -->|"navigatesTo"| RDV

    %% Networking interactions (API calls and responses)
    PVM -->|"callsAPI"| GNP
    RVM -->|"callsAPI"| GNP
    RDVM -->|"callsAPI"| GNP
    GNP -->|"returnsData"| PVM
    GNP -->|"returnsData"| RVM
    GNP -->|"returnsData"| RDVM

    %% GitHub Networking utilizes Common Networking
    GNP -->|"uses"| NP
    NP -->|"communicatesWith"| NC
    NP -->|"utilizes"| NU

    %% Utilities and Extensions usage
    PVM ---|"uses"| DI
    RVM ---|"uses"| DI
    RDVM ---|"uses"| DI
    PV ---|"extends"| VE
    RV ---|"extends"| VE
    PV ---|"bindsWith"| BE
    RV ---|"bindsWith"| BE

    %% Models integration
    PVM ---|"mapsTo"| User
    RVM ---|"mapsTo"| Rep
    RDVM ---|"mapsTo"| Rep

    %% Unit Testing dependencies
    UT ---|"tests"| GNP
    UT ---|"tests"| PVM
    UT ---|"tests"| RVM
    UT ---|"tests"| RDVM

    %% Click Events
    click A "https://github.com/huynguyencong/swiftui-mvvm-c/blob/main/SwiftUI-MVVM-C/SwiftUI-MVVM-C/AppDelegate.swift"
    click B "https://github.com/huynguyencong/swiftui-mvvm-c/blob/main/SwiftUI-MVVM-C/SwiftUI-MVVM-C/SceneDelegate.swift"
    click V "https://github.com/huynguyencong/swiftui-mvvm-c/blob/main/SwiftUI-MVVM-C/SwiftUI-MVVM-C/ContentView.swift"
    click L "https://github.com/huynguyencong/swiftui-mvvm-c/blob/main/SwiftUI-MVVM-C/SwiftUI-MVVM-C/Base.lproj/LaunchScreen.storyboard"
    click E "https://github.com/huynguyencong/swiftui-mvvm-c/blob/main/SwiftUI-MVVM-C/SwiftUI-MVVM-C/CommonShared/Views/EmptyNavigationLink.swift"
    click PV "https://github.com/huynguyencong/swiftui-mvvm-c/blob/main/SwiftUI-MVVM-C/SwiftUI-MVVM-C/Modules/Profile/Profile/ProfileView.swift"
    click PVM "https://github.com/huynguyencong/swiftui-mvvm-c/blob/main/SwiftUI-MVVM-C/SwiftUI-MVVM-C/Modules/Profile/Profile/ProfileViewModel.swift"
    click PC "https://github.com/huynguyencong/swiftui-mvvm-c/blob/main/SwiftUI-MVVM-C/SwiftUI-MVVM-C/Modules/Profile/ProfileCoordinator.swift"
    click RV "https://github.com/huynguyencong/swiftui-mvvm-c/blob/main/SwiftUI-MVVM-C/SwiftUI-MVVM-C/Modules/RepoList/RepoList/RepoListView.swift"
    click RVM "https://github.com/huynguyencong/swiftui-mvvm-c/blob/main/SwiftUI-MVVM-C/SwiftUI-MVVM-C/Modules/RepoList/RepoList/RepoListViewModel.swift"
    click RC "https://github.com/huynguyencong/swiftui-mvvm-c/blob/main/SwiftUI-MVVM-C/SwiftUI-MVVM-C/Modules/RepoList/RepoListCoordinator.swift"
    click RDV "https://github.com/huynguyencong/swiftui-mvvm-c/blob/main/SwiftUI-MVVM-C/SwiftUI-MVVM-C/Modules/RepoList/RepoDetails/RepoDetailsView.swift"
    click RDVM "https://github.com/huynguyencong/swiftui-mvvm-c/blob/main/SwiftUI-MVVM-C/SwiftUI-MVVM-C/Modules/RepoList/RepoDetails/RepoDetailsViewModel.swift"
    click Rep "https://github.com/huynguyencong/swiftui-mvvm-c/blob/main/SwiftUI-MVVM-C/SwiftUI-MVVM-C/Shared/Models/Repo.swift"
    click User "https://github.com/huynguyencong/swiftui-mvvm-c/blob/main/SwiftUI-MVVM-C/SwiftUI-MVVM-C/Shared/Models/User.swift"
    click NC "https://github.com/huynguyencong/swiftui-mvvm-c/blob/main/SwiftUI-MVVM-C/SwiftUI-MVVM-C/CommonShared/Networking/NetworkProvider/NetworkClient.swift"
    click NP "https://github.com/huynguyencong/swiftui-mvvm-c/blob/main/SwiftUI-MVVM-C/SwiftUI-MVVM-C/CommonShared/Networking/NetworkProvider/NetworkProvider.swift"
    click NU "https://github.com/huynguyencong/swiftui-mvvm-c/blob/main/SwiftUI-MVVM-C/SwiftUI-MVVM-C/CommonShared/Networking/NetworkProvider/NetworkUtils.swift"
    click GNP "https://github.com/huynguyencong/swiftui-mvvm-c/blob/main/SwiftUI-MVVM-C/SwiftUI-MVVM-C/Shared/Networking/GithubNetworkProvider.swift"
    click GR "https://github.com/huynguyencong/swiftui-mvvm-c/blob/main/SwiftUI-MVVM-C/SwiftUI-MVVM-C/Shared/Networking/GithubRouter.swift"
    click BE "https://github.com/huynguyencong/swiftui-mvvm-c/blob/main/SwiftUI-MVVM-C/SwiftUI-MVVM-C/CommonShared/Extensions/Binding+Utils.swift"
    click PE "https://github.com/huynguyencong/swiftui-mvvm-c/blob/main/SwiftUI-MVVM-C/SwiftUI-MVVM-C/CommonShared/Extensions/Publisher+Utils.swift"
    click VE "https://github.com/huynguyencong/swiftui-mvvm-c/blob/main/SwiftUI-MVVM-C/SwiftUI-MVVM-C/CommonShared/Extensions/View+Utils.swift"
    click DI "https://github.com/huynguyencong/swiftui-mvvm-c/blob/main/SwiftUI-MVVM-C/SwiftUI-MVVM-C/CommonShared/Utils/Container.swift"
    click UT "https://github.com/huynguyencong/swiftui-mvvm-c/tree/main/SwiftUI-MVVM-CTests"

    %% Styles
    classDef bootstrap fill:#FFDDCC,stroke:#333,stroke-width:2px;
    classDef view fill:#CCEEFF,stroke:#333,stroke-width:2px;
    classDef viewModel fill:#CCFFCC,stroke:#333,stroke-width:2px;
    classDef coordinator fill:#FFDDAA,stroke:#333,stroke-width:2px;
    classDef model fill:#FFCCCC,stroke:#333,stroke-width:2px;
    classDef networking fill:#CCFFFF,stroke:#333,stroke-width:2px;
    classDef utility fill:#FFCCFF,stroke:#333,stroke-width:2px;
    classDef testing fill:#EEEEEE,stroke:#333,stroke-width:2px;
```
