How rahulreddy006/full-stack-e-commerce works
1. Overall shape
- This repository is a three-part MERN ecommerce system: a customer-facing React app in frontend, an admin React app in admin, and an Express/MongoDB API in backend.
- The two UIs are separate deployable clients, each with its own Vite build and Vercel config, while the backend is a standalone Node service.
2. Customer storefront (frontend)
- The storefront is organized as a typical single-page app with pages, reusable components, and a shared context/ShopContext.jsx.
- Key user flows are implemented through pages like Home, Collection, Product, Cart, PlaceOrder, Orders, Login, Contact, and About.
- UI components such as Navbar, Hero, LatestCollection, BestSeller, RelatedProducts, CartTotal, and SearchBox suggest the app is product-browse and checkout oriented.
3. Storefront state and data access
- ShopContext is the main client-side state boundary for cart/session-related behavior.
- The frontend likely talks to the backend through API calls from pages/components, with context coordinating shared state such as cart contents, auth state, and product data.
- The presence of Orders and PlaceOrder indicates the frontend handles the full purchase journey: browse → cart → checkout → order history.
4. Admin panel (admin)
- The admin app is a separate React SPA focused on operational workflows rather than shopping.
- Its route-level UI is centered on Login, Add, List, and Orders, with shared chrome in Navbar and Sidebar.
- This app is the control plane for product catalog management and order review, distinct from the customer storefront.
5. Backend API (backend)
- The backend is an Express application organized into routes, controllers, models, middleware, and config.
- It exposes resource-oriented endpoints for products, cart, orders, and users through route files like productRoute.js, cartRoute.js, orderRoute.js, and userRoute.js.
- Controllers contain the business logic, keeping route definitions thin and making the API layer easier to diagram as route → controller → model/external service.
6. Domain data model
- MongoDB entities are defined in models/productModel.js, orderModel.js, and userModel.js.
- These models are the persistence boundary for catalog items, customer accounts, and purchase records.
- Orders are a central aggregate: they connect user identity, cart contents, payment state, and fulfillment history.
7. Authentication and authorization
- middleware/auth.js and middleware/adminAuth.js split access control into customer-authenticated and admin-only paths.
- JWT is the primary auth mechanism per the README, with passwords handled via bcrypt.js.
- This creates an important boundary: storefront users can browse and purchase, while admin routes are protected for catalog/order management.
8. File upload and product media
- middleware/multer.js handles multipart image uploads on the backend.
- Uploaded images are integrated with Cloudinary via config/cloudinary.js, making product media an externalized asset pipeline rather than local filesystem storage.
- In architecture diagrams, this is best shown as admin product creation/editing flowing through backend upload middleware to Cloudinary, then persisting the resulting image URLs in MongoDB.
9. Payments and order lifecycle
- The README identifies Razorpay as the payment provider, so checkout involves an external payment gateway before order finalization.
- The likely flow is: cart/checkout data from the storefront → backend order/payment endpoints → Razorpay transaction → order persisted in MongoDB.
- Order management is surfaced back to both customer and admin UIs through order routes and order-related pages.
10. Shared infrastructure and deployment
- Each app has its own vite.config.js and vercel.json, indicating separate frontend deployments and routing setup.
- The backend is intended for a Node hosting platform such as Render, while frontend/admin are Vercel-compatible static SPA deployments.
- This separation matters architecturally: the clients are independent builds, but both depend on the same API and data store.
11. Primary runtime/data flow
- Customer flow: React storefront → backend API → MongoDB, with Cloudinary for product images and Razorpay for payments.
- Admin flow: React admin app → authenticated backend API → MongoDB/Cloudinary.
- Both UIs are thin presentation layers over shared backend resources, which makes the backend the main system-of-record boundary.
12. Architecture summary for diagramming
- Draw three top-level boxes: storefront UI, admin UI, and backend API.
- Inside the backend, show controllers, routes, middleware, and models as layered responsibilities.
- External services to show explicitly are MongoDB, Cloudinary, and Razorpay; Vercel/hosting is deployment infrastructure rather than business logic.
Main entry points: src/App.jsx Storefront · src/App.jsx Admin · productController.js Controllers · productRoute.js Routes
Components 20
Storefront
Customer-facing React app for browsing, cart, checkout, and order history.
- Storefront · Customer-facing application shell and routing.
frontend/src/App.jsx - Shop state · Shared storefront state for cart, session, and API coordination.
frontend/src/context/ShopContext.jsx - Home · Landing page and featured product discovery.
frontend/src/pages/Home.jsx - Collection · Catalog browsing and filtering.
frontend/src/pages/Collection.jsx - Product · Single product detail and related items.
frontend/src/pages/Product.jsx - Cart · Cart review and totals.
frontend/src/pages/Cart.jsx - Place order · Checkout and order submission.
frontend/src/pages/PlaceOrder.jsx - Orders · Customer order history and tracking.
frontend/src/pages/Orders.jsx
Admin
Operational React app for catalog and order management.
Backend
Express API, business logic, auth, and persistence boundary.
- API · Backend entrypoint and application composition.
backend/server.js - Routes · Resource endpoints for products, carts, orders, and users.
backend/routes/productRoute.js - Controllers · Request handling and domain workflows.
backend/controllers/productController.js - Middleware · Access control and multipart upload handling.
backend/middleware/auth.js - Models · Persistence schemas for products, orders, and users.
backend/models/productModel.js
External
Managed services used by the backend.
- MongoDB · Primary data store for catalog, users, and orders.
backend/config/mongodb.js - Cloudinary · External image storage for product media.
backend/config/cloudinary.js - Razorpay · Checkout payment provider used for order payment.
Connections 20
- Storefront → Shop state: shares state · Storefront pages and components coordinate through shared client state.
- Storefront → Home: routes to · Customer-facing navigation starts from the home page.
- Storefront → Collection: routes to · Catalog browsing page.
- Storefront → Product: routes to · Product detail page.
- Storefront → Cart: routes to · Cart page.
- Storefront → Place order: routes to · Checkout flow page.
- Storefront → Orders: routes to · Customer order history page.
- Shop state → API: API calls · Client state boundary coordinating backend requests.
- Admin → Login: routes to · Admin login screen.
- Admin → Catalog: routes to · Catalog management screen.
- Admin → Orders: routes to · Order management screen.
- Admin → API: API calls · Admin UI talks to the shared backend API.
- API → Routes: exposes · Server mounts the resource route layer.
- Routes → Controllers: delegates · Routes stay thin and forward work to controllers.
- Controllers → Models: reads/writes · Controllers persist and query domain records.
- Routes → Middleware: protects · Auth and upload middleware guard selected endpoints.
- Models → MongoDB: persists to · MongoDB stores the main domain data.
- Controllers → Cloudinary: uploads media · Product image handling is externalized to Cloudinary.
- Controllers → Razorpay: charges payment · Checkout finalization integrates with the payment gateway.
- Middleware → Models: verifies user · Auth middleware depends on user records for access control.