How cuongle1025/ecommerce-store works
Project type and purpose
• This is a full‑stack MERN (MongoDB, Express, React, Node.js) e‑commerce application.
• The user-facing React/Redux front end communicates over HTTP (and optionally WebSockets) with an Express/Mongoose back end, which in turn persists data in MongoDB.
File structure
a. Top‑level
• frontend/ – React application (Vite‑powered) with components, pages, Redux slices, RTK Query services, assets, Tailwind CSS, etc.
• backend/ – Node.js/Express API with src/config, controllers, services, models, routes, middlewares, sockets, utils, validations.
b. Backend layers
• config (CORS, environment, MongoDB connection)
• routes → v1, v2 versioned endpoints
• controllers → request handlers
• services → business logic
• models → Mongoose schemas
• middlewares → error handling
• sockets → real‑time events
• utils/providers/validations
c. Frontend patterns
• src/app/store.ts – Redux store, RTK Query setup
• features – domain slices (Products, Cart, Checkout)
• components – UI primitives & widgets
• pages – route‑level views
• utils/constants
README
• Confirms MERN stack, highlights React + Redux Toolkit + RTK Query for data fetching, Tailwind CSS for styling.
• Back end: Node/Express with Mongoose.
• Instructions to install and run each tier independently.
a. Main components
1) Client (Browser)
– React SPA (App.tsx)
– Redux store + RTK Query
– UI components, pages, assets
2) API Gateway / HTTP Layer
– Vite dev server during development or nginx/CDN in production
3) Back‑end Server
– Express.js server (server.js)
– Middlewares (CORS, error handling)
– REST API endpoints (routes/v1, routes/v2)
– Socket.IO or WebSocket endpoint (exampleSocket.js)
4) Business Logic
– Services (productService, cartService, etc.)
5) Data Layer
– Mongoose models
– MongoDB database
6) External Services (optional)
– ExampleProvider may represent e‑mail, payment gateway, etc.
b. Relationships & interactions
• Browser → HTTP requests to Express REST endpoints
• RTK Query abstracts fetch/post calls, caches responses in Redux
• Express routes invoke controllers → services → models → MongoDB
• Socket events: server ↔ client for real‑time updates (e.g., cart changes, order notifications)
• Config modules initialize environment, set up DB connection, CORS policy
c. Architectural patterns & principles
– Layered architecture (Controller → Service → Data Model)
– Versioned API routes (v1, v2) for backward compatibility
– Separation of concerns: UI vs. state vs. data‑access
– Redux for predictable state management, RTK‑Query for caching & side‑effects
– Modular folder structure for testability and scalability
d. Key technologies/frameworks
– Front end: React, Redux Toolkit, RTK Query, Tailwind CSS, Vite
– Back end: Node.js, Express.js, Mongoose, Socket.IO (if used)
– Database: MongoDB