# vadimsorokolit/rickandmortyapp architecture

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

- Interactive diagram: https://gitdiagram.com/vadimsorokolit/rickandmortyapp
- Repository: https://github.com/vadimsorokolit/rickandmortyapp

## Overview

##### Project Type & Purpose
- The project is an iOS app that interfaces with the Rick and Morty API.
- It’s built using the VIP architecture (View, Interactor, Presenter), which is a variant of the Clean Architecture pattern tailored for iOS.
- The app handles networking (via Alamofire), UI layout (via SnapKit), image loading (via SDWebImage), and local persistence (via CoreData).

##### Analyzing the File Structure
- Top-Level Structure: The main directory “RickAndMortyApp” contains the Xcode project files along with the app’s source.
- App Delegate & Scene Delegate: Found in the “App” folder, these are entry points for app configuration and scene management.
- Scenes Directory: Contains feature-based modules such as “Characters” and “CharacterInfo.”
– Each scene follows the VIP split with separate files for the ViewController, Interactor, and Presenter.
– There are also supporting workers (e.g., CharactersNetworkWorker and CharactersStorageWorker) which encapsulate networking and persistent storage logic.
- Services Directory: Contains the CoreData models and Entities defined for local storage.
- Assets, Storyboards, and Xcode project folders: These cover the UI resources and build configurations.

##### Main Components
A. iOS Application Core:
- AppDelegate and SceneDelegate (the application’s entry points).
B. VIP Modules (For each major scene or feature):
- Characters Module:
- CharactersViewController (View layer)
- CharactersInteractor (Business logic)
- CharactersPresenter (Presentation logic)
- CharactersRouter (Navigation)
- Workers: CharactersNetworkWorker (handles networking via Alamofire) and CharactersStorageWorker (handles CoreData interactions)
- CharacterInfo Module:
- CharacterInfoViewController, Interactor, and Presenter (similar VIP structure)
C. Networking Component:
- Uses Alamofire to interact with the external Rick and Morty API.
- Represents the data fetching layer from the “https://rickandmortyapi.com” endpoint.
D. Persistence Component:
- CoreData setup, including managed objects and CoreData stack defined in the Services directory (with associated entities and xcdatamodeld).
E. UI Resources:
- Storyboards (for launch screens and default UI structure)
- Layout setup via SnapKit (applied in view controllers or custom views)
- Image resource handling using SDWebImage.

##### Relationships & Interactions
- The Interactor handles the business logic and communicates with network workers to fetch data from the external API.
- Once data is retrieved (or from CoreData storage), it is sent to the Presenter, which formats the data.
- The Presenter updates the View to display the content.
- External services like the Rick and Morty API endpoint.

##### Architectural Patterns & Design Principles
- VIP (clean separation between View, Interactor, and Presenter) is central.
- Separation of concerns by isolating networking, business logic, and UI rendering.

##### Putting It All Together
- Branch out to major feature modules (Characters and CharacterInfo) showing their internal VIP split.
- Modules to the external API (using Alamofire) and local persistence (via CoreData).

## Diagram (Mermaid)

```mermaid
graph TB
    %% iOS Application Core
    subgraph "iOS Application Core"
        A1("AppDelegate"):::iOSCore
        A2("SceneDelegate"):::iOSCore
    end

    %% Characters Module
    subgraph "Characters Module"
        C1("CharactersViewController"):::UI
        C2("CharactersInteractor"):::business
        C3("CharactersPresenter"):::business
        C4("CharactersRouter"):::business
        C5("CharactersNetworkWorker"):::network
        C6("CharactersStorageWorker"):::persistence
    end

    %% CharacterInfo Module
    subgraph "CharacterInfo Module"
        CI1("CharacterInfoViewController"):::UI
        CI2("CharacterInfoInteractor"):::business
        CI3("CharacterInfoPresenter"):::business
    end

    %% External Services
    subgraph "External Services"
        API("Rick and Morty API"):::external
        CoreData("CoreData Persistence"):::persistence
    end

    %% External Libraries
    subgraph "External Libraries"
        AL("Alamofire"):::network
        SK("SnapKit"):::UI
        SD("SDWebImage"):::UI
    end

    %% UI Resources
    subgraph "UI Resources"
        LS("LaunchScreen Storyboard"):::UI
        AS("Assets & App Icon"):::UI
    end

    %% Connections from iOS Core to Modules
    A2 -->|"launches"| C1
    A2 -->|"launches"| CI1

    %% Characters Module VIP Flow
    C1 -->|"UserAction"| C2
    C2 -->|"BusinessLogic"| C3
    C3 -->|"UpdateUI"| C1

    C2 -->|"APIRequest"| C5
    C5 -->|"fetch"| API

    C2 -->|"persistData"| C6
    C6 -->|"save/fetch"| CoreData

    %% CharacterInfo Module VIP Flow
    CI1 -->|"UserAction"| CI2
    CI2 -->|"BusinessLogic"| CI3
    CI3 -->|"UpdateUI"| CI1

    %% External Libraries Dependencies
    C5 -->|"uses"| AL
    C1 -->|"usesLayout"| SK
    CI1 -->|"usesLayout"| SK
    C1 -->|"loadsImages"| SD
    CI1 -->|"loadsImages"| SD

    %% UI Resources links
    LS -->|"bootResource"| A2
    AS -->|"assets"| A2

    %% Class Definitions with Colors
    classDef iOSCore fill:#f9e79f,stroke:#333,stroke-width:2px;
    classDef UI fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef business fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef network fill:#FFD580,stroke:#333,stroke-width:2px;
    classDef persistence fill:#DDA0DD,stroke:#333,stroke-width:2px;
    classDef external fill:#FFCCCB,stroke:#333,stroke-width:2px;

    %% Click Events for iOS Application Core
    click A1 "https://github.com/vadimsorokolit/rickandmortyapp/blob/main/RickAndMortyApp/RickAndMortyApp/App/AppDelegate.swift"
    click A2 "https://github.com/vadimsorokolit/rickandmortyapp/blob/main/RickAndMortyApp/RickAndMortyApp/App/SceneDelegate.swift"

    %% Click Events for Characters Module
    click C1 "https://github.com/vadimsorokolit/rickandmortyapp/blob/main/RickAndMortyApp/RickAndMortyApp/Scenes/Characters/CharactersViewController.swift"
    click C2 "https://github.com/vadimsorokolit/rickandmortyapp/blob/main/RickAndMortyApp/RickAndMortyApp/Scenes/Characters/CharactersInteractor.swift"
    click C3 "https://github.com/vadimsorokolit/rickandmortyapp/blob/main/RickAndMortyApp/RickAndMortyApp/Scenes/Characters/CharactersPresenter.swift"
    click C4 "https://github.com/vadimsorokolit/rickandmortyapp/blob/main/RickAndMortyApp/RickAndMortyApp/Scenes/Characters/CharactersRouter.swift"
    click C5 "https://github.com/vadimsorokolit/rickandmortyapp/blob/main/RickAndMortyApp/RickAndMortyApp/Scenes/Characters/Workers/CharactersNetworkWorker.swift"
    click C6 "https://github.com/vadimsorokolit/rickandmortyapp/blob/main/RickAndMortyApp/RickAndMortyApp/Scenes/Characters/Workers/CharactersStorageWorker.swift"

    %% Click Events for CharacterInfo Module
    click CI1 "https://github.com/vadimsorokolit/rickandmortyapp/blob/main/RickAndMortyApp/RickAndMortyApp/Scenes/CharacterInfo/CharacterInfoViewController.swift"
    click CI2 "https://github.com/vadimsorokolit/rickandmortyapp/blob/main/RickAndMortyApp/RickAndMortyApp/Scenes/CharacterInfo/CharacterInfoInteractor.swift"
    click CI3 "https://github.com/vadimsorokolit/rickandmortyapp/blob/main/RickAndMortyApp/RickAndMortyApp/Scenes/CharacterInfo/CharacterInfoPresenter.swift"

    %% Click Events for UI Resources
    click LS "https://github.com/vadimsorokolit/rickandmortyapp/blob/main/RickAndMortyApp/RickAndMortyApp/Base.lproj/LaunchScreen.storyboard"
    click AS "https://github.com/vadimsorokolit/rickandmortyapp/blob/main/RickAndMortyApp/RickAndMortyApp/Assets.xcassets"

    %% Click Event for Persistence Component
    click CoreData "https://github.com/vadimsorokolit/rickandmortyapp/blob/main/RickAndMortyApp/RickAndMortyApp/Services/CharacterEntity+CoreDataClass.swift"
```
