Fruta: Building a feature-rich app with SwiftUI
At a glance
| Item | Summary |
|---|---|
| Purpose | Create a shared codebase to build a multiplatform app that offers widgets and an App Clip. |
| App architecture | A Swift sample bundle with entry-bearing project variants Shared, Widgets, iOS, each leading to SwiftUI / StoreKit APIs. |
| Main patterns | Protocol-oriented abstraction, Coordinator, Builder, Publisher-backed observable state, Actor-isolated state |
| Project style | 56 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries. |
Project structure
Source bundle/
├── Shared/
│ ├── FrutaApp.swift
│ ├── Orders/
│ │ ├── OrderPlacedView.swift
│ │ └── RewardsView.swift
│ ├── Components/
│ │ ├── FlipView.swift
│ │ ├── StepperView.swift
│ │ └── BubbleView.swift
│ ├── Recipe/
│ │ └── RecipeView.swift
│ ├── Navigation/
│ │ ├── AppSidebarNavigation.swift
│ │ └── ContentView.swift
│ └── NutritionFacts/
│ └── NutritionFactView.swift
├── iOS/
│ └── FrutaAppClip.swift
└── Widgets/
└── FrutaWidgets.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 15 project/configuration file(s) and 78 source declaration(s).
Overall architecture
flowchart LR
Bundle["Sample bundle"]
V1["Shared"]
V2["Widgets"]
V3["iOS"]
Boundary["SwiftUI / StoreKit APIs"]
Bundle --> V1
V1 --> Boundary
Bundle --> V2
V2 --> Boundary
Bundle --> V3
V3 --> Boundary
Reference code
Shared/FrutaApp.swift:10 — architecture anchor
@main
struct FrutaApp: App {
// ...
}Interpretation
The branches represent separate entry-bearing project variants in the downloaded bundle, not runtime calls between those variants. Each branch is intentionally collapsed at the documented framework boundary; the detailed target-local flow remains in the cited files. Ownership is claimed only where the next section cites a stored property or assignment.
Ownership and state
classDiagram
FrutaApp *-- Model : model
FlipView o-- FlipViewSide : visibleSide
FlipView o-- Front : front
FlipView o-- Back : back
Ownership evidence
Shared/FrutaApp.swift:12 — stored dependency or nearest verified ownership anchor
@StateObject private var model = Model()| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
FrutaApp |
Model (model) |
owns wrapper-managed state | Owning lexical scope |
FlipView |
FlipViewSide (visibleSide) |
stores or receives | App/module collaborators |
FlipView |
Front (front) |
stores or receives | App/module collaborators |
FlipView |
Back (back) |
stores or receives | App/module collaborators |
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
Shared/NutritionFacts/UnitIcons.swift:22 — representative type boundary
private protocol UnitIconProvider {
var customUnitIcon: Image { get }
}| Type | Responsibility | Depends on or conforms to |
|---|---|---|
FrutaApp |
Application entry and top-level composition | App |
UnitIconProvider |
Defines a capability or collaboration contract | Concrete collaborators/imported frameworks |
OrderPlacedView |
User-interface presentation and input forwarding | View |
FlipView |
User-interface presentation and input forwarding | Concrete collaborators/imported frameworks |
StepperView |
User-interface presentation and input forwarding | View |
RecipeView |
User-interface presentation and input forwarding | View |
BubbleView |
User-interface presentation and input forwarding | View |
ContentView |
User-interface presentation and input forwarding | View |
NutritionFactView |
User-interface presentation and input forwarding | View |
RewardsView |
User-interface presentation and input forwarding | View |
The source explicitly defines local protocol relationships: Measurement → DisplayableMeasurement, UnitMass → UnitIconProvider, UnitVolume → UnitIconProvider.
Access control
| Symbol | Access | Verified effect | Likely rationale |
|---|---|---|---|
shimmer (Shared/Components/BubbleView.swift:16) |
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. |
shimmerDelay (Shared/Components/BubbleView.swift:17) |
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. |
float (Shared/Components/BubbleView.swift:19) |
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. |
floatDelay (Shared/Components/BubbleView.swift:20) |
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
Shared/Components/BubbleView.swift:16 — representative boundary
@State private var shimmer: Bool = .random()
@State private var shimmerDelay: Double = .random(in: 0.15...0.55)
@State private var float: Bool = .random()
@State private var floatDelay: Double = .random(in: 0.15...0.55)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 | FrutaApp |
The source’s App suffix makes this role explicit. |
| Incrementally constructs a framework value or graph | SmoothieArrayBuilder, SmoothieBuilder |
The source’s Builder suffix makes this role explicit. |
| Cross-object flow or session coordination | Coordinator |
The source’s Coordinator suffix makes this role explicit. |
| Feature data or observable state | Model |
The source’s Model suffix makes this role explicit. |
| Supplies a capability or framework resource | Provider, UnitIconProvider |
The source’s Provider suffix makes this role explicit. |
| User-interface presentation and input forwarding | BubbleView, ContentView, FeaturedSmoothieEntryView, FlipView |
The source’s View suffix makes this role explicit. |
Design patterns
| Pattern | Source evidence | Purpose or tradeoff |
|---|---|---|
| Protocol-oriented abstraction | Shared/NutritionFacts/DisplayableMeasurement.swift:22 |
A local protocol and concrete conformance create an explicit capability boundary. |
| Coordinator | Shared/Orders/PaymentButton.swift:64 |
A role-named coordinator centralizes cross-object flow. |
| Builder | Shared/Smoothie/Smoothie.swift:237 |
A builder-named type owns incremental construction. |
| Publisher-backed observable state | Shared/Model/Model.swift:13 |
Published properties notify observers while mutation remains with the state object. |
| Actor-isolated state | Shared/Model/Model.swift:146 |
Actor annotations make the concurrency ownership boundary explicit. |
Naming conventions
- Types: App: FrutaApp; Builder: SmoothieArrayBuilder, SmoothieBuilder; Coordinator: Coordinator; Model: Model; Provider: Provider, UnitIconProvider; View: BubbleView, ContentView, FeaturedSmoothieEntryView, FlipView, MeasurementView.
- Protocols:
UnitIconProvider,DisplayableMeasurement. - Methods:
handleUserActivity,toggle,body,increment,decrement. - Files:
Shared/FrutaApp.swift,iOS/FrutaAppClip.swift,Shared/Orders/OrderPlacedView.swift,Widgets/FrutaWidgets.swift,Shared/Components/FlipView.swift,Shared/Components/StepperView.swift.
Architecture takeaways
FrutaAppis the main source-visible entry or composition anchor for this sample.- Framework work reaches SwiftUI, StoreKit, AuthenticationServices, WidgetKit 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.
- Local protocol relationships provide an explicit substitution boundary.
Source map
| Source file | Relevant symbols |
|---|---|
Shared/FrutaApp.swift |
FrutaApp |
iOS/FrutaAppClip.swift |
FrutaAppClip |
Shared/Orders/OrderPlacedView.swift |
OrderPlacedView, Card, OrderPlacedView_Previews |
Widgets/FrutaWidgets.swift |
FrutaWidgets |
Shared/Components/FlipView.swift |
FlipView, FlipViewSide, FlipModifier, FlipView_Previews |
Shared/Components/StepperView.swift |
StepperView, Configuration, StepperView_Previews |
Shared/Recipe/RecipeView.swift |
RecipeView, RecipeIngredientRow, RecipeView_Previews |
Shared/Components/BubbleView.swift |
BubbleView, BubbleView_Previews |
Shared/Navigation/AppSidebarNavigation.swift |
AppSidebarNavigation, NavigationItem, Pocket, AppSidebarNavigation_Previews, AppSidebarNavigationPocket_Previews |
Shared/Navigation/ContentView.swift |
ContentView, ContentView_Previews |