# varol/themoviedb architecture

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

- Interactive diagram: https://gitdiagram.com/varol/themoviedb
- Repository: https://github.com/varol/themoviedb

## Overview

##### Project type and purpose
- This is an iOS client application (“TheMovieDB”) built with Swift using the VIPER architecture pattern.
- It displays movie data fetched from the external TheMovieDB API.
- It also includes a standalone Swift Package (“DistilledCoreAPI”) that provides a generic, modular network layer.

##### File structure
- Top-level Swift Package:
- DistilledCoreAPI/
– Sources/DistilledCoreAPI: NetworkManager, Endpoint, HttpMethod, ApiClientError
– Tests/DistilledCoreAPITests
- Main Xcode workspace & project:
- TheMovieDB.xcodeproj & workspace configuration files
- App target directory (“TheMovieDB/”):
- App/ (AppDelegate, SceneDelegate)
- Base.lproj (storyboards)
- Endpoints/ (MovieDBEndpoint definitions)
- Modules/ (VIPER modules – Splash and Home)
- Resources/
– Base components (e.g., BaseViewController, BaseLabel)
– Common, Extensions, Protocols (LoadingShowable), Utils/Views (LoadingView)
- Test targets:
- TheMovieDBTests (unit tests for cells & presenters)
- TheMovieDBUITests (UI test suites & screen objects)

##### README for additional insights
- VIPER architecture (“Testable and maintainable architecture with VIPER”)
- Features: generic network layer, animated splash screen, home screen with sorting, pagination, dark-mode, error management, unit/UI tests
- Dependencies managed via Swift Package Manager

##### Main components
a. Client App (iOS)
- VIPER Modules:
– SplashModule: ViewController, Presenter, Interactor, Router
– HomeModule: ViewController, Presenter, Interactor, Router, Entity (TopRatedTVShows), Cells (TVShowListCell + Presenter)
- Base & Resource Layer: common UI components, extensions, utilities (LoadingView)
- App Core: AppDelegate, SceneDelegate, Storyboards, Assets
b. Network Layer (DistilledCoreAPI Swift Package)
- NetworkManager ← handles URLSession, requests
- Endpoint definitions (MovieDBEndpoint)
- HttpMethod enum, ApiClientError handling
c. External Service
- TheMovieDB REST API (hosted externally)
d. Testing Layers
- Unit Tests (presenter, interactor mocks, JSON fixtures)
- UI Tests (screen objects, XCTest)

##### Relationships & data-flow
- App launch → SplashModule.Router → SplashView displays → SplashInteractor checks connectivity → passes to SplashPresenter → SplashRouter navigates to HomeModule
- HomeViewController → HomePresenter → HomeInteractor calls NetworkManager (via MovieDBEndpoint) → external API → JSON response → Entity mapping → HomePresenter → HomeViewController
- UI events in ViewController propagate to Presenter → Interactor → external API → back to Presenter → View
- Common utilities (LoadingView, extensions) used by ViewControllers
- Tests mock the Interactor and Router to isolate Presenter logic; UI tests drive the real app via BaseScreen objects

##### Architectural patterns & design principles
- VIPER: strict separation among View, Interactor (business logic), Presenter, Entity, Router (navigation)
- Modular network layer: extracted into a standalone Swift Package (DistilledCoreAPI)
- Dependency management: Swift Package Manager
- Reusable base components and protocols for consistency
- Clear testability: mocks for Interactors/Routers, JSON fixtures, UI screen abstractions

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% App Core
    subgraph "App Core"
        direction TB
        AppDelegate["AppDelegate"]:::logic
        SceneDelegate["SceneDelegate"]:::logic
        MainSB["Main.storyboard"]:::ui
        LaunchSB["LaunchScreen.storyboard"]:::ui
        Assets["Assets.xcassets"]:::ui
    end

    %% VIPER Modules
    subgraph "Splash Module" 
        direction TB
        SV["SplashViewController"]:::ui
        SP["SplashPresenter"]:::logic
        SI["SplashInteractor"]:::logic
        SR["SplashRouter"]:::route
    end

    subgraph "Home Module"
        direction TB
        HV["HomeViewController"]:::ui
        HP["HomePresenter"]:::logic
        HI["HomeInteractor"]:::logic
        HR["HomeRouter"]:::route
        subgraph "Home Entities & Cells"
            direction TB
            TE["TopRatedTVShows"]:::logic
            CCell["TVShowListCell"]:::ui
            CPC["TVShowListCellPresenter"]:::logic
        end
    end

    %% Resources
    subgraph "Resources"
        direction TB
        BVC["BaseViewController"]:::resources
        BL["BaseLabel"]:::resources
        BI["BaseImageView"]:::resources
        BCC["BaseCollectionViewCell"]:::resources
        EXT["UIView+Extensions"]:::resources
        LS["LoadingShowable"]:::resources
        LV["LoadingView"]:::resources
    end

    %% Network Layer
    subgraph "DistilledCoreAPI"
        direction TB
        NM["NetworkManager"]:::network
        EP["Endpoint"]:::network
        HM["HttpMethod"]:::network
        AE["ApiClientError"]:::network
    end

    %% External Service
    API["TheMovieDB API"]:::external

    %% Test Layers
    subgraph "Unit Tests"
        direction TB
        UT1["TVShowListCellPresenterTests"]:::tests
        UT2["MockTVShowListCell"]:::tests
        UT3["HomePresenterTests"]:::tests
        UT4["MockHomeInteractor"]:::tests
        UT5["MockHomeRouter"]:::tests
        UT6["MockHomeViewController"]:::tests
        UT7["TopRatedTVShows.json"]:::tests
        UT8["SplashPresenterTests"]:::tests
        UT9["MockSplashInteractor"]:::tests
        UT10["MockSplashRouter"]:::tests
        UT11["MockSplashViewController"]:::tests
    end

    subgraph "UI Tests"
        direction TB
        UIT1["BaseScreen"]:::tests
        UIT2["HomeScreen"]:::tests
        UIT3["HomeScreenTests"]:::tests
        UIT4["TheMovieDBUITestsLaunchTests"]:::tests
        UIT5["BaseTests"]:::tests
    end

    %% Connections
    AppDelegate --> SceneDelegate
    SceneDelegate --> SR
    SR --> SV
    SV --> SP
    SP --> SI
    SI --> NM
    NM --> API
    API --> NM
    NM --> EP
    SI --> EP
    EP --> HM
    SI -->|"uses"| LV
    SV -->|"uses"| BVC
    SV -->|"uses"| EXT
    HV --> HP
    HP --> HI
    HI --> NM
    HI --> EP
    HP --> HV
    HI --> TE
    HV --> CCell
    CCell --> CPC
    CPC --> HI

    %% Click Events
    click NM "https://github.com/varol/themoviedb/blob/main/DistilledCoreAPI/Sources/DistilledCoreAPI/NetworkManager.swift"
    click EP "https://github.com/varol/themoviedb/blob/main/DistilledCoreAPI/Sources/DistilledCoreAPI/Endpoint.swift"
    click HM "https://github.com/varol/themoviedb/blob/main/DistilledCoreAPI/Sources/DistilledCoreAPI/HttpMethod.swift"
    click AE "https://github.com/varol/themoviedb/blob/main/DistilledCoreAPI/Sources/DistilledCoreAPI/ApiClientError.swift"
    click AppDelegate "https://github.com/varol/themoviedb/blob/main/TheMovieDB/App/AppDelegate.swift"
    click SceneDelegate "https://github.com/varol/themoviedb/blob/main/TheMovieDB/App/SceneDelegate.swift"
    click MainSB "https://github.com/varol/themoviedb/blob/main/TheMovieDB/Base.lproj/Main.storyboard"
    click LaunchSB "https://github.com/varol/themoviedb/blob/main/TheMovieDB/Base.lproj/LaunchScreen.storyboard"
    click Assets "https://github.com/varol/themoviedb/tree/main/TheMovieDB/Assets.xcassets/"
    click EP "https://github.com/varol/themoviedb/blob/main/TheMovieDB/Endpoints/MovieDBEndpoint.swift"
    click SV "https://github.com/varol/themoviedb/blob/main/TheMovieDB/Modules/Splash/SplashViewController.swift"
    click SV "https://github.com/varol/themoviedb/blob/main/TheMovieDB/Modules/Splash/SplashViewController.xib"
    click SP "https://github.com/varol/themoviedb/blob/main/TheMovieDB/Modules/Splash/SplashPresenter.swift"
    click SI "https://github.com/varol/themoviedb/blob/main/TheMovieDB/Modules/Splash/SplashInteractor.swift"
    click SR "https://github.com/varol/themoviedb/blob/main/TheMovieDB/Modules/Splash/SplashRouter.swift"
    click HV "https://github.com/varol/themoviedb/blob/main/TheMovieDB/Modules/Home/HomeViewController.swift"
    click HV "https://github.com/varol/themoviedb/blob/main/TheMovieDB/Modules/Home/HomeViewController.xib"
    click HP "https://github.com/varol/themoviedb/blob/main/TheMovieDB/Modules/Home/HomePresenter.swift"
    click HI "https://github.com/varol/themoviedb/blob/main/TheMovieDB/Modules/Home/HomeInteractor.swift"
    click HR "https://github.com/varol/themoviedb/blob/main/TheMovieDB/Modules/Home/HomeRouter.swift"
    click TE "https://github.com/varol/themoviedb/blob/main/TheMovieDB/Modules/Home/Entity/TopRatedTVShows.swift"
    click CCell "https://github.com/varol/themoviedb/blob/main/TheMovieDB/Modules/Home/Cells/TVShowListCell/TVShowListCell.swift"
    click CCell "https://github.com/varol/themoviedb/blob/main/TheMovieDB/Modules/Home/Cells/TVShowListCell/TVShowListCell.xib"
    click CPC "https://github.com/varol/themoviedb/blob/main/TheMovieDB/Modules/Home/Cells/TVShowListCell/TVShowListCellPresenter.swift"
    click BVC "https://github.com/varol/themoviedb/blob/main/TheMovieDB/Resources/Base/BaseViewController.swift"
    click BL "https://github.com/varol/themoviedb/blob/main/TheMovieDB/Resources/Base/BaseLabel.swift"
    click BI "https://github.com/varol/themoviedb/blob/main/TheMovieDB/Resources/Base/BaseImageView.swift"
    click BCC "https://github.com/varol/themoviedb/blob/main/TheMovieDB/Resources/Base/BaseCollectionViewCell.swift"
    click EXT "https://github.com/varol/themoviedb/blob/main/TheMovieDB/Resources/Extensions/UIView+Extensions.swift"
    click LS "https://github.com/varol/themoviedb/blob/main/TheMovieDB/Resources/Protocols/LoadingShowable.swift"
    click LV "https://github.com/varol/themoviedb/blob/main/TheMovieDB/Resources/Utils/Views/LoadingView/LoadingView.swift"
    click UT1 "https://github.com/varol/themoviedb/blob/main/TheMovieDBTests/Cells/TVShowListCell/TVShowListCellPresenterTests.swift"
    click UT2 "https://github.com/varol/themoviedb/blob/main/TheMovieDBTests/Cells/TVShowListCell/MockTVShowListCell.swift"
    click UT3 "https://github.com/varol/themoviedb/blob/main/TheMovieDBTests/Screens/Home/HomePresenterTests.swift"
    click UT4 "https://github.com/varol/themoviedb/blob/main/TheMovieDBTests/Screens/Home/MockHomeInteractor.swift"
    click UT5 "https://github.com/varol/themoviedb/blob/main/TheMovieDBTests/Screens/Home/MockHomeRouter.swift"
    click UT6 "https://github.com/varol/themoviedb/blob/main/TheMovieDBTests/Screens/Home/MockHomeViewController.swift"
    click UT7 "https://github.com/varol/themoviedb/blob/main/TheMovieDBTests/Screens/Home/TopRatedTVShows.json"
    click UT8 "https://github.com/varol/themoviedb/blob/main/TheMovieDBTests/Screens/Splash/SplashPresenterTests.swift"
    click UT9 "https://github.com/varol/themoviedb/blob/main/TheMovieDBTests/Screens/Splash/MockSplashInteractor.swift"
    click UT10 "https://github.com/varol/themoviedb/blob/main/TheMovieDBTests/Screens/Splash/MockSplashRouter.swift"
    click UT11 "https://github.com/varol/themoviedb/blob/main/TheMovieDBTests/Screens/Splash/MockSplashViewController.swift"
    click UIT1 "https://github.com/varol/themoviedb/blob/main/TheMovieDBUITests/Screens/BaseScreen.swift"
    click UIT2 "https://github.com/varol/themoviedb/blob/main/TheMovieDBUITests/Screens/HomeScreen.swift"
    click UIT3 "https://github.com/varol/themoviedb/blob/main/TheMovieDBUITests/Tests/HomeScreenTests.swift"
    click UIT4 "https://github.com/varol/themoviedb/blob/main/TheMovieDBUITests/TheMovieDBUITestsLaunchTests.swift"
    click UIT5 "https://github.com/varol/themoviedb/blob/main/TheMovieDBUITests/Tests/BaseTests.swift"

    %% Styles
    classDef ui fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef logic fill:#90EE90,stroke:#333,stroke-width:1px
    classDef route fill:#FFFF99,stroke:#333,stroke-width:1px
    classDef network fill:#D8BFD8,stroke:#333,stroke-width:1px
    classDef external fill:#D3D3D3,stroke:#333,stroke-width:1px
    classDef resources fill:#F0F0F0,stroke:#333,stroke-width:1px
    classDef tests fill:#FFE4E1,stroke:#333,stroke-width:1px
```
