How hotrucdiep21/e-commerce works
Overall Project Type and Purpose
• This is a full-stack E-Commerce website that supports user authentication, product listings, shopping cart management, payment processing (via Stripe), sales analytics, category management, coupon systems, and an admin dashboard.
• The application emphasizes caching (Redis), cloud-based media storage (Cloudinary), and secure authentication using JWT with refresh and access tokens.
Project Structure
• The project is clearly divided into two main sections:
• Frontend: A React-based user interface built with Vite, styled with Tailwind, with components, pages, and state management (using custom stores).
• Backend: A Node.js/Express-based API handling core business logic, routes, controllers, models (for products, users, orders, coupons), middleware (e.g., authentication), and utility libraries for third-party integrations (MongoDB, Redis, Stripe, Cloudinary).
Identifying the Main Components
• Frontend:
• Client UI (React Components, Pages, and Stores)
• API Requests Layer (Axios integration for API calls)
• Routing & State Management (React pages, store files managing UI state)
• Backend:
• API Server (Express server in backend/server.js)
• Controllers (Handle business logic for analytics, authentication, cart, coupon, payment, and product operations)
• Routes (Mapping of URL endpoints to controller functions)
• Middleware (Authentication middleware for security)
• Models (Data schema definitions for coupons, orders, products, and users that interact with MongoDB)
• Libraries/Utils:
• Database Connection (MongoDB in backend/lib/db.js)
• Redis Integration (Caching logic in backend/lib/redis.js)
• Stripe Integration (Payment processing with backend/lib/stripe.js)
• Cloudinary (Image/media management via backend/lib/cloudinary.js)
• Auth Utilities (Helper functions related to authentication in backend/utils/auth.utils.js)
• Supporting Services & Databases:
• MongoDB for persistent data storage.
• Redis for caching.
• Stripe for processing payments.
• Cloudinary for handling media assets.
Determining Relationships and Interactions
• Backend routes map to specific controllers that contain the business logic.
• Controllers trigger interactions with:
1. Database: Read/write operations via models using MongoDB connection.
2. Cache: Save and retrieve data via Redis.
3. External Services:
• Payment (using Stripe)
• Media management (using Cloudinary)
• Authentication flows:
• Incoming requests pass through middleware that verifies JWT tokens.
• Auth controllers manage signup/login flows.
• Admin Dashboard: A dedicated path on the frontend interacts with backend analytics and administrative endpoints.
Architectural Patterns and Design Principles
• Clear separation of concerns: frontend and backend are distinct entities.
• MVC-like pattern in the backend where models, controllers, and routes are separated.
• Integration of third-party services (Stripe, Cloudinary, Redis) as separate utility modules.
• Use of middleware to handle cross-cutting concerns (security and authentication).