Skip to content

A cloud database for accessing persistent information, utilizing REST.

Notifications You must be signed in to change notification settings

nahidtopalovic/library_api

Repository files navigation

CLUBLIT! 📚

The place where readers come together to network and talk with their favorite authors and like-minded peers over voice. #QuarantineandChill #StayHomeStaySafe #togetherandhome

Clublit! in Azure Try in PWD

Docker Pull Command

docker pull hauni97/clublit_library_api_app

Table of Contents

About

CLUBLIT! is a drop-in-audio social media for book lovers and a platform that unites all readers to discuss their favorite novels and engage with fellow readers and authors in a community. We bring great minds together to discuss and share their reading experiences through co-reading, live readings, and online audio events. Our app assists you with the search for new potential reads and creates your customized wish lists.

Note: Not all features are available in the current release. This platform is developed in stages; the first and current version of the MVP (minimum viable product) demonstrates a backend developed in Node.js with CRUD operations for user accounts stored on a cloud-based MongoDB. Interaction with the external Google API REST service is used for querying book information allowing this information to be added to user's accounts. Concerning security mechanisms, the users' information follows salted and hash-based authentication. Furthermore, all our current cloud deployments have an RSA TLS (Azure) and SHA2 (Heroku) signed HTTPS certificate. For a local SSL deployment see Running Locally.

System Architecture

The front-end serves as a seamless user interface for IOS 14 and android (planned in a future release). The backend is a REST-based service interface for CRUD operations (for example, data query of books, user sign up & login, POST, PUT) deployed via Google Cloud to facilitate scalable performance with Kubernetes of our dockerized image. SSL deployments are facilitated through Microsoft Azure and Heroku. The node server interacts with Google Books API. Furthermore, our system uses a NoSQL external Cloud database (MongoDB) to securely store our community user information (salted and hashed).

Backend

It is advisable to use Postman for CRUD operations when accessing the backend.

CRUD Operations

Basic CRUD operations are possible by accessing the API routes via adding api/users and api/books at the end of the web address following the REST standard.

Note that for api/login a bearer token will be needed to access the webpage, which can be sought after a user has been registered. For more details, please see the CRUD operations documentation in the video clip.

Whereas api/books will allow querying a book sear utilizing the external Google Books API. An example JSON GET request to api/books could be:

{
    "name" : "Boris Johnson"

}

Cloud App

Our current backend is accessible as a cloud application 🚀 on Google Cloud, Azure and Heroku. Feel free to check them out!

Google Cloud

Run on Google Cloud

This is our load balanced deployment!

To deploy a load-balanced application with Kubernetes, the following approach can be followed by having logged into the cloud console and created a new project.

Pre-Checks

First, launch the cloud shell and clone the repository by:

git clone https://github.com/nahidtopalovic/library_api.git

Navigate into the repository by typing

cd library-api

Verify your project ID (note you must change PROJECT_ID with your project ID, which can be found by typing gloud projects list)

export PROJECT_ID= PROJECT_ID

Once applied, test it with the following command.

export PROJECT_ID= PROJECT_ID

Now you may copy-paste the following commands without adjusting.

Creating the Docker Image

Create our docker image with the "Dockerfile" from our repository by:
docker build -t gcr.io/${PROJECT_ID}/clublit:v1 .

List your Docker images to verify.

docker images
Pushing the Docker image to the Container Registry

Now we are required to enable the Container Registy API; please note that this may require further adjustments from your API settings to turn on the Kubernetes API (check out the Google Cloud API manager).

gcloud services enable containerregistry.googleapis.com

Furthermore, we need to authorize the docker configuration.

gcloud auth configure-docker

Now we push the image

docker push gcr.io/${PROJECT_ID}/clublit:v1

Creating a GKE cluster

Setting the project ID:

gcloud config set project $PROJECT_ID

Setting the zone or region (Europe as an example, adjust to your needs).

gcloud config set compute/zone europe-west1-b 

Creating our Standard Cluster:

gcloud container clusters create clublit-cluster

Checking the cluster's three nodes

kubectl get nodes

Deploying CLUBLIT! to GKE

Ensuing the connection to the appropriate cluster:

gcloud container clusters get-credentials clublit-cluster --zone europe-west1-b 

Creating the deployment

kubectl create deployment clublit --image=gcr.io/${PROJECT_ID}/clublit:v1

Setting a baseline to three deployment replicas

kubectl scale deployment clublit --replicas=3

Creating a HorizontalPodAutoscaler:

kubectl autoscale deployment clublit --cpu-percent=80 --min=1 --max=5

Checking if our pods are created successfully:

kubectl get pods

Exposing CLUBLIT! to the internet

In our case, we require port 3000, as our development .env file contains information to connect to MongoDB set to port 3000.

kubectl expose deployment clublit --name=clublit-service --type=LoadBalancer --port 3000 --target-port 3000

Verify that the services are running :

kubectl get service

Note that it may require you to wait until you can see your public IP address if it is saying <pending>.

Delete the Service, Cluster & Images

If you are done testing our educational application you may follow these steps:

kubectl delete service clublit-service
gcloud container clusters delete clublit-cluster --zone europe-west1-b
gcloud container images delete gcr.io/${PROJECT_ID}/clublit:v1  --force-delete-tags --quiet

More information can be found in this tutorial: Google cloud Kubernetes Engine Documentation

Microsoft Azure

Clublit! in Azure

This deployment is currently not load balanced yet but supports an HTTPS certificate.

Heroku

Run

This deployment is currently not load balanced yet but supports an HTTPS certificate.

NOTE: It is advisable to use Postman for CRUD operations when accessing the backend.

Running Locally

To run this repository on your local machine download the source code and extract its contents or clone the repository. We provide you with a few options shipped with this repository.

For a local SSL connection you may generate your own certificate into the root directory openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 of the repository and add the following code into the index.js file:

//This enables https

const https = require("https");
const fs = require("fs");

const options = {
    key: fs.readFileSync("key.pem"),
    cert: fs.readFileSync("cert.pem")
  };

Option 1: Starting a local server with your node.js installation running in version 14.13.0.

Option 2: Using nvm. If you have node.js already installed but are not running node version 14.13.0, you may wish to switch between node.js versions using nvm (nvm instrcutions).

Option 3: Using Docker.

Local Node Installation

Node.js is required.

  1. In your terminal navigate to the downloaded or cloned repository.
cd library_api | bash
  1. To install missing dependencies:
npm install
  1. To start the application:
npm start

NVM

Switching between node versions to run this app locally on your machine.

Installing nvm on mac:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash

Adding the source lines from the snippet below to the correct profile file:

export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm

Installing node.js version 14.13:

nvm install 14.13

Selecting node.js 14.13:

nvm use 14.13

For more information, see: nvm documentation

Docker Container

  1. Install Docker and verify your installation with docker -v
  2. Launch the terminal in the library_api folder or direct to this directory.
  3. Build the docker image (be sure to include the ". " at the end and to define your username whoami)
docker build -t <your username>/clublit . 
  1. Run your container:
docker run -it -p 3000:3000 <your username>/clublit 

This will map port 3000 to the host 3000 in our container.

  1. Access the backend from your browser via http://localhost:3000

More info: Dockerizing a Node.js web app

Front-end

The current version of the front-end can only be ran locally. It was successfully tested on macOS Big Sur launched over the command line. The IOS simulator or Android emulator can be launched through the web interface of the local server. Node.js is required alongside with the respective Node version, please see nvm and docker section above in further detail.

To launch the front end, navigate into the front-end folder of the repository.

cd front-end

Install dependencies.

npm install

Start the front-end node.js server by typing:

npm start

You may be asked to install further dependencies to run the IOS simulator (Xcode required) or android emulator.

Disclaimer

This project is part of a cloud computing coursework taught by Dr. Sukhpal Singh Gill and Ignacio De Castro Arribas at the Queen Mary University of London Electrical Engineering & Computer Science Department to create a prototype of a cloud application.

About

A cloud database for accessing persistent information, utilizing REST.

Resources

Stars

Watchers

Forks

Packages

No packages published