# tavt-dev/aivira-frontend architecture

> Architecture diagram of the GitHub repository tavt-dev/aivira-frontend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tavt-dev/aivira-frontend
- Repository: https://github.com/tavt-dev/aivira-frontend

## Overview

#### 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: [`src/App.jsx`](https://github.com/tavt-dev/aivira-frontend/blob/main/src/App.jsx) (Route composition), [`src/pages/admin/AdminLayout.jsx`](https://github.com/tavt-dev/aivira-frontend/blob/main/src/pages/admin/AdminLayout.jsx) (Admin layout), [`src/api/catalogApi.js`](https://github.com/tavt-dev/aivira-frontend/blob/main/src/api/catalogApi.js) (Customer API adapters), [`src/api/adminDashboardApi.js`](https://github.com/tavt-dev/aivira-frontend/blob/main/src/api/adminDashboardApi.js) (Admin API adapters)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["React SPA"]
  node_vite{{"Vite host &amp; build<br/>toolchain<br/>[vite.config.js]"}}
  node_entry["Browser entry<br/>React bootstrap<br/>[main.jsx]"]
  node_routes["Route composition<br/>React app<br/>[App.jsx]"]
  node_shell["Storefront shell<br/>shared UI<br/>[Layout.jsx]"]
  node_i18n["Localization<br/>i18n<br/>[i18n.js]"]
  node_auth_gates["Auth &amp; role gates<br/>route guards<br/>[RequireAuth.jsx]"]
  node_oauth["Google OAuth flow<br/>external identity flow"]
  node_storage["Browser state storage<br/>persistence utility<br/>[storage.js]"]
end

subgraph group_storefront["Customer storefront"]
  node_catalog["Catalog pages<br/>customer pages<br/>[HomePage.jsx]"]
  node_checkout["Cart &amp; checkout<br/>purchase flow<br/>[CheckoutPage.jsx]"]
  node_checkout_selection["Checkout selection<br/>client logic"]
end

subgraph group_admin["Admin back office"]
  node_admin_layout["Admin layout<br/>admin shell<br/>[AdminLayout.jsx]"]
  node_admin_dashboard["Dashboard analytics<br/>admin page"]
  node_admin_catalog["Catalog management<br/>admin page"]
  node_admin_operations["Order &amp; payment operations<br/>admin pages"]
end

subgraph group_api["API boundary"]
  node_http_client["Shared HTTP client<br/>API client<br/>[client.js]"]
  node_customer_apis["Customer API adapters<br/>domain adapters<br/>[catalogApi.js]"]
  node_admin_apis["Admin API adapters<br/>domain adapters"]
end

node_backend{{"External commerce API<br/>backend service"}}
node_google(("Google identity provider<br/>external IdP"))
node_vercel{{"Vercel deployment<br/>hosting<br/>[vercel.json]"}}

node_vite -->|"serves"| node_entry
node_entry -->|"mounts"| node_routes
node_routes -->|"composes"| node_shell
node_routes -->|"public routes"| node_catalog
node_routes -->|"purchase routes"| node_checkout
node_routes -->|"protects routes"| node_auth_gates
node_routes -->|"admin routes"| node_admin_layout
node_shell -->|"localized UI"| node_i18n
node_checkout -->|"selects checkout"| node_checkout_selection
node_catalog -->|"catalog data"| node_customer_apis
node_checkout -->|"cart, order &amp; payment"| node_customer_apis
node_auth_gates -->|"reads session"| node_storage
node_oauth -->|"OAuth"| node_google
node_oauth -->|"completes login"| node_customer_apis
node_admin_layout -->|"hosts"| node_admin_dashboard
node_admin_layout -->|"hosts"| node_admin_catalog
node_admin_layout -->|"hosts"| node_admin_operations
node_admin_dashboard -->|"analytics"| node_admin_apis
node_admin_catalog -->|"catalog operations"| node_admin_apis
node_admin_operations -->|"order &amp; payment operations"| node_admin_apis
node_customer_apis -->|"uses"| node_http_client
node_admin_apis -->|"uses"| node_http_client
node_http_client -->|"HTTP requests"| node_backend
node_vite -.->|"deployed to"| node_vercel

click node_vite "https://github.com/tavt-dev/aivira-frontend/blob/main/vite.config.js"
click node_entry "https://github.com/tavt-dev/aivira-frontend/blob/main/src/main.jsx"
click node_routes "https://github.com/tavt-dev/aivira-frontend/blob/main/src/App.jsx"
click node_shell "https://github.com/tavt-dev/aivira-frontend/blob/main/src/components/Layout.jsx"
click node_i18n "https://github.com/tavt-dev/aivira-frontend/blob/main/src/i18n.js"
click node_catalog "https://github.com/tavt-dev/aivira-frontend/blob/main/src/pages/HomePage.jsx"
click node_checkout "https://github.com/tavt-dev/aivira-frontend/blob/main/src/pages/CheckoutPage.jsx"
click node_checkout_selection "https://github.com/tavt-dev/aivira-frontend/blob/main/src/utils/checkoutSelection.js"
click node_auth_gates "https://github.com/tavt-dev/aivira-frontend/blob/main/src/components/RequireAuth.jsx"
click node_oauth "https://github.com/tavt-dev/aivira-frontend/blob/main/src/components/auth/GoogleLoginButton.jsx"
click node_storage "https://github.com/tavt-dev/aivira-frontend/blob/main/src/utils/storage.js"
click node_admin_layout "https://github.com/tavt-dev/aivira-frontend/blob/main/src/pages/admin/AdminLayout.jsx"
click node_admin_dashboard "https://github.com/tavt-dev/aivira-frontend/blob/main/src/pages/admin/AdminDashboardPage.jsx"
click node_admin_catalog "https://github.com/tavt-dev/aivira-frontend/blob/main/src/pages/admin/AdminProductsPage.jsx"
click node_admin_operations "https://github.com/tavt-dev/aivira-frontend/blob/main/src/pages/admin/AdminOrdersPage.jsx"
click node_http_client "https://github.com/tavt-dev/aivira-frontend/blob/main/src/api/client.js"
click node_customer_apis "https://github.com/tavt-dev/aivira-frontend/blob/main/src/api/catalogApi.js"
click node_admin_apis "https://github.com/tavt-dev/aivira-frontend/blob/main/src/api/adminDashboardApi.js"
click node_vercel "https://github.com/tavt-dev/aivira-frontend/blob/main/vercel.json"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_vite,node_entry,node_routes,node_shell,node_i18n,node_auth_gates,node_oauth,node_storage toneBlue
class node_catalog,node_checkout,node_checkout_selection toneAmber
class node_admin_layout,node_admin_dashboard,node_admin_catalog,node_admin_operations toneMint
class node_http_client,node_customer_apis,node_admin_apis toneRose
class node_backend,node_google,node_vercel toneNeutral
```

## Components

### React SPA

- [Vite host & build](https://github.com/tavt-dev/aivira-frontend/blob/main/vite.config.js): toolchain · Serves and builds the browser client. · `vite.config.js`
- [Browser entry](https://github.com/tavt-dev/aivira-frontend/blob/main/src/main.jsx): React bootstrap · `src/main.jsx`
- [Route composition](https://github.com/tavt-dev/aivira-frontend/blob/main/src/App.jsx): React app · `src/App.jsx`
- [Storefront shell](https://github.com/tavt-dev/aivira-frontend/blob/main/src/components/Layout.jsx): shared UI · Layout, navigation, and global styling. · `src/components/Layout.jsx`
- [Localization](https://github.com/tavt-dev/aivira-frontend/blob/main/src/i18n.js): i18n · English and Vietnamese translations. · `src/i18n.js`
- [Auth & role gates](https://github.com/tavt-dev/aivira-frontend/blob/main/src/components/RequireAuth.jsx): route guards · Protects signed-in and administrator routes. · `src/components/RequireAuth.jsx`
- [Google OAuth flow](https://github.com/tavt-dev/aivira-frontend/blob/main/src/components/auth/GoogleLoginButton.jsx): external identity flow · Login launch and OAuth result handling. · `src/components/auth/GoogleLoginButton.jsx`
- [Browser state storage](https://github.com/tavt-dev/aivira-frontend/blob/main/src/utils/storage.js): persistence utility · `src/utils/storage.js`

### Customer storefront

- [Catalog pages](https://github.com/tavt-dev/aivira-frontend/blob/main/src/pages/HomePage.jsx): customer pages · Home, category, and product browsing. · `src/pages/HomePage.jsx`
- [Cart & checkout](https://github.com/tavt-dev/aivira-frontend/blob/main/src/pages/CheckoutPage.jsx): purchase flow · Cart, checkout, order history, and payment result views. · `src/pages/CheckoutPage.jsx`
- [Checkout selection](https://github.com/tavt-dev/aivira-frontend/blob/main/src/utils/checkoutSelection.js): client logic · `src/utils/checkoutSelection.js`

### Admin back office

- [Admin layout](https://github.com/tavt-dev/aivira-frontend/blob/main/src/pages/admin/AdminLayout.jsx): admin shell · `src/pages/admin/AdminLayout.jsx`
- [Dashboard analytics](https://github.com/tavt-dev/aivira-frontend/blob/main/src/pages/admin/AdminDashboardPage.jsx): admin page · `src/pages/admin/AdminDashboardPage.jsx`
- [Catalog management](https://github.com/tavt-dev/aivira-frontend/blob/main/src/pages/admin/AdminProductsPage.jsx): admin page · Product and category operations. · `src/pages/admin/AdminProductsPage.jsx`
- [Order & payment operations](https://github.com/tavt-dev/aivira-frontend/blob/main/src/pages/admin/AdminOrdersPage.jsx): admin pages · `src/pages/admin/AdminOrdersPage.jsx`

### API boundary

- [Shared HTTP client](https://github.com/tavt-dev/aivira-frontend/blob/main/src/api/client.js): API client · Common backend transport boundary. · `src/api/client.js`
- [Customer API adapters](https://github.com/tavt-dev/aivira-frontend/blob/main/src/api/catalogApi.js): domain adapters · Catalog, cart, checkout, order, payment, and auth calls. · `src/api/catalogApi.js`
- [Admin API adapters](https://github.com/tavt-dev/aivira-frontend/blob/main/src/api/adminDashboardApi.js): domain adapters · Dashboard, catalog, order, payment, and other admin calls. · `src/api/adminDashboardApi.js`

### Other components

- **External commerce API**: backend service · Server-side commerce and administration logic.
- **Google identity provider**: external IdP
- [Vercel deployment](https://github.com/tavt-dev/aivira-frontend/blob/main/vercel.json): hosting · `vercel.json`

## Connections

- 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
