Skip to content

POS UI (Renderer)

1. Document Control

PropertyValue
Package@nx-app/sale-renderer
Version0.0.0
TypeWeb Application (SPA)
RuntimeTauri WebView / Browser
FrameworkReact 19 + Vite 7

2. Scope & Objectives

2.1. Scope

The POS UI is the visual and interactive layer of the Point-of-Sale system. It runs inside the WebView provided by the Tauri host process (sale-main) and handles all user interactions, business flows, and visual feedback.

2.2. Objectives

  • Touch Optimization: UI elements sized for touch interaction (minimum 44px target).
  • Speed: Instant feedback for cart operations.
  • Clarity: High-contrast design for various lighting conditions.
  • Offline Support: Functional core features without network.
  • Real-time Updates: WebSocket integration for order status.

3. Technology Stack

3.1. Core Framework

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

3.2. State Management

TechnologyVersionPurpose
Redux Toolkit^2.11.2Global State Management
React Redux^9.2.0React-Redux Bindings
TanStack Query^5.90.12Server State & Caching
ra-core^5.13.4Admin Framework Core

3.3. UI Components

TechnologyVersionPurpose
Radix UIVariousAccessible Primitives
Tailwind CSS^4.1.18Utility-first Styling
Lucide React^0.562.0Icon Library
shadcn^3.6.2Component Templates
cmdk^1.1.1Command Palette
vaul^1.1.2Drawer Component
sonner^2.0.7Toast Notifications

3.4. Tauri Integration

TechnologyVersionPurpose
@tauri-apps/api^2.9.1IPC Communication
@tauri-apps/plugin-os^2.3.2OS Information
@skipperndt/plugin-machine-uid^0.1.3Device Identification

3.5. Forms & Validation

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

3.6. Data Visualization

TechnologyVersionPurpose
Recharts2.15.4Charts & Graphs
react-qr-code^2.0.18QR Code Generation
react-day-picker^9.13.0Date Selection

3.7. Real-time Communication

TechnologyVersionPurpose
socket.io-client^4.8.3WebSocket Communication
RxJS^7.8.2Reactive Streams

3.8. Layout & Interaction

TechnologyVersionPurpose
react-grid-layout^2.2.2Dashboard Layouts
react-resizable^3.1.3Resizable Panels
react-virtuoso^4.17.0Virtualized Lists
@tanstack/react-virtual^3.13.13Virtual Scrolling

3.9. Build & Development

TechnologyVersionPurpose
Vite^7.2.4Build Tool
@vitejs/plugin-react^5.1.1React Integration
lightningcss^1.30.2CSS Processing
ESLint^9.39.1Code Linting
Prettier3.6.2Code Formatting

4. Architecture

4.1. Application Layers

User Touch
React UI
IPC Service
Tauri Backend

4.2. IPC Communication

The renderer communicates with the Tauri backend via a custom IPC service:

typescript
export class IpcRendererService {
  async invoke<TPayload, TResponse>(opts: {
    command: string;
    payload: TPayload;
  }): Promise<TResponse> {
    const res = await invoke(command, { payload });
    return { data: res } as TResponse;
  }
}

4.3. Data Provider Pattern

Uses a custom TauriIpcDataProvider that extends the REST provider pattern:

typescript
export class TauriIpcDataProvider extends DefaultRestDataProvider {
  override send<TResponse>(opts: {
    resource: string;
    params: ISendParams;
  }): Promise<ISendResponse<TResponse>> {
    return ipcService.invoke({
      command: resource,
      payload: params,
    });
  }
}

5. Project Structure

apps/sale-renderer/
├── src/
│   ├── application/                # DI Container & Providers
│   │   ├── decorators/             # Custom Decorators
│   │   ├── providers/              # Auth & IPC Providers
│   │   │   ├── auth.provider.ts    # Authentication provider
│   │   │   └── ipc-data.provider.ts # Tauri IPC data provider
│   │   └── services/               # API Services
│   │       ├── apis/               # Domain API Clients (15 files)
│   │       ├── environment.service.ts
│   │       └── ipc.service.ts      # Tauri IPC wrapper
│   ├── components/                 # Reusable UI Components
│   │   └── ui/                     # shadcn/ui components
│   ├── constants/                  # Application Constants
│   ├── helpers/                    # Utility Functions
│   ├── hooks/                      # Custom React Hooks
│   ├── interfaces/                 # TypeScript Interfaces
│   ├── layout/                     # Layout Components
│   ├── libs/                       # External Library Configs
│   ├── redux/                      # Redux Store
│   │   └── slices/                 # Redux Slices (8 slices)
│   ├── screens/                    # Screen Components (8 modules)
│   └── socket/                     # WebSocket Integration
│       ├── client/                 # Socket client
│       └── server/                 # Socket server handlers
├── scripts/                        # Build Scripts
└── public/                         # Static Assets

6. Screens & Routing

6.1. Screen Modules

ModulePathDescription
home/Dashboard with widgets and stats
sale/saleMain POS interface with cart
customer/customerCustomer management
settings/settingsApplication settings
sign-in/sign-inAuthentication
errors/401, /403, /404Error pages

6.2. Sale Screen Components

The sale screen is the primary interface with complex sub-components:

screens/sale/
├── index.tsx                       # Main sale screen
├── fnb/                            # Food & Beverage catalog
│   ├── category/                   # Category navigation
│   └── product-variant/            # Product variant selection
├── cart/                           # Shopping cart
│   ├── items/                      # Cart item list
│   │   ├── header/                 # Cart header
│   │   └── item/                   # Individual item
│   ├── detail/                     # Cart detail view
│   └── summary/                    # Cart summary
│       ├── details/                # Price breakdown
│       └── actions/                # Cart actions
│           ├── order-checkout/     # Checkout button
│           └── payment-dialog/     # Payment modal
│               ├── order-detail/   # Order summary
│               └── stepper/        # Payment stepper
│                   ├── methods/    # Payment methods
│                   └── actions/    # Step actions
└── manual-form/                    # Manual entry form

7. State Management

7.1. Redux Store Configuration

typescript
const appReducer = combineReducers({
  temporary: temporaryReducer,
  common: commonReducer,
  userProfile: userProfileReducer,
  order: orderReducer,
  sale: saleReducer,
  cart: cartReducer,
  product: productReducer,
  payment: paymentReducer,
});

7.2. Redux Slices

SlicePurposeKey State
cartShopping cart managementItems, totals, tax, payment method
orderOrder processingCurrent order, order history
paymentPayment statePayment method, status, attempt
productProduct catalog stateActive product, selection
saleSale session stateActive session, mode
userProfileUser informationProfile, preferences
commonShared UI stateFlags, settings
temporaryEphemeral dataForm drafts

7.3. Cart State Structure

typescript
interface ICartState {
  cartList: [];
  cartItems: { [id: string]: ICartItem };
  productVariantToCartItemsMap: { [variantId: string]: string };

  // Price calculations
  totalPrice: number;
  totalPurchaseVoucherPrice: number;
  totalDiscountVoucherPrice: number;
  totalTaxPrice: number;
  totalPaymentPrice: number;

  taxPercentage: string;
  paymentMethod: PaymentMethod;
}

7.4. Cart Actions

ActionDescription
resetCartReset to initial state
resetCartAfterPaymentClear cart after successful payment
loadCartItemsLoad items from backend
addCartItemAdd item to cart
removeCartItemRemove item from cart
updateQuantityCartItemUpdate item quantity
updateTaxPercentageSet tax rate

8. API Services

8.1. IPC API Services

All API services communicate via Tauri IPC:

ServiceCommandsDescription
AuthApisign_in, sign_out, who_am_iAuthentication
UserApiget_user_profileUser profile
CategoryApiCRUD operationsCategories
ProductApiCRUD operationsProducts
ProductVariantApiCRUD operationsVariants
MerchantApiCRUD operationsMerchants
OrganizerApiCRUD operationsOrganizers
SaleChannelApiCRUD operationsSales channels
CartApicart_items, add_item, clearCart management
CartItemApiupdate_quantityItem operations
OrderApicheckout, revert_checkoutOrder processing
PaymentApicheckout, cancel, system_ipnPayments
PaymentAttemptApifind_by_idPayment attempts
AssetApii18n_file, vnpay_qr_frameAssets

9. WebSocket Integration

9.1. Socket Architecture

socket/
├── client/                         # Client-side socket
│   ├── index.ts                    # Socket client exports
│   ├── socket-connection-manager.ts # Connection management
│   └── socket-subscription-manager.ts # Subscription handling
├── server/                         # Server message handlers
│   ├── base/                       # Base socket classes
│   │   ├── base-socket.ts          # Base socket class
│   │   └── base-socket-subscription-manager.ts
│   ├── messages/                   # Message handlers
│   │   └── market-data-socket-message-handler.ts
│   └── order-socket.service.ts     # Order socket service
├── constants.ts                    # Socket constants
├── helper.ts                       # Socket utilities
├── types.ts                        # Socket types
└── index.ts                        # Main exports

9.2. Socket Features

  • Order Status Updates: Real-time order state changes
  • Market Data: Live pricing updates
  • Connection Management: Auto-reconnect on disconnect
  • Subscription System: Subscribe/unsubscribe to channels

10. Radix UI Components

10.1. Installed Primitives

ComponentVersionUsage
Accordion^1.2.12Collapsible sections
Alert Dialog^1.1.15Confirmation modals
Avatar^1.1.11User avatars
Checkbox^1.3.3Form checkboxes
Collapsible^1.1.12Expandable panels
Context Menu^2.2.16Right-click menus
Dialog^1.1.15Modal dialogs
Dropdown Menu^2.1.16Dropdown menus
Label^2.1.8Form labels
Popover^1.1.15Floating panels
Radio Group^1.3.8Radio selections
Scroll Area^1.2.10Custom scrollbars
Select^2.2.6Dropdown selects
Separator^1.1.8Visual dividers
Slot^1.2.4Component slots
Switch^1.2.6Toggle switches
Tabs^1.1.13Tab navigation
Tooltip^1.2.8Hover tooltips

11. The Cart System

11.1. Cart Features

  • Item Aggregation: Group identical items by variant
  • Quantity Management: Increment/decrement with validation
  • Price Calculations: Real-time subtotal, tax, discounts
  • Payment Methods: Cash, QR, Card support
  • Tax Handling: Configurable tax percentage

11.2. Price Calculation Logic

typescript
// Calculate totals
totalPrice = items.reduce((sum, item) =>
  sum + item.unitPrice * item.quantity, 0);

// Apply discounts and tax
const taxableAmount = Math.max(0, totalPrice - discount);
totalTaxPrice = Math.round(taxableAmount * (taxRate / 100));

totalPaymentPrice = totalPrice
  - totalDiscountVoucherPrice
  - totalPurchaseVoucherPrice
  + totalTaxPrice;

12. Checkout Flow

12.1. Flow Diagram

Cart Review
Customer Link
Payment Select
Process Payment

12.2. Checkout Steps

  1. Cart Review: Final verification of items
  2. Customer Association: Optional customer linking
  3. Payment Selection: Choose Cash, QR, or Card
  4. Transaction Execution: Process via Tauri IPC
  5. Receipt Generation: Format for printer
  6. Order Completion: Clear cart and update state

13. Integration Points

13.1. Upstream (Tauri Backend)

  • IPC Commands: Invoke Rust functions via @tauri-apps/api
  • Events: Listen for init_ready, init_error, migration_error
  • Window API: Manage windows, external display

13.2. Lateral (Shared Packages)

  • @nx-app/core: Shared utilities and locales
  • @minimaltech/ra-core-infra: Base service infrastructure
  • @venizia/ignis-inversion: IoC container

13.3. Downstream (Backend API)

  • WebSocket: Real-time order updates
  • Telemetry: Error logging and analytics

14. Build & Scripts

14.1. Available Scripts

ScriptCommandPurpose
devvite --mode devDevelopment server
buildsh ./scripts/build.shProduction build
build:developsh ./scripts/rebuild.sh developmentDev build
build:productionsh ./scripts/rebuild.sh productionProd build
previewvite previewPreview build
lintsh ./scripts/lint.shESLint check
prettierprettier '**/*.{js,ts,jsx,tsx}' --writeFormat code

14.2. Build Output

The build is consumed by the Tauri host process:

  • Output directory: dist/
  • Served by Tauri's localhost plugin
  • Embedded in desktop/mobile app

15. Code Statistics

MetricCount
Source Files~337
Screen Modules8
Redux Slices8
API Services15
Radix Components18
Socket Handlers5+
Custom Hooks10+

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