# darktt/logosearch architecture

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

- Interactive diagram: https://gitdiagram.com/darktt/logosearch
- Repository: https://github.com/darktt/logosearch

## Overview

##### Main Components
- App Lifecycle: This includes the AppDelegate and SceneDelegate files, which are responsible for initializing and managing the app’s lifecycle.
- Redux Core: This is the heart of the Redux architecture consisting of:
- Store (LogoSearch/Redux/Store.swift) – central hub for state management.
- Actions & Middleware – actions as defined in LogoSearch/ViewModel/LogoSearchAction.swift, and middlewares such as the API, Error, and ImageLoader middlewares (e.g., ApiMiddleware.swift, ErrorMiddleware.swift, ImageLoaderMiddleware.swift). These coordinate data flow to update the state via reducers.
- Reducer/State management – the component that listens to dispatched actions and updates the state accordingly.
- UI Layer: Contains ViewControllers (MainViewController, LogoDetailViewController, SearchViewController, with associated xib/storyboard files) that both dispatch actions to the Redux store and subscribe to state changes.
- Models: Located under the Models directory, these handle API interactions, data fetching, image loading and logging.
- Utilities: Includes reusable Swift extensions (via the SwiftExtensions xcframework), protocols that provide contracts, and helper extensions. These support both the UI layer and the Redux core.
- Testing: Contains unit tests (LogoSearchTests) and UI tests (LogoSearchUITests) to verify functionality.

##### Relationships and Interactions
- The App Lifecycle components (AppDelegate and SceneDelegate) initialize the Redux Store.
- The UI Layer dispatches actions into the Redux core. Actions flow into Middleware first (for tasks like API calls, error handling, and image loading) before reaching the reducers that update the state.
- Updated state is then subscribed to by UI components so the UI always reflects the latest data.
- Middleware may interact with Models to perform tasks such as API calls or image retrieval.
- Utilities (Swift Extensions, Protocols, etc.) provide additional functionality and helper methods across the system.
- Testing components verify the operation of both Models and UI interactions.

##### Architectural Patterns and Notable Design Choices
- Redux Architecture: Enforces a unidirectional data flow (dispatch → middleware → reducer → state → view subscription).
- Separation of Concerns: Distinct separation among lifecycle management, business logic (Redux Core), UI presentation, data models, and utility extensions.
- Modularity: The project utilizes xcframeworks (SwiftExtensions) and segregates functionalities into directories like Models, Protocols, Extensions, and Redux, making the codebase easier to navigate and scale.

##### Technologies and Frameworks
- UIKit for the UI components.
- Redux-style state management, with custom middleware for handling API, errors, and image loading.
- Swift and related Apple development tools (Xcode project files are organized within LogoSearch.xcodeproj).
- The provided SwiftExtensions xcframework extends native functionality.
- Testing frameworks (likely XCTest, given the test directories).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% App Lifecycle Subgraph
    subgraph "App Lifecycle"
        A1["AppDelegate"]:::lifecycle
        A2["SceneDelegate"]:::lifecycle
    end

    %% Redux Core Subgraph
    subgraph "Redux Core"
        RC1["Store"]:::redux
        RC2["Actions"]:::redux
        RC3["API Middleware"]:::redux
        RC4["Error Middleware"]:::redux
        RC5["ImageLoader Middleware"]:::redux
        RC6["Reducer/State"]:::redux
    end

    %% UI Layer Subgraph
    subgraph "UI Layer"
        UI1["MainViewController.swift"]:::ui
        UI2["MainViewController.xib"]:::ui
        UI3["LogoDetailViewController.swift"]:::ui
        UI4["LogoDetailViewController.xib"]:::ui
        UI5["SearchViewController.swift"]:::ui
        UI6["SearchViewController.xib"]:::ui
    end

    %% Models Subgraph
    subgraph "Models"
        M1["Models"]:::models
    end

    %% Utilities Subgraph
    subgraph "Utilities"
        U1["ViewControllerExtension.swift"]:::utilities
        U2["Protocols"]:::utilities
        U3["SwiftExtensions.xcframework"]:::utilities
    end

    %% Testing Subgraph
    subgraph "Testing"
        T1["Unit Tests"]:::testing
        T2["UI Tests"]:::testing
    end

    %% Connections
    %% App Lifecycle initializes the Redux Store
    A1 -->|"init"| RC1
    A2 -->|"init"| RC1

    %% UI dispatches actions to Redux Core
    UI1 -->|"dispatch"| RC2
    UI3 -->|"dispatch"| RC2
    UI5 -->|"dispatch"| RC2

    %% Actions flow to Middlewares
    RC2 -->|"to_API"| RC3
    RC2 -->|"to_Error"| RC4
    RC2 -->|"to_ImageLoader"| RC5

    %% Middlewares process and send to Reducer/State
    RC3 -->|"process"| RC6
    RC4 -->|"process"| RC6
    RC5 -->|"process"| RC6

    %% Updated State flows back to UI Layer
    RC6 -->|"update_UI"| UI1
    RC6 -->|"update_UI"| UI3
    RC6 -->|"update_UI"| UI5

    %% Middleware interactions with Models
    RC3 -->|"API_call"| M1
    RC5 -->|"load_image"| M1

    %% Utilities support UI and Redux components (dotted lines)
    U1 -.-> UI1
    U1 -.-> UI3
    U1 -.-> UI5

    U2 -.-> UI1
    U2 -.-> RC2

    U3 -.-> RC1

    %% Testing interactions (dotted lines)
    T1 -.-> M1
    T2 -.-> UI1
    T2 -.-> UI3
    T2 -.-> UI5

    %% Click Events
    click A1 "https://github.com/darktt/logosearch/blob/main/LogoSearch/AppDelegate.swift"
    click A2 "https://github.com/darktt/logosearch/blob/main/LogoSearch/SceneDelegate.swift"
    click RC1 "https://github.com/darktt/logosearch/blob/main/LogoSearch/Redux/Store.swift"
    click RC2 "https://github.com/darktt/logosearch/blob/main/LogoSearch/ViewModel/LogoSearchAction.swift"
    click RC3 "https://github.com/darktt/logosearch/blob/main/LogoSearch/ViewModel/ApiMiddware.swift"
    click RC4 "https://github.com/darktt/logosearch/blob/main/LogoSearch/ViewModel/ErrorMiddware.swift"
    click RC5 "https://github.com/darktt/logosearch/blob/main/LogoSearch/ViewModel/ImageLoaderMiddware.swift"
    click RC6 "https://github.com/darktt/logosearch/blob/main/LogoSearch/ViewModel/LogoSearchState.swift"
    click UI1 "https://github.com/darktt/logosearch/blob/main/LogoSearch/Main/MainViewController.swift"
    click UI2 "https://github.com/darktt/logosearch/blob/main/LogoSearch/Main/MainViewController.xib"
    click UI3 "https://github.com/darktt/logosearch/blob/main/LogoSearch/LogoDetail/LogoDetailViewController.swift"
    click UI4 "https://github.com/darktt/logosearch/blob/main/LogoSearch/LogoDetail/LogoDetailViewController.xib"
    click UI5 "https://github.com/darktt/logosearch/blob/main/LogoSearch/SearchLogo/SearchViewController.swift"
    click UI6 "https://github.com/darktt/logosearch/blob/main/LogoSearch/SearchLogo/SearchViewController.xib"
    click M1 "https://github.com/darktt/logosearch/tree/main/LogoSearch/Models"
    click U1 "https://github.com/darktt/logosearch/blob/main/LogoSearch/Extensions/ViewControllerExtension.swift"
    click U2 "https://github.com/darktt/logosearch/tree/main/LogoSearch/Protocols"
    click U3 "https://github.com/darktt/logosearch/blob/main/Frameworks/SwiftExtensions.xcframework"
    click T1 "https://github.com/darktt/logosearch/blob/main/LogoSearchTests/LogoSearchTests.swift"
    click T2 "https://github.com/darktt/logosearch/blob/main/LogoSearchUITests/LogoSearchUITests.swift"

    %% Styles
    classDef lifecycle fill:#FFDDC1,stroke:#D2691E,stroke-width:2px;
    classDef redux fill:#C1FFC1,stroke:#2E8B57,stroke-width:2px;
    classDef ui fill:#C1D4FF,stroke:#4169E1,stroke-width:2px;
    classDef models fill:#FFE0B2,stroke:#FF8C00,stroke-width:2px;
    classDef utilities fill:#D1C4E9,stroke:#6A5ACD,stroke-width:2px;
    classDef testing fill:#FFCDD2,stroke:#CD5C5C,stroke-width:2px;
```
