How shanglin-wu/database-system-final-project works
Project type and purpose
• This is an iOS mobile-client application written in Swift that displays restaurant data.
• It fetches data from remote RESTful APIs (“getRestaurant”, “getRestaurantList”) backed by a MongoDB database, decodes JSON responses, caches or persists data locally (via Realm), and presents it in table views with image loading (SDWebImage), star ratings (Cosmos) and toast notifications (Toast).
File structure
• Top-level Xcode artifacts: DatabaseSystemProject.xcodeproj, DatabaseSystemProject.xcworkspace
• Core source folders under DatabaseSystemProject/:
• Api/… holds request/response model definitions
• ApiAgent/ApiAgent.swift encapsulates network calls
• JSONDecoder/JSONDecoder.swift is a custom JSON parsing helper
• DataManager/DataManager.swift orchestrates business logic (fetching, decoding, caching)
• View controllers and storyboard files under Base.lproj and .swift files (ContentViewController, RestaurantDetailViewController, etc.)
• Custom UITableViewCell implementations (restaurantResultTableViewCell, reviewTableViewCell)
• Third-party frameworks integrated via CocoaPods:
• Realm & RealmSwift for local persistence
• SDWebImage for asynchronous image downloading/caching
• Cosmos for rating UI
• Toast for in-app notifications
README
• Confirms the use of Swift and MongoDB as the remote data store.
Main components & interactions
a. Mobile Application (iOS)
– Presentation Layer: Storyboard/Swift UI classes (ViewControllers, custom Cells)
– Service Layer: DataManager (business logic), ApiAgent (network client), JSONDecoder (parsing)
– Persistence Layer: Realm (local DB/cache)
– Utilities & Third-Party Modules: SDWebImage, Cosmos, Toast
b. Remote Backend API Service
– REST endpoints: /getRestaurantList, /getRestaurant
– JSON over HTTPS
c. Remote Database
– MongoDB holds the authoritative restaurant data
Data flow:
ViewController → DataManager
DataManager → ApiAgent → Network request → Backend Service → MongoDB
Response JSON → ApiAgent → JSONDecoder → Swift models → DataManager
DataManager → (optional) Realm persistence → returns model(s) → ViewController
ViewController → Cell rendering → SDWebImage & Cosmos → UI display
ViewController → Toast → user notifications
Architectural patterns & design principles
• Layered architecture separating Presentation, Service, Persistence
• Single Responsibility: ApiAgent only does networking; JSONDecoder only decodes; DataManager orchestrates
• Dependency inversion: Controllers depend on DataManager protocol, not concrete networking details
• Offline caching: Realm used to persist or cache API responses for offline/fast retrieval