How seyityahya/ecommerce_react_node works
Project Type and Purpose
• This is a full-stack e-commerce style application.
• Frontend: React SPA (Create-React-App) with pages for authentication, product browsing, basket, orders, admin dashboard.
• Backend: Node.js/Express REST API with modules for auth, products, orders, role-based access, rate limiting.
• Data Stores: MongoDB (persistent storage) and Redis (cache and rate-limiter).
• Authentication: JWT (access + refresh tokens).
• Purpose: allow customers to browse products, place orders, maintain a shopping basket; allow admins to manage products and view orders.
File Structure
• Top‐level: /frontend and /backend.
• Backend layers under src/
• clients/ – MongoDB client (mongoose), Redis client (ioredis)
• controllers/ – business logic per resource (auth, product, order)
• models/ – Mongoose schemas (user, product, order)
• middlewares/ – grantAccess, input validations, JWT checks
• helpers/ – JWT token creation/verification
• rate-limiter.js – Redis‐based request throttling
• routes/ – Express router modules mapping endpoints to controllers
• app.js – Express server setup, CORS, body parsing, route mounting
• Frontend under src/
• pages/ – each route view (Auth, Products, Basket, Profile, Admin)
• components/ – reusable UI widgets (Card, Navbar, etc.)
• contexts/ – React Context for auth state and basket state
• api.js – axios instance pointing at backend API
• React-Query, Formik, Yup for data fetching and form management
1. Client Browser (React SPA)
2. Frontend Application (React + Context + React-Query + Router)
3. HTTP/API Layer (axios calls to backend)
4. Backend Application (Node.js/Express)
– Rate Limiter (Redis)
– Authentication Middleware (JWT)
– Controllers (Auth, Product, Order)
– Validation Layer (Joi/Yup rules)
5. Data Layer
– MongoDB (persistent)
– Redis (cache, session, rate-limiting)
• User → Browser → React SPA → triggers API call → axios →
• Express Router → Middleware (rate-limit → auth) → Controller →
• Controller uses Data Clients → reads/writes Redis or MongoDB → returns JSON →
• Axios receives response → React-Query updates cache → UI re-renders.
c. Architectural Patterns
• Layered (Presentation → API → Business Logic → Data Access)
• MVC-style within backend (Routes → Controllers → Models)
• Use of middleware chain (CORS, logging, rate-limit, auth, validation)
• Separation of concerns: dedicated clients for DB & cache, helpers for JWT, contexts for frontend state.
d. Key Technologies & Libraries
• Frontend: React, React Router, React-Query, Formik, Chakra UI, AntD, Axios
• Backend: Node.js, Express, Mongoose, ioredis, Joi, jsonwebtoken, accesscontrol, bcrypt
• Data Stores: MongoDB Atlas, Redis
• Dev & Env: Yarn, dotenv, sucrase, nodemon
Detail
• Cross-cutting concerns: validation, error handling (boom), logging if used.