How rishibakshii/mern-ecommerce works
Project type and purpose
• This is a full-stack MERN ecommerce application.
• Frontend: React + Redux Toolkit + Material UI SPA
• Backend: Node.js + Express REST API
• Database: MongoDB (via Mongoose)
• External services: SMTP/email provider for OTP & password resets
File structure
• Top-level “backend” folder
– routes/ → Express route definitions (one file per resource: Auth, Product, Order, etc.)
– controllers/ → business logic handlers invoked by routes (CRUD, validation)
– models/ → Mongoose schemas for User, Product, Order, Review, Cart, Wishlist, Address, OTP, PasswordResetToken
– middleware/ → VerifyToken (JWT auth)
– database/db.js → MongoDB connection setup
– utils/ → token generation, OTP/email utilities, user sanitization
– seed/ → sample data scripts to populate collections
– index.js → Express app bootstrapping, middleware registration, route mounting
• Top-level “frontend” folder
– src/app/store.js → Redux store configuration
– src/features/… → Redux “slices” and RTK Query APIs for each domain (auth, products, cart, orders, reviews, wishlist, addresses, brands, categories, user)
– src/features/**/components & src/pages → React components & pages for each feature
– src/config/axios.js → configured Axios instance pointing at backend
– src/hooks/useAuth → custom hooks for session checks
– src/layout/RootLayout.js → global layout (Navbar, Footer)
– src/assets & src/theme → static assets and Material UI theme
README insights
• Confirms MERN stack, Redux Toolkit, Material UI
• Highlights features for both User and Admin
• Mentions OTP/email flows, JWT auth, seeding, environment variables
Main components
A. Client (Browser / React SPA)
• UI Layer (Material UI components)
• Presentation Layer (pages, layouts)
• State Layer (Redux store, slices, RTK Query)
B. API Server (Express)
• HTTP Layer (routes)
• Controller Layer (controllers folder)
• Business Logic / Utilities (utils for tokens, emails, sanitization)
• Security Layer (VerifyToken middleware)
C. Data Layer
• MongoDB collections (Users, Products, Orders, Reviews, Cart, Wishlist, Addresses, OTPs, PasswordResetTokens)
D. External Services
• Email/SMTP provider for OTPs & password resets
E. DevOps / Deployment (optional)
• Vercel config (backend/vercel.json)
• Environment variables (.env files)
Relationships and data flow
1. User interacts with React SPA → dispatches Redux actions / RTK Query calls → Axios issues HTTP requests (GET/POST/PUT/DELETE)
2. Express routes receive requests → pass through VerifyToken (for protected routes) → route handlers invoke controllers
3. Controllers call Mongoose models → perform CRUD on MongoDB
4. Controllers use utils to generate JWT, OTP, send emails via SMTP provider
5. MongoDB sends back documents → controllers sanitize output → responses flow back to client → Redux updates UI
Architectural patterns & design principles
• MVC-inspired layering on backend (routes → controllers → models)
• Slice-based architecture on frontend (feature folder per domain, co-locating API calls, slice logic, and UI)
• Single-Page Application with client-side routing (React Router implied in pages setup)
• Stateless REST API with JWT session management
• Data seeding utility for rapid dev/testing
Detail level—capture all essential modules
• Frontend: store.js, feature slices & APIs, UI components, hooks, config
• Backend: routes, controllers, models, middleware, utils, seed script
• Data: collection names
• External: email/SMTP provider