E-Commerce Mobile Application
E-Commerce Mobile Application
E-Commerce Mobile Application
Bachelor’s thesis
Information Technology
Bachelor of Engineering
2021
Author (authors) Degree title Time
Supervisor
Timo Hynninen
Abstract
The thesis goal is to create a mobile application that allows users to trade products online.
The application’s target user is everyone. The theoretical background was composed to
provide the study concepts and definition of React Native, Nodejs, MongoDB, REST API,
mobile application development, and software development lifecycle models. The
theoretical background provides a solid basis for the practical implementation.
The practical implementation part provides the planning for server-side implementation and
the deloping process of server-side and client-side. In this part, the application
development was demonstrated. This part also provides images of the application which
help demonstrate how to use the application.
The final result is the functional mobile application that allows users to trade products
online. The application was developed using methods and technologies that were
introduced in the theoretical background.
Keywords
1 INTRODUCTION .......................................................................................................... 4
2.4 Nodejs..................................................................................................................... 8
3 PRACTICAL IMPLEMENTATION............................................................................... 10
4 CONCLUSION ............................................................................................................ 42
REFERENCES ................................................................................................................. 44
4
1 INTRODUCTION
Nowadays, we have a trend called "mobile first", which means designing user
interface for mobile first before desktop applications and mobile applications.
Smartphones play a crucial role in our life. More and more mobile applications
are developed in order to improve our life. In software development, we have
various options, for example, desktop applications, web applications, mobile
applications and others. However, the reason why mobile is leading is that almost
everyone now owns a smartphone so it would be the easiest way for people to
approach an application.
E-commerce is a model that allow firms and individuals to trade things online. It
was first introduced in 1979 when Michael Aldrich invented electronic shopping
by connecting a customized TV to a transaction-processing computer through a
telephone line. The significant development of E-commerce happened in 1995
when Amazon and eBay were introduced to the market. Amazon was started by
Jeff Bezos, while Pierre Omidyar launched eBay. Due to the pandemic situation,
the demand for online shopping has increased rapidly because social distancing
is required. Moreover, convenience is one reason why online shopping demand
has developed quickly.
The application target users are everyone who want to trade products online. The
application provides a platform for people who want to do ecommerce. E-
commerce is so popular that many online buying websites are developed.
However, the number of people that are using mobile are increasing day by day.
It is easier to carry a smart phone outside instead of a laptop so mobile
5
In order to achieve the goals, the thesis will be divided into different parts,
described as follows:
During the development process, there were several issues and limitations. The
most significant problem is bug. I have met several bugs during the
implementation. To resolve these bugs, I have spent many times to investigate
and fix them. Moreover, the platform that I used to deploy the server is free to use
so it is quite slow. Also, there is a problem that still cannot find a solution for it is
some images that upload to the server are not display in the application. This
problem might be caused by the storage of images. However, I still cannot find a
solution to replace it.
2 THEORETICAL BACKGROUND
This section covers the study concepts of technologies that are used in the
project. It will provide both basic and detailed knowlegde of methods that are
used to develop the mobile application. Following that, the requirements for the
application and a brief introduction to mobile development are also described.
6
Mobile applications can be divided into three types, which are native application,
hybrid application and cross-platform application. Native applications are
applications that are developed for a specific operating system. It can be Java or
Kotlin for Android and Objective-C for iOS (Sergey 2019). The most important
advantage that native applications have is that they are high performing
applications, which create an impressive user experience. However, it is
expensive to create a native application because it requires a different code base
for different operating systems. One more way which we can approach mobile
application development is hybrid application. Hybrid application can be
described as a webview object that is deployed in a native container. Developing
a hybrid application is simple and take less time, however, a hybrid application
doesn’t provide a brilliant user experience. Another approach is cross-platform
application. Cross-platform application is closest to a native application. The code
base is written in JavaScript and connects to native components using bridges
(Sergey 2019). It allows sharing code between different platforms, therefore, with
one code base we can develop applications for both Android and iOS. Some
cross-platform tools which allow creating cross-platform applications are Xamarin
and React Native. The application in this project is considered as an cross-
platform application.
As a result, the application should be working with the provided features. The
application will have two roles, which are users and admins. For users, they can
use all the features as follows:
• Sign in and sign out
• Register
• Search and select products
• Checkout process: Fill in shipping form, choose payment method, confirm
order
There is one tab for admin to manage the products. Admins are allowd to do
these actions as follows:
7
React Native is a platform that allows developers to create mobile applications for
both Android and iOS. It was first released in 2015 by Facebook. React Native
combines the best parts of native development with React and a best-in-class
JavaScript library for building user interfaces. (React Native 2021.) React Native
is built by JavaScript, and therefore both JavaScript and TypeScript can be used
in development. It will use native view instead of webview so the result
application will be an native application.
There are two important threads in React Native, which are Main Thread and JS
Thread. JS Thread is responsible for the application logic, which means the code
execution, API fetch and other processes. Main Thread is responsible for
rendering native views. JS Thread is also used to decide what will be displayed in
the screen and it will inform the Main Thread. However, Main Thread and JS
Thread will never communicate directly. These two threads will communicate by
using React Native bridge. This bridge allows two threads that are written in two
different languages to communicate, which makes “bridge” a core aspect of
React Native structure.
8
2.4 Nodejs
2.5 MongoDB
will collaborate in planning, processing and evaluating each iteration to get the
best result. In the Agile group, it includes variable models, for example, Scrum,
Kanban, Extreme Programming and Adaptive Project Framework. Scrum model
is now one of the most popular model of Agile. Scrum seperate the development
process into small iteration call sprint. Each sprint usually lasts for two to four
weeks. Before each sprint starts, there will be a sprint planning meeting to decide
which issues should be handled in this sprint. At the end of each sprint, there will
be a retrospective meeting to clarify what the team has achieved and what should
be improve. Scrum model will help organize and speed up the development
process.
3 PRACTICAL IMPLEMENTATION
This section is divided into three parts, which are application overview, server
implementation ,and mobile application implementation. The first part is about
which features are included in the application. The second part will cover the
details about what is the plan for the server and how it was implemented. The last
part will be about the implementation of the mobile application.
To provide a clearer picture of the implementation process, I will use the following
typography in this section:
• API paths will be in bold
• Code snippets are color-coded
• Code quotes are in italic
The mobile application provides a platform that contains two roles which are user
and admin. For users, they can search, select and order products that they
demand. For admins, the application is used to manage all the available
products. Moreover, they can also add new products to the platform.
11
The following list will describe the features and funtions that are available in the
mobile application to make it simpler to understand how it works:
• Product list includes all the available products so that users can search for
products and view their details. They can search products by their name
using the search bar or by categories. Users can also add the wanted
items to their shopping cart.
• The shopping cart displays all the items that are selected by a user. Users
can do the checkout process in the cart. The checkout process will include
a form for shipping information, payment method ,and confirmation before
placing an order.
• User management allows users to sign in and sign out the application.
Moreover, users can also see their profile.
• Product management is only available for accounts that have admin rights.
The admin rights will include product management, category management
,and order management. Admins can add a new product with all the
required information. They can also manage orders by updating their
status.
In the implementation, this table helps organize all the APIs that are used during
the development. All the APIs are created base on the mobile application
requirements.
Before implementing the server, a database is needed to store all the data. In this
development, I chose MongoDB as the database to implement. The database
includes five collections which are categories, orders, products, users, and
orderItems. These collections usage is listed below:
• Users collection is for storing all users’ data include username, password,
and profile information.
• Orders collection are used to store information about customers’ orders,
which includes the shipping information and order items.
• Orderitems collection stores the detail about the items that are included in
an order. From the products’ id, the products’ details can be retrieved.
• Categories collection has information about the existing categories
• Products collection include information on all products
As mentioned above, there are two options for MongoDB which are cloud and
server. In this project, I chose to use the cloud version of MongoDB called Atlas.
For MongoDB, there are three ways that we can connect the database to the
14
server: connect with MongoDB Shell, connect your application, and connect
using MongoDB Compass. I chose to connect to my application which requires a
connection string that is provided by MongoDB. Figure 3 displays how to connect
to MongoDB in your application.
However, to use the schema in the collection, it must be converted into Model.
Figure 5 shows how to convert schema to model
In the database, there are five collections, each of them should have a model and
schema to shape the documents within the collection. After defining all the
models for each collection, I created a route or URL path for each request that
was described in Table 1. Each API path will be a route. To make it easier to
understand, I will divide the API paths into small groups of paths that have a
similar function. First, to create a route, I had to choose a method for each route.
Four methods were used in this project: GET, POST, PUT, and DELETE.
Second, based on each path description, I defined a prefix and a function for the
route.
16
Figure 6 displays how to create a GET route to get a list of all categories.
router.get() was used to create a GET method. /getListCategory is the prefix for
this route. The description of this API path is to get all the categories that are
existing in the application so from the Category model, I used find() to retrieve all
the data that is available. If the path was able to get data from the collection, the
API path will return a response including data and a success status, which is true.
If there are any problems that prevent getting data, the route will send an error
message with a false success status. According to the API path description,
/products/getProductList, /categories/getListCategory, and
/orders/getOrderList have similar functions so all of them will have a similar
codebase but with different prefixes.
The next part explains how to create a GET route that requires input to get
sufficient data. These /users/getProfile/:id and /products/getProduct/:id. In
these two paths, there is :id after the prefixes. This means a parameter called id
is needed in this path. Based on the id, the route can get the exact information for
each product or user in the collections. In order to get the information, findById()
method is used to get data by id in these API paths. Figure 7 displays how to
create these routes.
17
In the mobile application, there is a feature that allows users to search for the
products. The /products/searchProduct path is used for this feature. This path
allows getting products whose names have the keyword that users are searching.
For this route, the search keyword is the required input. This route returns all the
products whose names have the keyword inside regardless of position and case
sensitive. This API path code is displayed in Figure 8.
unable to save, the response will be an error message, which is “User cannot be
created”.
user’s email and token in the response. Figure 10 displays how to implement
login API.
Figure 9.
11.Login
LoginAPI
API
When creating a product, information about the name, brand, price, image, etc is
required. This API path also has quite a similar function with /users/register
path, however, the difference is that this path has a function to upload images. To
store images, I use multer library. The destination to store images is
/public/images folder. There is also the validation for file types. In this application,
I configured it to allow only jpg, png, and jpeg files. In case of the wrong type, the
route sends an error message. By using this library, I can upload images from the
mobile application to the server. Figure 10 shows to configure the storage for
images.
20
The /products/createProducts path configures the path for images that are
uploaded to the database. The image path will be used to render the image in the
mobile application. Except for the uploading function, this route saves the product
to the database. If the process is successful, it returns the updated products.
Otherwise, it returns an error message. The code for this path is described below.
router.post(`/createProducts`, upload.single("image"), async (req, res) => {
const category = await Category.findById(req.body.category);
if (!category) {
return res.status(400).json({
message: "Invalid category",
success: false
});
}
name: req.body.name,
description: req.body.description,
richDescription: req.body.richDescription,
image: `${imagePath}${fileName}`,
brand: req.body.brand,
price: req.body.price,
category: req.body.category,
countInStock: req.body.countInStock,
rating: req.body.rating,
numReviews: req.body.numReviews,
isFeatured: req.body.isFeatured,
});
product
});
}
});
Besides adding new products, there is a feature to delete products. The API path
is /products/deleteProduct/:id. It uses the product id to retrieve that product and
to remove that from the collection.
22
To improve security for the application, the token is required in all the API paths.
However, there are some paths that do not need to apply the token. The token is
only generated after login. However, users are allowed to view the products,
place orders, and register a new account while not signed in. Figure 13 specifies
paths that do not need the token: login, register, all the GET requests for
products, GET requests for categories, GET requests for images, and POST
requests for orders.
24
The server runs locally using localhost. To run the server globally, I need to
deploy the server to a deployment platform. I chose Heroku as the deployment
platform to deploy my server. To do the deployment, we can use the command
line to choose to deploy on Heroku website. In this project, I chose to deploy on
Heroku website by connecting to my repository on GitHub. On Heroku, I created
an application called nhu-eshop-server. After that, I selected GitHub as the
deployment method. From that, I can choose the branch that I want to deploy to
Heroku and deploy it.
For every application, navigation plays a crucial role, therefore, I created the
navigation for the application first. To create the navigation, I used a react-
navigation library. For every library that was used in this application, they were
installed by using the npm install command. The main navigation is the bottom
tab navigation that includes four tabs, which are Home, Cart, User, and Admin.
Each tab will be a navigation stack. Each screen must be defined in its
navigation. Figure 15 displays the mobile application’s navigation.
For tab navigation, each screen is a tab and a tab icon is required. In each tab,
the component must be defined. As mentioned above, each tab also contains a
navigation stack so that in Figure 16 the component for the Home tab is a stack
instead of a screen.
26
All the available screens are in the Screen folder. This would help organize the
project making it easier to find files. In this part, I will describe the screens by
their navigation stack. The first stack is the Product navigation stack. It includes
two screens, which are the Product screen and Product detail screen. In the
Product screen, a list of all products is shown and there is also a search bar for
28
users to search for any products. Moreover, users can also choose to filter
products by category. By clicking on the category name, only products that
belong to that category are shown. In the Product detail screen, users are
allowed to add products to the shopping cart. Figure 19 includes a picture of
product and product detail screens.
The list of items is shown in a card item form. This card item is a custom
component. When users click on an item, it navigates to the product detail screen
to display more information about the product. To create the custom card item, I
use the Touchable Opacity component which allows users to click on it. To
render it as a list, I used the Flatlist component. Flatlist allows rendering a list of
data under a custom view. Figure 20 displays the implementation process.
29
To have the product data, I can get it from the API path. The
/products/getProductList path is used to get the product list while
/products/getProduct/:id is to get product details. /products/searchProduct is
used when the search bar text changes to get products that their name includes
that keyword. To make the request, I used the axios library. It allows you to make
a request from the application to get data from the server.
30
When the users click Add button in the product detail screen, the product is
added to the cart. Users can add as many products as they want. When the Add
button is clicked, the product id is stored to use that id to get the product on the
cart screen. The product id is stored in reducer. When users click the button, it
dispatches the a predefined action to store data in reducer. Reducer can be used
everywhere in the project, therefore, storing data in reducer allows that data can
be accessed on different screens.
31
To render the selected products, I used the selected ids that are stored in the
reducer and the /products/getProduct/:id path to get the product information. At
the bottom of the screen, there are Clear and Checkout buttons. The Clear button
is used to delete all items in the cart. The Checkout button navigates to the
checkout process. Users are also able to delete a single item by swiping left on
that item. The Clear and Delete buttons dispatch EMPTY_CART and
DELETE_FROM_CART actions that are shown in Figure 23.
32
After clicking Checkout, the application navigates to the checkout process. This
process has three steps: shipping, payment, and confirmation. In this process, I
used a top tab bar that includes three screens: shipping, payment and confirm.
For the shipping tab, users are required to fill in all the shipping information. If any
information is missing, there is an error message under each missing input.
33
For showing the purpose of error message, I created a custom input called
TextField that displays a message when users click out of the input without filling
it. When the input is focused, the message is clear. By using refs, the application
can access the appropriate component and execute the code for that component.
This custom input is created based on the React Native TextInput component.
Figure 25 shows how to implement the TextField.
34
The next step is to choose a payment method. There are three methods which
are cash on delivery, bank transfer, and card payment. However, in this
application, the payment gateway is not implemented yet. In the Confirm tab,
there is a summarization for shipping information and selected products,
therefore, users can check all information before placing an order. When users
press the Place order button, the order detail is sent to the server using
/orders/createOrder path. When an order is placed successfully, there is a pop-
up message to indicate that the order has been made and the cart is clear.
The next part was to implement the User tab. If users are not signed in, when
they press the User tab, it shows the login screen. On the login screen, the user
can log in with an existing account or register for a new account. The
/users/login path is used to login user and returns a token. A token is required
for making other requests. The token is stored in local storage called async
storage. The token value is stored in the storage until I removed it or the
application is uninstalled. Previously, when I implemented the server, I generated
the token that included the value of the isAdmin field, consequently, in the mobile
application, I can decode it to get the isAdmin value. This value is used to verify if
the login account is an admin or not. Moreover, when logging in successfully, the
user’s information is saved in a reducer similar to the cart process. From there,
the user’s information can be accessed on every other screen throughout the
application. The application uses the token to check whether the account has
admin rights or not. If the user is admin, in the bottom tab it will show the Admin
36
tab. Figure 28 shows the implementation of the login process and saving the
information to the reducer.
If users do not have accounts, they can register for a new account. When
pressing the Register button, the application navigates to the Register screen.
There is a form to fill in personal information. The required information is name,
email, phone number, and password. After registering successfully, the
application displays login for users to log in. If users are signed in, when they
press on the User tab, it shows the Profile screen, which displays the user’s
personal information. Users can sign out in the Profile screen also. When users
press the Sign out button, all the information that is stored in store and async
storage will be removed.
38
For admins, there is an Admin tab that allows admins to do management. Admins
can add new products and categories, update products and orders, and delete
products. When pressing the Admin tab, it shows the list of all existing products.
An admin can edit or delete the product by swiping left on that product. There are
two buttons, Edit and Delete. There is also a search bar for admins to search for
products. This search bar has a similar function to the one on the Product screen.
Name, brand, price, and category are shown on each card. At the top of the
screen, there are three buttons which are Orders, Product, and Category.
Pressing the Orders button, the application navigates to the Orders screen where
admins can manage all orders. The Product and Category buttons are used to
navigate the application to the Product and Category screens. In these two
screens, admins can add new products and categories.
39
40
On the Orders screen, there is a list of orders that includes information about the
orders. In this screen, admins are allowed to update the orders’ status. When
admins press the Update button, it displays a bottom sheet that contains all
statuses. From there, admins can choose which one to update. After updating
success, it navigates to the Product List screen. To custom the bottom sheet, I
used the Modal component. To render the list of status, I used Flatlist and each
item is a button. When admins press one button, it shows the check icon to mark
the selected options. When touching outside the bottom sheet, it closes the
sheet. Figure 32 displays the Orders screen and the bottom sheet.
To add new products, admins need to fill in all the information for the product.
The information includes brand, name, price, count in stock, description,
category, and picture. Other fields use the custom TextField that was created to
use in the Register screen except for picture and category. For the category field,
it displays the bottom sheet similar to one in the Orders screen. There is a new
function in this screen which is adding an image. To add images, I used a library
41
Unlike other requests, this request is made differently. Usually, the data sent to
the server is in JSON format. However, in this request, it is in FormData. I
created a new FormData and appended all the required fields to the FormData.
For the image, the different operating system has a different URI. Because of
that, in iOS, I had to change the image’s URI to make the request. After creating
a new product successfully, the application navigates to the Product List screen
and displays a success message.
4 CONCLUSION
The goal of this thesis is to create an online shopping mobile application and to
do research to put it into action. The application is for everyone who wants to do
shopping online. The theoretical background section has covered the study
43
The practical implementation part describes the process of making the server and
mobile application. It also provides the planning on how to implement the
application. The pictures of all the screens in the application is displayed in this
section. By applying the methods and technologies, the application was
developed successfully. With the provided tools, the application fulfills the
predefined goals in the beginning. The application still needs to be developed
more in the future. More features should be included to provide the best user
experience. Possible further development ideas are sending an email
confirmation, changing email and password, adding comments and so on.
To ensure that the application is working, I have done some testing on the
application. I tested it based on my experience when using other applications. I
tried to ensure that there are no crashes in the application. The server side of this
thesis was deployed to Heroku so that the API can be used in public. However,
the application has not been deployed to any platforms. The requirement for
publishing the application to App Store ang Play Store is quite complex so I have
not done it in this thesis.
44
REFERENCES
IBM Cloud Education. 2021. REST APIs. WWW document. Available at:
https://www.ibm.com/cloud/learn/rest-apis [Accessed 28 August 2021]
Louise, M. 2018. E-commerce: The Past, Present and Future. WWW document.
Available at: https://www.spiralytics.com/blog/past-present-future-ecommerce/
[Accessed 5 August 2021]
Saket, K. 2018. How React Native Works ?. WWW document. Available at:
https://www.codementor.io/@saketkumar95/how-react-native-works-mhjo4k6f3
[Accessed 28 August 2021]