How googlearchive/science-journal-ios works
Project type and purpose
• This is an iOS mobile application (“Science Journal for iOS”) that captures sensor data (built‐in and external BLE), visualizes it, persists it locally, and syncs or exports experiments (e.g., to Google Drive, PDF, CSV).
• It’s implemented in Swift, uses CocoaPods for dependencies, and Protocol Buffers for data interchange.
High‑level architecture overview
a. Hardware & OS Layer (bottom)
– iOS device sensors (accelerometer, light, audio, etc.)
– BLE peripherals
– AVFoundation, CoreLocation, CoreMotion, CoreBluetooth frameworks
b. & Sensor Abstraction Layer
– CaptureSession (AudioCapture, CameraCaptureSessionManager, AudioSession, etc.)
– Sensors module (SensorController, individual Sensor implementations, SensorTimer)
– BLESupport / BLEProtocols layer (BLEPeripheralInterface, BLESensorInterface)
c. Core Logic & Data Layer
– Recording & Experiment modules (Recorder, RecordingManager, TrialStatsAdjuster)
– Metadata & Persistence (Core Data through SensorData/DataModel.xcdatamodeld, MetadataManager, ExperimentUpdateManager)
– Wrappers & Protos (Protos folder + GeneratedProtos, WrappedModels for serialization)
– Filters & Processing (SensorFilters, FFTAnalyzer for pitch, ToneGenerator)
– Operations framework (GSJOperationQueue, GSJBlockOperation, GroupOperation)
– Feature modules: DriveSyncManager, AccountsManager, RemoteConfigManager, AnalyticsReporter, FeedbackReporter
d. Presentation Layer (top)
– UI folder (ViewControllers, Views, Drawer, Onboarding, ExperimentList, TrialDetail, ChartView, etc.)
– ViewData layer (DisplayItem, DisplayTrialViewData, etc.)
– App flow controllers (AppFlowViewController, SignInFlowViewController, LaunchManager, ExperimentCoordinatorViewController)
Inter‑component relationships
• Sensor data flow:
Hardware sensors → CaptureSession → SensorController → RecordingManager → SensorDataManager → Core Data
• UI update flow:
User taps UI → ViewController → Core Logic (e.g., RecordingManager, MetadataManager) → ViewData → UI renders data/graph
• Export & sync:
SensorDataManager (or Protos exporter) → Protobuf messages → DriveSyncManager (Google Drive API)
or → PDFExportController / CSVWriter → sharable document (PDF/CSV)
• BLE integration:
BLEServiceScanner → PacketAssembler → BLESensorInterface → SensorController → Data pipeline
• Account & remote services:
AccountsManager → Google Sign‑In → DriveSyncManager
RemoteConfigManager → feature flags → FeatureEnabler in UI/logic
AnalyticsReporter → event stream → Google Analytics
Architectural patterns & principles
• MVC/MVVM hybrid:
– Model: Core Data, Protos, WrappedModels, business logic managers
– ViewModel/ViewData: view‑specific data structures in ViewData folder
– View & Controller: UI classes
• Modular design: features isolated in subfolders (Sensors, Chart, Drive, BLE, Metadata, PDFExport, Feedback, RemoteConfig, Extensions)
• Asynchronous operations: GSJOperationQueue, Observers, BackgroundTaskObserver
• Dependency inversion for external services: protocols (e.g., RemoteConfigFlagProtocol), “Disabled” implementations allow stubbing/testing
• Extensive use of protocols and extension over concrete classes for testability and swapping implementations