# essentialdevelopercom/essential-feed-case-study architecture

> Architecture diagram of the GitHub repository essentialdevelopercom/essential-feed-case-study, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/essentialdevelopercom/essential-feed-case-study
- Repository: https://github.com/essentialdevelopercom/essential-feed-case-study

## Overview

##### Main components
- UI Layer (Client Application): This is in EssentialApp (and Prototype) where the app delegate, scene delegate, storyboards, view controllers, table view/cell management, and asset catalogs live. It also includes components like FeedImageCell, FeedViewController, and Controllers in EssentialFeediOS.
- Presentation Layer: Presenters such as FeedPresenter, FeedImagePresenter, and LoadResourcePresenter exist to transform domain models into view models. Also include any localization and error UI components.
- Domain / Use Case Layer: Encapsulates the use cases (load feed from remote, load feed from cache, validate cache, save feed, load image data, etc.) as described in the README. This represents the core business logic.
- Networking / API Layer: Contains the “Feed API”, “Image Comments API,” HTTP clients (like URLSessionHTTPClient), endpoint definition files, data mappers, and payload contracts for both feed items and image comments.
- Cache / Persistence Layer: Shows components for caching the feed – both using Core Data (CoreDataFeedStore, ManagedCache, ManagedFeedImage) and an InMemory option for testing. It also includes cache validation, expiry logic, and saving/deleting mechanisms.
- Shared Modules/Infrastructure: Includes shared API Infra (HTTPClient protocols), shared presentation (error, loading, and resource view models), and standard helper components. This covers helper classes for testing, extensions, and common utilities.

- That the Use Case Layer (Domain) first attempts to load data from the Remote API via the Networking Layer. In parallel, note the feed caching operations where the Domain asks the Persistence Layer to either retrieve or save feed data.
- Error paths (e.g., no connectivity, invalid data) flowing from the API Layer back to the Presentation Layer and then displayed through the UI.
- For image comments, create a similar flow chain: UI (when a user requests comments) to the Image Comments API, mapping, and then to a presenter and view.
- Optionally, represent integration test frameworks and CI workflows as separate but interacting “modules” ensuring quality assurance.

##### Architectural patterns and design principles
- The separation of concerns: clearly differentiating between UI, presentation/business logic, networking, and caching layers.
- Client-Server architecture for remote feed loading and REST API integration.
- Incorporation of a Clean Architecture/MVC/MVP-like flow, where the responsibilities for presentation, domain logic, and data handling are kept separate.

##### Technologies, frameworks, and libraries
- Xcode for project configuration.
- Swift as the programming language.
- Core Data (and an InMemory alternative) for caching.
- URLSession-based networking for remote requests.
- Storyboards and Swift UI components for the UI.
- GitHub Actions for Continuous Integration and Deployment.
- Testing frameworks (integration, acceptance, snapshot tests) are spread across the EssentialAppTests, EssentialFeedTests, and EssentialFeediOSTests directories.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI Layer Subgraph
    subgraph "UI Layer"
        EAUI["EssentialApp UI – App Delegate, Scene Delegate, FeedUIComposer, etc"]:::ui
        PUI["Prototype UI – FeedViewController, FeedImageCell, Storyboards"]:::ui
        FEUI["EssentialFeediOS UI – Feed UI Controllers & Assets"]:::ui
    end

    %% Presentation Layer Subgraph
    subgraph "Presentation Layer"
        FP["Feed Presentation – FeedPresenter, FeedImagePresenter"]:::presentation
        SP["Shared Presentation – LoadResourcePresenter, ResourceErrorView"]:::presentation
    end

    %% Domain / Use Case Layer Subgraph
    subgraph "Domain / Use Case Layer"
        FU["Feed Use Cases – Load Feed, Cache Feed, Validate Cache"]:::domain
    end

    %% Networking / API Layer Subgraph
    subgraph "Networking / API Layer"
        FAPI["Feed API – FeedEndpoint, FeedImageDataMapper, etc"]:::network
        ICAPI["Image Comments API – ImageCommentsEndpoint, Mapper"]:::network
        HTTP["HTTP Client – URLSessionHTTPClient & Helpers"]:::network
    end

    %% Cache / Persistence Layer Subgraph
    subgraph "Cache / Persistence Layer"
        CDS["CoreData Feed Store – CoreDataFeedStore, ManagedCache, etc"]:::cache
        IMS["InMemory Feed Store – InMemoryFeedStore.swift"]:::cache
    end

    %% External Services & CI/CD Subgraph
    subgraph "External & CI/CD"
        CICD["CI/CD – GitHub Actions, Deployment Configurations"]:::external
    end

    %% Connections between layers
    %% UI Layer to Presentation Layer
    EAUI -->|"triggers"| FP
    PUI  -->|"triggers"| FP
    FEUI -->|"triggers"| FP
    %% Also, UI errors or status can be routed to shared presentation
    EAUI -->|"error/display"| SP
    PUI  -->|"error/display"| SP
    FEUI -->|"error/display"| SP

    %% Presentation Layer to Domain / Use Case Layer
    FP -->|"invokes use case"| FU
    SP -->|"provides feedback to"| FU

    %% Domain Layer interactions with Networking and Cache
    FU -->|"fetches feed"| FAPI
    FAPI -->|"uses"| HTTP
    FU -->|"cache operations"| CDS
    CDS -->|"cache validation/deletion"| FU
    FU -.-|"alternative caching"| IMS
    FU -->|"loads image comments"| ICAPI

    %% Error flows from Networking layers back to Presentation
    FAPI -.->|"error"| SP
    ICAPI -.->|"error"| SP

    %% CI/CD involvement with build & tests
    CICD -->|"triggers build&deploy"| EAUI
    CICD -->|"runs tests"| FU

    %% Styles
    classDef ui fill:#F8B195,stroke:#F67280,stroke-width:2px;
    classDef presentation fill:#C06C84,stroke:#6C5B7B,stroke-width:2px;
    classDef domain fill:#355C7D,stroke:#6C5B7B,stroke-width:2px;
    classDef network fill:#99B898,stroke:#2A363B,stroke-width:2px;
    classDef cache fill:#F8B195,stroke:#E84A5F,stroke-width:2px;
    classDef external fill:#DCE775,stroke:#7CB342,stroke-width:2px;

    %% Click Events for Component Mapping
    click EAUI "https://github.com/essentialdevelopercom/essential-feed-case-study/tree/master/EssentialApp/EssentialApp"
    click PUI "https://github.com/essentialdevelopercom/essential-feed-case-study/tree/master/Prototype/Prototype"
    click FEUI "https://github.com/essentialdevelopercom/essential-feed-case-study/tree/master/EssentialFeed/EssentialFeediOS/Feed UI"
    click FP "https://github.com/essentialdevelopercom/essential-feed-case-study/tree/master/EssentialFeed/EssentialFeed/Feed Presentation"
    click SP "https://github.com/essentialdevelopercom/essential-feed-case-study/tree/master/EssentialFeed/EssentialFeed/Shared Presentation"
    click FU "https://github.com/essentialdevelopercom/essential-feed-case-study/tree/master/EssentialFeed/EssentialFeed/Feed Cache"
    click FAPI "https://github.com/essentialdevelopercom/essential-feed-case-study/tree/master/EssentialFeed/EssentialFeed/Feed API"
    click ICAPI "https://github.com/essentialdevelopercom/essential-feed-case-study/tree/master/EssentialFeed/EssentialFeed/Image Comments API"
    click HTTP "https://github.com/essentialdevelopercom/essential-feed-case-study/tree/master/EssentialFeed/EssentialFeed/Shared API Infra"
    click CDS "https://github.com/essentialdevelopercom/essential-feed-case-study/tree/master/EssentialFeed/EssentialFeed/Feed Cache/Infrastructure/CoreData"
    click IMS "https://github.com/essentialdevelopercom/essential-feed-case-study/blob/master/EssentialFeed/EssentialFeed/Feed Cache/Infrastructure/InMemory/InMemoryFeedStore.swift"
    click CICD "https://github.com/essentialdevelopercom/essential-feed-case-study/blob/master/.github"
```
