Zaayka - consultantjay/LTIMEARN GitHub Wiki
Walkthrough of Zaayka:
Zaayka is a web application developed for unearthing restaurants all over the world. Zaayka imparts all the required details of the restaurants across various countries all over the world. We all need to discover restaurants in our city everyday, and providing the details of those restaurants is the main concept behind Zaayka.
Product Description:
This is an application for restaurant search and discovery using MEAN Stack which allows user to search and list Restaurants according to their current location and also through desired searches. The product gives the facility to the user to view the Restaurants on the map.
Features to be delivered:
- Detecting the users' Current location and provide restaurants accordingly.
- Locating restaurants on the map with multiple markers.
- Login/ Logout
- Password Reset
- Review Form
- Search Restaurant on the basis of:
- Country
- State
- Cuisines
- Ratings
- Delivery service
- Get description about a restaurant which includes:
- Address
- Ratings
- Upvotes
- Average price for two
- Has online delivery or not
- Has table booking or not
Future Scope (because there is always a scope):
- Bookmarking Restaurants.
- Book table Online.
- Expanding Dataset.
About
Zaayka is built on all the latest technologies that include:
- MongoDB
- Node.js
- Express.js
- Angular
- React
Mongo:
MongoDB is a document database with the scalability and flexibility that you want with the querying and indexing that you need. MongoDB is a free and open-source cross-platform document-oriented database program. Classified as a NoSQL database program, MongoDB uses JSON-like documents with schemas. MongoDB is developed by MongoDB Inc., and is published under a combination of the GNU Affero General Public License and the Apache License.
Why NoSQL? NoSQL systems are distributed, non-relational databases designed for large-scale data storage and for massively-parallel, high-performance data processing across a large number of commodity servers. They arose out of a need for agility, performance, and scale, and can support a wide set of use cases, including exploratory and predictive analytics in real-time. They arose out of a need for agility, performance, and scale, and can support a wide set of use cases, including exploratory and predictive analytics in real-time. Built by top internet companies to keep pace with the data deluge, NoSQL data base scales horizontally, and is designed to scale to hundreds of millions and even billions of users doing updates as well as reads.
Following MongoDB Coding-style is used:
- Consistency: The most important guideline is to be consistent with the existing style in the files. Ex: Followed the spacing or naming conventions in the file that is to be edited.
- Adding tests for new functionalities.
- Ensuring code is readable with proper comments wherever necessary.
- Maintaining backwards compatibility by:
- Avoid changes that break the project's functionality and cause existing tests to fail unexpectedly.
- Avoid changes that affect the project's compatibility with other projects.
- ReStructured Text and Typesetting: Placing spaces between nested parentheticals and elements in JavaScript examples. For example, prefering { [ a, a, a ] } over {[a,a,a]}.
Node.js:
Node.js is an open-source, cross-platform JavaScript run-time environment that executes JavaScript code server-side. Historically, JavaScript was used primarily for client-side scripting, in which scripts written in JavaScript are embedded in a webpage's HTML and run client-side by a JavaScript engine in the user's web browser.
Following Nodejs and npm Coding-style is used:
npm's coding style is a bit unconventional. It is not different for difference's sake, but rather a carefully crafted style that is designed to reduce visual clutter and make bugs more apparent.
- Line Length: Keep lines shorter than 80 characters.
- Indentation: Two-spaces. Tab can be used but Node uses 2 spaces and so followed this.
- Curly braces:
- Using this:
function(){ ..}
- Avoiding this:
function() {..}
- Comma First:
- Using this:
var magicWords = [ 'abracadabra'` , 'gesundheit'` , 'ventrilo'` ]
- Quotes:
Use single quotes for strings except to avoid escaping.
- Preferring this:
var ok = 'String contains "double" quotes'
- Preferring this:
- Callbacks, Sync/async Style:
- Use the asynchronous/non-blocking versions of things as much as possible. It might make more sense for npm to use the synchronous fs APIs, but this way, the fs and http and child process stuff all uses the same callback-passing methodology.
- The callback should always be the last argument in the list. Its first argument is the Error or null.
- Errors:
- Always create a new Error object with your message. Don't just return a string message to the callback. Stack traces are handy.
- Logging: Logging is done using the npmlog utility.
- Case, naming:
- Use lowerCamelCase for multiword identifiers when they refer to objects, functions, methods, properties, or anything not specified in this section.
- Use UpperCamelCase for class names.
- null, undefined:
- Don't set things to undefined. Reserve that value to mean "not yet set to anything.
- Boolean objects are forbidden.
Express.js:
Express.js, or simply Express, is a web application framework for Node.js, released as free and open-source software under the MIT License. It is designed for building web applications and APIs.It has been called the de facto standard server framework for Node.js.
Following Express.js Coding-style is used:
- 2 spaces – for indentation
- Single quotes for strings
- No semicolons
- No unused variables
- Always use === instead of == – but obj == null is allowed to check null || undefined.
Angular:
Angular (commonly referred to as "Angular 2+" or "Angular v2 and above") is a TypeScript-based open-source front-end web application platform led by the Angular Team at Google and by a community of individuals and corporations. Angular is a complete rewrite from the same team that built AngularJS.
Following Coding-style is used:
- File structure conventions:
- The name of the components should make resemblance with the functionality for which it has been built.
- Single responsibility:
- This helps make the app cleaner, easier to read and maintain, and more testable.
- Naming:
- Naming conventions help provide a consistent way to find content at a glance. Consistency within the project is vital. Consistency with a team is important. Consistency across a company provides tremendous efficiency
- Names of folders and files should clearly convey their intent.
- Bootstrapping: Avoid putting app logic in main.ts. Instead, consider placing it in a component or service.
- Directive selectors: lower camel case for naming the selectors of directives.
- Unit test file names: Naming test specification files the same as the component they test.
- Coding conventions
- Classes: Upper camel case when naming classes.
- Constants: Declaring variables with const if their values should not change during the application lifetime.
- Properties and methods: Lower camel case to name properties and methods.
React:
In computing, React (also known as React.js or ReactJS) is a JavaScript library for building user interfaces. It is maintained by Facebook and a community of individual developers and companies.React can be used as a base in the development of single-page or mobile applications. Complex React applications usually require the use of additional libraries for state management, routing, and interaction with an API.
Following Coding-style is used:
- Destructuring props: It makes assigning object properties to variables feel like much less of a chore.
- One tag, one line
- Wrap up: Only write JSX on the right side of an = or a return.
Functionality:
MongoDB queries are used to access list of required details from the Database. * Documents: 9542 * Fields : 21
Node.js Query example. Documents are returned on the basis of city name provided. Business Name and description is returned by the following query.
var mongojs = require('mongojs');
var db = mongojs('Zomato',['zomato_code']);
var City = "Pune";
db.zomato_code.aggregate([{
$match:{
"City":City
}},
{$sort:{
"Aggregate rating": -1
}}],
function(err,res)
{
var json=res;
var x;
for(x of json){
console.log(x);
}
});
The Service APIs are called whenever an event is hit on the User Interface. Express APIs are written in nodejs with callback functions to avoid any blocking, and allows other code to be run in the meantime. Express APIs are routing and middle ware web framework.
const express = require('express');
const router = express.Router();
const MongoClient = require('mongodb').MongoClient;
const ObjectID = require('mongodb').ObjectID;
// Connect
const connection = (closure) => {
return MongoClient.connect('mongodb://localhost:27017/Zomato', (err, db) => {
if (err) return console.log(err);
closure(db);
});
};
// Error handling
const sendError = (err, res) => {
response.status = 501;
response.message = typeof err == 'object' ? err.message : err;
res.status(501).json(response);
};
// Response handling
let response = {
status: 200,
data: [],
message: null
};
router.get('/city/Zomato/:name', (req, res) => {
var id = req.params.name;
connection((db) => {
db.collection('zomato_code1')
.find({"City": id}, { _id: 0, Country_code: 0 })
.sort({Rating: -1})
.toArray()
.then((zomato_code1) => {
response.data = zomato_code1;
res.json(response);
})
.catch((err) => {
sendError(err, res);
});
});
});
Help
- MongoDB
- Node.js
- Express.js
- Angular