Project Structure(Backend)
Backend Dependencies:
"dependencies": {
"cors": "^2.8.5",
"express": "^4.18.2",
"mongoose": "^8.0.3",
"nodemon": "^3.0.2"
}
Example: Create server.js file and add the following code.
//server.js
const express = require("express");
const mongoose = require("mongoose");
const cors = require("cors");
const app = express();
const PORT = process.env.PORT || 5000;
app.use(cors());
app.use(express.json());
mongoose
.connect("mongodb://localhost:27017/food-delivery-app", {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => console.log("Connected to db"))
.catch((err) => console.log("Error connecting to db", err));
const restaurantSchema = new mongoose.Schema({
name: String,
image: String,
menu: [
{
name: String,
price: Number,
image: String,
},
],
rating: Number,
});
const Restaurant = mongoose.model("Restaurant", restaurantSchema);
// Define the PreviousOrder schema
const previousOrderSchema = new mongoose.Schema({
orderId: { type: String, required: true },
dateOfOrder: { type: Date, required: true },
amount: { type: Number, required: true },
});
const PreviousOrder = mongoose.model("PreviousOrder", previousOrderSchema);
// Seed initial data
const seedData = [
{
name: "Italian Delight",
image: "https://media.w3wiki.org/wp-content/uploads/20240110004602/pexels-chan-walrus-958545-(1).jpg",
menu: [
{
name: "Pasta Alfredo",
price: 10,
image:
"https://media.w3wiki.org/wp-content/uploads/20240110004646/file.jpg",
},
{
name: "Margherita Pizza",
price: 15,
image:
"https://media.w3wiki.org/wp-content/uploads/20240110004646/file.jpg",
},
{
name: "Chicken Parmesan",
price: 20,
image:
"https://media.w3wiki.org/wp-content/uploads/20240110004646/file.jpg",
},
],
rating: 4.5,
},
{
name: "Seafood Paradise",
image:
"https://media.w3wiki.org/wp-content/uploads/20240110004602/pexels-chan-walrus-958545-(1).jpg",
menu: [
{
name: "Grilled Salmon",
price: 12,
image:
"https://media.w3wiki.org/wp-content/uploads/20240110004602/pexels-chan-walrus-958545-(1).jpg",
},
{
name: "Lobster Bisque",
price: 18,
image:
"https://media.w3wiki.org/wp-content/uploads/20240110004602/pexels-chan-walrus-958545-(1).jpg",
},
{
name: "Shrimp Scampi",
price: 25,
image:
"https://media.w3wiki.org/wp-content/uploads/20240110004602/pexels-chan-walrus-958545-(1).jpg",
},
],
rating: 3.8,
},
{
name: "Vegetarian Haven",
image: "https://media.w3wiki.org/wp-content/uploads/20240110004602/pexels-chan-walrus-958545-(1).jpg",
menu: [
{
name: "Quinoa Salad",
price: 8,
image:
"https://media.w3wiki.org/wp-content/uploads/20240110004602/pexels-chan-walrus-958545-(1).jpg",
},
{
name: "Eggplant Parmesan",
price: 12,
image:
"https://media.w3wiki.org/wp-content/uploads/20240110004602/pexels-chan-walrus-958545-(1).jpg",
},
{
name: "Mushroom Risotto",
price: 16,
image:
"https://media.w3wiki.org/wp-content/uploads/20240110004602/pexels-chan-walrus-958545-(1).jpg",
},
],
rating: 4.2,
},
{
name: "Sizzling Steakhouse",
image: "https://media.w3wiki.org/wp-content/uploads/20240110004602/pexels-chan-walrus-958545-(1).jpg",
menu: [
{
name: "Filet Mignon",
price: 22,
image: "https://media.w3wiki.org/wp-content/uploads/20240110004602/pexels-chan-walrus-958545-(1).jpg",
},
{
name: "New York Strip",
price: 18,
image: "https://media.w3wiki.org/wp-content/uploads/20240110004602/pexels-chan-walrus-958545-(1).jpg",
},
{
name: "Ribeye Steak",
price: 25,
image: "https://media.w3wiki.org/wp-content/uploads/20240110004602/pexels-chan-walrus-958545-(1).jpg",
},
],
rating: 4.7,
},
{
name: "Asian Fusion",
image: "https://media.w3wiki.org/wp-content/uploads/20240110004602/pexels-chan-walrus-958545-(1).jpg",
menu: [
{
name: "Sushi Platter",
price: 20,
image: "https://media.w3wiki.org/wp-content/uploads/20240110004602/pexels-chan-walrus-958545-(1).jpg",
},
{
name: "Pad Thai",
price: 15,
image: "https://media.w3wiki.org/wp-content/uploads/20240110004602/pexels-chan-walrus-958545-(1).jpg",
},
{
name: "Mongolian Beef",
price: 18,
image: "https://media.w3wiki.org/wp-content/uploads/20240110004602/pexels-chan-walrus-958545-(1).jpg",
},
],
rating: 4.0,
},
];
const seedDatabase = async () => {
try {
await Restaurant.deleteMany(); // Clear existing data
await Restaurant.insertMany(seedData);
console.log("Database seeded successfully.");
} catch (error) {
console.error("Error seeding the database:", error.message);
}
};
// Seed data when the server starts
seedDatabase();
// Insert dummy data when the server starts
const insertDummyData = async () => {
try {
const existingOrders = await PreviousOrder.find();
// Insert dummy data only if the database is empty
if (existingOrders.length === 0) {
const dummyOrders = [
{ orderId: "001", dateOfOrder: new Date(), amount: 30 },
{ orderId: "002", dateOfOrder: new Date(), amount: 45 },
// Add more dummy orders as needed
];
await PreviousOrder.insertMany(dummyOrders);
console.log("Dummy data inserted successfully!");
}
} catch (error) {
console.error("Error inserting dummy data:", error);
}
};
insertDummyData();
app.get("/restaurants", async (req, res) => {
try {
// Use the 'find' method of the 'Restaurant' model to retrieve all restaurants
const restaurants = await Restaurant.find({});
// Send the retrieved restaurants as a JSON response
res.json(restaurants);
} catch (error) {
// Handle any errors that may occur during the process and send a 500 Internal Server Error response
res.status(500).json({ error: error.message });
}
});
// Endpoint to retrieve previous orders
app.get("/previousOrders", async (req, res) => {
try {
const orders = await PreviousOrder.find();
res.status(200).json(orders);
} catch (error) {
res.status(500).json({ error: "Internal server error" });
}
});
// Endpoint to save order data
app.post("/previousOrders", async (req, res) => {
try {
const { orderId, dateOfOrder, amount } = req.body;
console.log(orderId, dateOfOrder, amount);
const newOrder = new PreviousOrder({
orderId,
dateOfOrder: new Date(dateOfOrder),
amount,
});
await newOrder.save();
res.status(201).json({ message: "Dummy order saved successfully!" });
} catch (error) {
res.status(500).json({ error: "Internal server error" });
}
});
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});
Step 4: To start the backend run the following command.
nodemon server.js
Step 5: Go to the root directory of the application and create the frontend application.
npx create-react-app client
cd client
Step 6: Install important dependencies: axios
npm i axios
Food Delivery Application Project in Software Development
Food Delivery Application is one of the most common software development projects to date. In this article, we are going to make the Food Delivery Application software development project, from scratch, for final-year students. We will be covering all the steps you have to do while developing this project.
Table of Content
- Step 1- Team Formation Phase: Creating a Dynamic Team
- Step 2- Topic Selection
- Step 3- Project Synopsys for Food Delivery Application
- Step 4- Requirement Gathering (Creating SRS for Food Delivery Application)
- Software Requirement Specification (SRS) Document | Food Delivery Application
- 4.1 SRS (Food Delivery Application) | Introduction:
- 4.2 SRS (Food Delivery Application) | Overall Description:
- 4.3 SRS (Food Delivery Application) | Designing Food Delivery Application :
- Use case Diagram for Food Delivery Application:
- ER Model of Food Delivery Application:
- Data Flow Diagram of Food Delivery Application:
- 4.4 Functional Requirements | SRS (Food Delivery Application)
- 4.5 Non Functional Requirements | SRS (Food Delivery Application)
- 4.6 SRS (Food Delivery Application) | Appendices:
- 5. Coding or Implementation of Food Delivery Application
- Prerequisites:
- Approach to create Restaurant App using MERN:
- Steps to create Application:
- Project Structure(Backend):
- Project Structure(Frontend):
- Step 6- Testing Food Delivery Application
- Step 7- Creating Project Presentation on Food Delivery Application:
- Step 8- Writing a Research Paper on Food Delivery Application:
Project Development is a multiphase process in which every process is equally important. Here in this post, we are also going to develop our Food Delivery Application Project in multiple phases, such as:
- Team Formation
- Topic Selection
- Creating Project Synopsys
- Requirement Gathering
- Coding or Implementation
- Testing
- Project Presentation
- Writing a Research Paper
Let us look into the steps one by one.
Contact Us