# intelehealth/intelehealth-fhw-mobileapp architecture

> Architecture diagram of the GitHub repository intelehealth/intelehealth-fhw-mobileapp, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-09-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/intelehealth/intelehealth-fhw-mobileapp
- Repository: https://github.com/intelehealth/intelehealth-fhw-mobileapp

## Overview

##### Project type and purpose
- This is a full-stack Android application (Intelehealth FHW MobileApp) for community health workers (CHWs) to collect patient data, run decision trees, conduct exams, and sync information + video calls with remote doctors.
- It includes two Gradle modules:
- “app” – the primary Android client with UI, local database, sync, API clients, and background services.
- “webrtc” – a library for video/RTC interactions (peer connection, Firebase signaling, chat UI).

##### File structure
- Top-level “app” folder contains:
- src/main/java – UI Activities, Adapters, Utilities, Data Models, DAO, Sync and Network packages
- src/main/res – layouts, drawables, menus, values, xml configs
- services – download/upload/sync IntentServices, FirebaseMessaging
- syncModule – WorkManager, SyncUtils, LastSyncWork
- database/dao – SQLite helper, DAOs for Encounters, Patients, Visits, Images, Sync, RTCConnection
- appointment/api & networkApiCalls – Retrofit/OkHttp API interfaces and clients
- knowledgeEngine – clinical decision tree nodes
- “webrtc” module contains:
- apprtc services, activities, adapters, Manager for peer connections
- SocketBackgroundService for signaling, FirebaseUtils
- resources for chat UI and camera toggles

##### README
- Confirms a low-bandwidth telemedicine mobile client that:
- collects clinical data via guided flows
- uploads to a cloud EHR backend
- supports real-time video/voice via WebRTC and Firebase
- uses offline storage and scheduled sync

##### Main components
a. MobileApp UI Layer
- Activities & Fragments (Intro, Login, PatientDetail, PhysicalExam, Prescription, VideoLibrary, AppointmentListing…)
- knowledgeEngine for dynamic flows
b. Local Data Layer
- SQLite DB (InteleHealthDatabaseHelper + DAOs)
- SharedPreferences / SessionManager
c. Sync & Background Services
- SyncModule (WorkManager jobs: LastSyncWork, VisitSummaryWork)
- IntentServices: DownloadService, MyIntentService, UpdateDownloadPrescriptionService
- OfflineLogin, NetworkChangeListener
d. Network Layer
- Retrofit clients: ApiClient, ApiClientAppointment, ApiInterface, Appointment APIs
- PushRequestApiCall & PushResponseApiCall DTOs
- AppointmentSync, ActivitySync, EventManager
e. Real-Time Communication
- webrtc module: PeerConnection Manager, ChatActivity, SocketBackgroundService
- FirebaseMessaging for signaling (MyFirebaseMessagingService, CallListenerBackgroundService)
f. External Services / Servers
- Cloud EHR Server (OpenMRS REST endpoints)
- Firebase Cloud Messaging (FCM)
- WebRTC STUN/TURN servers
- Remote Doctor Web UI / API

##### Relationships & data flow
- UI → Local DB: writes form data, images, patient visits
- UI → Network Layer: triggers API calls (login, patient search, upload survey, appointment booking)
- SyncModule ↔ Local DB: reads pending records → uploads via network clients → marks synced
- Background Services → Network Layer: periodic download of protocols, prescriptions, and survey configs
- webrtc module ↔ Firebase → PeerConnection: call signaling messages → establish P2P media streams
- MobileApp ↔ Cloud EHR: RESTful JSON over HTTPS
- MobileApp ↔ Firebase FCM: push notifications for call invites, sync acknowledgements

##### Architectural patterns & principles
- MVVM/MVP-style separation: Activities/Adapters ≠ Data Models ≠ API/DAO
- Repository pattern: DAO + API clients feed ViewModels/Activities
- WorkManager for reliable background sync
- IntentService for on-demand tasks
- Modularization: core app + RTC module

- Notes on protocols: HTTPS/REST, WebRTC P2P, FCM push
- Key design patterns (Repository, WorkManager scheduling)

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "UI Layer"
        UI["Activities & Fragments"]:::ui
        KE["KnowledgeEngine"]:::ui
    end

    subgraph "Local Storage"
        DB["SQLite Database Helper"]:::data
        DAOs["DAOs (Encounters, Patients, Visits, Images, Sync, RTCConnection)"]:::data
        SM["SessionManager (SharedPreferences)"]:::data
    end

    subgraph "Sync & Background Services"
        SyncModule["SyncModule (WorkManager Jobs)"]:::sync
        Intents["IntentServices (Download/Upload/Sync)"]:::sync
        FCMService["FirebaseMessaging Services"]:::sync
    end

    subgraph "Network Layer"
        ApiCore["ApiClient & ApiInterface"]:::network
        ApptApi["Appointment APIs & Clients"]:::network
        DTO["PushRequest & Response DTOs"]:::network
    end

    subgraph "RTC Module"
        RTCMod["webrtc Module (PeerConnection Manager, Chat UI)"]:::rtc
        Signaling["SocketBackgroundService & FirebaseUtils"]:::rtc
    end

    subgraph "External Services"
        EHR["Cloud EHR Server (OpenMRS REST)"]:::external
        FCM["Firebase Cloud Messaging"]:::external
        STUN["WebRTC STUN/TURN Servers"]:::external
        DoctorUI["Remote Doctor Web UI/API"]:::external
    end

    %% Data Flows
    UI -->|"writes data"| DB
    UI -->|"reads/writes"| DAOs
    UI -->|"uses"| SM
    UI -->|"triggers API calls"| ApiCore
    UI -->|"triggers appointment calls"| ApptApi
    UI -->|"drives flows"| KE

    SyncModule <-->|"sync data"| DB
    SyncModule -->|"HTTP/REST"| ApiCore
    Intents -->|"HTTP/REST"| ApiCore
    FCMService -->|"push handling"| SyncModule

    EHR <-->|"HTTPS/REST"| ApiCore
    EHR <-->|"HTTPS/REST"| ApptApi
    FCM <--->|"push notifications"| FCMService
    FCM <--->|"call invites"| Signaling

    RTCMod -->|"P2P media"| STUN
    RTCMod -->|"uses signaling"| Signaling
    Signaling -->|"FCM signaling"| FCM

    %% Click Events
    click UI "https://github.com/intelehealth/intelehealth-fhw-mobileapp/tree/master-2.0/app/src/main/java/org/intelehealth/app/activities"
    click KE "https://github.com/intelehealth/intelehealth-fhw-mobileapp/tree/master-2.0/app/src/main/java/org/intelehealth/app/knowledgeEngine"
    click DB "https://github.com/intelehealth/intelehealth-fhw-mobileapp/blob/master-2.0/app/src/main/java/org/intelehealth/app/database/InteleHealthDatabaseHelper.java"
    click DAOs "https://github.com/intelehealth/intelehealth-fhw-mobileapp/tree/master-2.0/app/src/main/java/org/intelehealth/app/database/dao"
    click SM "https://github.com/intelehealth/intelehealth-fhw-mobileapp/blob/master-2.0/app/src/main/java/org/intelehealth/app/utilities/SessionManager.java"
    click SyncModule "https://github.com/intelehealth/intelehealth-fhw-mobileapp/tree/master-2.0/app/src/main/java/org/intelehealth/app/syncModule"
    click Intents "https://github.com/intelehealth/intelehealth-fhw-mobileapp/tree/master-2.0/app/src/main/java/org/intelehealth/app/services"
    click FCMService "https://github.com/intelehealth/intelehealth-fhw-mobileapp/tree/master-2.0/app/src/main/java/org/intelehealth/app/services/firebase_services"
    click ApiCore "https://github.com/intelehealth/intelehealth-fhw-mobileapp/blob/master-2.0/app/src/main/java/org/intelehealth/app/networkApiCalls/ApiClient.java"
    click ApiCore "https://github.com/intelehealth/intelehealth-fhw-mobileapp/blob/master-2.0/app/src/main/java/org/intelehealth/app/networkApiCalls/ApiInterface.java"
    click ApptApi "https://github.com/intelehealth/intelehealth-fhw-mobileapp/tree/master-2.0/app/src/main/java/org/intelehealth/app/appointment/api"
    click DTO "https://github.com/intelehealth/intelehealth-fhw-mobileapp/tree/master-2.0/app/src/main/java/org/intelehealth/app/models/pushRequestApiCall"
    click DTO "https://github.com/intelehealth/intelehealth-fhw-mobileapp/tree/master-2.0/app/src/main/java/org/intelehealth/app/models/pushResponseApiCall"
    click RTCMod "https://github.com/intelehealth/intelehealth-fhw-mobileapp/tree/master-2.0/webrtc/src/main/java/org/intelehealth/apprtc"
    click Signaling "https://github.com/intelehealth/intelehealth-fhw-mobileapp/blob/master-2.0/webrtc/src/main/java/org/intelehealth/apprtc/services/SocketBackgroundService.java"
    click Signaling "https://github.com/intelehealth/intelehealth-fhw-mobileapp/blob/master-2.0/webrtc/src/main/java/org/intelehealth/apprtc/utils/FirebaseUtils.java"

    %% Styles
    classDef ui fill:#e3fcef,stroke:#2e7d32,stroke-width:1px,color:#2e7d32;
    classDef data fill:#fff3e0,stroke:#ef6c00,stroke-width:1px,color:#ef6c00;
    classDef sync fill:#e3f2fd,stroke:#1e88e5,stroke-width:1px,color:#1e88e5;
    classDef network fill:#f3e5f5,stroke:#8e24aa,stroke-width:1px,color:#8e24aa;
    classDef rtc fill:#e0f7fa,stroke:#00838f,stroke-width:1px,color:#00838f;
    classDef external fill:#eceff1,stroke:#546e7a,stroke-width:1px,color:#546e7a;
```
