Skip to main content

Architecture & Tech stack

Tech stack

LayerTechnology
FrameworkReact 18 + TypeScript 4.9
BuildCreate React App 5 + CRACO 7
Routingreact-router-dom v6 (BrowserRouter)
StylingTailwind CSS 3 + CSS variables (design tokens)
HTTPAxios 1.3
Formsreact-hook-form 7
Toastreact-hot-toast
Iconslucide-react
CAPTCHA@marsidev/react-turnstile (Cloudflare Turnstile)
Phone inputreact-phone-number-input
QR / Posterqrcode, html-to-image
Datedate-fns
MobileCapacitor 7 (Android wrapper, remote URL mode)
Monorepo@kioskgaming/ui, @kioskgaming/page-loading

Directory structure

kioskgaming_shop/
├── src/
│ ├── index.tsx # Entry point, Service Worker registration
│ ├── App.tsx # Router + AuthProvider
│ ├── index.css # Tailwind + CSS variables
│ ├── config/env.ts # Centralized environment variables
│ ├── constants/index.ts # API URL, storage keys, custom events
│ ├── types/index.ts # TypeScript interfaces
│ ├── services/api.ts # HTTP client + all API functions
│ ├── hooks/ # useAuth, ledger hooks, zerox methods
│ ├── pages/ # 18 route pages
│ ├── components/
│ │ ├── auth/ # Login, forgot password, ProtectedRoute
│ │ ├── layout/ # AppLayout (sidebar, header, nav)
│ │ ├── credits/ # Buy credits, crypto wallets
│ │ ├── dashboard/ # Dashboard overview
│ │ ├── finance/ # Withdrawal limits panel
│ │ ├── players/ # Player detail panel
│ │ ├── poster/ # Promo poster templates
│ │ └── ui/ # ModalPortal, empty states
│ └── utils/ # format, ban, phone, ledger helpers
├── public/ # Static assets, PWA manifest, service worker
├── android/ # Capacitor Android wrapper
├── scripts/ # set-android-app-name.js
├── craco.config.js # CRA override (monorepo UI package)
├── capacitor.config.ts # Capacitor remote URL config
├── tailwind.config.js
├── vercel.json # SPA rewrite
└── deploy/nginx-spa.conf.example

Entry points

FileRole
src/index.tsxMount React, register Service Worker (production only)
src/App.tsxDefine routes, wrap AuthProvider
src/services/api.tsBackend integration layer (~1146 lines)

State management

No Redux/Zustand. State architecture:

PatternLocationPurpose
React Contexthooks/useAuth.tsxAuth state (user, token, login/logout)
Local useStateEach page/componentUI state, form, modal
Custom hooksuseShopWalletTransactions, useShopOnlineBalanceLedger, useSupportedZeroxMethodsData fetching with reload
localStorageAuth tokens, user data, zerox methods cache (24h TTL)
Custom Eventswindow.dispatchEventCross-component sync

Custom events

EventConstantWhen dispatched
shop-auth-token-changedSHOP_AUTH_TOKEN_CHANGED_EVENTLogin / logout
shop-credit-balance-refreshSHOP_CREDIT_BALANCE_REFRESH_EVENTAfter balance change flow
auth:unauthorizedAxios interceptor receives 401

Storage keys

KeyContent
shop_auth_tokenShop bearer token
shop_user_dataShop profile (JSON)
cashier_auth_tokenCashier token (separate client, not main flow)
cashier_user_dataCashier profile

Authentication flow

sequenceDiagram
participant U as Shop user
participant S as Shop Portal
participant B as Backend

U->>S: Enter loginId + password
S->>B: POST /portal-auth/login
alt OTP required (2FA)
B-->>S: needsOtp + pendingToken
U->>S: Enter OTP
S->>B: POST /shop-auth/verify-otp
end
B-->>S: accessToken + shop profile
S->>S: Save token to localStorage
S->>B: GET /shop/me (refresh profile)
  • Header: Authorization: Bearer {token}
  • 401 → dispatch auth:unauthorized → auto logout
  • ProtectedRoute redirects to /login if not authenticated

Environment variables

VariableRequiredDescriptionDefault
REACT_APP_API_BASE_URLYesBackend API base URLhttp://localhost:3001/api
REACT_APP_TURNSTILE_ENABLEDNoEnable Cloudflare Turnstilefalse
REACT_APP_TURNSTILE_SITE_KEYWhen Turnstile enabledSite key''
REACT_APP_APP_NAMENoDisplay app nameKiosk Gaming — Shop
REACT_APP_CLIENT_TELEGRAM_SUPPORT_URLNoTelegram support link
REACT_APP_CLIENT_ANDROID_APK_URLNoAndroid APK download link
REACT_APP_CLIENT_IOS_VIDEO_URLNoiOS setup video
PORTNoDev server port3004
CAP_SERVER_URLBuild APKRemote URL for Capacitorhttps://shop.kioskservice.club/
warning

Backend must set SHOP_FRONTEND_URL to the app origin so payment redirects to /payment/success and /payment/cancelled.


npm scripts

ScriptDescription
npm startDev server port 3004 (CRACO)
npm run buildProduction build
npm run cap:sync:devSync Capacitor → https://dev-shop.kioskservice.club/
npm run cap:sync:prodSync Capacitor → https://shop.kioskservice.club/
npm run apk:dev / apk:prodBuild debug APK

Special configuration

CRACO + Monorepo UI

craco.config.js imports configureKioskgamingUi from ../packages/ui so webpack resolves the shared UI package.

Capacitor Android

  • App ID: club.kioskservice.kioskgaming.shop
  • Remote URL mode: does not bundle web assets, loads from remote URL
  • Dev: https://dev-shop.kioskservice.club/
  • Prod: https://shop.kioskservice.club/

SPA routing (production)

PlatformConfig
Vercelvercel.json rewrite /(.*) → /index.html
Netlify/Cloudflarepublic/_redirects
Nginxdeploy/nginx-spa.conf.example (try_files)

Service Worker

  • public/sw.js + serviceWorkerRegistration.ts
  • Registers only when NODE_ENV === 'production'

Shared UI package

Shared components from @kioskgaming/ui:

  • PortalCreditTransactionsLedger, PortalUsdWalletLedgerTable
  • CreditTransactionDetailModal, UsdWalletTransactionDetailModal
  • WithdrawOtpStep, WithdrawBlockedAlert
  • FormField, Modal, Button, Input, Select, Textarea
  • PlayerFraudIndicatorsPanel, SupportDownloadRail

Overview diagram

flowchart TB
subgraph Client["kioskgaming_shop"]
Index[index.tsx] --> App[App.tsx]
App --> Auth[AuthProvider]
Auth --> Router[React Router]
Router --> Public["/login, /forgot-password"]
Router --> Protected["ProtectedRoute + Pages"]
Protected --> Layout[AppLayout]
Layout --> API[services/api.ts]
end

subgraph Backend["kioskgaming_backend"]
API -->|Bearer token| ShopAPI["/shop/*"]
API --> AuthAPI["/shop-auth/*, /portal-auth/*"]
API --> PaymentAPI["/payment/*"]
end

subgraph Storage["Browser"]
Auth --> LS["localStorage: shop_auth_token"]
end