MiNap: Backend Architecture and Implementation

Summary

The MiNap application ecosystem primarily has two different applications:

  1. The Smartwatch Application
  2. The Smartphone Application

The mobile application and the watch application are separate applications that share the same backend resources.  


Figure: Illustration of the backend architecture and processes.

Smart watch Application

The current Smatwatch application is for the Apple Smart watches and is built using Swift. The smart watch is designed for research participants and is dedicated to recording sleep sessions. Its simple intuitive user interface requires participants to simply press a button before sleep and upon waking up, eliminating the complexities adhered to traditional sleep diaries.The application's technical backbone processes user interactions and translates them into API requests. A simple button press initiates a cascade of actions, culminating in the secure storage of sleep session data within DynamoDB.

Mobile Application

The mobile application is built using React Native, aiming to guarantee cross-platform compatibility and to allow participants to engage with their recent sleep sessions. The application supports the same 'Sign in' interface as the Smartwatch and the initial Screen enlists the recent sleep sessions for the participant, which is generated by querying the data stored within the AWS DynamoDB . Participants can click on the session on the list to fill out a survey form to help researchers get ad-hoc insight into the collected data. 

Data Collection and Storage

At the centre of MiNap's  Backend Architecture lies Amazon Web Services (AWS), the robust cloud computing which provides the infrastructure for data storage and management. The application relies on AWS DynamoDB, a NoSQL database service, to handle the storage of data. There are primarily two tables within the DynamoDB :

  • The Authentication Table - Dedicated for authentication processes. The attributes include the research study id and the research participant id. The data is synced from the Oracle database hosted at the Michigan Medicine's end.
  • The Sleep Session Table - This table is designed to store all the data related to an instance of sleep session against the study id and participant id. Primarily it includes the time when a participant clicks on the "Sleep" button, as the session start time, the session end time when the participant clicks on the "Wake Up" button, the survey inputs for the specific record, the study id and the participant's id. The study id and participant id compositely serve as the unique identifier.

The integration of GraphQL API with AWS DynamoDB facilitates smooth interaction between the smartwatch and the backend. This enables participants to effortlessly log sleep sessions directly from their smartwatches, ensuring a seamless user experience. Additionally, AWS Datastore, skillfully implemented within the watchOS application, enables local storage of sleep session data on the smartwatch itself. This feature ensures data persistence even in scenarios where the internet connection is unavailable..

The official AWS documentation for the setup can be accessed here

Data Syncronization

One standout feature of MiNap's backend architecture is its data synchronization mechanism. A Docker containerized script orchestrates the synchronization of data between AWS resources and the Oracle SQL database housed within the University of Michigan medical school's secure environment. This script should be hosted on an internal University of Michigan server, to serve as a bridge, ensuring that authentication information and sleep session data are seamlessly synchronized between AWS DynamoDB and Oracle database tables.

Once the sleep session data from AWS DynamoDB is successfully synchronized with the Oracle database, data is purged from DynamoDB to maintain data security. This meticulous approach safeguards sensitive sleep data while enabling researchers to derive insights from a secure environment.

Setting up

 The resource setup for MiNap's smartwatch application leverages  AWS Amplify's capabilities, to efficiently establish the backend resources required for data storage, synchronization, and retrieval. This step lays the foundation for subsequent integration with the mobile application and paves the way for seamless data management. Here's a technical walkthrough of the resource setup process:

Sequential Setup: Smartwatch Before Mobile

To ensure a smooth integration process, it's imperative to establish the smartwatch application's backend resources before proceeding with the mobile application. This sequential approach guarantees that the necessary infrastructure is in place to accommodate data flow and storage.

Leveraging AWS Amplify for WatchOS

The backbone of MiNap's smartwatch application is forged using AWS Amplify, a powerful backend resource provisioning tool. It offers a comprehensive suite of functionalities that facilitates resource management and data interactions.

Step by Step Setup Guide

  1. Begin by accessing the AWS Amplify documentation tailored for setting up resources for watchOS applications. This guide serves as a definitive roadmap for the technical steps required to lay the groundwork: AWS Amplify WatchOS Documentation

  2. Set up an AWS IAM user for the application to gain access of all backend resource. You may do it in a user group to allow multiple users to have the user-level access to our backend resources in the future. For the setup, give the user full access to AWS DataStore, AWS DynamoDB, AWS Amplify and AWS AppSync services. Here's how we set up our user group:  

  3. Use the admin user within the user group o initialize an AWS Amplify project within our cloned repo. You will be asked to provide an access key. We created two access keys to initialize two AWS Amplify backends: one for watchOS and one for mobile. Set up both access keys to be invoked by AWS CLI. When prompted about creating GraphQL schema during the setup. Simply ignore it and leave it to AWS Amplify Studio. Use the first access key to initialize AWS Amplify project for watchOS ​​​​​​.

  4. Although it could be done programmatically, it might be easier to launch AWS Amplify Studio to manage the data models. Click on "Data" section and edit the visual editor to match our version. 

  5. Next, you want to go to GraphQL API section and run the code to update API resources in the project. 

  6. Now the watchOS app should be up and running!

  7. Navigate to the folder for mobile application. You'd want to use AWS AppSync to provision the backend resources. Open AWS AppSync Console and select the GraphQL API you created for watchOS.

  8. Go to the "Integrate with your app" section and run the commands listed there. When running amplify init, this is where you would use your second access key for your IAM user. Note: Do NOT do this in the Amplify project for watchOS. watchOS and iOS applications should be TWO separate AWS Amplify backend applications.

  9. Now the mobile app should be up and running!

For the database synchronization script, it is intended to be hosted within a secure network (ex. Michigan Medicine Network) that has higher-level security measures than enterprise network. It is a stateless script that is by default to run every 5 minutes following a cron schedule. In real practice, it should be run as a daemon process after Oracle SQL DB is set up. It syncs authentication data from Oracle to AWS DynamoDB and sleep session data from AWS DynamoDB to Oracle. The schema for both AWS DynamoDB and Oracle should be the same. Note that for the survey field on Oracle SQL DB, long string type should be used. 

The documentation must be followed meticulously, adhering to each step and command outlined to integrate AWS Amplify with watchOS application. The platform introduces specific considerations for resource provisioning and data synchronization.

AWS Amplify introduces a host of advantages in the context of smartwatch application development, including modularity, scalability and flexibility to seamlessly accommodate increased demand, standardized methods for interacting with AWS services, ensuring consistency in data exchanges  and most importantly AWS Amplify abstracts the complexities of backend infrastructure setup, allowing developers to focus on functionality rather than configuration. 

Github

 The application source code and associated resources are available at the Depression Center's GitHub repository (https://github.com/DepressionCenter/MiNap). The details to replicate the code and details on the file tree are documented within the repository.

Future Scopes

The companion mobile application can be used to generate simultaneous log-in (digital tokens) and real-time data sync the SmartWatch leveraging bluetooth technology. Furthermore, the backend can include access level management to help assign user-based access to features and data, for example researcher's could be granted a access to the mobile application to view the data associated to their study id/s  and the participants within them and get insights from embedded visualizations. If further smartwatch operating systems such as Fitbit, Garmin etc. are targeted for the sleep medicine study, the backend architecture would remain the same but separate watch applications would need to be developed appropriate to the technology.

In conclusion, the backend architecture of the MiNap smartwatch-based sleep diary application showcases a harmonious amalgamation of cutting-edge technologies. The integration of AWS services, GraphQL API, Docker, and React Native empowers researchers and participants alike with a user-friendly, secure, and efficient platform for collecting, managing, and analyzing sleep data. As the field of sleep medicine research advances, MiNap's technical backend architecture stands as a testament to the potential of technology-driven innovation in enhancing our understanding of sleep and its profound impact on health and well-being. In the future, it may be more convenient for researchers to adapt to our project by building a IaC (infrastructure as code) pipeline to help provision our cloud infrastructure for a smoother setup. 

About the Authors

Anika Raisa Chowdhury is a graduate student pursuing Masters of Data Science, at the University of Michigan . Anika has worked as a project Manager for MiNap Sleep diary during her Internship at University of Michigan Information and Technology Services in Summer2023. Alongside Assuming the role of a project manager, she also worked on the backend, to set up the databases and the synchronization scripts.

 | 

Max Liu is a Junior at the University of Michigan pursuing his Bachelor's in Computer Science and Data Science. Max has worked as the primary backend developer for the MiNap sleep diary, sponsored by the Eisenberg Family Depression Center. He worked on both the mobile/watchOS app setup and database synchronization scripts. 

 | 

 
Print Article

Related Articles (2)

This article introduces MiNap, an application developed to serve as a prototype for sleep medicine research data collection. The article shares an overview of the problem in hand, the designed solution and its future potential in the medical research domain.
This article walks through the MiNap application ecosystem, specifically the two front-end apps and researcher's dashboard.