Medium Feed

 

Tuesday, December 18, 2018

How to build a basic online Taxi service mobile application

In this tutorial, we will see how to build a basic UBER or OLA like functional Taxi booking service mobile application and what it involves to host in google play store.

This is the experiment I did few months back in spare time. Here, will try to explain  technology stack involved in development from end to end and sharing my github repository where you can access entire source code too.


To develop back end and front end, the technology stack I have chosen are

  • Node as web server
  • Node Express JS - as web framework
  • HTML 5 Geo location API /Google map API -  for location navigation
  • Mongo DB - as data source to store cab driver & user information.
  • Socket.IO - as websocket programming library for real-time bidirectional event-based communication for live location emitting
  • RabbitMQ - for scalability as message broker to the subscribed web sockets.
  • Cordova - Hybrid mobile application development framework ( i.e can run in both IOS and Android)
  • Express JS - Building Rest API services backbone.

* Note: I have read in google, currently the Uber architecture also is based on Node Server only.


For any basic can booking service application, the high level requirements can be


As Uber driver login:


  • Ability to sign up and login as driver
  • Create profile Email, Phone number payment account information.
  • Live navigation to cab service booked user pick up and drop location
  • Push notification if new users booked.
  • Ability to view booked users basic information.

As Uber user login:


  • Ability to sign up and login as user
  • Create profile Email, Phone number, etc
  • Live listings of taxi's which are near by
  • Ability to see list of taxi options available ( Mini, Zedan...etc)
  • Ability to book taxi for trip
  • Live navigation tracking of where cab driver coming now
:-) Hope it has basic needed functionalities.


Ok..Let's IMPLEMENT...


Before we start coding, let us first setup the development environment needed to run our application.



Node setup 


if you are new to Node development, you can follow below steps to setup node dev environment in your machine.

Download and install Node from
        https://nodejs.org/en/
  • Make sure you added Node JS in your system environment PATH variable.
  • To test installation, open command prompt and type "node ---version". If version number displayed. It installed correctly and working !


Setting Up Database environment


 For user management and taxi booking session management the backend database system I used is MongoDB instance. Considering the advantages, easy Node +  MongoDB integration  and cost fact of cloud service provider with the account I have, i had chosen MonogDB as DB instance, but it is absolutely your choice to prefer a reliable DB system.

For peoples who are new to MongoDB, you can follow my old post related to setting up MongoDB development environment.


http://ramstepsonweb.blogspot.in/2016/01/how-to-setup-mongodb-environment.html.



Testing MongoDB installation in your machine.


Open command prompt

  • Navigate to “C:\MongoDB\Bin” folder (or the path you have installed MongoDB)  in command prompt
  • Type “Mongod” and hit enter. Now you should be able to see message like “Waiting for connections on port 27017” in your command prompt
  • Open a new command prompt ( don’t close exiting command prompt ) and navigate to “C:\MongoDB\Bin” folder in command prompt. Type “Mongo” and enter. You will be getting a message “MongoDB shell version and connecting to “test” db” Also you can notice in other opened command prompt, the console message got changed to         “Connection accepted from “127.0.0.1”…etc”


Setting Up Cordova platform


Corodova is the mobile development platform for Hybrid mobile application development.


For peoples who are new to Cordova Hybrid app development, here are the steps to setup development environment in your local machine.


Cordova behind the scenes running in GIT version control system, so as prerequisites first install GIT in your machine ( ignore if you already have GIT installed in your machine)  Download and install from: http://git-scm.com. Default settings are recommended.


After GIT installation you can install Cordova using Node Package Manager (npm). 


npm install -g cordova


You can confirm the installation by running cordova --version in your command prompt.


Other Dependencies Setup


  • Download and install RabbitMQ from :https://www.rabbitmq.com/install-windows.html
  • In command prompt navigate to project folder run below commands to setup the express and mongo client dependencies.    
               npm install -g express
           npm install mongodb -- save   (IMPORTANT : Npm installs latest version of                          MongoDB which does not supprt. db.collection() function, hence update project.json file                to change mongodb version to "^2.1.4")
           npm install socket.io --save


All Done, you have the development environment setup.


Run the Code and Mobile APP build 


Clone the source code from my Github repository
https://github.com/ramkrivas/ani-hola.git

In the command prompt 

> Navigate to "C:\MongoDB\bin" and start MongoDB instance
      Type Mongod in one command prompt
      Type Mongo in another command prompt 

> Navigate to "NodeAppDevelopment" folder and run node server file by " node hehaserver.js". This will run the application in your local machine.

> Navigate to "Services" folder and APIServer.js NODE server file, this will run API in your machine.


Host the app in Google Play store.


As prerequisites makes sure your node App and DB instance are running in cloud or in your on-premises system.

To host your application in play store, you would need a google play store licence which may cost of 25 $ 

To build your application for play store hosting ready. you can follow below steps.

Assuming your project folder is C:\MyUberApp

Step 1: Navigate to your Project Folder in command prompt

Step 2: Type "cordova build --release android"

Step 3 : Navigate to build output path: ...\platforms\android\build\outputs\apk

Step 4: Sign apk using below command
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore YOURAPP.keystore android-release-unsigned.apk YOURAPP

Step 5: Compress/zip  apk
Naivate to below path in command prompt:
C:\AndroidStudio\build-tools\23.0.2\
Run the below command
zipalign -v 4 android-release-unsigned.apk YOURAPP.apk

Now the APK is ready in below path to release in Play store
  ../platforms\android\build\outputs\apk\YOURAPP.apk


The above steps will give an APK which you can upload in your play store account and make it LIVE !! .


That's all.. Your Taxi booking service application is now ready. Enjoy riding with your friends !!!

Thursday, November 29, 2018

Moving Azure Application Insights alerts from one app insight to another app insight using Powershell


I was working with a person who works in Microsoft US and helping him as freelancer for Powershell scripting. Recently he had come to me with the task of moving azure App insights alerts/rules from one app insight to another another app insight. He wanted a quick solution since he was having demo with customer in few days. As there was NO straight forward PS scripting approach to accomplish this, I've find a workaround to implement using Management.azure.com token and calling azure internal API to do this operation and it worked like a charm !.

Here is the script which I wrote:

Tuesday, January 30, 2018

How to Create Azure AD B2C app programmatically using Powershell or Graph API

We've had critical business need to create or register native /web client applications on Azure AD B2C blade programmatically. Currently Graph API or Powershell cmdlets supports creating applications only in AD blade, NOT under B2C blade (V2 app), we've even tried with MSGraph API, though MSGraph post API was able to create application in the B2C, the application was getting created as "faulted app"(useless). We approached Microsoft support team many times and  all the times the response from them was "NO, currently we are NOT supporting B2C app creation programmatically". We even approached PM's in Microsoft and got the same answer, saying this functionalities will be available only be next year (2019) - insane ..right

As this was a critical need for us, I was forced to find atleast a temporary workaround for this and here's what I tried and worked for me.

As  we know the only way to crate B2C app is creating to manually from portal.azure.com...so as a first step I tried to mock that activities using Powershell.

So, using fiddler first I try to capture the access token and Azure internal API which being used while doing it manually from portal.

With JWT token captured through fiddler, I decoded token and get the "Audi" audience information which is the resource server which accepts the token. Then using RM context refresh token grant type, I invoked a rest method which will give API token for the particular "aud" or resource which we get in previous steps.

Now, with this internal API token, I invoked "https://main.b2cadmin.ext.azure.com/API/ApplicationV2/PostNewApplication" to create B2C app... Below is the same code.
Note : This is just a temporary workaround for this , not recommended for production.