How yesshreyes/real-time-ecg-monitoring-and-arrhythmia-detection-using-edge-ai works
1. Project shape
- RhythmAI is a single Android app module built with Kotlin, Jetpack Compose, and TensorFlow Lite.
- There is no backend or cloud service in this repo; the core architecture is fully on-device.
2. App shell
- MainActivity is the entry point and hosts the Compose navigation shell.
- AppNavGraph and BottomBar define a three-tab user flow: Connect, Monitor, and Stats.
3. Primary UI boundaries
- The UI is split into feature screens under presentation/.
- Each screen has its own ViewModel and composable widgets, keeping monitoring, connection, and analytics concerns separated.
4. ECG input source
- The app reads ECG data from bundled CSV assets such as ecg_sample.csv, 100_ekg.csv, and 200_ekg.csv.
- EcgAssetLoader is the ingestion boundary from packaged data into the runtime pipeline; it appears to simulate or replay ECG streams rather than consume a live sensor in the current repo.
5. Real-time monitoring pipeline
- MonitorViewModel is the orchestration layer for ECG processing.
- It maintains the live signal window, heart-rate calculation, signal-quality status, and current prediction state that drive the monitor screen.
6. On-device ML inference
- EcgTFLiteClassifier is the inference boundary around the bundled TFLite models.
- The app ships multiple models in app/src/main/assets/: sqi_model.tflite, stage1_model.tflite, stage2_model.tflite, plus ecg_multiclass_compat.tflite for compatibility or alternative classification.
- The intended inference flow is: SQI quality check → Stage 1 abnormal/normal screening → Stage 2 arrhythmia type classification.
7. Monitor screen composition
- MonitorScreen combines live waveform rendering, signal-quality feedback, and prediction output.
- Reusable UI pieces like EcgWaveform, SignalQualityCard, and PredictionCard visualize the current stream state and model result.
8. Alert and safety behavior
- The README describes alerting based on consecutive abnormal detections, quality gating, vibration, and SOS access.
- In architecture terms, this is an application-layer response driven by ViewModel state and Android platform actions rather than a separate service.
9. Stats and event history
- StatsViewModel and the stats composables present arrhythmia event history and detailed prediction information.
- ArrhythmiaEventCard, ArrhythmiaEventItem, and DetailedPredictionView suggest the stats screen is an analytics/readout layer over logged detection events, likely maintained locally in app state.
10. Connect flow
- ConnectScreen and ConnectViewModel represent the device-connection boundary.
- Based on the current file set, this looks like the UI and state layer for selecting or pairing a source device, but the actual Bluetooth/sensor integration is not shown in this repo.
11. Architecture style
- The repo follows a clean feature split: data/inference, presentation/state, navigation, and UI components.
- There is no visible persistence layer such as Room, network client, or repository abstraction; the app is centered on streaming ECG data into local inference and rendering the results immediately.
12. Supporting structure
- ui/theme contains the Compose theme system, and res/ holds the Android resources and manifest configuration.
- Tests exist in androidTest and test, but they are peripheral to the runtime architecture.
13. ML deployment boundary
- The model-training workflow is described in README.md and ML_implementation.md, but the Android app itself only consumes exported TFLite artifacts.
- That makes the repo’s runtime boundary clear: training happens offline, inference happens inside the app, and all predictions remain on device.
Main entry points: MonitorViewModel.kt MonitorViewModel · AppNavGraph.kt AppNavGraph · MonitorScreen.kt MonitorScreen · StatsScreen.kt StatsScreen
Components 22
App shell
Activity entry point and navigation scaffolding.
- MainActivity · App entry point that hosts the Compose UI shell.
app/src/main/java/com/example/rhythmai/MainActivity.kt - AppNavGraph · Defines the top-level Compose navigation flow.
app/src/main/java/com/example/rhythmai/navigation/AppNavGraph.kt - BottomBar · Bottom navigation for the three main tabs.
app/src/main/java/com/example/rhythmai/navigation/BottomBar.kt - BottomNavItem · Tab definitions used by the bottom navigation.
app/src/main/java/com/example/rhythmai/navigation/BottomNavItem.kt
ECG pipeline
On-device data ingestion and inference.
- EcgAssetLoader · Loads packaged ECG CSV assets into the runtime pipeline.
app/src/main/java/com/example/rhythmai/data/EcgAssetLoader.kt - EcgTFLiteClassifier · Wraps the on-device TensorFlow Lite models for ECG classification.
app/src/main/java/com/example/rhythmai/data/EcgTFLiteClassifier.kt
Monitoring
Live ECG monitoring screen and widgets.
- MonitorScreen · Composes live waveform, quality, and prediction panels.
app/src/main/java/com/example/rhythmai/presentation/monitor/MonitorScreen.kt - MonitorViewModel · Coordinates ECG windowing, heart rate, quality, and prediction state.
app/src/main/java/com/example/rhythmai/presentation/monitor/MonitorViewModel.kt - MonitorViewModelFactory · Creates the monitor ViewModel with its dependencies.
app/src/main/java/com/example/rhythmai/presentation/monitor/MonitorViewModelFactory.kt - EcgWaveform · Renders the live ECG waveform.
app/src/main/java/com/example/rhythmai/presentation/monitor/EcgWaveform.kt - SignalQualityCard · Shows signal quality and gating feedback.
app/src/main/java/com/example/rhythmai/presentation/monitor/SignalQualityCard.kt - PredictionCard · Displays the current model prediction and status.
app/src/main/java/com/example/rhythmai/presentation/monitor/PredictionCard.kt
Stats
Event history and prediction readout.
- StatsScreen · Screen for arrhythmia event history and prediction details.
app/src/main/java/com/example/rhythmai/presentation/stats/StatsScreen.kt - StatsViewModel · Provides stats data and detailed prediction history.
app/src/main/java/com/example/rhythmai/presentation/stats/StatsViewModel.kt - ArrhythmiaEventCard · Card view for arrhythmia event summaries.
app/src/main/java/com/example/rhythmai/presentation/stats/ArrhythmiaEventCard.kt - ArrhythmiaEventItem · List item for individual arrhythmia events.
app/src/main/java/com/example/rhythmai/presentation/stats/ArrhythmiaEventItem.kt - DetailedPredictionView · Expanded view of prediction details and context.
app/src/main/java/com/example/rhythmai/presentation/stats/DetailedPredictionView.kt
Connect
Source/device connection flow.
- ConnectScreen · UI for selecting or pairing an ECG source device.
app/src/main/java/com/example/rhythmai/presentation/connect/ConnectScreen.kt - ConnectViewModel · Owns connect-screen state and device selection flow.
app/src/main/java/com/example/rhythmai/presentation/connect/ConnectViewModel.kt
Theme
Compose theme system.
- Theme · App-wide Material theme entry point.
app/src/main/java/com/example/rhythmai/ui/theme/Theme.kt - Color · Color definitions for the Compose theme.
app/src/main/java/com/example/rhythmai/ui/theme/Color.kt - Type · Typography definitions for the Compose theme.
app/src/main/java/com/example/rhythmai/ui/theme/Type.kt
Connections 24
- MainActivity → AppNavGraph: hosts · Activity launches the Compose navigation shell.
- AppNavGraph → BottomBar: uses · Navigation shell includes the bottom tab bar.
- BottomBar → BottomNavItem: reads · Bottom bar is driven by tab definitions.
- AppNavGraph → ConnectScreen: routes · Navigation exposes the Connect tab.
- AppNavGraph → MonitorScreen: routes · Navigation exposes the Monitor tab.
- AppNavGraph → StatsScreen: routes · Navigation exposes the Stats tab.
- ConnectScreen → ConnectViewModel: binds · Connect UI is state-driven.
- MonitorScreen → MonitorViewModel: binds · Monitor UI is state-driven.
- MonitorViewModel → MonitorViewModelFactory: created by · Factory constructs the monitor ViewModel.
- MonitorViewModel → EcgAssetLoader: ingests · Monitor logic consumes ECG data from packaged assets.
- MonitorViewModel → EcgTFLiteClassifier: infers · Monitor logic runs on-device model inference.
- MonitorScreen → EcgWaveform: renders · Waveform widget visualizes the live stream.
- MonitorScreen → SignalQualityCard: renders · Quality card shows signal gating status.
- MonitorScreen → PredictionCard: renders · Prediction card shows the current classification.
- StatsScreen → StatsViewModel: binds · Stats UI is state-driven.
- StatsScreen → ArrhythmiaEventCard: renders · Stats screen shows event summaries.
- StatsScreen → ArrhythmiaEventItem: renders · Stats screen lists individual events.
- StatsScreen → DetailedPredictionView: renders · Stats screen exposes detailed prediction context.
- MainActivity → Theme: wraps · Root UI is wrapped in the app theme.
- Theme → Color: uses · Theme is built from shared color tokens.
- Theme → Type: uses · Theme is built from shared typography tokens.
- MonitorViewModel → PredictionCard: drives · Prediction state feeds the monitor output card.
- MonitorViewModel → SignalQualityCard: drives · Quality state feeds gating feedback.
- MonitorViewModel → EcgWaveform: drives · Live signal window feeds waveform rendering.