Sample CodeiOS, iPadOS, Mac Catalyst, macOSReviewed 2026-07-26View on Apple Developer

Origami: Crafting a dynamic tutorial for Apple Intelligence

At a glance

Item Summary
Purpose Build interactive experiences with Foundation Models and Private Cloud Compute using multimodal prompts.
App architecture OrigamiApp composes SwiftUI around an observable Orchestrator, which owns feature models, reduces events into effects, and executes Foundation Models work.
Main patterns Reducer-style event-effect orchestration, Binding-based state propagation, Actor-isolated state, Static cache
Project style 61 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries.

Project structure

Source bundle/
└── Origami/
    ├── OrigamiApp.swift
    ├── Models/
    │   ├── Orchestrator.swift
    │   └── OrchestratorState.swift
    ├── Brainstorm/
    │   ├── BrainstormView.swift
    │   └── BrainstormModel.swift
    ├── Terms/
    │   ├── TermView.swift
    │   └── TermModel.swift
    ├── Tutorial/
    │   ├── Views/
    │   │   └── TutorialStepTextView.swift
    │   ├── Models/
    │   │   └── TutorialGenerationModel.swift
    │   └── Intelligence/
    │       └── CraftTools.swift
    ├── Projects/
    │   └── LibraryView.swift
    ├── UI/
    │   └── Photos/
    │       └── PhotoView.swift
    └── Coach/
        ├── CoachModel.swift
        └── CoachView.swift

Structure observations

  • Architecturally prominent files are ranked from entry points and role-named declarations; resource-only paths are omitted.
  • Primary languages: Swift.
  • The verified tree contains 4 project/configuration file(s) and 134 source declaration(s).

Overall architecture

Reference code

Origami/Models/Orchestrator.swift:16 — architecture anchor

@Observable
final class Orchestrator {
    let brainstorm: BrainstormModel
    let tutorial: TutorialGenerationModel
    let coach: CoachModel
    let term: TermModel

    var state: OrchestratorState {
        // ...
    }
    // ...
}

Interpretation

The diagram shows the dominant event and state path, not every model or tool. Views send typed events to one observable owner. That owner mutates its state and child models, returns effect values, and executes those effects against its shared language-model session.

Ownership and state

Ownership evidence

Origami/Models/Orchestrator.swift:69 — stored dependency or nearest verified ownership anchor

init(project: Project, modelContext: ModelContext) {
    self.project = project
    self.state = OrchestratorState(
        mode: project.tutorialJSON != nil ? .tutorial : .brainstorm
    )
    self.brainstorm = BrainstormModel(
        project: project,
        modelContext: modelContext
    )
    // ...
}
Owner Object or state Relationship Mutation authority
Orchestrator Project (project) stores a dependency received at initialization The project/model layer remains authoritative for persisted project data
Orchestrator OrchestratorState (state) owns observable value state Orchestrator.reduce(_:) mutates it
Orchestrator BrainstormModel, TutorialGenerationModel, CoachModel, TermModel creates and strongly owns feature models Orchestrator coordinates cross-feature mutation; each model owns its local details
Orchestrator LanguageModelSession (session) privately owns a lazy shared framework session Only Orchestrator can access or replace the session

Composition arrows indicate a source-visible construction expression or locally owned value state; aggregation means the owner stores or receives a dependency without proving exclusive lifetime ownership.

Class and protocol design

Origami/OrigamiApp.swift:13 — representative type boundary

struct OrigamiApp: App {
    // ...
}
Type Responsibility Depends on or conforms to
OrigamiApp Application entry and top-level composition App
Orchestrator Owns shared feature state, dispatch, reduction, and effect execution Project, feature models, LanguageModelSession
OrchestratorEvent Defines the closed set of inputs accepted by the orchestrator Event payload model types
OrchestratorState Stores the orchestrator’s top-level mode and selection state OrchestratorMode
OrchestratorEffect Defines deferred operations returned by reduction Event payload model types
BrainstormView User-interface presentation and input forwarding View
TermView User-interface presentation and input forwarding View
StatusView User-interface presentation and input forwarding View
TutorialStepTextView User-interface presentation and input forwarding View
TutorialTermView User-interface presentation and input forwarding View
GlyphRevealTextRenderer Owns drawing, GPU, or presentation processing TextRenderer, Animatable
LibraryView User-interface presentation and input forwarding View
LibraryEmptyView User-interface presentation and input forwarding View
PhotoView User-interface presentation and input forwarding View

No local protocol conformance is claimed as protocol-oriented design; external framework conformances are listed only as dependencies.

Access control

Symbol Access Verified effect Likely rationale
session (Origami/Models/Orchestrator.swift:42) private Use is restricted to Orchestrator and its same-file extensions. Keep the shared conversation lifetime and mutation behind one owner.
reduce (Origami/Models/Orchestrator.swift:181) private Only Orchestrator can translate events into state changes and effects. Preserve a single mutation path behind public send(_:).
execute (Origami/Models/Orchestrator.swift:283) private Only Orchestrator can execute returned effects. Prevent views from bypassing dispatch and calling orchestration effects directly.
decodeIdeas (Origami/Brainstorm/BrainstormModel.swift:47) private Use is restricted to the lexical declaration and same-file extensions allowed by Swift. Inference: hide an implementation step that is not part of the collaboration surface.
cacheIdeasOnProject (Origami/Brainstorm/BrainstormModel.swift:56) private Use is restricted to the lexical declaration and same-file extensions allowed by Swift. Inference: hide an implementation step that is not part of the collaboration surface.
orchestrator (Origami/Brainstorm/BrainstormView.swift:12) private Use is restricted to the lexical declaration and same-file extensions allowed by Swift. Inference: keep state mutation or dependency lifetime inside the owning implementation.
orchestrator (Origami/Brainstorm/BrainstormView.swift:44) private Use is restricted to the lexical declaration and same-file extensions allowed by Swift. Inference: keep state mutation or dependency lifetime inside the owning implementation.

Reference code

Origami/Brainstorm/BrainstormModel.swift:47 — representative boundary

    private static func decodeIdeas(from data: Data?) -> [BrainstormIdea] {
        // ...
    }

Swift declarations without a modifier are internal; explicit private, fileprivate, private(set), public, or open entries above are interpreted by language semantics. Objective-C/C samples instead rely on header and implementation boundaries, which are not equivalent to Swift lexical privacy.

Logic ownership and placement

Logic Owning type or file Placement rationale
Application entry and top-level composition OrigamiApp The source’s App suffix makes this role explicit.
Event dispatch, state transition, and effect execution Orchestrator One observable owner exposes send(_:), keeps reduce(_:) and execute(_:) private, and owns the shared session.
Feature data or observable state BrainstormModel, CoachModel, DataModel, ProjectModel The source’s Model suffix makes this role explicit.
Owns capture or recording work TranscriptRecorder The source’s Recorder suffix makes this role explicit.
Owns drawing, GPU, or presentation processing GlyphRevealTextRenderer The source’s Renderer suffix makes this role explicit.
Centralized state or persistence access TutorialTemplateStore The source’s Store suffix makes this role explicit.
User-interface presentation and input forwarding BrainstormView, ButtonBackgroundView, CheckMarkView, CoachView The source’s View suffix makes this role explicit.

Design patterns

Pattern Source evidence Purpose or tradeoff
Reducer-style event-effect orchestration Origami/Models/Orchestrator.swift:165, Origami/Models/OrchestratorState.swift:14 Typed events enter send(_:); private reduction mutates state and returns typed effects; the same owner executes them.
Static cache Origami/Models/DataModels/TutorialTemplateStore.swift:10 An enum namespace owns a private static tutorial-template cache.
Binding-based state propagation Origami/Coach/CoachView.swift:98 A binding exposes controlled read/write access while the upstream owner remains authoritative.
Actor-isolated state Origami/Models/DataModels/DataModel.swift:11 Actor annotations make the concurrency ownership boundary explicit.

Reducer-loop reference code

Origami/Models/Orchestrator.swift:165 — event dispatch remains the only public orchestration entry

func send(_ event: OrchestratorEvent) {
    // ...
    let effects = reduce(event)
    guard !effects.isEmpty else { return }
    currentTask = Task {
        for effect in effects {
            await execute(effect)
            // ...
        }
    }
}

TutorialTemplateStore is separate from the event/effect loop: it is an enum namespace around a private static template cache.

Naming conventions

  • Types: App: OrigamiApp; Orchestrator: Orchestrator; Event/State/Effect: OrchestratorEvent, OrchestratorState, OrchestratorEffect; Model: BrainstormModel, CoachModel, DataModel, ProjectModel, SettingsModel; Recorder: TranscriptRecorder; Renderer: GlyphRevealTextRenderer; Store: TutorialTemplateStore; View: BrainstormView, ButtonBackgroundView, CheckMarkView, CoachView, ContentView.
  • Protocols: no local protocol declaration in the scanned source.
  • Methods: reduce, playReveal, draw, applyReorder, instantImage, photoImage, instantCaption, setCraftDomain.
  • Files: Origami/OrigamiApp.swift, Origami/Brainstorm/BrainstormView.swift, Origami/Terms/TermView.swift, Origami/Tutorial/Views/TutorialStepTextView.swift, Origami/Projects/LibraryView.swift, Origami/UI/Photos/PhotoView.swift.

Architecture takeaways

  • OrigamiApp is the main source-visible entry or composition anchor for this sample.
  • Orchestrator is the cross-feature owner: it receives typed events, mutates state, creates effects, and executes Foundation Models work.
  • The event/effect flow is deliberately centralized: the same owner mutates owner and child-model state, then executes the effects it returns.
  • TutorialTemplateStore is a cache namespace, while Orchestrator owns the feature event, state, and effect flow.
  • Stored-property evidence identifies lifecycle collaboration; it does not by itself prove exclusive object ownership.
  • Access-control conclusions separate verified language visibility from the likely design rationale.
  • The source does not justify labeling the design protocol-oriented.

Source map

Source file Relevant symbols
Origami/OrigamiApp.swift OrigamiApp
Origami/Models/Orchestrator.swift Orchestrator, send, reduce, execute
Origami/Models/OrchestratorState.swift OrchestratorMode, OrchestratorEvent, OrchestratorState, OrchestratorEffect
Origami/Brainstorm/BrainstormView.swift BrainstormView, BrainstormResultCard, BrainstormOptionRow, BrainstormSelectionButtons, BrainstormActionRow, StartTutorialButton
Origami/Terms/TermView.swift TermView, TermHeader, TermContent, StatusView, TermTurn
Origami/Tutorial/Views/TutorialStepTextView.swift TutorialStepTextView, TutorialTermButton, TermAnchorPreferenceKey, TutorialTermView, GlyphRevealTextRenderer
Origami/Projects/LibraryView.swift LibraryView, ProjectGrid, ArchivedHeader, LibraryEmptyView
Origami/UI/Photos/PhotoView.swift PhotoView, Style, InstantMetrics, InstantCaptionSkeleton
Origami/Tutorial/Models/TutorialGenerationModel.swift TutorialGenerationModel, State
Origami/Brainstorm/BrainstormModel.swift BrainstormModel, State, IdeaSnapshot
Origami/Coach/CoachModel.swift CoachModel, State, StepKey
Origami/Coach/CoachView.swift CoachView, CoachActionRow, MoveStepConfirmRow