How dustopia1203/hhm-fe works
Project type and purpose
• This is a client-side Single Page Application built with React + TypeScript, bundled by Vite.
• It implements an e-commerce storefront: user account management, product/catalog browsing, shopping cart, checkout/payment flows (including Solana and VNPAY callbacks), order management, product reviews, and vendor/shop dashboards.
File structure
• Top-level “public” contains static assets and index.html.
• “src” is the application code:
• apis/ – a thin REST client layer (axiosClient + useXxxApis hooks)
• components/ – reusable UI pieces (common, UI primitives, domain features)
• routes/ – file-based routing: auth, products, cart, orders, payment callbacks, vendor shop area
• stores/ – client state management (e.g. Zustand or similar hooks)
• utils/ & lib/ – assorted helpers (auth helpers, Cloudinary integration, search utils)
• main.tsx & routeTree.gen.ts – Vite entry point and generated route manifest for the router.
• Config files: vite.config.ts, tsconfig*.json, eslint.config.js.
README for additional insights
• It’s a minimal Vite + React + TypeScript starter, with recommendations for ESLint.
• No backend code lives here; all server interactions go through the REST hooks in src/apis.
Main components
a. Frontend SPA (React + Vite)
– Entry: index.html → main.tsx → React application
– Router & routeTree.gen.ts → dynamic route resolution
– UI layers:
• Domain pages (Login, Register, ProductList, Checkout, ShopDashboard, etc.)
• Reusable components (ProductCard, ReviewForm, Header/Footer, Loader, NotFound)
• UI primitives (dialog, sonner notifications)
– State stores (useProfileStore, useShopStore)
– API client layer (axiosClient + useAccountApis, useCartApis, usePaymentApis, etc.)
– Utility modules (auth token management, Cloudinary image uploads, client-side search)
b. Backend REST services
– User service (account creation, login, verify-account)
– Product/Catalog service (categories, products, reviews)
– Cart service
– Order service
– Payment service (checkout initiation, Solana & VNPAY callbacks)
– Shop service (vendor-specific data, shop settings)
– Shipping service
c. External third-party services
– Cloudinary (image hosting)
– Payment gateways (Solana network, VNPAY)
Relationships and data flow
• User interacts with SPA in browser → React router resolves route → React components call hooks in src/apis → axiosClient sends HTTP requests to backend service endpoints → backend returns JSON → hooks update UI and stores → UI renders updated state.
• For uploads: React component invokes utils/cloudinary.ts to upload images → Cloudinary responds with URL → URL passed to product/shop APIs.
• Checkout flow: React component invokes usePaymentApis → backend returns payment URL or transaction details → browser redirects to gateway → gateway calls back to /payment/solana-callback or /payment/vnpay-callback → React route handler finalizes order via order API.
Architectural patterns & principles
• Layered architecture: Presentation (components & routes) → Application (hooks & stores) → Infrastructure (axiosClient) → External services.
• Separation of concerns: UI components vs. domain pages vs. API hooks vs. utility modules.
• File-based routing for automatic route registration (routeTree.gen.ts).
• Single source of truth for API base URL and interceptors in axiosClient.
• Local state stores for profile & shop context.