# mostafanafie/swiftui-mvvm-di architecture

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

- Interactive diagram: https://gitdiagram.com/mostafanafie/swiftui-mvvm-di
- Repository: https://github.com/mostafanafie/swiftui-mvvm-di

## Overview

##### Main Components

- Application Entry Point:
– Represent the App’s lifecycle (ModularSwiftUIApp.swift and AppDelegate.swift) showing the initialization of the DI container and the starting point for SwiftUI.

- UI Layer (View Layer):
– Include separate modules for the UI such as CharacterList and CharacterDetails.
– Within each module, denote the SwiftUI views and how these views are bound to their respective ViewModels.

- ViewModel Layer (MVVM Pattern):
– For each UI module (like CharacterList and CharacterDetails), highlight their ViewModels.
– Represent how these VMs use separate Use Cases for business logic.

- Model/Domain Layer:
– Indicate models related to characters under CharacterModels, likely used across modules.

- Common Infrastructure:
– Networking:
▫ Show the Common/Networking and Common/NetworkingInterface components that handle API calls.
▫ Indicate HTTP Client (URLSessionClient.swift) and request/response classes.
– Dependency Injection (DI) Container:
▫ Include the DI folder (AppContainer, CharacterDetailsContainer, CharactersListContainer) that wires together dependencies.
– Utilities:
▫ List helper extensions like view helpers for navigation, error alerts, etc.

- Navigation / Coordinator:
– Emphasize the Coordinator pattern implemented in the Common/Coordinator folder.
– Show how the CharacterCoordinator is used to manage navigation between different screens.

- External Dependencies:
– Mark integration with external libraries such as Swinject (for DI) and Kingfisher (for image downloading and caching).

##### Relationships and Interactions

- Data Flow:
– Illustrate that the UI invokes actions in ViewModels, which in turn call UseCases to fetch data via the Networking layer.

- DI and IoC:
– Display how the DI container is responsible for resolving dependencies between ViewModels, UseCases, Network Clients, and Coordinators.

- Navigation Flow:
– Map out Navigator/Coordinator responsibilities that trigger navigation between the CharacterList view and the CharacterDetails view.

##### Architectural Patterns and Design Principles

- Modularization:
– Distinct modules (CharacterList, CharacterDetails, CharacterModels) reinforce separation of concerns.
– Emphasize how each module encapsulates its own networking, business logic, and UI components.

- MVVM:

- Dependency Injection and IoC:
– Show the central DI container and its role in constructing and providing dependencies.

- Coordinator Pattern:
– Illustrate the navigation flow handled by the Coordinator.

##### Relevant Technologies, Frameworks, and Libraries

- SwiftUI for UI rendering.
- MVVM for organizing presentation logic.
- Swift Package Manager as the dependency manager, coordinating package-based submodules (common libraries like Networking and Utilities are built as Swift Packages).
- External Libraries:
– Swinject for dependency management.
– Kingfisher for image caching.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Application Entry Point
    subgraph "Application Entry Point"
        AppA("ModularSwiftUIApp"):::appEntry
        AppDel("AppDelegate"):::appEntry
    end

    %% DI & Common Infrastructure
    subgraph "DI & Infrastructure"
        DI("DI Container"):::diContainer
        subgraph "Common Infrastructure"
            NET("Networking (HTTP Client)"):::infrastructure
            NETI("Networking Interface"):::infrastructure
            UTI("Utilities"):::infrastructure
            COORD("Coordinator"):::infrastructure
        end
    end

    %% Modules
    subgraph "Modules"
        subgraph "CharacterList Module"
            CLView("CharacterList View"):::uiLayer
            CLVM("CharacterList ViewModel"):::viewModel
            CLView -->|"binds"| CLVM
            CLVM -->|"fetches_data"| NET
        end
        subgraph "CharacterDetails Module"
            CDView("CharacterDetails View"):::uiLayer
            CDVM("CharacterDetails ViewModel"):::viewModel
            CDView -->|"binds"| CDVM
            CDVM -->|"fetches_data"| NET
        end
        subgraph "Domain / Models"
            CHAR("CharacterModels"):::domain
        end
    end

    %% External Dependencies
    subgraph "External Dependencies"
        SW("Swinject"):::external
        KF("Kingfisher"):::external
    end

    %% Relationships between components
    AppA -->|"initializes"| DI
    AppDel -->|"handles_lifecycle"| DI
    DI -->|"injects"| CLVM
    DI -->|"injects"| CDVM
    DI -->|"injects"| COORD
    COORD -->|"navigates_to"| CLView
    COORD -->|"navigates_to"| CDView
    NETI -->|"defines_API"| NET
    DI -->|"uses"| SW
    NET -->|"uses"| KF

    %% Styles
    classDef appEntry fill:#f9c74f,stroke:#000,stroke-width:2px;
    classDef uiLayer fill:#90be6d,stroke:#000,stroke-width:2px;
    classDef viewModel fill:#f9844a,stroke:#000,stroke-width:2px;
    classDef domain fill:#577590,stroke:#000,stroke-width:2px;
    classDef infrastructure fill:#f94144,stroke:#000,stroke-width:2px;
    classDef diContainer fill:#f3722c,stroke:#000,stroke-width:2px;
    classDef external fill:#277da1,stroke:#000,stroke-width:2px;

    %% Click Events
    click AppA "https://github.com/mostafanafie/swiftui-mvvm-di/blob/main/ModularSwiftUI/ModularSwiftUIApp.swift"
    click AppDel "https://github.com/mostafanafie/swiftui-mvvm-di/blob/main/ModularSwiftUI/AppDelegate.swift"
    click CLView "https://github.com/mostafanafie/swiftui-mvvm-di/tree/main/ModularSwiftUI/Modules/CharacterList/Sources/CharacterList/View"
    click CDView "https://github.com/mostafanafie/swiftui-mvvm-di/tree/main/ModularSwiftUI/Modules/CharacterDetails/Sources/CharacterDetails/View"
    click CLVM "https://github.com/mostafanafie/swiftui-mvvm-di/blob/main/ModularSwiftUI/Modules/CharacterList/Sources/CharacterList/ViewModel/CharacterListViewModel.swift"
    click CDVM "https://github.com/mostafanafie/swiftui-mvvm-di/blob/main/ModularSwiftUI/Modules/CharacterDetails/Sources/CharacterDetails/ViewModel/CharacterDetailsViewModel.swift"
    click CHAR "https://github.com/mostafanafie/swiftui-mvvm-di/blob/main/ModularSwiftUI/Modules/CharacterModels/Sources/CharacterModels/CharacterModels.swift"
    click NET "https://github.com/mostafanafie/swiftui-mvvm-di/blob/main/ModularSwiftUI/Common/Networking/Sources/Networking/Networking.swift"
    click NETI "https://github.com/mostafanafie/swiftui-mvvm-di/tree/main/ModularSwiftUI/Common/NetworkingInterface/Sources/NetworkingInterface"
    click DI "https://github.com/mostafanafie/swiftui-mvvm-di/tree/main/ModularSwiftUI/Common/DI"
    click UTI "https://github.com/mostafanafie/swiftui-mvvm-di/tree/main/ModularSwiftUI/Common/Utilities/Sources/Utilities"
    click COORD "https://github.com/mostafanafie/swiftui-mvvm-di/tree/main/ModularSwiftUI/Common/Coordinator"
```
