Book Tracker: Using Evaluations to evaluate an intelligent feature
At a glance
| Item | Summary |
|---|---|
| Purpose | Measure and improve the quality of your app’s intelligence-powered features using the Evaluations framework. |
| App architecture | A Swift sample with the source-visible chain BookTrackerApp → ContentView → BookTaggingService → Evaluations APIs. |
| Main patterns | Service object, Binding-based state propagation, Actor isolation |
| Project style | 20 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries. |
| Execution model | Source-visible boundaries: await suspension point, @MainActor, actor, Sendable or @Sendable, Task; none alone proves a background thread. |
| State/event model | Source-visible mechanisms: SwiftUI state property wrapper. |
| Key frameworks/packages | SwiftUI, Foundation, FoundationModels, SwiftData, Evaluations; these are source dependencies, not architecture labels. |
Project structure
Source bundle/
├── DatasetExtractor/
│ └── main.swift
├── BookTracker/
│ ├── BookTrackerApp.swift
│ ├── Services/
│ │ ├── BookSearchTools.swift
│ │ └── BookTaggingService.swift
│ ├── Views/
│ │ ├── BookDetailView.swift
│ │ ├── LibraryView.swift
│ │ ├── SearchView.swift
│ │ └── AddBookView.swift
│ └── ContentView.swift
├── BookSampleGenerator/
│ └── main.swift
├── HillClimbingEvaluations/
│ └── ModelJudgeAlignmentEvaluation.swift
└── BookTrackerEvaluations/
└── SearchBooks.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 3 project/configuration file(s) and 47 source declaration(s).
Overall architecture
flowchart LR
N1["BookTrackerApp"]
N2["ContentView"]
N3["BookTaggingService"]
N4["Evaluations APIs"]
N1 --> N2
N2 --> N3
N3 --> N4
Reference code
BookTracker/BookTrackerApp.swift:12 — architecture anchor
@main
struct BookTrackerApp: App {
let container: ModelContainer = {
do {
let container = try ModelContainer(for: Book.self)
addSampleBooks(in: container.mainContext)
return container
} catch {
fatalError("Failed to create ModelContainer: \(error)")
}
}()
var body: some Scene {
WindowGroup {
ContentView()
}
.modelContainer(container)
}
}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 Evaluations.
Ownership and state
classDiagram
BookTrackerApp o-- ModelContainer : container
BookSearchCollector *-- Array : orderedIDs
BookSearchCollector *-- Set : seen
BookSnapshot *-- String : id
Ownership evidence
BookTracker/BookTrackerApp.swift:14 — stored dependency or nearest verified ownership anchor
let container: ModelContainer = {
// ...
let container = try ModelContainer(for: Book.self)
// ...
}()| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
BookTrackerApp |
ModelContainer (container) |
stores or receives | Initialized by the owner; the binding is immutable |
BookSearchCollector |
Array (orderedIDs) |
owns value state | Owning lexical scope |
BookSearchCollector |
Set (seen) |
owns value state | Owning lexical scope |
BookSnapshot |
String (id) |
owns value state | 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 |
|---|---|---|---|
| Suspension boundary | await suspension point |
The source declares or crosses an asynchronous boundary; it does not by itself establish background execution. | BookSampleGenerator/main.swift:67 |
| Main isolation | @MainActor |
The cited annotation marks its attached declaration or closure as main-actor isolated. | BookTracker/BookTrackerApp.swift:33 |
| Actor isolation | actor |
The cited type is actor-isolated; this does not select a background thread. | BookTracker/Services/BookSearchTools.swift:24 |
| Transfer contract | Sendable or @Sendable |
The source declares a sendability boundary; this alone does not synchronize mutable state. | BookTracker/Services/BookSearchTools.swift:42 |
| Task creation | Task |
The source creates an unstructured task; surrounding context determines inherited actor isolation. | BookTracker/Views/AddBookView.swift:106 |
@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
BookSampleGenerator/main.swift:67 — representative execution boundary
for try await sample in generator.run() {
// Access results during iteration.
expandedDataset.append(sample)
}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 | SwiftUI state property wrapper |
A SwiftUI property wrapper supplies or observes UI state. | BookTracker/ContentView.swift:41 |
| Source import | SwiftUI |
The cited file imports this module; runtime use and architectural role are not inferred. | BookTracker/BookTrackerApp.swift:9 |
| Source import | Foundation |
The cited file imports this module; runtime use and architectural role are not inferred. | BookSampleGenerator/main.swift:9 |
| Source import | FoundationModels |
The cited file imports this module; runtime use and architectural role are not inferred. | BookSampleGenerator/main.swift:10 |
| Source import | SwiftData |
The cited file imports this module; runtime use and architectural role are not inferred. | BookTracker/BookTrackerApp.swift:8 |
| Source import | Evaluations |
The cited file imports this module; runtime use and architectural role are not inferred. | BookSampleGenerator/main.swift:8 |
| Source import | BookTracker |
The cited file imports this module; runtime use and architectural role are not inferred. | BookTrackerEvaluations/BookTags.swift:12 |
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
BookTracker/BookTrackerApp.swift:13 — representative type boundary
@main
struct BookTrackerApp: App {
// ...
let container = try ModelContainer(for: Book.self)
// ...
}| Type | Responsibility | Depends on or conforms to |
|---|---|---|
BookTrackerApp |
Application entry and top-level composition | App |
DatasetExtractorCommand |
Represents or runs a user/system command | ParsableCommand |
BookDetailView |
User-interface presentation and input forwarding | View |
BookTagsView |
User-interface presentation and input forwarding | View |
BookTaggingService |
Framework-facing operations | Concrete collaborators/imported frameworks |
ContentView |
User-interface presentation and input forwarding | View |
LibraryView |
User-interface presentation and input forwarding | View |
SearchView |
User-interface presentation and input forwarding | View |
AddBookView |
User-interface presentation and input forwarding | View |
ResultKey |
Defines a closed set of feature states or choices | Concrete collaborators/imported frameworks |
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 |
|---|---|---|---|
addSampleBooks (BookTracker/BookTrackerApp.swift:34) |
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. |
books (BookTracker/ContentView.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. |
modelContext (BookTracker/ContentView.swift:41) |
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. |
orderedIDs (BookTracker/Services/BookSearchTools.swift:25) |
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
BookTracker/BookTrackerApp.swift:34 — representative boundary
@MainActor
private func addSampleBooks(in context: ModelContext) {
let existing = (try? context.fetch(FetchDescriptor<Book>())) ?? []
// ...
}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 | BookTrackerApp |
The source’s App suffix makes this role explicit. |
| Represents or runs a user/system command | DatasetExtractorCommand |
The source’s Command suffix makes this role explicit. |
| Framework-facing operations | BookTaggingService |
The source’s Service suffix makes this role explicit. |
| User-interface presentation and input forwarding | AddBookView, BookDetailView, BookTagsView, ContentView |
The source’s View suffix makes this role explicit. |
Design patterns
| Pattern | Source evidence | Purpose or tradeoff |
|---|---|---|
| Service object | BookTracker/Services/BookTaggingService.swift:20 |
A role-named service contains framework-facing operations. |
| Binding-based state propagation | BookTracker/Views/BookDetailView.swift:206 |
A binding exposes controlled read/write access while the upstream owner remains authoritative. |
| Actor isolation | BookTracker/Services/BookSearchTools.swift:24 |
A declared actor creates an explicit isolation boundary; its executor is not described as a background thread. |
Naming conventions
- Types: App: BookTrackerApp; Command: DatasetExtractorCommand; Service: BookTaggingService; View: AddBookView, BookDetailView, BookTagsView, ContentView, LibraryView.
- Protocols: no local protocol declaration in the scanned source.
- Methods:
run,extractPairs,extractPrompt,resolvedOutputURL,defaultOutputURL,addSampleBooks,add,call. - Files:
BookTracker/BookTrackerApp.swift,BookTracker/Views/BookDetailView.swift,BookTracker/Services/BookTaggingService.swift,BookTracker/ContentView.swift,BookTracker/Views/LibraryView.swift,BookTracker/Views/SearchView.swift.
Architecture takeaways
BookTrackerAppis the main source-visible entry or composition anchor for this sample.- Framework work reaches SwiftUI, FoundationModels, SwiftData, Evaluations 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 |
|---|---|
BookTracker/BookTrackerApp.swift |
Cited implementation, BookTrackerApp, @MainActor, SwiftUI, SwiftData |
BookTracker/ContentView.swift |
Cited implementation, SwiftUI state property wrapper, ContentView, BookDetailDestination |
BookTracker/Services/BookSearchTools.swift |
Cited implementation, BookSearchCollector, actor, Sendable or @Sendable, BookAssistant, BookSnapshot, SearchBooksArguments, GetBookDetailsArguments, FindSimilarBooksArguments, SearchBooksTool, GetBookDetailsTool, FindSimilarBooksTool, BookDetailsPayload |
BookTracker/Services/BookTaggingService.swift |
BookTaggingService, BookTags |
BookTracker/Views/BookDetailView.swift |
Cited implementation, BookDetailView, BookDetailHeader, BookReview, BookTagsView |
BookSampleGenerator/main.swift |
await suspension point, Foundation, FoundationModels, Evaluations, Feature implementation |
BookTracker/Views/AddBookView.swift |
Task, AddBookView |
BookTrackerEvaluations/BookTags.swift |
BookTracker, BookTaggingEvaluation, BookTagEvaluationTests |
DatasetExtractor/main.swift |
ResultKey, InputKey, OutputKey, DatasetExtractorCommand |
BookTracker/Views/LibraryView.swift |
LibraryView, BookCover |
BookTracker/Views/SearchView.swift |
SearchView, BookRow |
HillClimbingEvaluations/ModelJudgeAlignmentEvaluation.swift |
BundleToken, BookTagJudgmentValue, CodingKeys, BookTagJudgmentCalibration, BookTagJudgmentCalibrationTests |
BookTrackerEvaluations/SearchBooks.swift |
BookResult, BookResults, SearchToolEvaluations, SearchToolEvaluationsTest |
BookTracker/Models/Book.swift |
Book, CodingKeys |
BookTracker/Models/MockBooksModifier.swift |
MockBooksModifier |
BookTracker/Views/GeneratedBookCover.swift |
GeneratedBookCover, CoverColorScheme |