Skip to content

Back Office Client

1. Document Control

PropertyValue
Package@nx-app/client
Version0.0.2-37
TypeWeb Application (SPA)
RuntimeBrowser / Bun (dev)
DeploymentDocker / Nginx

2. Scope & Objectives

2.1. Scope

The Back Office Client is the administrative interface for the BANA platform. It provides business owners, operators, and system administrators with comprehensive tools to manage their entire operation through a web browser.

2.2. Objectives

  • Comprehensive Management: Full control over products, categories, merchants, employees, and reporting.
  • Data Visualization: Rich charts and tables for business insights.
  • Responsive Design: Functional on Desktop, Tablet, and Mobile browsers.
  • Type Safety: End-to-end type safety with TypeScript and Zod validation.

3. Technology Stack

3.1. Core Framework

TechnologyVersionPurpose
React^19.2.1UI Component Library
React DOM^19.2.1DOM Rendering
React Router^7.9.4Client-side Routing
TypeScript~5.9.3Type Safety

3.2. State Management

TechnologyVersionPurpose
Redux Toolkit^2.9.1Global State Management
React Redux^9.2.0React-Redux Bindings
TanStack Query^5.90.5Server State & Caching
ra-core^5.13.2Admin Framework Core

3.3. UI Components

TechnologyVersionPurpose
@nx-app/admin-ui-kitworkspace:*Shared UI Component Library
Radix UIVariousAccessible Primitives
Tailwind CSS^4.1.16Utility-first Styling
Lucide React^0.552.0Icon Library
next-themes^0.4.6Theme Switching

3.4. Forms & Validation

TechnologyVersionPurpose
React Hook Form^7.66.0Form State Management
@hookform/resolvers^5.2.2Schema Validation Integration
Zod^4.1.12Runtime Schema Validation

3.5. Data Tables & Drag-and-Drop

TechnologyVersionPurpose
TanStack Table^8.21.3Headless Data Tables
TanStack Virtual^3.13.12Virtualized Lists
@dnd-kit/core^6.3.1Drag-and-Drop Core
@dnd-kit/sortable^10.0.0Sortable Lists

3.6. Build & Development

TechnologyVersionPurpose
Vite^7.1.7Build Tool & Dev Server
@vitejs/plugin-react^5.0.4React Integration
vite-plugin-pwa^1.1.0PWA Support
ESLint^9.36.0Code Linting
Prettier3.6.2Code Formatting

4. Architecture

4.1. Application Layers

Browser Request
React Router
Screen Component
API Service
Backend API

4.2. Context Providers

The application wraps components with multiple context providers for dependency injection and state management:

ApplicationContext
├── CoreApplicationContext (DI Container)
│   └── ReduxProvider (State Management)
│       └── ThemeProvider (Dark/Light Mode)
│           └── ActiveThemeProvider (Theme Customization)
│               └── App (Routes & Layout)

4.3. Core Admin Integration

The application uses ra-core (React Admin Core) with custom providers:

ProviderImplementationPurpose
dataProviderCustom REST ProviderAPI Communication
authProviderAuthProvider classAuthentication Flow
i18nProviderCustom ImplementationInternationalization

5. Project Structure

apps/client/
├── src/
│   ├── application/              # DI Container & Providers
│   │   ├── decorators/           # Custom Decorators
│   │   ├── providers/            # Auth & Data Providers
│   │   └── services/             # API Services
│   │       ├── apis/             # Domain-specific API Clients (25 files)
│   │       └── networks/         # Network Configuration
│   ├── components/               # Reusable UI Components
│   │   └── core/                 # Core Components
│   │       ├── breadcrumb/       # Navigation Breadcrumbs
│   │       ├── common/           # Shared Components
│   │       ├── input/            # Form Input Components
│   │       ├── notification/     # Toast Notifications
│   │       ├── table/            # Data Table Components
│   │       │   ├── base/         # Base Table Implementation
│   │       │   ├── data/         # Data Table Variants
│   │       │   └── view/         # View Table Variants
│   │       └── title/            # Page Titles
│   ├── constants/                # Application Constants
│   │   ├── screens/              # Screen-specific Constants
│   │   └── sub-screens/          # Sub-screen Constants
│   ├── helpers/                  # Utility Functions
│   ├── hooks/                    # Custom React Hooks
│   │   ├── api/                  # API Hooks
│   │   ├── table/                # Table Hooks
│   │   └── view/                 # View Hooks
│   ├── interfaces/               # TypeScript Interfaces (35 files)
│   │   └── product/              # Product-related Interfaces
│   ├── layout/                   # Layout Components
│   │   └── main/                 # Main Layout
│   ├── libs/                     # External Library Configs
│   │   └── tanstack/             # TanStack Query Config
│   ├── redux/                    # Redux Store
│   │   └── slices/               # Redux Slices (5 slices)
│   ├── screens/                  # Screen Components (23 modules)
│   └── themes/                   # Theme Configuration
├── scripts/                      # Build Scripts
└── public/                       # Static Assets

6. Screens & Routing

6.1. Screen Modules

The application contains 23 screen modules, each following a consistent structure:

ModulePathOperationsDescription
home/DashboardMain dashboard with statistics
product/productList, Create, EditProduct management
category/categoryList, Create, EditCategory management
category-template/category-templateList, Create, EditCategory templates
organizer/organizerList, Create, EditOrganizer management
merchant/merchantList, Create, EditMerchant management
user/userList, Create, EditSystem user management
user-employee/employeeList, Create, EditEmployee management
customer/customerList, Create, EditCustomer management
role/roleList, Create, EditRole & permissions
device/deviceList, Create, EditPOS device management
terminal/terminalList, Create, EditPayment terminal management
sale-channel/sale-channelList, Create, EditSales channel configuration
order/orderList, ShowOrder viewing
transaction/transactionList, ShowTransaction history
invoice/invoiceListE-invoice management
report/report/*Revenue, OrderBusiness reports
settings/settings/*Profile, PasswordUser settings
sign-in/loginLoginAuthentication
sign-up/sign-upRegisterUser registration
errors/401, /403, /404Error PagesHTTP error pages

6.2. Screen Structure Pattern

Each screen module follows a consistent folder structure:

screens/{module}/
├── index.ts                    # Module exports
├── list/
│   └── index.tsx               # List view component
├── create/
│   └── index.tsx               # Create form component
├── edit/
│   └── index.tsx               # Edit form component
├── show/
│   └── index.tsx               # Detail view component (optional)
├── form/
│   └── index.ts                # Shared form configuration
├── common/
│   └── index.ts                # Shared utilities
└── actions/
    └── index.ts                # Screen-specific actions

7. API Services

7.1. Service Architecture

All API services extend BaseApiService which provides standard CRUD operations:

typescript
export class BaseApiService extends BaseService {
  protected resource: string;

  constructor(opts: { scope: string; resource: string }) {
    super({ scope: opts.scope });
    this.resource = opts.resource;
  }
}

7.2. Available API Services

ServiceResourceDescription
AuthApi/authAuthentication operations
OAuth2Api/oauth2OAuth2 integration
UserApi/usersUser management
UserConfigurationApi/user-configurationsUser preferences
EmployeeApi/employeesEmployee operations
OrganizerApi/organizersOrganizer management
MerchantApi/merchantsMerchant operations
MerchantTypeApi/merchant-typesMerchant type definitions
ProductApi/productsProduct catalog
ProductVariantApi/product-variantsProduct variants
VariantApi/variantsVariant definitions
CategoryApi/categoriesCategory management
SaleChannelApi/sale-channelsSales channels
DeviceApi/devicesPOS devices
RoleApi/rolesRole management
OrderApi/ordersOrder operations
TransactionApi/transactionsTransaction history
InvoiceApi/invoicesInvoice management
CustomerApi/customersCustomer data
ReportApi/reportsBusiness reports
BucketApi/bucketsFile storage
MetaLinkApi/meta-linksAsset metadata
StaticAssetsApi/static-assetsStatic file serving

8. State Management

8.1. Redux Store Configuration

The Redux store is configured with multiple reducers and middleware:

typescript
const appReducer = combineReducers({
  route: routeReducer,
  temporary: temporaryReducer,
  common: commonReducer,
  product: productReducer,
  listView: listViewReducer,
});

8.2. Redux Slices

SlicePurposeKey State
routeNavigation stateCurrent route, history
temporaryEphemeral dataForm drafts, unsaved changes
commonShared application stateUI flags, global settings
productProduct editing stateActive tab, merchant context
listViewTable view preferencesFilters, sorting, pagination

8.3. Server State with TanStack Query

Server state (API data) is managed separately using TanStack Query:

HookPurposeUsage
useGetDataFetch single resourceDetail pages
useInfiniteGetDataInfinite scrollingLong lists
useMutationDataCreate/Update/DeleteForm submissions
useRefreshCache invalidationAfter mutations
useVirtualAutocompleteVirtualized searchAutocomplete fields

9. TypeScript Interfaces

9.1. Core Interfaces

The application defines 35+ interface files for type safety:

Interface FilePurpose
common.interface.tsShared utility types
redux.interface.tsRedux action/state types
result.interface.tsAPI response types
table.interface.tsTable component types
sidebar.interface.tsNavigation types

9.2. Domain Interfaces

Interface FileDomain
product.interface.tsProduct management
product/addon.interface.tsProduct addons
product/combo.interface.tsProduct combos
product/quota.interface.tsProduct quotas
product/product-variant.interface.tsProduct variants
product/product-feature.interface.tsProduct features
category.interface.tsCategory management
category-template.interface.tsCategory templates
merchant.interface.tsMerchant data
merchant-type.interface.tsMerchant types
organizer.interface.tsOrganizer data
user.interface.tsUser management
role.interface.tsRole definitions
permission.interface.tsPermission types
order.interface.tsOrder data
invoice.interface.tsInvoice data
transaction.interface.tsTransaction records
customer.interface.tsCustomer data
device.interface.tsPOS devices
terminal.interface.tsPayment terminals
sale-channel.interface.tsSales channels
variant.interface.tsProduct variants
bucket.interface.tsFile storage
meta-link.interface.tsAsset metadata

10. Custom Hooks

10.1. API Hooks

Located in src/hooks/api/:

HookPurpose
useGetDataFetch data with caching
useInfiniteGetDataPaginated data fetching
useMutationDataData mutations
useRefreshQuery cache refresh
useVirtualAutocompleteVirtualized autocomplete
useVirtualAutocompleteArrayMulti-select autocomplete

10.2. Table Hooks

Located in src/hooks/table/:

HookPurpose
useDataTableControllerTable instance management
useDataTableStateTable state synchronization

10.3. View Hooks

Located in src/hooks/view/:

HookPurpose
useViewConfigView configuration
useViewStateView state management

10.4. Utility Hooks

HookFilePurpose
useDataProviderHeadersuseDataProviderHeaders.tsAPI header injection
useWarnUnsavedChangesuseWarnUnsavedChanges.tsUnsaved changes warning
useLogoutuseLogout.tsLogout handling

11. Authentication Flow

11.1. Auth Provider

The AuthProvider class extends DefaultAuthProvider and implements:

MethodPurpose
login()Handle sign-in with credentials
logout()Clear auth state and redirect
checkAuth()Verify token validity
checkError()Handle HTTP errors (401, 403)
getIdentity()Retrieve current user
getPermissions()Get user permissions
getRoles()Get user roles

11.2. Authentication State

1. User submits credentials
2. AuthProvider.login() calls REST API
3. On success: save token, userId, username
4. Redirect to dashboard
5. checkAuth() validates on each protected route
6. 401/403 errors trigger logout

12. Theme System

12.1. Theme Provider Stack

ThemeProvider (next-themes)
└── ActiveThemeProvider (Custom)
    └── Tailwind CSS v4 (Dark mode via class)

12.2. Theme Features

  • Dark/Light Mode: Toggle via next-themes
  • System Preference: Respects OS preference
  • Persistent: Stores preference in localStorage
  • CSS Variables: Tailwind CSS custom properties

13. Build & Deployment

13.1. Build Scripts

ScriptCommandPurpose
devvite --mode devDevelopment server
buildsh ./scripts/build.shProduction build
build:developsh ./scripts/rebuild.sh developmentDevelopment build
build:productionsh ./scripts/rebuild.sh productionProduction build
previewvite preview --port 4173Preview production build
lintsh ./scripts/lint.shRun ESLint

13.2. Docker Deployment

dockerfile
# Build Stage
FROM node:20-alpine AS builder
COPY . .
RUN bun install && bun run build

# Runtime Stage
FROM nginx:alpine
COPY --from=builder /app/dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/nginx.conf

13.3. Environment Configuration

Environment variables are loaded via Vite's env system:

VariablePurpose
VITE_NODE_ENVEnvironment mode
VITE_API_BASE_URLBackend API endpoint
VITE_AUTH_ENDPOINTAuthentication endpoint

14. Dependencies

14.1. Internal Dependencies

PackagePurpose
@nx-app/admin-ui-kitShared UI components
@nx-app/coreShared utilities & locales

14.2. External Infrastructure

PackagePurpose
@minimaltech/ra-core-infraReact Admin infrastructure
@venizia/ignis-inversionIoC Container
@loopback/filterQuery filter building

15. Code Statistics

MetricCount
Source Files~637
Screen Modules23
API Services25
TypeScript Interfaces35+
Redux Slices5
Custom Hooks15+
React Components100+

Proprietary and Confidential. Unauthorized copying, distribution, or use of this software is strictly prohibited.