How aninik4444/amazon-clone works
Project Type and Purpose
• This is a full-stack MERN application that clones Amazon’s core shopping flow.
• Front-end: React.js SPA (components, state management, theming, axios utils)
• Back-end: Node.js + Express REST API (routes → controllers → models), connected to MongoDB via Mongoose
• Purpose: Allow users to browse products, filter/sort/search, sign up/log in (JWT auth), add to cart, place orders
File-Structure Analysis
• amazon-frontend/
• public/: Static assets (index.html, redirects, manifest)
• src/: App entry (index.js), global CSS, themes, utils (axiosInstance, loader, store)
• components/: UI modules (Home, Product, ProductDetails, Checkout, Orders, Login, SignUp, NavBar, PrivateRoute, ErrorBoundary) each with styling and reducer logic
• backend/
• app.js: Express server setup
• routes/: Defines /api/v1/{products,users,carts,orders} endpoints
• controllers/: Business logic for each resource
• models/: Mongoose schemas (Product, User, Cart, Order)
• middleware/: JWT auth, error handling, 404 handling
• db/connect.js: MongoDB connection
• errors/: Custom error classes
Core Architectural Patterns
• Front-end: Component-based UI + Reducer state management (React Context or Redux-style), external service calls via axiosInstance
• Back-end: MVC style (Routes → Controllers → Models), middleware pipeline for auth and error handling
• Security: JWT-based authentication / authorization at the middleware layer
• Data layer: MongoDB as a document store
Main Components & Data Flows
a. Front-End SPA (browser)
• User interacts with React components
• Components dispatch actions to local store (cart, search, login reducers)
• UI makes HTTP(S) requests via axiosInstance to API endpoints
b. API Layer (Express server)
• Express Router maps incoming requests to controllers
• Auth middleware validates JWT, then routes to controller
• Controllers perform CRUD operations via Mongoose models
• ErrorHandler middleware catches and formats errors
c. Database (MongoDB Atlas or self-hosted)
• Persists collections: users, products, carts, orders
Data flow example (Add to Cart):
User clicks “Add” → React component dispatches action → axiosInstance.POST /api/v1/cart → auth.js middleware verifies JWT → CartController.create() → CartModel.save() → Respond with updated cart → UI updates store → Cart page re-renders
Technology & Deployment Notes
• Front-end: React, React Router, styled-components ( *.styles.js), Context API/reducers
• Back-end: Node.js, Express.js, Mongoose, JWT
• Deployment:
• Front-end can be built and hosted on Netlify / Vercel / S3 + CloudFront
• Back-end containerized via Dockerfile or deployed on Heroku / ECS
• Environment variables (.env) for API URLs, JWT secret/expiry, Mongo connection string
Essential Details
• Don’t omit reducers and axiosInstance on the front-end—they’re critical glue
• JWT auth flow in middleware on the server
• Error handling path (errorHandler middleware)
• If time permits, annotate sequence of calls for pagination, search, sort features