tahamajs's picture
|
download
raw
42.4 kB

Air Mouse Android App - Complete Architecture & Folder Structure Documentation

πŸ“‹ Table of Contents

  1. Overview
  2. Architecture
  3. Package Structure
  4. Module Breakdown
  5. Data Flow
  6. Layer Diagrams
  7. Key Components
  8. Dependency Injection
  9. Testing Strategy
  10. Build Variants
  11. Third-Party Libraries
  12. Development Guidelines

Overview

The Air Mouse Android app follows Clean Architecture principles with a modern MVVM (Model-View-ViewModel) pattern using Jetpack Compose for UI. The architecture is designed to be:

  • Testable - Each layer is independently testable
  • Maintainable - Clear separation of concerns
  • Scalable - Easy to add new features
  • Decoupled - Low coupling between layers

Architecture

Layer Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         PRESENTATION LAYER                          β”‚
β”‚                    (UI / Compose Screens)                           β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚  Activities / Composables / ViewModels                     β”‚   β”‚
β”‚  β”‚  - HomeScreen, CalibrationScreen, SettingsScreen           β”‚   β”‚
β”‚  β”‚  - HomeViewModel, CalibrationViewModel                     β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                          DOMAIN LAYER                              β”‚
β”‚                    (Business Logic)                                β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚  Use Cases / Models / Repository Interfaces                β”‚   β”‚
β”‚  β”‚  - ConnectToServerUseCase, SendMovementUseCase             β”‚   β”‚
β”‚  β”‚  - IConnectionRepository, IMouseRepository                 β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                          DATA LAYER                                β”‚
β”‚                    (Data Sources & Repositories)                   β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚  Repositories / Data Sources / Mappers                     β”‚   β”‚
β”‚  β”‚  - ConnectionRepositoryImpl, CalibrationDataSourceImpl     β”‚   β”‚
β”‚  β”‚  - DomainToEntityMapper, EntityToDomainMapper              β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                      INFRASTRUCTURE LAYER                          β”‚
β”‚                    (External Dependencies)                         β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚  Network / Database / Sensors / Bluetooth / USB            β”‚   β”‚
β”‚  β”‚  - ConnectionManager, WebSocketManager                     β”‚   β”‚
β”‚  β”‚  - Room Database, PreferencesDataStore                     β”‚   β”‚
β”‚  β”‚  - SensorService, BluetoothHidService                      β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Dependency Direction

Presentation β†’ Domain ← Data β†’ Infrastructure
     ↓           ↓        ↓          ↓
     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
              (Dependency Injection)

Package Structure

Complete Directory Tree

app/src/main/java/com/airmouse/
β”‚
β”œβ”€β”€ AirMouseApplication.kt              # Application entry point
β”‚
β”œβ”€β”€ auth/                                # Authentication
β”‚   └── AuthManager.kt
β”‚
β”œβ”€β”€ data/                                # Data Layer
β”‚   β”œβ”€β”€ datasource/                      # Data sources
β”‚   β”‚   β”œβ”€β”€ local/                       # Local data sources
β”‚   β”‚   β”‚   β”œβ”€β”€ AppDatabase.kt
β”‚   β”‚   β”‚   β”œβ”€β”€ Converters.kt
β”‚   β”‚   β”‚   β”œβ”€β”€ CalibrationDao.kt
β”‚   β”‚   β”‚   β”œβ”€β”€ GestureDao.kt
β”‚   β”‚   β”‚   β”œβ”€β”€ ProfileDao.kt
β”‚   β”‚   β”‚   β”œβ”€β”€ StatisticsDao.kt
β”‚   β”‚   β”‚   β”œβ”€β”€ TrainingSampleDao.kt
β”‚   β”‚   β”‚   β”œβ”€β”€ CalibrationEntity.kt
β”‚   β”‚   β”‚   β”œβ”€β”€ GestureTemplateEntity.kt
β”‚   β”‚   β”‚   β”œβ”€β”€ ProfileEntity.kt
β”‚   β”‚   β”‚   β”œβ”€β”€ StatisticsEntity.kt
β”‚   β”‚   β”‚   β”œβ”€β”€ TrainingSampleEntity.kt
β”‚   β”‚   β”‚   β”œβ”€β”€ ILocalDataSource.kt
β”‚   β”‚   β”‚   └── LocalDataSourceImpl.kt
β”‚   β”‚   β”‚
β”‚   β”‚   └── remote/                     # Remote data sources
β”‚   β”‚       β”œβ”€β”€ IConnectionDataSource.kt
β”‚   β”‚       └── ConnectionDataSourceImpl.kt
β”‚   β”‚
β”‚   β”œβ”€β”€ mapper/                         # Data mappers
β”‚   β”‚   β”œβ”€β”€ DomainToEntityMapper.kt
β”‚   β”‚   └── EntityToDomainMapper.kt
β”‚   β”‚
β”‚   └── repository/                     # Repository implementations
β”‚       β”œβ”€β”€ CalibrationRepositoryImpl.kt
β”‚       β”œβ”€β”€ ConnectionRepositoryImpl.kt
β”‚       β”œβ”€β”€ GestureRepositoryImpl.kt
β”‚       β”œβ”€β”€ MouseRepositoryImpl.kt
β”‚       β”œβ”€β”€ ProfileRepositoryImpl.kt
β”‚       β”œβ”€β”€ ProximityRepositoryImpl.kt
β”‚       β”œβ”€β”€ SensorRepositoryImpl.kt
β”‚       β”œβ”€β”€ StatisticsRepositoryImpl.kt
β”‚       └── VoiceCommandRepositoryImpl.kt
β”‚
β”œβ”€β”€ domain/                             # Domain Layer
β”‚   β”œβ”€β”€ model/                          # Domain models
β”‚   β”‚   β”œβ”€β”€ ConnectionModels.kt
β”‚   β”‚   β”œβ”€β”€ MouseModels.kt
β”‚   β”‚   β”œβ”€β”€ GestureModels.kt
β”‚   β”‚   β”œβ”€β”€ CalibrationModels.kt
β”‚   β”‚   β”œβ”€β”€ SensorModels.kt
β”‚   β”‚   β”œβ”€β”€ ProximityModels.kt
β”‚   β”‚   β”œβ”€β”€ UpdateModels.kt
β”‚   β”‚   β”œβ”€β”€ UserProfileModels.kt
β”‚   β”‚   β”œβ”€β”€ StatisticsModels.kt
β”‚   β”‚   β”œβ”€β”€ VoiceCommandModels.kt
β”‚   β”‚   β”œβ”€β”€ ErrorModels.kt
β”‚   β”‚   └── UIStateModels.kt
β”‚   β”‚
β”‚   β”œβ”€β”€ repository/                     # Repository interfaces
β”‚   β”‚   β”œβ”€β”€ ICalibrationRepository.kt
β”‚   β”‚   β”œβ”€β”€ IConnectionRepository.kt
β”‚   β”‚   β”œβ”€β”€ IGestureRepository.kt
β”‚   β”‚   β”œβ”€β”€ IMouseRepository.kt
β”‚   β”‚   β”œβ”€β”€ IProfileRepository.kt
β”‚   β”‚   β”œβ”€β”€ IProximityRepository.kt
β”‚   β”‚   β”œβ”€β”€ ISensorRepository.kt
β”‚   β”‚   β”œβ”€β”€ IStatisticsRepository.kt
β”‚   β”‚   β”œβ”€β”€ IUpdateRepository.kt
β”‚   β”‚   └── IVoiceCommandRepository.kt
β”‚   β”‚
β”‚   └── usecase/                        # Use cases
β”‚       β”œβ”€β”€ ConnectToServerUseCase.kt
β”‚       β”œβ”€β”€ SendMovementUseCase.kt
β”‚       β”œβ”€β”€ CalibrationUseCase.kt
β”‚       β”œβ”€β”€ DetectGestureUseCase.kt
β”‚       β”œβ”€β”€ ManageGestureTemplatesUseCase.kt
β”‚       β”œβ”€β”€ GetProximityStateUseCase.kt
β”‚       β”œβ”€β”€ UpdateProximityConfigUseCase.kt
β”‚       β”œβ”€β”€ GetStatisticsUseCase.kt
β”‚       β”œβ”€β”€ RecordStatisticsUseCase.kt
β”‚       β”œβ”€β”€ ManageProfileUseCase.kt
β”‚       β”œβ”€β”€ HandleVoiceCommandUseCase.kt
β”‚       β”œβ”€β”€ CheckForUpdatesUseCase.kt
β”‚       β”œβ”€β”€ DiscoverServersUseCase.kt
β”‚       β”œβ”€β”€ TestConnectionUseCase.kt
β”‚       └── GetConnectionStatusUseCase.kt
β”‚
β”œβ”€β”€ features/                           # Feature orchestration
β”‚   β”œβ”€β”€ ConnectionFeature.kt
β”‚   β”œβ”€β”€ MouseControlFeature.kt
β”‚   β”œβ”€β”€ CalibrationFeature.kt
β”‚   β”œβ”€β”€ GestureRecognitionFeature.kt
β”‚   β”œβ”€β”€ ProximityFeature.kt
β”‚   β”œβ”€β”€ StatisticsFeature.kt
β”‚   β”œβ”€β”€ VoiceFeature.kt
β”‚   β”œβ”€β”€ ProfileFeature.kt
β”‚   β”œβ”€β”€ UpdateFeature.kt
β”‚   └── SensorFeature.kt
β”‚
β”œβ”€β”€ network/                            # Network layer
β”‚   β”œβ”€β”€ ConnectionManager.kt
β”‚   β”œβ”€β”€ WebSocketManager.kt
β”‚   β”œβ”€β”€ TcpClient.kt
β”‚   β”œβ”€β”€ UdpDiscovery.kt
β”‚   β”œβ”€β”€ NetworkQualityMonitor.kt
β”‚   β”œβ”€β”€ NetworkStateHelper.kt
β”‚   β”œβ”€β”€ MessageTypes.kt
β”‚   β”œβ”€β”€ ConnectionHelper.kt
β”‚   └── ConnectionQuality.kt
β”‚
β”œβ”€β”€ presentation/                       # Presentation Layer
β”‚   β”œβ”€β”€ base/                           # Base classes
β”‚   β”‚   └── BaseViewModel.kt
β”‚   β”‚
β”‚   β”œβ”€β”€ extensions/                     # Compose extensions
β”‚   β”‚   └── ComposableExtensions.kt
β”‚   β”‚
β”‚   β”œβ”€β”€ navigation/                     # Navigation
β”‚   β”‚   β”œβ”€β”€ Navigation.kt
β”‚   β”‚   └── Destinations.kt
β”‚   β”‚
β”‚   β”œβ”€β”€ theme/                          # Theme
β”‚   β”‚   β”œβ”€β”€ Theme.kt
β”‚   β”‚   β”œβ”€β”€ Type.kt
β”‚   β”‚   └── Color.kt
β”‚   β”‚
β”‚   └── ui/                             # UI Screens
β”‚       β”œβ”€β”€ home/
β”‚       β”‚   β”œβ”€β”€ HomeScreen.kt
β”‚       β”‚   β”œβ”€β”€ HomeViewModel.kt
β”‚       β”‚   └── components/
β”‚       β”‚
β”‚       β”œβ”€β”€ calibration/
β”‚       β”‚   β”œβ”€β”€ CalibrationScreen.kt
β”‚       β”‚   β”œβ”€β”€ CalibrationViewModel.kt
β”‚       β”‚   └── components/
β”‚       β”‚
β”‚       β”œβ”€β”€ settings/
β”‚       β”‚   β”œβ”€β”€ SettingsScreen.kt
β”‚       β”‚   β”œβ”€β”€ SettingsViewModel.kt
β”‚       β”‚   └── components/
β”‚       β”‚
β”‚       β”œβ”€β”€ gesture/
β”‚       β”‚   β”œβ”€β”€ GestureStudioScreen.kt
β”‚       β”‚   β”œβ”€β”€ GestureStudioViewModel.kt
β”‚       β”‚   └── components/
β”‚       β”‚
β”‚       β”œβ”€β”€ proximity/
β”‚       β”‚   β”œβ”€β”€ ProximityScreen.kt
β”‚       β”‚   β”œβ”€β”€ ProximityViewModel.kt
β”‚       β”‚   └── components/
β”‚       β”‚
β”‚       β”œβ”€β”€ statistics/
β”‚       β”‚   β”œβ”€β”€ StatisticsScreen.kt
β”‚       β”‚   β”œβ”€β”€ StatisticsViewModel.kt
β”‚       β”‚   └── components/
β”‚       β”‚
β”‚       β”œβ”€β”€ profiles/
β”‚       β”‚   β”œβ”€β”€ ProfilesScreen.kt
β”‚       β”‚   β”œβ”€β”€ ProfilesViewModel.kt
β”‚       β”‚   └── components/
β”‚       β”‚
β”‚       β”œβ”€β”€ voice/
β”‚       β”‚   β”œβ”€β”€ VoiceCommandsScreen.kt
β”‚       β”‚   └── VoiceCommandsViewModel.kt
β”‚       β”‚
β”‚       β”œβ”€β”€ edge/
β”‚       β”‚   β”œβ”€β”€ EdgeGesturesScreen.kt
β”‚       β”‚   └── EdgeGesturesViewModel.kt
β”‚       β”‚
β”‚       β”œβ”€β”€ network/
β”‚       β”‚   β”œβ”€β”€ NetworkDiscoveryScreen.kt
β”‚       β”‚   └── NetworkDiscoveryViewModel.kt
β”‚       β”‚
β”‚       β”œβ”€β”€ logs/
β”‚       β”‚   β”œβ”€β”€ ServerLogsScreen.kt
β”‚       β”‚   └── ServerLogsViewModel.kt
β”‚       β”‚
β”‚       β”œβ”€β”€ onboarding/
β”‚       β”‚   β”œβ”€β”€ OnboardingScreen.kt
β”‚       β”‚   └── OnboardingViewModel.kt
β”‚       β”‚
β”‚       β”œβ”€β”€ themes/
β”‚       β”‚   └── ThemesScreen.kt
β”‚       β”‚
β”‚       β”œβ”€β”€ touchpad/
β”‚       β”‚   └── TouchpadScreen.kt
β”‚       β”‚
β”‚       └── components/                 # Shared UI components
β”‚           β”œβ”€β”€ AnimatedConnectionStatus.kt
β”‚           β”œβ”€β”€ AnimatedCounter.kt
β”‚           β”œβ”€β”€ AnimatedSwitch.kt
β”‚           β”œβ”€β”€ AnimatedToast.kt
β”‚           β”œβ”€β”€ CircularProgressWithLabel.kt
β”‚           β”œβ”€β”€ ConnectionStatusBadge.kt
β”‚           β”œβ”€β”€ DataChart.kt
β”‚           β”œβ”€β”€ FloatingActionMenu.kt
β”‚           β”œβ”€β”€ GestureWaveform.kt
β”‚           β”œβ”€β”€ HolographicText.kt
β”‚           β”œβ”€β”€ InteractiveTutorialCard.kt
β”‚           β”œβ”€β”€ NeonButton.kt
β”‚           β”œβ”€β”€ NotificationBadge.kt
β”‚           β”œβ”€β”€ PullToRefresh.kt
β”‚           β”œβ”€β”€ RadarAnimation.kt
β”‚           β”œβ”€β”€ SensorVisualizer.kt
β”‚           β”œβ”€β”€ SlideUpPanel.kt
β”‚           └── VoiceWaveAnimation.kt
β”‚
β”œβ”€β”€ sensors/                            # Sensor processing
β”‚   β”œβ”€β”€ CalibrationHelper.kt
β”‚   β”œβ”€β”€ MadgwickAHRS.kt
β”‚   └── EnhancedGestureDetector.kt
β”‚
β”œβ”€β”€ service/                            # Background services
β”‚   β”œβ”€β”€ SensorService.kt
β”‚   β”œβ”€β”€ BluetoothHidService.kt
β”‚   β”œβ”€β”€ ProximityService.kt
β”‚   β”œβ”€β”€ ProximityAwareService.kt
β”‚   β”œβ”€β”€ VoiceCommandService.kt
β”‚   β”œβ”€β”€ GestureInferenceService.kt
β”‚   β”œβ”€β”€ GestureRecorderService.kt
β”‚   β”œβ”€β”€ UsbHidService.kt
β”‚   β”œβ”€β”€ UsbSerialService.kt
β”‚   β”œβ”€β”€ OrientationMonitorService.kt
β”‚   β”œβ”€β”€ EdgeGestureService.kt
β”‚   β”œβ”€β”€ DebugOverlayService.kt
β”‚   └── ForegroundServiceManager.kt
β”‚
β”œβ”€β”€ utils/                              # Utility classes
β”‚   β”œβ”€β”€ PreferencesManager.kt
β”‚   β”œβ”€β”€ PermissionManager.kt
β”‚   β”œβ”€β”€ BatteryOptimizer.kt
β”‚   β”œβ”€β”€ ErrorHandler.kt
β”‚   β”œβ”€β”€ AnalyticsManager.kt
β”‚   β”œβ”€β”€ AppConstants.kt
β”‚   β”œβ”€β”€ ResultExtensions.kt
β”‚   β”œβ”€β”€ DialogHelper.kt
β”‚   β”œβ”€β”€ PermissionUIHelper.kt
β”‚   β”œβ”€β”€ ViewHelpers.kt
β”‚   β”œβ”€β”€ JsonHelper.kt
β”‚   β”œβ”€β”€ FileHelper.kt
β”‚   β”œβ”€β”€ ResourceHelper.kt
β”‚   └── ValidationHelper.kt
β”‚
β”œβ”€β”€ notifications/                      # Notifications
β”‚   └── NotificationManager.kt
β”‚
β”œβ”€β”€ receivers/                          # Broadcast receivers
β”‚   β”œβ”€β”€ BootReceiver.kt
β”‚   β”œβ”€β”€ UsbReceiver.kt
β”‚   β”œβ”€β”€ BluetoothReceiver.kt
β”‚   β”œβ”€β”€ NetworkReceiver.kt
β”‚   └── NotificationReceiver.kt
β”‚
β”œβ”€β”€ di/                                 # Dependency Injection
β”‚   β”œβ”€β”€ AppModule.kt
β”‚   β”œβ”€β”€ NetworkModule.kt
β”‚   β”œβ”€β”€ DatabaseModule.kt
β”‚   β”œβ”€β”€ RepositoryModule.kt
β”‚   β”œβ”€β”€ UseCaseModule.kt
β”‚   β”œβ”€β”€ FeatureModule.kt
β”‚   β”œβ”€β”€ ViewModelModule.kt
β”‚   β”œβ”€β”€ ServiceModule.kt
β”‚   β”œβ”€β”€ SensorModule.kt
β”‚   β”œβ”€β”€ ViewModelKey.kt
β”‚   └── AppContainer.kt
β”‚
└── sync/                               # Sync manager
    └── DataSyncManager.kt

Module Breakdown

1. Auth Module

  • Purpose: Authentication and token management
  • Key Files:
    • AuthManager.kt - Manages authentication state

2. Data Module

  • Purpose: Data persistence and retrieval
  • Sub-packages:
    • datasource/local/ - Room database and local storage
    • datasource/remote/ - Network data sources
    • mapper/ - Data mappers between domain and entities
    • repository/ - Repository implementations

3. Domain Module

  • Purpose: Business logic and models
  • Sub-packages:
    • model/ - Domain models
    • repository/ - Repository interfaces
    • usecase/ - Business logic use cases

4. Features Module

  • Purpose: Feature orchestration
  • Key Files:
    • ConnectionFeature.kt - Network connection management
    • MouseControlFeature.kt - Mouse control
    • CalibrationFeature.kt - Sensor calibration
    • GestureRecognitionFeature.kt - Gesture detection
    • ProximityFeature.kt - Proximity security
    • StatisticsFeature.kt - Statistics tracking
    • VoiceFeature.kt - Voice commands
    • ProfileFeature.kt - User profiles
    • UpdateFeature.kt - App updates
    • SensorFeature.kt - Sensor management

5. Network Module

  • Purpose: Network communication
  • Key Files:
    • ConnectionManager.kt - Unified connection manager
    • WebSocketManager.kt - WebSocket communication
    • TcpClient.kt - TCP communication
    • UdpDiscovery.kt - UDP discovery
    • NetworkQualityMonitor.kt - Network quality monitoring
    • MessageTypes.kt - Message type constants

6. Presentation Module

  • Purpose: UI and user interaction
  • Sub-packages:
    • base/ - Base classes (ViewModel)
    • extensions/ - Compose extensions
    • navigation/ - Navigation
    • theme/ - Theming
    • ui/ - UI Screens and components

7. Sensors Module

  • Purpose: Sensor data processing
  • Key Files:
    • CalibrationHelper.kt - Sensor calibration
    • MadgwickAHRS.kt - Sensor fusion
    • EnhancedGestureDetector.kt - Gesture detection

8. Service Module

  • Purpose: Background services
  • Key Files:
    • SensorService.kt - Sensor data service
    • BluetoothHidService.kt - Bluetooth HID
    • ProximityService.kt - Proximity monitoring
    • VoiceCommandService.kt - Voice recognition

9. Utils Module

  • Purpose: Utility classes and helpers
  • Key Files:
    • PreferencesManager.kt - Shared preferences
    • PermissionManager.kt - Permission handling
    • BatteryOptimizer.kt - Battery optimization
    • ErrorHandler.kt - Error handling
    • AnalyticsManager.kt - Analytics tracking

10. DI Module

  • Purpose: Dependency injection
  • Key Files:
    • All *Module.kt files for Hilt

Data Flow

UI β†’ Data Flow

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                               UI FLOW                                   β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                         β”‚
β”‚  User Action β†’ ViewModel β†’ UseCase β†’ Repository β†’ DataSource β†’ Network β”‚
β”‚       ↓           ↓          ↓          ↓            ↓          ↓      β”‚
β”‚  Compose      StateFlow   Business   Data       Local/      Server     β”‚
β”‚  Screen      Update       Logic      Access     Remote                 β”‚
β”‚                                                                         β”‚
β”‚  ────────────────────────────────────────────────────────────────────── β”‚
β”‚                                                                         β”‚
β”‚  Network β†’ DataSource β†’ Repository β†’ UseCase β†’ ViewModel β†’ UI          β”‚
β”‚     ↓          ↓           ↓          ↓          ↓          ↓          β”‚
β”‚  Server     Data        Data        Business   State     Compose       β”‚
β”‚             Access      Storage     Logic      Update    Screen        β”‚
β”‚                                                                         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

State Management Flow

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   User      β”‚    β”‚  ViewModel  β”‚    β”‚   State     β”‚
β”‚   Action    │───▢│  Event      │───▢│   Update    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                              β”‚
                                              β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Compose   │◀───│   State     │◀───│   State     β”‚
β”‚   Screen    β”‚    β”‚   Flow      β”‚    β”‚   Container β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Layer Diagrams

Clean Architecture Layers

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                           PRESENTATION LAYER                           β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚  Activities & Composables                                      β”‚   β”‚
β”‚  β”‚  - HomeScreen, CalibrationScreen, SettingsScreen              β”‚   β”‚
β”‚  β”‚  - GestureStudioScreen, ProximityScreen                       β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚  ViewModels                                                    β”‚   β”‚
β”‚  β”‚  - HomeViewModel, CalibrationViewModel, SettingsViewModel      β”‚   β”‚
β”‚  β”‚  - GestureStudioViewModel, ProximityViewModel                 β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                           DOMAIN LAYER                                β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚  Use Cases                                                     β”‚   β”‚
β”‚  β”‚  - ConnectToServerUseCase, SendMovementUseCase                β”‚   β”‚
β”‚  β”‚  - CalibrationUseCase, DetectGestureUseCase                   β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚  Domain Models                                                 β”‚   β”‚
β”‚  β”‚  - ConnectionModels, MouseModels, GestureModels               β”‚   β”‚
β”‚  β”‚  - CalibrationModels, SensorModels, ProximityModels           β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚  Repository Interfaces                                          β”‚   β”‚
β”‚  β”‚  - IConnectionRepository, IMouseRepository                     β”‚   β”‚
β”‚  β”‚  - IGestureRepository, ICalibrationRepository                  β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                           DATA LAYER                                  β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚  Repository Implementations                                    β”‚   β”‚
β”‚  β”‚  - ConnectionRepositoryImpl, MouseRepositoryImpl              β”‚   β”‚
β”‚  β”‚  - GestureRepositoryImpl, CalibrationRepositoryImpl            β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚  Data Sources                                                  β”‚   β”‚
β”‚  β”‚  - Local: Room Database, Preferences                           β”‚   β”‚
β”‚  β”‚  - Remote: WebSocket, TCP, UDP                                 β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚  Mappers                                                       β”‚   β”‚
β”‚  β”‚  - DomainToEntityMapper, EntityToDomainMapper                  β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                       INFRASTRUCTURE LAYER                            β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚  Network                                                       β”‚   β”‚
β”‚  β”‚  - ConnectionManager, WebSocketManager, TcpClient             β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚  Database                                                      β”‚   β”‚
β”‚  β”‚  - AppDatabase, Room DAOs, DataStore                           β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚  Sensors                                                       β”‚   β”‚
β”‚  β”‚  - CalibrationHelper, MadgwickAHRS, EnhancedGestureDetector   β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚  Services                                                      β”‚   β”‚
β”‚  β”‚  - SensorService, BluetoothHidService, ProximityService        β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Dependency Injection Graph

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         DI MODULES                                 β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  AppModule          β”‚  Provides: Preferences, Sensors, Utils      β”‚
β”‚  NetworkModule      β”‚  Provides: OkHttp, ConnectionManager        β”‚
β”‚  DatabaseModule     β”‚  Provides: Room Database, DAOs              β”‚
β”‚  RepositoryModule   β”‚  Provides: Repository Implementations       β”‚
β”‚  UseCaseModule      β”‚  Provides: Use Cases                        β”‚
β”‚  FeatureModule      β”‚  Provides: Features                         β”‚
β”‚  ViewModelModule    β”‚  Provides: ViewModels                       β”‚
β”‚  ServiceModule      β”‚  Provides: Services                         β”‚
β”‚  SensorModule       β”‚  Provides: Sensor Components                β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
                              β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Hilt Components Tree                            β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  SingletonComponent                                                β”‚
β”‚  β”œβ”€β”€ AppModule                                                     β”‚
β”‚  β”œβ”€β”€ NetworkModule                                                 β”‚
β”‚  β”œβ”€β”€ DatabaseModule                                                β”‚
β”‚  β”œβ”€β”€ RepositoryModule                                              β”‚
β”‚  β”œβ”€β”€ UseCaseModule                                                 β”‚
β”‚  β”œβ”€β”€ FeatureModule                                                 β”‚
β”‚  β”œβ”€β”€ ServiceModule                                                 β”‚
β”‚  └── SensorModule                                                  β”‚
β”‚                                                                     β”‚
β”‚  ViewModelComponent                                                β”‚
β”‚  └── ViewModelModule                                               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Key Components

1. BaseViewModel

abstract class BaseViewModel<State, Event>(initialState: State) : ViewModel() {
    private val _state = MutableStateFlow(initialState)
    val state: StateFlow<State> = _state.asStateFlow()
    
    private val _event = MutableSharedFlow<Event>()
    val event: SharedFlow<Event> = _event.asSharedFlow()
    
    protected fun setState(reducer: State.() -> State) {
        _state.update { it.reducer() }
    }
    
    protected fun sendEvent(event: Event) {
        viewModelScope.launch { _event.emit(event) }
    }
    
    abstract fun onEvent(event: Event)
}

2. ConnectionManager

@Singleton
class ConnectionManager @Inject constructor(
    @ApplicationContext private val context: Context,
    private val prefs: PreferencesManager
) {
    // Unified connection management for WebSocket and TCP
    // StateFlow for connection status and quality
    // Auto-reconnection with exponential backoff
}

3. Feature Pattern

@Singleton
class ConnectionFeature @Inject constructor(
    private val connectToServerUseCase: ConnectToServerUseCase,
    private val discoverServersUseCase: DiscoverServersUseCase,
    private val getConnectionStatusUseCase: GetConnectionStatusUseCase,
    private val testConnectionUseCase: TestConnectionUseCase
) {
    // Orchestrates multiple use cases
    // Provides high-level feature API
    // Manages feature state
}

Testing Strategy

Test Pyramid

        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚   UI    β”‚  ← Espresso, Compose UI Testing
       β”Œβ”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”
       β”‚ Integrationβ”‚  ← Integration Tests
      β”Œβ”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”
      β”‚   Unit Tests  β”‚  ← JUnit, Mockito, MockK
     β”Œβ”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”
     β”‚   Domain Logic  β”‚  ← Use Case Testing
    β”Œβ”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”
    β”‚  Repository Tests  β”‚  ← Data Layer Testing
   β”Œβ”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”
   β”‚  Instrumentation Testsβ”‚  ← Android Testing
   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Test Locations

app/src/
β”œβ”€β”€ test/                          # Unit tests
β”‚   β”œβ”€β”€ java/com/airmouse/
β”‚   β”‚   β”œβ”€β”€ domain/
β”‚   β”‚   β”‚   β”œβ”€β”€ model/
β”‚   β”‚   β”‚   β”œβ”€β”€ repository/
β”‚   β”‚   β”‚   └── usecase/
β”‚   β”‚   β”œβ”€β”€ features/
β”‚   β”‚   └── utils/
β”‚   └── resources/
β”‚
└── androidTest/                   # Instrumentation tests
    β”œβ”€β”€ java/com/airmouse/
    β”‚   β”œβ”€β”€ presentation/
    β”‚   β”‚   β”œβ”€β”€ ui/
    β”‚   β”‚   └── navigation/
    β”‚   β”œβ”€β”€ data/
    β”‚   └── service/
    └── resources/

Build Variants

Flavor Dimensions

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         BUILD VARIANTS                              β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                     β”‚
β”‚  Environment:                                                       β”‚
β”‚  β”œβ”€β”€ dev     (Development)                                         β”‚
β”‚  β”œβ”€β”€ staging (Staging)                                             β”‚
β”‚  └── prod    (Production)                                          β”‚
β”‚                                                                     β”‚
β”‚  Mode:                                                              β”‚
β”‚  β”œβ”€β”€ debug   (Debug)                                               β”‚
β”‚  └── release (Release)                                             β”‚
β”‚                                                                     β”‚
β”‚  Flavors:                                                           β”‚
β”‚  β”œβ”€β”€ free    (Free version)                                        β”‚
β”‚  └── pro     (Pro version)                                         β”‚
β”‚                                                                     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Third-Party Libraries

Library Purpose Version
Jetpack Compose UI Framework 2024.10.00
Material 3 Material Design 1.3.0
Hilt Dependency Injection 2.52
Room Database 2.6.1
DataStore Preferences 1.1.1
OkHttp Networking 4.12.0
Retrofit REST Client 2.11.0
Gson JSON Parsing 2.11.0
Coroutines Async Programming 1.7.3
TensorFlow Lite ML Inference 2.16.1
UsbSerial USB Communication 3.8.0
Timber Logging 5.0.1
Truth Assertions 1.1.5
Mockk Mocking 1.13.8

Development Guidelines

1. Package Naming Convention

com.airmouse.[layer].[feature].[component]

2. Class Naming Convention

Layer Prefix/Suffix Example
Model No suffix ConnectionConfig
Repository Interface I prefix IConnectionRepository
Repository Implementation Impl suffix ConnectionRepositoryImpl
Use Case UseCase suffix ConnectToServerUseCase
ViewModel ViewModel suffix HomeViewModel
Screen Screen suffix HomeScreen
Service Service suffix SensorService
Feature Feature suffix ConnectionFeature

3. File Organization

Each feature should have:
β”œβ”€β”€ domain/
β”‚   β”œβ”€β”€ model/          # Feature-specific models
β”‚   β”œβ”€β”€ repository/     # Repository interfaces
β”‚   └── usecase/        # Feature use cases
β”œβ”€β”€ data/
β”‚   β”œβ”€β”€ datasource/     # Data sources
β”‚   └── repository/     # Repository implementations
└── presentation/
    β”œβ”€β”€ ui/             # UI Screens
    β”œβ”€β”€ viewmodel/      # ViewModels
    └── components/     # UI Components

4. State Management

  • Use StateFlow for UI state
  • Use SharedFlow for events
  • Use MutableStateFlow for mutable state
  • Use update {} for atomic updates

5. Error Handling

  • Use Result<T> for operations
  • Use sealed class for error types
  • Use ErrorHandler for centralized error handling

6. Logging

  • Use Timber for logging
  • Use Log.d() for debug
  • Use Log.e() for errors
  • Use Log.w() for warnings

Summary

The Air Mouse Android app follows a Clean Architecture with MVVM pattern, using Jetpack Compose for UI and Hilt for dependency injection. The architecture is designed to be:

  • βœ… Testable - Each layer is independently testable
  • βœ… Maintainable - Clear separation of concerns
  • βœ… Scalable - Easy to add new features
  • βœ… Decoupled - Low coupling between layers
  • βœ… Modern - Uses latest Android technologies
  • βœ… Production-ready - Error handling, logging, analytics

The app is structured to handle:

  • πŸ”Œ Multiple Protocols: WebSocket, TCP, UDP, Bluetooth, USB
  • 🎯 Gesture Recognition: TensorFlow Lite model
  • πŸ“‘ Proximity Lock: Bluetooth RSSI-based
  • πŸŽ™οΈ Voice Commands: Speech recognition
  • πŸ–±οΈ Mouse Control: Cross-platform cursor control
  • πŸ“Š Analytics: Usage tracking and statistics
  • πŸ” Profiles: Multiple user profiles
  • πŸ“¦ Updates: In-app updates

Xet Storage Details

Size:
42.4 kB
Β·
Xet hash:
2ad5786ad76a298a80f6d4a95d0ca81acf83c650142b5c9e28ca43236afcb054

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.