# kean/nuke architecture

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

- Interactive diagram: https://gitdiagram.com/kean/nuke
- Repository: https://github.com/kean/nuke

## Overview

##### Project type and purpose
- This is a native Swift image‐loading framework (not a full-stack app).
- It provides a core “ImagePipeline” (Sources/Nuke) plus three higher-level modules:
- NukeUI – SwiftUI & UIKit/AppKit image views
- NukeExtensions – convenience extensions for UIImageView/AppKit
- NukeVideo – video decoding & playback helpers

##### File structure
- Top-level directories:
- .scripts – CI, linting, testing, build helpers
- Documentation – guides, API docs, migration notes
- Sources – four modules: Nuke, NukeUI, NukeExtensions, NukeVideo
- Tests – thousands of unit, performance, thread-safety, UI tests
- Inside Sources/Nuke: clearly defined subpackages for Caching, Decoding, Encoding, Loading, Pipeline orchestration, Prefetching, Processing, Tasks, Internal utilities

##### Extract architectural clues from README
- Core abstraction: ImagePipeline + ImageTask + ImageRequest + ImageResponse
- Key features: memory/disk cache, request coalescing, priority, progressive JPEG, async/await & Combine, extensibility points (plugins for networking, codecs)

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "UI Modules"
        subgraph "NukeUI (SwiftUI & UIKit)" 
            FetchImage["FetchImage"]:::ui
            LazyImage["LazyImage"]:::ui
        end
        ImageViewExt["UIImageView Extensions"]:::ext
    end

    subgraph "Core Pipeline"
        Pipeline["ImagePipeline"]:::core
        TaskManager["Task Manager"]:::core
        ImageRequest["ImageRequest"]:::core
        ImageResponse["ImageResponse"]:::core
        ImageTask["ImageTask"]:::core
        AsyncPipelineTask["AsyncPipelineTask"]:::core
        AsyncTask["AsyncTask"]:::core
    end

    subgraph "Cache Layer"
        MemoryCache["MemoryCache"]:::cache
        DiskCache["DataCache (Disk)"]:::cache
    end

    subgraph "Loading Layer"
        DataLoader["URLSessionDataLoader / DataLoaderProtocol"]:::load
    end

    subgraph "Decoding Layer"
        DecoderRegistry["ImageDecoderRegistry"]:::decode
    end

    subgraph "Processing Layer"
        Processing["ImageProcessors"]:::process
    end

    subgraph "Encoding Layer"
        Encoding["ImageEncoders (Optional)"]:::encode
    end

    Prefetcher["ImagePrefetcher"]:::prefetch

    subgraph "Plugin Points"
        NetworkingPlugin["Networking Plugin"]:::plugin
        FormatPlugin["Format Plugin"]:::plugin
    end

    %% Connections
    FetchImage -->|"calls imageTask"| Pipeline
    LazyImage -->|"calls imageTask"| Pipeline
    ImageViewExt -->|"calls imageTask"| Pipeline

    Pipeline --> ImageRequest
    Pipeline --> TaskManager
    TaskManager --> ImageTask
    Pipeline --> AsyncPipelineTask
    AsyncPipelineTask --> AsyncTask
    TaskManager --> AsyncTask

    Pipeline -->|1 check cache| MemoryCache
    MemoryCache -->|2 check cache| DiskCache
    DiskCache -->|3 miss| DataLoader
    DataLoader -->|4 load data| DecoderRegistry
    DecoderRegistry -->|5 decode| Processing
    Processing -->|6 process| Encoding
    Processing -->|update cache| MemoryCache
    Encoding -->|7 encode| DiskCache
    Encoding -->|return| ImageResponse
    ImageResponse -->|deliver| FetchImage

    Prefetcher -->|"enqueues"| Pipeline

    Pipeline -.-> NetworkingPlugin
    Pipeline -.-> FormatPlugin

    %% Click Events
    click Pipeline "https://github.com/kean/nuke/blob/main/Sources/Nuke/Pipeline/ImagePipeline.swift"
    click ImageRequest "https://github.com/kean/nuke/blob/main/Sources/Nuke/ImageRequest.swift"
    click ImageResponse "https://github.com/kean/nuke/blob/main/Sources/Nuke/ImageResponse.swift"
    click ImageTask "https://github.com/kean/nuke/blob/main/Sources/Nuke/ImageTask.swift"
    click AsyncPipelineTask "https://github.com/kean/nuke/blob/main/Sources/Nuke/Tasks/AsyncPipelineTask.swift"
    click AsyncTask "https://github.com/kean/nuke/blob/main/Sources/Nuke/Tasks/AsyncTask.swift"
    click MemoryCache "https://github.com/kean/nuke/blob/main/Sources/Nuke/Caching/ImageCache.swift"
    click DiskCache "https://github.com/kean/nuke/blob/main/Sources/Nuke/Caching/DataCache.swift"
    click DataLoader "https://github.com/kean/nuke/blob/main/Sources/Nuke/Loading/DataLoader.swift"
    click DecoderRegistry "https://github.com/kean/nuke/blob/main/Sources/Nuke/Decoding/ImageDecoderRegistry.swift"
    click Processing "https://github.com/kean/nuke/blob/main/Sources/Nuke/Processing/ImageProcessing.swift"
    click Encoding "https://github.com/kean/nuke/blob/main/Sources/Nuke/Encoding/ImageEncoders.swift"
    click Prefetcher "https://github.com/kean/nuke/blob/main/Sources/Nuke/Prefetching/ImagePrefetcher.swift"
    click FetchImage "https://github.com/kean/nuke/blob/main/Sources/NukeUI/FetchImage.swift"
    click LazyImage "https://github.com/kean/nuke/blob/main/Sources/NukeUI/LazyImage.swift"
    click ImageViewExt "https://github.com/kean/nuke/blob/main/Sources/NukeExtensions/ImageViewExtensions.swift"

    %% Styles
    classDef core fill:#bbdefb,stroke:#1e88e5,color:#0d47a1
    classDef cache fill:#c5e1a5,stroke:#558b2f,color:#33691e
    classDef load fill:#ffe082,stroke:#f57f17,color:#bf360c
    classDef decode fill:#bbdefb,stroke:#1e88e5,color:#0d47a1
    classDef process fill:#bbdefb,stroke:#1e88e5,color:#0d47a1
    classDef encode fill:#bbdefb,stroke:#1e88e5,color:#0d47a1
    classDef ui fill:#c8e6c9,stroke:#2e7d32,color:#1b5e20
    classDef ext fill:#c8e6c9,stroke:#2e7d32,color:#1b5e20
    classDef plugin fill:#ffe0b2,stroke:#ef6c00,color:#e65100
    classDef prefetch fill:#bbdefb,stroke:#1e88e5,color:#0d47a1
```
