How saurabh-8585/mern-e-commerce-backend works
Project type and purpose
• This repository implements the backend of a MERN-stack e-commerce application.
• It serves a React/Material-UI frontend (separate repo) by exposing RESTful endpoints for user auth, product/catalog operations, cart & order management, payments, reviews, and administration.
File structure
• Top-level entry point: index.js (bootstraps Express, mounts routes, connects to MongoDB).
• config.js: application configuration (MongoDB URI, JWT secrets, payment gateway keys).
• controllers/: business-logic layer (AdminControl, AllProductInfo, forgotPasswordController, paymentController, deleteUser, etc.).
• routes/: Express routers broken out by feature (auth.js, product.js, cart.js, paymentRoute.js, review.js, wishlist.js, plus an Admin subfolder).
• middleware/: JWT-based API authentication, admin/user role guards.
• models/: Mongoose schemas (User, Product, Cart, Wishlist, Review, Payment).
• Deployment config: vercel.json (serverless or deployment settings).
README for additional insights
• Confirms use of MongoDB, NodeJS, Express, JWT auth, payment gateway integration, mailing service.
• Frontend uses React, ContextAPI, React-Router—so the client invokes your API via HTTP/HTTPS.
Sketch the high-level components and interactions
a. Main components
• Client (React SPA hosted at e-shopit.vercel.app)
• API Server (Node.js + Express)
• MongoDB Atlas (or your chosen MongoDB host)
• External Services:
– Payment Gateway (e.g., Stripe, PayPal)
– Mail Service (e.g., SendGrid, NodeMailer + SMTP)
– Cloudinary (for image uploads & hosting)
b. Relationships & data flows
1. User ↔ Client (HTTPS requests, JWT stored in client)
2. Client → API Gateway (Express routes: /auth, /products, /cart …)
3. API Gateway → Auth Middleware → Controller → Model → MongoDB
4. PaymentController ↔ Payment Gateway API
5. forgotPasswordController ↔ Mail Service API
6. Controllers ↔ Cloudinary SDK for image upload URLs
c. Architectural patterns & principles
– MVC-inspired layering: Routes (entry points) → Middleware (cross-cutting concerns) → Controllers (use-case logic) → Models (persistence)
– Stateless JWT-based authentication (scalable horizontally)
– Clear separation of concerns: admin vs user routes via authAdmin/authUser middleware
d. Key technologies
– ExpressJS (web framework)
– Mongoose (ODM)
– JWT (authentication)
– MongoDB
– External SDKs (Payment, Mail, Cloudinary)