--- title: Frontend Service — amn-frontend tags: [service, frontend, nextjs, react, web3, telegram] created: 2026-06-08 updated: 2026-06-12 --- # Frontend Service — amn-frontend ## 1. Overview `amn-frontend` is the primary user-facing application for the Amanat (AMN) escrow marketplace. It serves buyers, sellers, and admins through a unified Next.js 16 App Router application with a Persian-first (RTL) UI. | Field | Value | |---|---| | Package name | `amn-frontend` | | Version | **2.11.89** | | Status | Active — `main` deployed to `dev.amn.gg`; `feature/white-label-shops` deployed to `multi.amn.gg` | | Framework | Next.js 16 (App Router + Turbopack), React 19, TypeScript strict | | Dev port | `8083` (both local and Docker) | | Package manager | `yarn@1.22.22` | | Node requirement | `>=20` | | Repo | `git@git.tbs.amn.gg:escrow/frontend.git` | The app covers the full escrow lifecycle: request creation, multi-seller offer collection, negotiation, on-chain payment (BSC/ETH/Base/TON), delivery confirmation, dispute handling, loyalty points, tenant admin for white-label shops, public seller-shop browsing, and a Telegram Mini App shell for mobile-native access. > [!note] Multi-shop branch > `feature/white-label-shops` adds `TenantProvider`, `/dashboard/admin/tenants`, custom-domain controls, bot activation links, and the `WEBAPP_ENABLED` middleware gate that keeps `multi.amn.gg` Mini App-first while leaving dashboard/auth routes reachable. --- ## 2. Tech Stack | Layer | Library / Version | Notes | |---|---|---| | Framework | `next@^16.1.1` | App Router, Turbopack dev server | | UI runtime | `react@^19.1.0`, `react-dom@^19.1.0` | Server + Client Components | | Component library | `@mui/material@^9.0.1` | MUI v9 with Emotion; `@mui/lab`, `@mui/x-data-grid`, `@mui/x-date-pickers`, `@mui/x-tree-view` | | Styling engine | `@emotion/react`, `@emotion/styled`, `stylis-plugin-rtl` | RTL support via stylis | | State / data fetching | `@tanstack/react-query@^5.83.0`, `swr@^2.3.3` | TanStack Query is primary; SWR used in some legacy paths | | Real-time | `socket.io-client@^4.8.1` | Bidirectional events; custom `SocketContext` | | Forms | `react-hook-form@^7.77.0`, `@hookform/resolvers@^5.0.1`, `zod@^4.0.10` | Schema validation via Zod v4 | | i18n | `i18next@^26.3.0`, `react-i18next@^17.0.8` | 6 locales (en, fa, ar, fr, cn, vi); RTL for fa/ar | | Web3 — EVM | `wagmi@^2.19.5`, `viem@^2.31.7`, `ethers@^6.15.0` | WalletConnect + MetaMask + Trezor | | Web3 — TON | `@tonconnect/ui-react@^2.4.4`, `@ton/core@^0.63.1` | TON wallet payments | | Hardware wallet | `@trezor/connect-web@^9.7.3` | Trezor signing flow | | Chain indexing | `alchemy-sdk@^3.6.1` | Alchemy for multi-chain queries | | Rich text editor | `@tiptap/react@^3.23.6` + extensions | Used in post/blog editor | | Charts | `apexcharts@^5.10.1`, `react-apexcharts@^2.1.0` | Dashboard KPI charts | | Animation | `framer-motion@^12.13.0` | Page transitions and UI motion | | Carousel | `embla-carousel-react@8.6.0` | Product / shop carousels | | Maps | `mapbox-gl@^3.12.0`, `react-map-gl@^8.0.4` | Address / location pickers | | HTTP client | `axios@^1.11.0` | Centralised instance with auth interceptors in `src/lib/axios.ts` | | Notifications | `notistack@^3.0.2`, `sonner@^2.0.3` | Snackbar + toast | | Error monitoring | `@sentry/nextjs@^10.22.0` | SDK wraps Next.js build + runtime | | CAPTCHA | `@marsidev/react-turnstile@^1.5.2` | Cloudflare Turnstile | | Dates | `dayjs@^1.11.13`, `date-fns-jalali@^4.1.0-0` | Jalali (Persian) calendar support | | QR code | `qrcode@^1.5.4` | Wallet payment QR generation | | Fonts | DM Sans, Inter, Nunito Sans, Public Sans, Barlow | Variable fonts via `@fontsource-variable` | --- ## 3. App Router Page Structure All routes live under `frontend/src/app/`. The dev server and Docker container both bind port `8083`. ### Top-level route segments | Route | Type | Purpose | |---|---|---| | `/` | Public | Landing / marketing home | | `/api/health` | API Route | Container health-check endpoint | | `/api/llm` | API Route | LLM proxy for amanat-assist features | | `/auth/jwt/*` | Public | Sign-in, sign-up, OTP verify, password reset, update | | `/checkout/request-network/*` | Public | Request Network payment checkout shell | | `/dashboard/*` | Protected | Main authenticated app (see below) | | `/design-preview` | Internal | Theme/component sandbox | | `/error` | Public | Global error display | | `/payment/callback`, `/payment/cancel` | Public | Payment gateway redirect landing | | `/post/[slug]` | Public | Blog post reader | | `/shop/[seller]/[id]` | Public | Public seller shop / item view | | `/store/items`, `/store/checkout` | Public | Storefront browsing and checkout | | `/telegram` | Mini App | Telegram Mini App shell (see §7) | ### Dashboard sub-routes (AuthGuard + EmailVerificationGuard) | Route | Purpose | |---|---| | `/dashboard` → `/dashboard/overview` | KPI home tiles, recent activity | | `/dashboard/chat` | Real-time escrow chat | | `/dashboard/account/*` | Profile, address, notifications, wallet, passkey | | `/dashboard/request/*` | Buyer purchase requests | | `/dashboard/request-template/*` | Seller request templates | | `/dashboard/payment/*` | Payment history and detail | | `/dashboard/points/*` | Loyalty hub — transactions, referrals, levels | | `/dashboard/disputes/*` | Dispute creation and management | | `/dashboard/seller/*` | Seller-side offer management | | `/dashboard/shop-settings/*` | Seller shop configuration (incl. Telegram config) | | `/dashboard/shops/*` | Browse / checkout from within dashboard | | `/dashboard/user/*` | Admin user management | | `/dashboard/post/*` | Admin blog editor (Tiptap) | | `/dashboard/admin/tenants/*` | Tenant admin (white-label shops; `feature/white-label-shops` only) | | `/dashboard/assist/*` | AI assistant (amanat-assist) | --- ## 4. Key Sections / Features ### Marketplace and escrow flow The primary buyer journey: 1. Buyer submits a **purchase request** (`/dashboard/request/new`) — product description, budget, chain preference. 2. Sellers see the request and submit **offers** via request templates (`/dashboard/request-template`). 3. Buyer selects an offer; both sides enter the **escrow chat** (`/dashboard/chat`). 4. Buyer initiates payment — on-chain via Wagmi/Trezor or off-chain via Request Network. 5. After delivery, buyer releases escrow funds; on dispute, both parties access `/dashboard/disputes`. ### Dashboard Multi-role dashboard accessible post-login. Guards: - `AuthGuard` — redirects unauthenticated users to `/auth/jwt/sign-in`. - `EmailVerificationGuard` — blocks unverified accounts on key routes. Sidebar nav adapts to role: buyer, seller, admin, or multi-tenant operator. ### Admin `/dashboard/user` and `/dashboard/post` are admin-only sections gated by role check in the layout. Tenant admin (`/dashboard/admin/tenants`) is only visible on the `feature/white-label-shops` build. ### Telegram Mini App Full Telegram Mini App (TMA) at `/telegram`. See §7 for integration details. ### White-label shops `feature/white-label-shops` branch adds multi-tenancy: `TenantProvider` (Context), `/dashboard/admin/tenants` CRUD, custom domain config per tenant, and a `WEBAPP_ENABLED` middleware flag to route Mini App-first for `multi.amn.gg`. ### Blog / content Public blog at `/post/[slug]` rendered server-side. Admin writes posts via Tiptap rich-text editor at `/dashboard/post`. ### AI assistant (amanat-assist) `/api/llm` proxies requests to the amanat-assist backend service. The dashboard `/assist` section provides the in-app chat interface. --- ## 5. State Management | Layer | Mechanism | Usage | |---|---|---| | Server cache / async state | `@tanstack/react-query` | All API data fetching, mutation, background refetch | | Legacy async state | `swr` | Some older sections not yet migrated to TQ | | Real-time events | `SocketContext` (`src/contexts/`) | Socket.io connection; exposes socket via `useSocket` hook | | Global UI state | React Context (multiple providers) | Auth, Settings (theme/direction/language), Web3 | | Form state | `react-hook-form` + Zod | All forms; validation on client | | Zustand | Not in use | No Zustand dependency in package.json | The root layout stacks providers in order: `ThemeProvider` → `SettingsProvider` → `AuthProvider` → `QueryClientProvider` → `SocketContextProvider` → `Web3Provider`. The Telegram layout uses a minimal provider stack: `TonConnectUIProvider` + `QueryClientProvider` only — no dashboard providers. --- ## 6. Internationalization | Detail | Value | |---|---| | Library | `i18next@^26.3.0` + `react-i18next@^17.0.8` | | Language detection | `i18next-browser-languagedetector` + `accept-language` (server hint) | | Locales shipped | English (`en`), Persian/Farsi (`fa`), Arabic (`ar`), French (`fr`), Chinese (`cn`), Vietnamese (`vi`) | | RTL locales | `fa`, `ar` — `direction: rtl` applied at theme level; `stylis-plugin-rtl` transforms MUI Emotion styles | | Jalali calendar | `date-fns-jalali@^4.1.0-0` — date pickers switch to Jalali for `fa` locale | | Translation files | `src/locales/langs/{en,fa,ar,fr,cn,vi}/*.json` (lazy-loaded via `i18next-resources-to-backend`) | | Telegram locales | `src/sections/telegram/locales/{en,fa}.ts` — standalone namespace for TMA strings | | Default locale | Determined by browser; Persian is the primary product locale | RTL layout direction is set in `SettingsProvider` and passed to the MUI theme. The `stylis-plugin-rtl` plugin auto-mirrors margin/padding/float/border-radius CSS properties. --- ## 7. Telegram Mini App Integration ### Loading mechanism `/app/telegram/layout.tsx` injects the Telegram SDK via `next/script` with `strategy="beforeInteractive"`: ```tsx