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 | A Swift sample with the source-visible chain OrigamiApp → ContentView → TutorialTemplateStore → GlyphRevealTextRenderer → FoundationModels APIs. |
| Main patterns | Central store, Binding-based state propagation |
| Project style | 61 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries. |
| Execution model | Source-visible boundaries: Sendable or @Sendable, async declaration or closure, @MainActor, Task; none alone proves a background thread. |
| State/event model | Source-visible mechanisms: @Observable, SwiftUI state property wrapper. |
| Key frameworks/packages | SwiftUI, Foundation, FoundationModels, SwiftData, os; these are source dependencies, not architecture labels. |
Project structure
Source bundle/
└── Origami/
├── OrigamiApp.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
flowchart LR
N1["OrigamiApp"]
N2["ContentView"]
N3["TutorialTemplateStore"]
N4["GlyphRevealTextRenderer"]
N5["FoundationModels APIs"]
N1 --> N2
N2 --> N3
N3 --> N4
N4 --> N5
Reference code
Origami/OrigamiApp.swift:12 — architecture anchor
@main
struct OrigamiApp: App {
// Store the data model in app state so SwiftUI creates and owns a single
// instance for the lifetime of the app.
@State private var dataModel = DataModel()
var body: some Scene {
WindowGroup {
ContentView()
.task {
do {
try dataModel.prepareData()
} catch {
logger.error("Failed to prepare the app's data: \(error)")
}
}
}
// Add the model container to the environment so views can query and update SwiftData.
.modelContainer(dataModel.modelContainer)
}
}Interpretation
The arrows summarize the source-visible entry, role-named types or folders, and framework direction; when nodes come from structural folders, the sequence is a high-level interpretation rather than proof that every adjacent node calls the next. Ownership is claimed only where the next section cites a stored property or assignment. The diagram is intentionally limited to the dominant path into Foundation Models.
Ownership and state
classDiagram
BrainstormOptionRow *-- Int : index
BrainstormOptionRow o-- BrainstormIdea : idea
BrainstormModel o-- Project : project
BrainstormModel o-- ModelContext : modelContext
Ownership evidence
Origami/Brainstorm/BrainstormView.swift:106 — stored dependency or nearest verified ownership anchor
struct BrainstormOptionRow: View {
let index: Int
// ...
}| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
BrainstormOptionRow |
Int (index) |
owns value state | Initialized by the owner; the binding is immutable |
BrainstormOptionRow |
BrainstormIdea (idea) |
stores or receives | Initialized by the owner; the binding is immutable |
BrainstormModel |
Project (project) |
stores or receives | Initialized by the owner; the binding is immutable |
BrainstormModel |
ModelContext (modelContext) |
stores or receives | Initialized by the owner; the binding is immutable |
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.
Concurrency, scheduling, and thread safety
Evidence limit: actor isolation, async/await, or Task creation does not by itself prove background-thread execution; Sendable conformance alone does not prove thread-safe mutation.
| Concern | Source mechanism | Verified placement or handoff | Evidence |
|---|---|---|---|
| Transfer contract | Sendable or @Sendable |
The source declares a sendability boundary; this alone does not synchronize mutable state. | Origami/Brainstorm/BrainstormIdea.swift:12 |
| Suspension boundary | async declaration or closure |
The source declares or crosses an asynchronous boundary; it does not by itself establish background execution. | Origami/Brainstorm/BrainstormInstructions.swift:76 |
| Main isolation | @MainActor |
The cited annotation marks its attached declaration or closure as main-actor isolated. | Origami/Models/DataModels/DataModel.swift:11 |
| Task creation | Task |
The source creates an unstructured task; surrounding context determines inherited actor isolation. | Origami/Models/Orchestrator.swift:173 |
@MainActor/MainActor.run, DispatchQueue.main, and RunLoop.main are reported as distinct isolation, queue, and event-loop mechanisms. A plain Task is kept separate from Task.detached; neither is labeled as a background thread.
Reference code
Origami/Brainstorm/BrainstormIdea.swift:12 — representative execution boundary
@Generable(description: "A single brainstorm idea")
struct BrainstormIdea: Identifiable, Sendable {
let id = UUID()
var title: String
var description: String
}State propagation, frameworks, and dependencies
Evidence limit: an import proves a source-level compilation dependency at the cited line; it does not prove runtime use, architectural adoption, or whether a Swift package is a direct application dependency.
| Category | Mechanism or module | Verified role | Evidence |
|---|---|---|---|
| State propagation | @Observable |
Observation macro publishes source-visible changes. | Origami/Brainstorm/BrainstormModel.swift:16 |
| State propagation | SwiftUI state property wrapper |
A SwiftUI property wrapper supplies or observes UI state. | Origami/Brainstorm/BrainstormView.swift:12 |
| Source import | SwiftUI |
The cited file imports this module; runtime use and architectural role are not inferred. | Origami/Brainstorm/BrainstormModel.swift:14 |
| Source import | Foundation |
The cited file imports this module; runtime use and architectural role are not inferred. | Origami/Brainstorm/BrainstormIdea.swift:8 |
| Source import | FoundationModels |
The cited file imports this module; runtime use and architectural role are not inferred. | Origami/Brainstorm/BrainstormIdea.swift:9 |
| Source import | SwiftData |
The cited file imports this module; runtime use and architectural role are not inferred. | Origami/Brainstorm/BrainstormModel.swift:13 |
| Source import | os |
The cited file imports this module; runtime use and architectural role are not inferred. | Origami/Brainstorm/BrainstormModel.swift:12 |
| Source import | Observation |
The cited file imports this module; runtime use and architectural role are not inferred. | Origami/Brainstorm/BrainstormModel.swift:11 |
receive(on:) describes downstream delivery scheduling, while subscribe(on:) describes upstream subscription/request/cancel scheduling. An import Combine alone establishes neither behavior nor a Store, reducer, Redux, or other application architecture.
Class and protocol design
Origami/OrigamiApp.swift:13 — representative type boundary
@main
struct OrigamiApp: App {
// ...
@State private var dataModel = DataModel()
// ...
}| Type | Responsibility | Depends on or conforms to |
|---|---|---|
OrigamiApp |
Application entry and top-level composition | App |
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 |
|---|---|---|---|
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] {
guard let data,
let snapshots = try? JSONDecoder().decode([IdeaSnapshot].self, from: data)
// ...
}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. |
| 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 |
|---|---|---|
| Central store | Origami/Models/DataModels/TutorialTemplateStore.swift:10 |
A store-named type centralizes feature state or persistence. |
| Binding-based state propagation | Origami/Coach/CoachView.swift:98 |
A binding exposes controlled read/write access while the upstream owner remains authoritative. |
Naming conventions
- Types: App: OrigamiApp; 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
OrigamiAppis the main source-visible entry or composition anchor for this sample.- Framework work reaches SwiftUI, FoundationModels, SwiftData, PhotosUI through a deliberately small high-level chain; the detailed API graph remains inside the cited implementation files.
- 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 |
Cited implementation, OrigamiApp |
Origami/Brainstorm/BrainstormView.swift |
Cited implementation, SwiftUI state property wrapper, BrainstormView, BrainstormResultCard, BrainstormOptionRow, BrainstormSelectionButtons, BrainstormActionRow, StartTutorialButton |
Origami/Brainstorm/BrainstormModel.swift |
Cited implementation, @Observable, SwiftUI, SwiftData, os, Observation, BrainstormModel, State, IdeaSnapshot |
Origami/Models/DataModels/TutorialTemplateStore.swift |
TutorialTemplateStore |
Origami/Coach/CoachView.swift |
Cited implementation, CoachView, CoachActionRow, MoveStepConfirmRow |
Origami/Brainstorm/BrainstormIdea.swift |
Sendable or @Sendable, Foundation, FoundationModels, BrainstormIdea, BrainstormIdeaList |
Origami/Brainstorm/BrainstormInstructions.swift |
async declaration or closure, BrainstormInstructions |
Origami/Models/DataModels/DataModel.swift |
@MainActor, DataModel |
Origami/Models/Orchestrator.swift |
Task, Orchestrator |
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/Coach/CoachModel.swift |
CoachModel, State, StepKey |
Origami/Terms/TermModel.swift |
TermModel, State, Turn |