The cart and checkout flow takes a customer from browsing the menu all the way to a completed Stripe payment. Cart state is held in memory via React Context and mirrored in MongoDB so that logged-in users never lose their basket between sessions. When the customer is ready to pay, a Stripe Checkout session is created on the backend and the user is redirected to Stripe’s hosted payment page.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.
How the Cart Works
Cart state lives inStoreContext as a plain object called cartItems. Each key is a food item’s _id and each value is the quantity currently in the basket:
loadCartData syncs the server-side cart to this local map:
addToCart and removeFromCart
Both functions optimistically update local state first, then persist the change to the backend when a token is present.Cart changes made by a guest (no token) are kept in memory only for the current browser session and are not persisted to the database.
Cart Page
The/cart route renders the Cart component, which lists every item where cartItems[item._id] > 0. For each row the component shows the item image, name, unit price, quantity, and line total. The × button calls removeFromCart.
The Cart Totals panel at the bottom summarises:
| Line | Calculation |
|---|---|
| Subtotal | getTotalCartAmount() — sum of price × quantity |
| Delivery Fee | Flat Rs.2 (waived when the cart is empty) |
| Total | Subtotal + Rs.2 |
/order. Unauthenticated users are redirected back to /cart, as are users who reach /order with an empty cart.
PlaceOrder Page
The/order route renders the PlaceOrder component. It presents a delivery address form alongside a final cost summary.
Delivery Address Fields
Delivery Address Fields
| Field | Input type | Placeholder |
|---|---|---|
firstName | text | First Name |
lastName | text | Last Name |
email | Email address | |
street | text | Street |
city | text | City |
state | text | State |
zipcode | text | Zip code |
country | text | Country |
phone | text | Phone |
required.Stripe Payment Flow
POST /api/order/place
The frontend posts the full order payload —
items, address, and amount — along with the auth token.The backend:- Saves a new
Orderdocument to MongoDB withpayment: false - Clears the user’s
cartDatain theUserdocument - Builds a Stripe
line_itemsarray from the ordered items plus a Delivery Charges line item - Creates a Stripe Checkout session and returns
session_url
Redirect to Stripe
The frontend replaces the current page with the Stripe-hosted checkout URL:Using
replace removes the order page from browser history so the customer cannot navigate back to it after paying.All Stripe line items use the INR currency, as set in
orderController.js. Prices are passed to Stripe in paise (price * 100).Delivery Fee Line Item
The flat Rs.2 delivery charge is appended to the Stripeline_items array on the backend so it appears as a named line on the Stripe-hosted receipt: