BOT-anist
At a glance
| Item | Summary |
|---|---|
| Purpose | Build a multiplatform app that uses windows, volumes, and animations to create a robot botanist’s greenhouse. |
| App architecture | BOTanistApp composes WindowGroup + volumetric window around ContentView; AppState holds shared experience state and RealityKit components and systems own per-entity behavior. |
| Main patterns | SwiftUI scene composition, SwiftUI–RealityKit bridge, Observable state owner, Entity-component-system, Async update consumer |
| Project style | Code-rich sample with 30 scanned Swift file(s) and 2782 Swift line(s); resources and generated assets are excluded from those counts. |
Project structure
Source bundle/
├── BOT-anist/BOTanistApp.swift # BOTanistApp
├── Packages/BOTanistAssets/Sources/BOTanistAssets/Components/PlantComponent.swift # PlantComponent, PlantTypeKey
├── BOT-anist/Robot/RobotData.swift # RobotData, RobotMaterial, BodyType
├── BOT-anist/Views/RobotView.swift # RobotView, ResizableRealityView, StartPlantingButtonView
├── BOT-anist/Views/ContentView.swift # ContentView
├── BOT-anist/AppState.swift # AppPhase, AppState
├── BOT-anist/Components/JointPinComponent.swift # JointPinComponent
├── BOT-anist/Systems/JointPinSystem.swift # JointPinSystem
└── Packages/BOTanistAssets/Package.realitycomposerpro/ProjectData/main.json # authored RealityKit content
Structure observations
- The runtime boundary is WindowGroup + volumetric window; the pruned tree lists only files that explain lifecycle, state, or framework integration.
- App code is split into role-named views, models, managers, providers, components, or systems.
- Authored
.realityor Reality Composer Pro content is a real implementation boundary; Swift loads or drives it rather than reproducing its entity graph.
Overall architecture
flowchart LR
BOTanistApp_1["BOTanistApp"]
WindowGroup___volumetric_window_2["WindowGroup + volumetric window"]
ContentView_3["ContentView"]
AppState_4["AppState"]
RealityView_entity_graph_5["RealityView entity graph"]
RealityKit_components_and_systems_6["RealityKit components and systems"]
BOTanistApp_1 --> WindowGroup___volumetric_window_2
WindowGroup___volumetric_window_2 --> ContentView_3
ContentView_3 --> AppState_4
AppState_4 --> RealityView_entity_graph_5
RealityView_entity_graph_5 --> RealityKit_components_and_systems_6
Reference code
BOT-anist/BOTanistApp.swift:16 — the app or executable entry declares the outer scene lifecycle.
struct BOTanistApp: App {
// ...
}The diagram is a responsibility flow, not a claim that every adjacent node directly calls the next. It keeps scene ownership, shared state, RealityKit content, and framework-provider work at separate levels.
Ownership and state
classDiagram
BOTanistApp *-- AppState : appState
ContentView o-- AppState : appState
BOTanistApp *-- Size3D : initialVolumeSize
PlantAnimationProvider *-- PlantAnimationProvider : shared
Ownership evidence
BOT-anist/BOTanistApp.swift:20 — representative stored state or the nearest verified lifecycle anchor.
@State private var appState = AppState()
/// The initial 3D dimensions of the volumetric window.
private var initialVolumeSize: Size3D = Size3D(width: 900, height: 500, depth: 900)
/// The initial 2D dimensions of the content view window.
private var initialWindowSize: CGSize = CGSize(width: 1166, height: 680)| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
BOTanistApp |
AppState as appState |
creates and retains | Only the declaring scope writes |
ContentView |
AppState as appState |
receives a shared/non-owning reference | The upstream owner controls lifetime; this scope may invoke its mutable API |
BOTanistApp |
Size3D as initialVolumeSize |
creates and retains | Only the declaring scope writes |
PlantAnimationProvider |
PlantAnimationProvider as shared |
creates and retains | The owning type coordinates writes |
Ownership here is deliberately narrow: @Environment and weak references are shared links, initialized @State or stored services are lifecycle ownership, and a RealityView content closure owns additions to its entity graph without making the SwiftUI view a reference-type owner.
Class and protocol design
| Type | Responsibility | Depends on or conforms to |
|---|---|---|
BOTanistApp (BOT-anist/BOTanistApp.swift:16) |
Declares app scenes and top-level dependency lifetime. | App |
ContentView (BOT-anist/Views/ContentView.swift:14) |
Presents UI and forwards gestures or lifecycle events. | View |
AppState (BOT-anist/AppState.swift:27) |
Owns observable feature state and domain transitions. | Concrete framework collaborators |
JointPinComponent (BOT-anist/Components/JointPinComponent.swift:11) |
Stores RealityKit entity data. | Component |
JointPinSystem (BOT-anist/Systems/JointPinSystem.swift:11) |
Updates matching RealityKit entities. | System |
PlantComponent (Packages/BOTanistAssets/Sources/BOTanistAssets/Components/PlantComponent.swift:11) |
Stores RealityKit entity data. | Component, Codable |
PlantAnimationProvider (BOT-anist/PlantAnimationProvider.swift:16) |
Wraps a framework or transport capability. | Concrete framework collaborators |
The source defines no local substitution protocol in the reviewed boundary. Its protocol use is framework-facing (App, View, RealityKit/ARKit protocols, or platform adapters), so this document does not label the whole app protocol-oriented.
Access control
| Symbol | Access | Verified effect | Likely rationale |
|---|---|---|---|
@State private var appState = AppState() (BOT-anist/BOTanistApp.swift:20) |
private |
Use is restricted to the declaration and same-file extensions permitted by Swift. | Inference: Hide implementation details and lifecycle-sensitive state. |
fileprivate func pinEntity(indices: [Int], (BOT-anist/Systems/JointPinSystem.swift:42) |
fileprivate |
Use is restricted to declarations in this source file. | Inference: Share a helper across same-file extensions without making it module-wide. |
public var growAnimations = [PlantComponent.PlantTypeKey: AnimationReso... (BOT-anist/PlantAnimationProvider.swift:20) |
public |
The declaration is available to importing modules, subject to its containing type’s visibility. | Inference: Satisfy a cross-target or framework-facing surface without implying subclassability. |
@Environment(\.openWindow) internal var openWindow (BOT-anist/Views/RobotView.swift:130) |
internal |
With no narrower modifier, Swift keeps the declaration module-internal. | Inference: Allow app-target collaboration without exporting a library API. |
No reviewed declaration uses private(set), open; unmodified Swift declarations are internal.
Reference code
BOT-anist/BOTanistApp.swift:20 — representative visibility boundary.
@main
struct BOTanistApp: App {
// ...
@State private var appState = AppState()
// ...
}Logic ownership and placement
| Logic | Owning type or file | Placement rationale |
|---|---|---|
| Scene declaration and dependency lifetime | BOTanistApp |
The App/entry boundary determines window, volume, and immersive-space lifetime. |
| Presentation, attachments, and gestures | ContentView |
SwiftUI view code forwards user intent and RealityView lifecycle events. |
| Shared feature state and commands | AppState |
A role-named owner prevents sibling views from duplicating transitions. |
| Per-frame entity behavior | BOT-anist/Systems/JointPinSystem.swift:11 |
RealityKit systems query component data instead of centralizing every entity update in SwiftUI. |
Design patterns
| Pattern | Source evidence | Purpose or tradeoff |
|---|---|---|
| SwiftUI scene composition | BOT-anist/BOTanistApp.swift:16 |
Keeps windows, volumes, and immersive-space lifecycle visible at the app boundary. |
| SwiftUI–RealityKit bridge | BOT-anist/Views/RobotView.swift:21 |
Builds and updates a RealityKit entity graph from SwiftUI lifecycle closures. |
| Observable state owner | BOT-anist/AppState.swift:27 |
Shares feature state across multiple views without moving framework resources into view values. |
| Entity-component-system | BOT-anist/Systems/JointPinSystem.swift:11 |
Stores per-entity data in components and advances behavior in registered RealityKit systems. |
| Async update consumer | BOT-anist/PlantAnimationProvider.swift:28 |
Consumes provider or event streams in cancellable structured tasks. |
Naming conventions
- Role suffixes are evidence, not decoration: App:
BOTanistApp; Provider:PlantAnimationProvider; View:ContentView,ExplorationView,FaceSelectorView,LightColorSelectView,MaterialColorSelectView. - ECS names pair data and behavior: components
JointPinComponent,PlantComponent; systemsJointPinSystem. - Protocols: no app-defined protocol in the reviewed source.
- Commands use verb-led methods:
partForMaterialName,color,randomColor,face,hash,handleDrag,adjustRobotToFillCenterOfView. - Files generally match their primary type;
Views,Models,Managers,Providers,Components,Systems, andPackagesfolders describe architectural roles where present.
Architecture takeaways
- Treat
BOTanistAppas the owner of scene declarations, not as the owner of every RealityKit entity created later. - Keep view-local interaction in SwiftUI, but move provider sessions, playback resources, shared game state, or transport state into a stable owner when their lifetime exceeds one render pass.
- Use RealityKit components for per-entity data and systems for repeated simulation instead of a monolithic view model.
Source map
| Source file | Relevant symbols |
|---|---|
BOT-anist/BOTanistApp.swift:16 |
BOTanistApp |
Packages/BOTanistAssets/Sources/BOTanistAssets/Components/PlantComponent.swift:11 |
PlantComponent, PlantTypeKey |
BOT-anist/Robot/RobotData.swift:15 |
RobotData, RobotMaterial, BodyType, RobotPart, RobotLightColor, RobotFace |
BOT-anist/Views/RobotView.swift:13 |
RobotView, ResizableRealityView, StartPlantingButtonView |
BOT-anist/Views/ContentView.swift:14 |
ContentView |
BOT-anist/AppState.swift:15 |
AppPhase, AppState |
BOT-anist/Components/JointPinComponent.swift:11 |
JointPinComponent |
BOT-anist/Systems/JointPinSystem.swift:11 |
JointPinSystem |