How venkatasai24/ecommerce works
Project Type and Purpose
• Full-stack e-commerce application built with React on the frontend and Node/Express + MongoDB on the backend.
• Provides user authentication (JWT), product browsing/filtering/search, cart/checkout, Stripe payments, and order history.
Main Components
a. Frontend (React App)
• Public/index.html (entry point)
• src/index.js → src/App.js (root)
• UI Components: Navbar, HomePage, Product/ProductCard, Cart, Checkout, FilterModel, Search, Profile, Order, Login/Register, Success, Missing (404), RequireAuth, PersistLogin
• Context & Hooks: AuthProvider, useAuth, useAxiosPrivate, useLogout, useRefreshToken
• API Layer: axios.js (configuring base URL, interceptors for JWT)
• Assets & CSS
b. Backend (Node.js + Express; separate repo)
• REST API Endpoints for auth, products, orders, payments
• JWT generation/verification
• Stripe integration for payments
• MongoDB collections: Users, Products, Orders
c. External Services
• MongoDB Atlas (or self-hosted MongoDB)
• Stripe API
Component Interactions & Data Flow
• User’s Browser renders React App, triggers UI events.
• API requests:
• Public data (products) → simple GET via axios.
• Protected routes (cart, order history, checkout) → axiosPrivate with JWT in Authorization header.
• Token refresh endpoint via useRefreshToken hook when access token expires.
• Backend receives requests, authenticates JWT, performs DB operations, returns JSON.
• Checkout flow: React calls backend /create-payment-intent, backend talks to Stripe, returns client secret, React mounts Stripe Elements, collects card details, confirms payment.
Architectural Patterns & Design Principles
• Component-based UI (separation of concerns)
• Context API for global auth state
• Custom hooks abstract cross-cutting concerns (auth, API calls, token refresh)
• RESTful API design on backend
• JWT-based stateless authentication
• Third-party integration (Stripe) as a service boundary
Elements
• Optional: annotate key protocols (HTTPS, Webhook) and data formats (JSON, JWT).