# lgtout/essential-feed-case-study architecture

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

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

## Overview

##### Main Components

a. UI Layer (Presentation)
- iOS UI Components (UIKit)
- Composers (FeedUIComposer, CommentsUIComposer)
- View Controllers (ListViewController, FeedViewController)
- Presenters (FeedPresenter, ImageCommentsPresenter)
- View Models

b. Domain Layer
- Feed Feature (FeedImage, ImageComment)
- Use Cases
- Load Feed
- Cache Feed
- Load Comments
- Validate Cache

c. Data Layer
- Remote Data (API)
- Feed API
- Comments API
- HTTP Client
- Local Data (Cache)
- CoreData Store
- In-Memory Store

##### Component Relationships

**UI Layer → Domain Layer ← Data Layer**

Use these visual elements:
- Blue: UI Layer
- Green: Domain Layer
- Orange: Data Layer

##### Specific Implementation Details

a. UI Module (EssentialFeediOS)
- ListViewController as the main UI component
- To Feed and Comments UI composers
- Presentation adapters and view models

b. Domain Module (EssentialFeed)
- Feed and Comments entities at the center
- Surround with use case interfaces
- Validation and business rules

c. Data Module
- Split into Remote and Local sections
- CoreData and API implementations
- Caching strategy

##### Additional Elements

- Notes about the MVVM + Clean Architecture pattern
- Testing boundaries (as indicated by the test folders)
- Localization support (shown by .lproj folders)

##### Key Architectural Patterns to Highlight

- Dependency Injection
- Protocol-oriented design
- Composition Root pattern
- Repository pattern for data access
- SOLID principles application

##### Cross-Cutting Concerns

- Error handling flow
- Memory management considerations
- Threading/async operations
- Cache validation flow

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef ui fill:#e1f5fe,stroke:#01579b
    classDef domain fill:#e8f5e9,stroke:#1b5e20
    classDef data fill:#fff3e0,stroke:#e65100
    classDef shared fill:#f3e5f5,stroke:#4a148c

    %% UI Layer
    subgraph UI
        ListVC["ListViewController"]:::ui
        FeedComposer["FeedUIComposer"]:::ui
        CommentsComposer["CommentsUIComposer"]:::ui
        FeedPresenter["FeedPresenter"]:::ui
        CommentsPresenter["ImageCommentsPresenter"]:::ui
        ResourcePresenter["LoadResourcePresenter"]:::shared
    end

    %% Domain Layer
    subgraph Domain
        FeedFeature["Feed Feature"]:::domain
        FeedImage["FeedImage Entity"]:::domain
        CommentsFeature["Comments Feature"]:::domain
        ImageComment["ImageComment Entity"]:::domain
    end

    %% Data Layer
    subgraph Data
        RemoteFeed["Remote Feed API"]:::data
        RemoteComments["Remote Comments API"]:::data
        HTTPClient["HTTPClient"]:::data
        URLSessionHTTP["URLSessionHTTPClient"]:::data
        LocalCache["Local Feed Cache"]:::data
        CoreDataStore["CoreData Store"]:::data
        InMemoryStore["InMemory Store"]:::data
    end

    %% Relationships
    ListVC --> FeedComposer
    ListVC --> CommentsComposer
    FeedComposer --> FeedPresenter
    CommentsComposer --> CommentsPresenter
    FeedPresenter --> ResourcePresenter
    CommentsPresenter --> ResourcePresenter

    FeedPresenter --> FeedFeature
    CommentsPresenter --> CommentsFeature
    FeedFeature --> FeedImage
    CommentsFeature --> ImageComment

    RemoteFeed --> HTTPClient
    RemoteComments --> HTTPClient
    HTTPClient --> URLSessionHTTP
    LocalCache --> CoreDataStore
    LocalCache --> InMemoryStore

    RemoteFeed -.-> FeedFeature
    RemoteComments -.-> CommentsFeature
    LocalCache -.-> FeedFeature

    %% Click Events
    click ListVC "https://github.com/lgtout/essential-feed-case-study/blob/master/EssentialFeed/EssentialFeediOS/Shared UI/Controllers/ListViewController.swift"
    click FeedComposer "https://github.com/lgtout/essential-feed-case-study/blob/master/EssentialApp/EssentialApp/FeedUIComposer.swift"
    click CommentsComposer "https://github.com/lgtout/essential-feed-case-study/blob/master/EssentialApp/EssentialApp/CommentsUIComposer.swift"
    click FeedPresenter "https://github.com/lgtout/essential-feed-case-study/blob/master/EssentialFeed/EssentialFeed/Feed Presentation/FeedPresenter.swift"
    click CommentsPresenter "https://github.com/lgtout/essential-feed-case-study/blob/master/EssentialFeed/EssentialFeed/Image Comments Presentation/ImageCommentsPresenter.swift"
    click ResourcePresenter "https://github.com/lgtout/essential-feed-case-study/blob/master/EssentialFeed/EssentialFeed/Shared Presentation/LoadResourcePresenter.swift"
    click FeedFeature "https://github.com/lgtout/essential-feed-case-study/tree/master/EssentialFeed/EssentialFeed/Feed Feature/"
    click FeedImage "https://github.com/lgtout/essential-feed-case-study/blob/master/EssentialFeed/EssentialFeed/Feed Feature/FeedImage.swift"
    click CommentsFeature "https://github.com/lgtout/essential-feed-case-study/tree/master/EssentialFeed/EssentialFeed/Image Comments Feature/"
    click ImageComment "https://github.com/lgtout/essential-feed-case-study/blob/master/EssentialFeed/EssentialFeed/Image Comments Feature/ImageComment.swift"
    click RemoteFeed "https://github.com/lgtout/essential-feed-case-study/tree/master/EssentialFeed/EssentialFeed/Feed API/"
    click RemoteComments "https://github.com/lgtout/essential-feed-case-study/tree/master/EssentialFeed/EssentialFeed/Image Comments API/"
    click HTTPClient "https://github.com/lgtout/essential-feed-case-study/blob/master/EssentialFeed/EssentialFeed/Shared API/HTTPClient.swift"
    click URLSessionHTTP "https://github.com/lgtout/essential-feed-case-study/blob/master/EssentialFeed/EssentialFeed/Shared API Infra/URLSessionHTTPClient.swift"
    click LocalCache "https://github.com/lgtout/essential-feed-case-study/tree/master/EssentialFeed/EssentialFeed/Feed Cache/"
    click CoreDataStore "https://github.com/lgtout/essential-feed-case-study/tree/master/EssentialFeed/EssentialFeed/Feed Cache/Infrastructure/CoreData/"
    click InMemoryStore "https://github.com/lgtout/essential-feed-case-study/blob/master/EssentialFeed/EssentialFeed/Feed Cache/Infrastructure/InMemory/InMemoryFeedStore.swift"

    %% Legend
    subgraph Legend
        UI_Component["UI Component"]:::ui
        Domain_Component["Domain Component"]:::domain
        Data_Component["Data Component"]:::data
        Shared_Component["Shared Component"]:::shared
    end
```
