# 3lvis/viewer architecture

> Architecture diagram of the GitHub repository 3lvis/viewer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/3lvis/viewer
- Repository: https://github.com/3lvis/viewer

## Overview

Viewer is a Swift media-viewing library for iOS and tvOS. The principal workflow is that an app selects a Viewable item and presents ViewerController; it obtains items from the app’s data source, pages among them, and displays image or video content with browsing controls. The repository also includes a photo-gallery demo with local and remote collections. README documents focus, rotation, image zoom, and tvOS support; the excerpts show the main viewer, paging, slideshow, and media-display components. Relationships in the demo beyond those listed in the source index are omitted where their calls were not shown.

Main entry points: [`Source/ViewerController.swift`](https://github.com/3lvis/viewer/blob/master/Source/ViewerController.swift) (ViewerController), [`Library/PhotosController.swift`](https://github.com/3lvis/viewer/blob/master/Library/PhotosController.swift) (PhotosController), [`Source/ViewableController.swift`](https://github.com/3lvis/viewer/blob/master/Source/ViewableController.swift) (ViewableController), [`Source/Viewable.swift`](https://github.com/3lvis/viewer/blob/master/Source/Viewable.swift) (Viewable contract)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_viewer["Viewer orchestration"]
  node_viewercontroller["ViewerController"]
  node_pagination["Paginated browsing"]
  node_slideshow["Slideshow"]
  node_container["Controller container"]
end

subgraph group_display["Media display"]
  node_itemcontroller["ViewableController"]
  node_videoview["Video playback<br/>[VideoView.swift]"]
  node_progress["Video progress"]
  node_defaultheader["Default header"]
end

subgraph group_demo["Gallery demo"]
  node_gallery["PhotosController"]
  node_cell["Photo cell<br/>[PhotoCell.swift]"]
  node_layout["Collection layout"]
  node_header["Gallery header<br/>[HeaderView.swift]"]
  node_footer["Gallery footer<br/>[FooterView.swift]"]
end

subgraph group_media["Media model"]
  node_photo["Photo model<br/>[Photo.swift]"]
  node_viewable["Viewable contract<br/>[Viewable.swift]"]
end

node_app(("App user"))
node_photo_library[("Apple Photos")]
node_avfoundation["AV playback APIs"]

node_app -->|"selects media"| node_gallery
node_app -->|"presents viewer"| node_viewercontroller
node_gallery -->|"creates viewer"| node_viewercontroller
node_gallery -->|"provides items"| node_photo
node_gallery -->|"configures cell"| node_cell
node_gallery -.->|"uses layout"| node_layout
node_gallery -.->|"uses header"| node_header
node_gallery -->|"uses footer"| node_footer
node_photo -->|"implements"| node_viewable
node_photo -->|"fetches assets"| node_photo_library
node_viewercontroller -->|"requests items"| node_viewable
node_viewercontroller -->|"configures paging"| node_pagination
node_viewercontroller -->|"configures slideshow"| node_slideshow
node_viewercontroller -->|"implements data source"| node_container
node_viewercontroller -->|"creates controllers"| node_itemcontroller
node_pagination -->|"requests pages"| node_container
node_slideshow -->|"requests pages"| node_container
node_slideshow -->|"displays controllers"| node_itemcontroller
node_itemcontroller -->|"loads media"| node_viewable
node_itemcontroller -->|"controls playback"| node_videoview
node_itemcontroller -->|"updates progress"| node_progress
node_videoview -->|"prepares media"| node_viewable
node_videoview -->|"plays video"| node_avfoundation
node_defaultheader -.->|"integrates controls"| node_viewercontroller

click node_gallery "https://github.com/3lvis/viewer/blob/master/Library/PhotosController.swift"
click node_photo "https://github.com/3lvis/viewer/blob/master/Library/Photo.swift"
click node_viewable "https://github.com/3lvis/viewer/blob/master/Source/Viewable.swift"
click node_viewercontroller "https://github.com/3lvis/viewer/blob/master/Source/ViewerController.swift"
click node_pagination "https://github.com/3lvis/viewer/blob/master/Source/PaginatedScrollView.swift"
click node_slideshow "https://github.com/3lvis/viewer/blob/master/Source/SlideshowView.swift"
click node_container "https://github.com/3lvis/viewer/blob/master/Source/ViewableControllerContainer.swift"
click node_itemcontroller "https://github.com/3lvis/viewer/blob/master/Source/ViewableController.swift"
click node_videoview "https://github.com/3lvis/viewer/blob/master/Source/VideoView.swift"
click node_progress "https://github.com/3lvis/viewer/blob/master/Source/VideoProgressView.swift"
click node_defaultheader "https://github.com/3lvis/viewer/blob/master/Source/DefaultHeaderView.swift"
click node_cell "https://github.com/3lvis/viewer/blob/master/Library/PhotoCell.swift"
click node_layout "https://github.com/3lvis/viewer/blob/master/Library/PhotosCollectionLayout.swift"
click node_header "https://github.com/3lvis/viewer/blob/master/Library/HeaderView.swift"
click node_footer "https://github.com/3lvis/viewer/blob/master/Library/FooterView.swift"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_viewercontroller,node_pagination,node_slideshow,node_container,node_app toneBlue
class node_itemcontroller,node_videoview,node_progress,node_defaultheader,node_photo_library toneAmber
class node_gallery,node_cell,node_layout,node_header,node_footer,node_avfoundation toneMint
class node_photo,node_viewable toneRose
```

## Components

### Viewer orchestration

- [ViewerController](https://github.com/3lvis/viewer/blob/master/Source/ViewerController.swift): `Source/ViewerController.swift`
- [Paginated browsing](https://github.com/3lvis/viewer/blob/master/Source/PaginatedScrollView.swift): `Source/PaginatedScrollView.swift`
- [Slideshow](https://github.com/3lvis/viewer/blob/master/Source/SlideshowView.swift): `Source/SlideshowView.swift`
- [Controller container](https://github.com/3lvis/viewer/blob/master/Source/ViewableControllerContainer.swift): `Source/ViewableControllerContainer.swift`

### Media display

- [ViewableController](https://github.com/3lvis/viewer/blob/master/Source/ViewableController.swift): `Source/ViewableController.swift`
- [Video playback](https://github.com/3lvis/viewer/blob/master/Source/VideoView.swift): `Source/VideoView.swift`
- [Video progress](https://github.com/3lvis/viewer/blob/master/Source/VideoProgressView.swift): `Source/VideoProgressView.swift`
- [Default header](https://github.com/3lvis/viewer/blob/master/Source/DefaultHeaderView.swift): `Source/DefaultHeaderView.swift`

### Gallery demo

- [PhotosController](https://github.com/3lvis/viewer/blob/master/Library/PhotosController.swift): `Library/PhotosController.swift`
- [Photo cell](https://github.com/3lvis/viewer/blob/master/Library/PhotoCell.swift): `Library/PhotoCell.swift`
- [Collection layout](https://github.com/3lvis/viewer/blob/master/Library/PhotosCollectionLayout.swift): `Library/PhotosCollectionLayout.swift`
- [Gallery header](https://github.com/3lvis/viewer/blob/master/Library/HeaderView.swift): `Library/HeaderView.swift`
- [Gallery footer](https://github.com/3lvis/viewer/blob/master/Library/FooterView.swift): `Library/FooterView.swift`

### Media model

- [Photo model](https://github.com/3lvis/viewer/blob/master/Library/Photo.swift): `Library/Photo.swift`
- [Viewable contract](https://github.com/3lvis/viewer/blob/master/Source/Viewable.swift): `Source/Viewable.swift`

### Other components

- **App user**
- **Apple Photos**
- **AV playback APIs**

## Connections

- App user → PhotosController: selects media (evidence: `README.md`)
- App user → ViewerController: presents viewer (evidence: `README.md`)
- PhotosController → ViewerController: creates viewer (evidence: `Library/PhotosController.swift`)
- PhotosController → Photo model: provides items (evidence: `Library/PhotosController.swift`)
- PhotosController → Photo cell: configures cell (evidence: `Library/PhotosController.swift`)
- PhotosController → Collection layout: uses layout (evidence: `Library/PhotosController.swift`)
- PhotosController → Gallery header: uses header (evidence: `Library/PhotosController.swift`)
- PhotosController → Gallery footer: uses footer (evidence: `Library/PhotosController.swift`)
- Photo model → Viewable contract: implements (evidence: `Library/Photo.swift`)
- Photo model → Apple Photos: fetches assets (evidence: `Library/Photo.swift`)
- ViewerController → Viewable contract: requests items (evidence: `Source/ViewerController.swift`)
- ViewerController → Paginated browsing: configures paging (evidence: `Source/ViewerController.swift`)
- ViewerController → Slideshow: configures slideshow (evidence: `Source/ViewerController.swift`)
- ViewerController → Controller container: implements data source (evidence: `Source/ViewerController.swift`)
- ViewerController → ViewableController: creates controllers (evidence: `Source/ViewerController.swift`)
- Paginated browsing → Controller container: requests pages (evidence: `Source/PaginatedScrollView.swift`)
- Slideshow → Controller container: requests pages (evidence: `Source/SlideshowView.swift`)
- Slideshow → ViewableController: displays controllers (evidence: `Source/SlideshowView.swift`)
- ViewableController → Viewable contract: loads media (evidence: `Source/ViewableController.swift`)
- ViewableController → Video playback: controls playback (evidence: `Source/ViewableController.swift`)
- ViewableController → Video progress: updates progress (evidence: `Source/ViewableController.swift`)
- Video playback → Viewable contract: prepares media (evidence: `Source/VideoView.swift`)
- Video playback → AV playback APIs: plays video (evidence: `Source/VideoView.swift`)
- Default header → ViewerController: integrates controls (evidence: `Source/ViewerController.swift`)
