# mchirino89/rickandmorty architecture

> Architecture diagram of the GitHub repository mchirino89/rickandmorty, 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/mchirino89/rickandmorty
- Repository: https://github.com/mchirino89/rickandmorty

## Overview

##### Project Type and Purpose
- The project is a Proof-of-Concept (PoC) for a programmatic UIKit app that displays a simple list of characters and a detail view. It interacts with the public Rick and Morty API to fetch random characters.
- It uses Swift Package Manager (SPM) dependencies (MauriUtils, MauriNet, MauriKit) and is built in Xcode, indicating an iOS client app with a focus on clean architecture and a modular approach.

##### File Structure
- Notice the top-level "R&M" directory that contains the main source code.
- Inside, the project is organized by Clean Architecture layers:
- Entities (core business objects like endpoint descriptions)
- UseCases (user actions – e.g., fetching random characters, showing character details)
- InterfaceAdapters (UI layer implementing MVVM: view controllers, views, UI assets, DTOs)
- Drivers (frameworks and external connections – e.g., network requests, in-house cache framework for images, app setup files)
- There is also a comprehensive tests directory (R&MTests) containing unit tests, integration tests (NavigationTestCases and SnapshotTestCases), and various test doubles (dummies, fakes, stubs, spies).
- Additional project configuration files (e.g., .swiftlint.yml, Info.plist files), CI integration workflows (.github/workflows), and documentation resources (DocResources, Preview) are also present.

##### README for Additional Insights
- The README emphasizes that the architecture is based on Uncle Bob’s Clean Architecture – with clearly defined layers for Entities, Use Cases, Interface Adapters, and Drivers.
- It details that the UI design pattern is MVVM, with responsibilities split among view controllers, view models, and data transmission objects.
- It presents reasoning behind using SOLID principles, component decoupling, and integration tests to safeguard navigation and layout behaviors.

a. Main Components:
- Entities: Representing the core objects (e.g., endpoint data for characters).
- Use Cases: Contain the business logic for actions like loading a list of random characters and presenting details.
- Interface Adapters: The MVVM components – view controllers, UI components, DTOs, and asset management.
- Frameworks/Drivers: External integrations, including the network layer (via MauriNet), caching (in-house CacheFramework), and iOS setup/configuration.
- Test Suite: An additional layer to indicate testing of repositories, navigation, and UI snapshots.

b. Relationships and Interactions:
- Data flows from the Drivers (network requests, caching layer) into the Use Cases. The Use Cases process the business logic.
- Processed data is handed off to Interface Adapters, which transform it into UI-friendly data structures (using DTOs) and ultimately render it via MVVM views and controllers.
- Entities remain at the core, stable data representations used across the other layers.
- Additionally, there is a navigation coordinator pattern (via the MainCoordinator in the Navigation folder) ensuring loose coupling between UI components.

c. Architectural Patterns or Design Principles:
- Clean Architecture: Segregation of responsibilities across Entities, Use Cases, Interface Adapters, and Drivers.
- MVVM for organizing the UI code.
- Use of SOLID principles throughout the codebase with specific emphasis on single responsibilities (as seen with dedicated files for delegates, data sources, and test doubles).
- “Lego-oriented” design which emphasizes composability and modularity.

d. Relevant Technologies, Frameworks, or Libraries:
- UIKit for the UI.
- Swift Package Manager (SPM) for dependency management.
- The external libraries: MauriUtils, MauriNet, MauriKit.
- Testing frameworks (embedded within Xcode) alongside unit and snapshot testing.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Drivers Layer
    subgraph "Drivers (Frameworks & External Integrations)"
        DR1["Cache Framework"]
        DR2["Repositories"]
        DR3["App Setup"]
    end

    %% Use Cases Layer
    subgraph "Use Cases (Business Logic)"
        UC1["Actions"]
        UC2["Navigation (MainCoordinator)"]
        UC3["ViewModels"]
    end

    %% Interface Adapters Layer (MVVM Components)
    subgraph "Interface Adapters (MVVM Components)"
        IA1["Components (List & Detail)"]
        IA2["DTOs"]
        IA3["UI Assets & Base Storyboard"]
        IA4["General ViewController"]
    end

    %% Entities Layer (Core Business Objects)
    subgraph "Entities"
        EN["Entities"]
    end

    %% Test Suite Layer
    subgraph "Test Suite"
        TS1["Test Cases"]
        TS2["Test Doubles"]
    end

    %% Connections between layers
    %% Drivers feed into Use Cases
    DR1 -->|"providesData"| UC1
    DR2 -->|"providesData"| UC1
    DR3 -->|"initiates"| UC1

    %% Use Cases use Entities
    UC1 -->|"uses"| EN
    UC2 -->|"uses"| EN
    UC3 -->|"uses"| EN

    %% Use Cases connect to Interface Adapters
    UC1 -->|"processes"| IA1
    UC1 -->|"transforms"| IA2
    UC2 -->|"navigatesTo"| IA4
    UC3 -->|"bindsTo"| IA4

    %% Interface Adapters display data from Entities
    IA4 -->|"renders"| EN

    %% Test Suite interactions (dotted lines)
    TS1 ---|"testsLogic"| UC1
    TS1 ---|"testsUI"| IA4
    TS2 ---|"mocksDependencies"| DR2

    %% Styles
    classDef drivers fill:#d1c4e9,stroke:#673ab7,stroke-width:2px;
    classDef usecases fill:#d0f0c0,stroke:#9acd32,stroke-width:2px;
    classDef adapters fill:#fefbd8,stroke:#f5a623,stroke-width:2px;
    classDef entities fill:#ffd1dc,stroke:#ff6384,stroke-width:2px;
    classDef tests fill:#cce5ff,stroke:#279af1,stroke-width:2px;

    class DR1,DR2,DR3 drivers;
    class UC1,UC2,UC3 usecases;
    class IA1,IA2,IA3,IA4 adapters;
    class EN entities;
    class TS1,TS2 tests;

    %% Click Events for Components
    click EN "https://github.com/mchirino89/rickandmorty/tree/main/R&M/R&M/Entities"
    click UC1 "https://github.com/mchirino89/rickandmorty/tree/main/R&M/R&M/UseCases/Actions"
    click UC2 "https://github.com/mchirino89/rickandmorty/blob/main/R&M/R&M/UseCases/Navigation/MainCoordinator.swift"
    click UC3 "https://github.com/mchirino89/rickandmorty/tree/main/R&M/R&M/UseCases/ViewModels"
    click IA1 "https://github.com/mchirino89/rickandmorty/tree/main/R&M/R&M/InterfaceAdapters/Components"
    click IA2 "https://github.com/mchirino89/rickandmorty/tree/main/R&M/R&M/InterfaceAdapters/DTOs"
    click IA3 "https://github.com/mchirino89/rickandmorty/tree/main/R&M/R&M/InterfaceAdapters/UI"
    click IA4 "https://github.com/mchirino89/rickandmorty/blob/main/R&M/R&M/InterfaceAdapters/ViewController.swift"
    click DR1 "https://github.com/mchirino89/rickandmorty/tree/main/R&M/R&M/Drivers/CacheFramework"
    click DR2 "https://github.com/mchirino89/rickandmorty/tree/main/R&M/R&M/Drivers/Repositories"
    click DR3 "https://github.com/mchirino89/rickandmorty/tree/main/R&M/R&M/Drivers/Setup"
    click TS1 "https://github.com/mchirino89/rickandmorty/tree/main/R&M/R&MTests/TestCases"
    click TS2 "https://github.com/mchirino89/rickandmorty/tree/main/R&M/R&MTests/TestDoubles"
```
