How tranductuan2001/kaisershop_fe works
Project Type and Purpose
• This is a single‐page React e‑commerce frontend application (bootstrapped with Create React App) that lets users browse products, place orders, sign in/up, and (for admins) manage products, orders, and users. It relies on a Redux store for state management, React Router for navigation, and a thin services layer (src/services/*.js) to communicate with a backend REST API and payment gateway.
File‐Structure Analysis
• public/: Static HTML entry point and manifest; served as-is.
• src/index.js + App.js: Root; mounts <App> into the DOM and sets up Redux <Provider> and <BrowserRouter>.
• src/routes/index.js: Defines route→page mapping.
• src/pages/: Top‐level “page” containers (AdminPage, HomePage, SignInPage, etc.).
• src/components/: Reusable presentational components (cards, buttons, modals, charts, forms).
• src/hooks/: Custom React hooks (useDebounceHook, useMutationHook) for common logic.
• src/redux/: Redux Toolkit slices (orderSlide.js, productSlide.js, userSlide.js) and store.js.
• src/services/: Abstraction over HTTP calls to external APIs (OrderService, ProductService, UserService, PaymentService).
• src/utils.js / src/contant.js: Shared utilities/constants.
Key Architecture Patterns
• Component‐Based Architecture (atomic components in components/)
• Container/Page Pattern (pages/ handle data + state)
• Layered Structure: UI layer → State layer (Redux) → Service/Network layer → External APIs
• Separation of concerns: custom hooks pull out logic, services encapsulate HTTP details, Redux slices handle state + async thunks.
Main Components and Interactions
a. User Browser (Chrome/Firefox/etc.)
b. React SPA (served from a CDN/static host)
‑ UI Components (components/)
‑ Page Components (pages/)
‑ React Router for navigation
‑ Redux Store (with three slices: products, orders, users)
‑ Custom Hooks (useDebounce, useMutation for form handling or data fetching)
‑ Services Layer (OrderService, ProductService, UserService, PaymentService)
c. External Systems
‑ Backend REST API (e‑commerce endpoints: /products, /orders, /users)
‑ Payment Gateway (Stripe/PayPal)
‑ Static asset host (CDN for images, public/ folder)