How dowells-mike/sleepsafe works
Project Type and Purpose
• SleepSafe is an Android mobile app focused on sleep tracking and analysis. It leverages device motion and audio inputs to monitor sleep, provides smart alarm features, and displays detailed sleep statistics.
• The app follows the MVVM (Model-View-ViewModel) pattern and makes use of modern Android technologies like Jetpack Compose for UI, Room for local data storage, and Kotlin Coroutines for concurrency.
Main Architectural Components
a. User Interface Layer (View)
• Screens: HomeScreen, AnalysisScreen, AccountScreen, SettingsScreen & WelcomeScreen, among others.
• Theme and styling defined in the ui/theme package.
b. Presentation Layer (ViewModel)
• Individual ViewModels (AccountViewModel, AnalysisViewModel, HomeViewModel, SettingsViewModel) which handle state management and business logic.
c. Data Layer (Model)
• Data models in the data/ package covering SleepData, SleepPhaseStats, SleepQualityMetrics, and SleepSessionSummary.
• Local persistence managed by SleepDatabase through Room.
d. Services & Utilities
• Core services such as SleepTrackingService for real-time sleep monitoring.
• Utility classes (in utils/) like MotionDetector, AudioRecorder, AlarmReceiver, SnoozeReceiver, and others for managing sensors, audio, and alarms.
e. External/Platform Components
• Android system components (manifest declarations, permissions for ACTIVITY_RECOGNITION, RECORD_AUDIO, FOREGROUND_SERVICE, SCHEDULE_EXACT_ALARM).
Relationships and Interactions
• The UI layer (screens and components) communicates with ViewModels to retrieve state and post user actions.
• ViewModels interact with the data layer for CRUD operations—reading and writing sleep data from SleepDatabase.
• Background services (SleepTrackingService) and utilities (MotionDetector, AudioRecorder) continuously monitor sleep parameters and feed data into the data layer or update relevant ViewModels.
• All layers adhere to MVVM, separating concerns and ensuring that UI, business logic, and data persistence operate independently.
Important Architectural Patterns and Technologies
• MVVM: Cleanly separates UI (View), business logic (ViewModel), and data (Model).
• Modular Android Components: The project separates concerns via distinct packages (screens, viewmodel, data, utils, components).
• Modern Android Practices: Use of Jetpack Compose for declarative UI, Room for local persistence, and Kotlin Coroutines for asynchronous programming.
• (From README) Use of dependency injection with Hilt, though not explicitly visible in the file tree, is part of the technical stack.
Final Advice
• The goal is to offer an at-a-glance view of how SleepSafe implements sleep tracking with local data handling using a clear MVVM architecture.