ArchitectureOverview

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

  1. Customer browses menu → MenuService fetches from menu_items table
  2. Customer adds to cart → CartViewModel manages state, persists to UserDefaults
  3. Customer checks out → CheckoutViewModel orchestrates payment
  4. Payment processed → SquarePaymentService calls process-payment Edge Function
  5. Order created → OrderService inserts into orders, order_items, order_item_modifiers
  6. Stars awarded → OrderService.awardStars() updates loyalty_accounts
  7. Order synced → OrderService.syncToSquare() calls sync-square-order Edge Function

Staff Order Flow

  1. Order arrives → Supabase Realtime pushes to OrderQueueViewModel
  2. Employee claims → OrderQueueService.claimOrder() sets assigned_to and status to in_progress
  3. Order ready → OrderQueueService.markReady() sets status to ready
  4. Order completed → OrderQueueService.completeOrder() sets status to completed

Key Design Decisions

DecisionRationale
MVVM ArchitectureClean separation of UI and business logic, native SwiftUI pattern
Singleton ServicesShared state management, single Supabase client instance
Direct Supabase AccessNo middleware API needed — RLS handles authorization
Edge Functions for SquareKeeps Square API keys server-side, runs on Supabase infrastructure
UserDefaults for CartLightweight persistence, survives app restarts
Idempotency KeysPrevents duplicate payments and orders on retry
Non-blocking Square SyncOrder succeeds even if Square sync fails