iOS App Architecture
The iOS app follows the MVVM (Model-View-ViewModel) pattern with a service layer.
Layer Diagram
App Entry Point
StaccatoCoffeeApp.swift is the @main entry point:
@main
struct StaccatoCoffeeApp: App {
@StateObject private var authViewModel = AuthViewModel()
@StateObject private var cartViewModel = CartViewModel()
var body: some Scene {
WindowGroup {
ContentView()
.environmentObject(authViewModel)
.environmentObject(cartViewModel)
}
}
}Key responsibilities:
- Initializes
SupabaseManagersingleton - Creates and injects
AuthViewModelandCartViewModelas environment objects - Handles OAuth callback URLs (
staccatocoffee://auth/callback) - Preloads menu data and modifier cache after authentication
Navigation Structure
ContentView.swift uses a TabView with role-based tabs:
| Tab | View | Roles |
|---|---|---|
| Home | HomeTabView | All |
| Order | MenuTabView | All |
| Orders | StaffOrdersView | Employee, Admin |
| Analytics | AdminDashboardView | Admin |
| Rewards | RewardsTabView | All |
| Account | AccountTabView | All |
A cart button overlay (top right) opens CartSlideOver.
File Structure
StaccatoCoffee/
├── App/
│ └── StaccatoCoffeeApp.swift # @main entry point
├── Core/
│ ├── Environment.swift # AppConfig enum
│ └── Extensions/
│ ├── Color+Brand.swift # Brand colors
│ └── View+Extensions.swift # View helpers
├── Models/ # 6 data model files
├── Services/ # 9 service files
├── ViewModels/ # 7 view model files
└── Views/
├── ContentView.swift # Tab container
├── Auth/ # Login, Apple Sign In
├── Home/ # Home tab, location picker
├── Menu/ # Menu browsing, item detail
├── Cart/ # Cart slide-over
├── Checkout/ # Checkout, payments
├── Rewards/ # Rewards tab
├── Account/ # Profile, settings
└── Staff/ # Order queue, admin dashboardConcurrency Model
The app uses Swift’s modern concurrency throughout:
async/awaitfor all network calls@MainActoron ViewModels for thread-safe UI updatesasync letfor parallel data fetching (e.g.,MenuService.getItemDetails)AsyncStreamfor observing auth state changesTask {}blocks for launching async work from synchronous contexts
Caching Strategy
| Cache | Storage | Purpose |
|---|---|---|
MenuCache | UserDefaults | Categories, items, featured items |
ModifierCache | In-memory singleton | Modifier groups and modifiers |
LoyaltyCache | UserDefaults | Loyalty account data |
CartStorageService | UserDefaults (staccato-cart) | Shopping cart persistence |