This repository has code a online food delivery web app that is configured with the MEAN stack (MongoDB, Express.js, Angular 7, Node.js) Note: This project was generated with Angular CLI version 7.3.9. Markdown editor.
Before you begin I recommend you read about the basic building blocks that assemble this MEAN application:
- MongoDB - Go through MongoDB Official Website and proceed to their Official Manual, which should help you understand NoSQL and MongoDB better.
- Express - The best way to understand express is through its Official Website, which has a Getting Started guide, as well as an ExpressJS guide for general express topics. You can also go through this StackOverflow Thread for more resources.
- AngularJS - Angular's Official Website is a great starting point. You can also use Thinkster Popular Guide, and Egghead Videos.
- Node.js - Start by going through Node.js Official Website and this StackOverflow Thread, which should get you going with the Node.js platform in no time.
- The user views the Angular 7 web app with a browser.
- With both components written in Node.js, the AngularJS front end communicates with the Express back end via RESTful APIs.
- The back-end Express application uses the Mongo database for storing and retrieving data.
- Back-end results are communicated back to the the front end.
- Front-end results are rendered in a human readable format to the user.
Make sure you have installed all of the following prerequisites on your development machine:
- Git - Download & Install Git. OSX and Linux machines typically have this already installed.
- Node.js - Download & Install Node.js and the npm package manager. If you encounter any problems, you can also use this GitHub Gist to install Node.js.
- MongoDB - Download & Install MongoDB, and make sure it's running on the default port (27017).
The recommended way to get this repository is to use git to directly clone the Waffle Park repository:
$ git clone https://sagban_@bitbucket.org/sagban_/wafflepark.git
This will clone the latest version of the Waffle Park repository into a wafflePark folder. Also, this should be your project structure
wafflePark/
e2e/
node_modules/
server/
src/
.editorconfig
.gitignore
angular.json
package.json
package-lock.json
README.md
tsconfig.json
tslint.json
To install client-side dependencies, run this in the application folder from the command-line:
$ npm install
Also, to install all server-side dependencies, run this in the application folder from the command-line:
$ cd server && npm install
Run ng serve --host 0.0.0.0
for a dev server. Navigate to http://0.0.0.0:4200/
. The app will automatically reload if you change any of the source files.
Run cd server && npm start
for a backend server. Navigate to http://0.0.0.0:3000/api
. This will show you the Waffle park API service page.
Once you've installed all the prerequisites and all the dependencies, you must have the waffle park app running successfully in on your machine. But to get started we must seed some data in our MongoDB database. For seeding data in the data just run the following commands:
$ cd server/seed
server/seed$ node seeder.js
The file seeder.js
contains the code which seeds up to the MongoDB database with the help of ODM mongoose.
As the client-side I've used Angular 7, hence this the major building blocks for the client side applications are the following components
and services
-
HeaderComponent - This component contains the header of the application which can be used for the branding purpose.
-
NavbarComponent - This component contains the nav links of the application which can be seen at the top of the page after the header. In the mobile view, it draws from the left side. The most important nav links are Sign and user cart. On clicking Sign in it open the popups for Login and signup by calling
OpenDialogService
respectively. Also,FormSubmitService
andSessionService
are called from this component to get the login status of the user. -
LoginComponent - This component showed up in the popup which is called by the
OpenDialogService
. Here user login into his pre-existing account by using his valid credentials. The input of the login form is passed to the 'FormSubmittingService' which further send the data to the server where the validation is done by aPOST: /api/login
request. -
SignupComponent - This component works the same as the
LoginComponent
. Instead of login into the pre-existing account, the user can sign in to a new account. Data is sent to the server by callingPOST: /api/signup
request. -
FooterComponent - This component contains the footer of the application which consists of the links and other details of the company.
-
WaffleCardComponent - This component contains the list of the menu item fetched from the server using
GET: /api/waffles
request into awaffles: any
variable, which is further used to display fetched data. -
ShowWaffleComponent - This component is nothing but the extended part of the
WaffleCardComponent
. It shows the detailed version of each menu item in the popup view. Here, users can add the clicked item into their cart which is the required quantity. After that these items are returned to theWaffleCardComponent
and which further calls theCartService
to push the items to sessions on the server. -
SidecartComponent - This component contains the cart of the application where all the selected item will be shown with their respected quantities. It also provides the functionalities like controlling the quantity of the item and deleting an item by calling the functions. At the same time, these changes are also updated to the session of the server.
-
HomeComponent - This component is cumulative of all the above-described components. This is basically the home page of the application and can be found at
/
route of client-server. -
CheckoutComponent - This component is the most important component of the application because it is a place where user can place the order by completing the steps like Login, Adding delivery address, and finally making a successful payment of his order. This component also contains
SidecartComponent
,NavbarComponent
, andFooterComponent
as its sub-components. This page can be found at/checkout
route of client-server.
-
Cart.js - This is not a typical database mongoose schema. It is a module/class written in javascript for making cart-sessions operations like adding the item to the cart, updating the cart like total items, and total price of a cart, and providing a final list of cart items in the form of an array easily. What is happening is that when the user (signed/ not signed both) added the item to his cart, that item is received by the server from the client-server and further saved into the sessions. Functions Add - It takes two args, one is the item object itself and the other is the object id. So first it checks if the item is to add is already present in the dictionary or not. If it's present already it takes that item and only updates that item quantity, total quantity and the total price of the price. Elsewhere, it adds that item to the dictionary and does rest same operations. GetList - This function just provides the required list of cart items in the form of an array, which can be very handy in returning data to the client server.
-
Waffles.js - This is the first and most important mongoose schema for storing the items.
-
User.js - This model is used for storing the user/ customer details. Note that we are not asking for the address from the user at the time of signup. The address field will only be updated when the user has one successful order. So when he places a new order he gets his previously delivered addresses.
-
Login.js - This model is used for the login purpose only. It consists of a user id which is an email id in our case and user password. The main reason behind not storing the password alongside the
user.js
because there may be a case arise when a user has successfully entered his details but hasn't completed the email ID verification. So the next time a user uses that same email id we can just ask him for email verification and a new password only. -
UserCart.js - This model is used for storing the user-cart into a database alongside the sessions for logged in users.
-
Orders.js - This model is used for storing the order details. It has two important keys
UserId
, andUserCartId
.
-
Waffles - This method is called when the req
GET /api/waffles
is made. It just returns the list of items present in the database. -
Waffle - This method is called when the req
GET /api/waffle/:id
is made, whereid
is the id of the requested item. It returns a requested item. -
AddCart - This method is called when the req
POST /api/add_cart
is made along with the item is to added into the cart. Its basic functionality is just to add an item to the cart session by usingCart.js
class. If the user is signed in then it further adds that item to theusercart.js
model with the userid by taking help of helper functionupdateUserCart(req, res, msg, data = false)
written in samecontrollers.js
file. So that, when user login again he gets the previously added item back into his cart. -
FetchCart - This method is called when the req
GET /api/fetch_cart
is made and it just returns the item present in the cart. If a user is signed in it gets the data from theusercart.js
model otherwise from the session. -
UpdateCart - This method is called when the req
POST /api/update_cart
is made along with the updated cart items details like quantity or removal of some items. If a user is signed it takes help from a helper functionupdateUserCart(req, res, msg, data = false)
like others to update the details. Otherwise, update the session cart. -
Signup - This method is called when the req
POST /api/signup
is made along with the signup form data. The basic functionality is to first verify that there should not be a user with an already registered email address. After that, it saves the signup form data into database i.euser.js
model. After it creates a login credential for the user and saves them into thelogin.js
model. Also, it further checks if the cart sessions are not empty and assign that cart to this new user by again taking the help ofupdateUserCart(req, res, msg, data = false)
. -
Login - This method is called when the req
POST /api/login
is made along with the login form data. Its basic functionality is to first verify the credentials and successfully log in to the user else report errors. Same as in signup it also further checks if the cart sessions are not empty and assign that cart to this new user by again taking the help ofupdateUserCart(req, res, msg, data = false)
. -
Logout - This method is called when the req
GET /api/logout
is made. Its basic functionality is to delete the set sessions and successfully log out to the user.
Healthcoco Pvt. Ltd