Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/bhavnesh7781/Food-Delivery-App/llms.txt

Use this file to discover all available pages before exploring further.

The Food Delivery App uses MongoDB as its primary data store, accessed through the Mongoose ODM. All three data collections — food items, users, and orders — are defined as Mongoose schemas in the backend/models/ directory. Before the server can handle any requests, a valid MONGODB_URI must be present in backend/.env and the database must be reachable. If the connection fails on startup, the process exits immediately to prevent the app from running in a broken state.

How the Connection Works

Database initialisation lives in a single file, backend/config/db.js. The connectDB function is called once in server.js before any routes are registered:
backend/config/db.js
import mongoose from "mongoose";

export const connectDB = async () => {
    try {
        await mongoose.connect(process.env.MONGODB_URI);
        console.log("Database Connected Successfully!!!");
    } catch (error) {
        console.error("Database connection failed:", error.message);
        process.exit(1);
    }
};
The connection string is read from process.env.MONGODB_URI, which is populated by dotenv when the server starts. There is no explicit database name in the mongoose.connect() call — the database name is embedded in the URI itself (e.g. /food-delivery at the end of the Atlas connection string).

Setting Up Your Database

Use a local MongoDB Community Server instance during development when you do not need cloud access.1. Install MongoDB Community ServerDownload and install MongoDB Community Edition for your operating system from the MongoDB download page.2. Start the mongod daemon
mongod --dbpath /your/data/directory
On macOS with Homebrew you can instead run:
brew services start mongodb-community
3. Set your connection stringAdd the following to backend/.env:
backend/.env
MONGODB_URI=mongodb://localhost:27017/food-delivery
MongoDB will automatically create the food-delivery database the first time a document is inserted — no manual database creation is required.

Data Models

The app defines three Mongoose collections. All models use the pattern mongoose.models.<name> || mongoose.model(...) to avoid re-registering a model if the module is imported multiple times.

food Collection

Stores the menu items displayed in the storefront and managed through the admin dashboard.
FieldTypeRequiredNotes
nameStringDisplay name of the food item
descriptionStringShort description shown on the menu card
priceNumberPrice in INR; multiplied by 100 when passed to Stripe
imageStringFilename of the uploaded image stored in backend/uploads/
categoryStringMenu category (e.g. “Salad”, “Rolls”, “Desserts”)

user Collection

Stores registered customer accounts and their active shopping cart state.
FieldTypeRequiredNotes
nameStringFull name of the user
emailStringMust be unique across all users
passwordStringBcrypt-hashed password
cartDataObjectMap of { foodId: quantity }. Defaults to {}
The user schema sets { minimize: false } as a schema option. By default, Mongoose removes empty objects from documents before saving them to MongoDB. Setting minimize: false disables this behaviour, ensuring that an empty cartData object ({}) is preserved in the database rather than being stripped out. This is important because the frontend reads cartData on login to restore the user’s cart state.

order Collection

Stores every order placed through the checkout flow, including its payment and fulfilment status.
FieldTypeRequiredNotes
userIdStringMongoDB ObjectId of the user who placed the order
itemsArrayArray of cart item objects { name, price, quantity, ... }
amountNumberTotal order value in INR
addressObjectDelivery address fields submitted at checkout
statusStringFulfilment status. Defaults to "Food Processing"
dateDateOrder creation timestamp. Defaults to Date.now()
paymentBooleantrue once Stripe confirms payment. Defaults to false

Build docs developers (and LLMs) love