How tavt-dev/aivira-frontend works
Purpose and runtime
AIRIVA FRONTEND is a Vite-served React single-page storefront and administration client. It covers catalog browsing, authentication, cart/checkout, orders/payments, reviews, blog content, and a protected admin back office. Browser deployment is configured for Vercel (vercel.json); environment values are represented by .env.example.
Application bootstrap and shell
The browser entry point is src/main.jsx, which mounts the application, while src/App.jsx defines the top-level route composition. Shared storefront chrome and global UI behavior are centralized in src/components/Layout.jsx, src/components/Navbar.jsx, and src/styles.css. index.html is the Vite host document.
API boundary
All backend interaction is isolated under src/api/, with src/api/client.js as the shared HTTP-client boundary. Domain adapters separate customer flows—such as src/api/catalogApi.js, src/api/cartApi.js, and src/api/checkoutApi.js—from administrative operations such as src/api/adminOrdersApi.js and src/api/adminDashboardApi.js. The frontend therefore depends on an external API backend rather than containing server-side commerce logic.
Customer storefront flow
Public pages compose API data into catalog and purchase journeys: home/product/category views (src/pages/HomePage.jsx, src/pages/ProductPage.jsx, src/pages/CategoryPage.jsx), cart and checkout (src/pages/CartPage.jsx, src/pages/CheckoutPage.jsx), and post-transaction state (src/pages/OrdersPage.jsx, src/pages/PaymentResultPage.jsx). Checkout selection logic is isolated in src/utils/checkoutSelection.js; order/payment calls cross through src/api/orderApi.js and src/api/paymentApi.js.
Identity, authorization, and external OAuth
Authentication calls are encapsulated in src/api/authApi.js. UI gates enforce session and role boundaries through src/components/RequireAuth.jsx and src/components/RequireAdmin.jsx, with authorization decisions supported by src/utils/authz.js. Google OAuth is an external identity-provider flow surfaced through src/components/auth/GoogleLoginButton.jsx and completed at src/pages/GoogleOAuthResultPage.jsx. Browser-persisted state is abstracted by src/utils/storage.js.
Administration subsystem
Admin routes use a dedicated layout at src/pages/admin/AdminLayout.jsx and access specialized backend APIs. Core operational surfaces include dashboard analytics (src/pages/admin/AdminDashboardPage.jsx, src/api/adminDashboardApi.js), catalog/category management (src/pages/admin/AdminProductsPage.jsx, src/api/adminProductsApi.js), and order/payment operations (src/pages/admin/AdminOrdersPage.jsx, src/api/adminPaymentsApi.js). Additional admin domains include users, permissions, promotions/coupons, reviews, and blog management.
Presentation and localization
Reusable domain/UI components render product cards, introductory content, review forms, and dashboard charts, including src/components/BookCard.jsx, src/components/reviews/ReviewForm.jsx, and src/components/admin/RevenueChart.jsx. Internationalization is initialized in src/i18n.js with English and Vietnamese translation sources at src/locales/en/translation.js and src/locales/vi/translation.js.
Delivery and verification
The project uses the Vite frontend toolchain (vite.config.js), Tailwind/PostCSS styling configuration, and a GitHub frontend workflow at .github/workflows/frontend.yml. Unit/component API mocking infrastructure lives in src/test/, while browser smoke coverage uses Playwright under tests/e2e/smoke.spec.js.
Main entry points: App.jsx Route composition · AdminLayout.jsx Admin layout · catalogApi.js Customer API adapters · adminDashboardApi.js Admin API adapters
Components 21
React SPA
- Vite host & build · Serves and builds the browser client.
vite.config.js - Browser entry
src/main.jsx - Route composition
src/App.jsx - Storefront shell · Layout, navigation, and global styling.
src/components/Layout.jsx - Localization · English and Vietnamese translations.
src/i18n.js - Auth & role gates · Protects signed-in and administrator routes.
src/components/RequireAuth.jsx - Google OAuth flow · Login launch and OAuth result handling.
src/components/auth/GoogleLoginButton.jsx - Browser state storage
src/utils/storage.js
Customer storefront
- Catalog pages · Home, category, and product browsing.
src/pages/HomePage.jsx - Cart & checkout · Cart, checkout, order history, and payment result views.
src/pages/CheckoutPage.jsx - Checkout selection
src/utils/checkoutSelection.js
Admin back office
- Admin layout
src/pages/admin/AdminLayout.jsx - Dashboard analytics
src/pages/admin/AdminDashboardPage.jsx - Catalog management · Product and category operations.
src/pages/admin/AdminProductsPage.jsx - Order & payment operations
src/pages/admin/AdminOrdersPage.jsx
API boundary
- Shared HTTP client · Common backend transport boundary.
src/api/client.js - Customer API adapters · Catalog, cart, checkout, order, payment, and auth calls.
src/api/catalogApi.js - Admin API adapters · Dashboard, catalog, order, payment, and other admin calls.
src/api/adminDashboardApi.js
Other components
- External commerce API · Server-side commerce and administration logic.
- Google identity provider
- Vercel deployment
vercel.json
Connections 24
- Vite host & build → Browser entry: serves
- Browser entry → Route composition: mounts
- Route composition → Storefront shell: composes
- Route composition → Catalog pages: public routes
- Route composition → Cart & checkout: purchase routes
- Route composition → Auth & role gates: protects routes
- Route composition → Admin layout: admin routes
- Storefront shell → Localization: localized UI
- Cart & checkout → Checkout selection: selects checkout
- Catalog pages → Customer API adapters: catalog data
- Cart & checkout → Customer API adapters: cart, order & payment
- Auth & role gates → Browser state storage: reads session
- Google OAuth flow → Google identity provider: OAuth
- Google OAuth flow → Customer API adapters: completes login
- Admin layout → Dashboard analytics: hosts
- Admin layout → Catalog management: hosts
- Admin layout → Order & payment operations: hosts
- Dashboard analytics → Admin API adapters: analytics
- Catalog management → Admin API adapters: catalog operations
- Order & payment operations → Admin API adapters: order & payment operations
- Customer API adapters → Shared HTTP client: uses
- Admin API adapters → Shared HTTP client: uses
- Shared HTTP client → External commerce API: HTTP requests
- Vite host & build → Vercel deployment: deployed to