Architecture Overview
Staccato Coffee follows a modern mobile architecture with a native iOS frontend, Supabase backend, and Square payment integration.
System Diagram
Data Flow
Customer Order Flow
- Customer browses menu →
MenuServicefetches frommenu_itemstable - Customer adds to cart →
CartViewModelmanages state, persists toUserDefaults - Customer checks out →
CheckoutViewModelorchestrates payment - Payment processed →
SquarePaymentServicecallsprocess-paymentEdge Function - Order created →
OrderServiceinserts intoorders,order_items,order_item_modifiers - Stars awarded →
OrderService.awardStars()updatesloyalty_accounts - Order synced →
OrderService.syncToSquare()callssync-square-orderEdge Function
Staff Order Flow
- Order arrives → Supabase Realtime pushes to
OrderQueueViewModel - Employee claims →
OrderQueueService.claimOrder()setsassigned_toand status toin_progress - Order ready →
OrderQueueService.markReady()sets status toready - Order completed →
OrderQueueService.completeOrder()sets status tocompleted
Key Design Decisions
| Decision | Rationale |
|---|---|
| MVVM Architecture | Clean separation of UI and business logic, native SwiftUI pattern |
| Singleton Services | Shared state management, single Supabase client instance |
| Direct Supabase Access | No middleware API needed — RLS handles authorization |
| Edge Functions for Square | Keeps Square API keys server-side, runs on Supabase infrastructure |
| UserDefaults for Cart | Lightweight persistence, survives app restarts |
| Idempotency Keys | Prevents duplicate payments and orders on retry |
| Non-blocking Square Sync | Order succeeds even if Square sync fails |