# abdallahsaadelbasuoiny/cashier architecture

> Architecture diagram of the GitHub repository abdallahsaadelbasuoiny/cashier, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/abdallahsaadelbasuoiny/cashier
- Repository: https://github.com/abdallahsaadelbasuoiny/cashier

## Overview

This repository is an offline-first, multi-branch POS and business-management system. Cashiers create sales at a terminal, which can persist transactions locally and synchronize them to Laravel for idempotent checkout and inventory updates; administrators also manage products and business operations. The README documents offline checkout, device authorization, inventory integrity, and session reconciliation. Several frontend pages and sync components are represented from the tree and README rather than inspected source, so those links are documented or left unverified.

Main entry points: [`backend/app/Services/POS/CheckoutService.php`](https://github.com/abdallahsaadelbasuoiny/cashier/blob/main/backend/app/Services/POS/CheckoutService.php) (Checkout service), [`backend/app/Http/Controllers/Api/V1/SyncController.php`](https://github.com/abdallahsaadelbasuoiny/cashier/blob/main/backend/app/Http/Controllers/Api/V1/SyncController.php) (Sync API), [`frontend/src/pages/POSPage.tsx`](https://github.com/abdallahsaadelbasuoiny/cashier/blob/main/frontend/src/pages/POSPage.tsx) (POS screen), [`backend/resources/js/sync/sync-engine.js`](https://github.com/abdallahsaadelbasuoiny/cashier/blob/main/backend/resources/js/sync/sync-engine.js) (Sync engine)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_terminal["POS terminal"]
  node_pos_ui["POS screen<br/>[POSPage.tsx]"]
  node_pos_cart["Cart logic<br/>[cart.js]"]
end

subgraph group_sync["Offline synchronization"]
  node_offline_db[("Offline storage<br/>[db.js]")]
  node_sync_engine["Sync engine<br/>[sync-engine.js]"]
  node_service_worker["PWA worker<br/>[service-worker.js]"]
  node_sync_api["Sync API<br/>[SyncController.php]"]
  node_sync_push["Push processing"]
  node_sync_pull["Pull processing"]
end

subgraph group_sales["Sales and inventory"]
  node_sale_api["Sale endpoint<br/>[SaleController.php]"]
  node_checkout["Checkout service"]
  node_inventory_ledger["Inventory ledger"]
  node_sales_data[("Sales records<br/>[Sale.php]")]
  node_inventory_data[("Inventory records")]
  node_sessions_api["Session endpoint"]
  node_session_data[("Cashier sessions<br/>[CashierSession.php]")]
end

subgraph group_admin["Business management"]
  node_product_api["Product API"]
  node_product_data[("Product catalog<br/>[Product.php]")]
  node_admin_ui["Management screens<br/>[ProductsPage.tsx]"]
  node_other_admin["Business operations<br/>[CustomersPage.tsx]"]
end

subgraph group_security["Identity and devices"]
  node_auth_ui["Sign-in state<br/>[useAuth.tsx]"]
  node_auth_api["Authentication API<br/>[AuthController.php]"]
  node_device_api["Device management"]
  node_device_guard["Device authorization"]
end

node_cashier(("Cashier"))

node_cashier -->|"uses"| node_pos_ui
node_pos_ui -.->|"manages cart"| node_pos_cart
node_pos_ui -.->|"stores transactions"| node_offline_db
node_sync_engine -.->|"reads queued work"| node_offline_db
node_sync_engine -->|"pushes batches"| node_sync_api
node_service_worker -.->|"supports reconnect"| node_sync_engine
node_sync_api -->|"dispatches push"| node_sync_push
node_sync_api -->|"dispatches pull"| node_sync_pull
node_sync_push -->|"processes sales"| node_checkout
node_sale_api -->|"calls checkout"| node_checkout
node_checkout -->|"records movement"| node_inventory_ledger
node_checkout -->|"creates sale"| node_sales_data
node_inventory_ledger -->|"updates balance"| node_inventory_data
node_checkout -->|"checks session"| node_session_data
node_sessions_api -->|"opens and closes"| node_session_data
node_sessions_api -->|"reconciles sales"| node_sales_data
node_product_api -->|"manages products"| node_product_data
node_admin_ui -.->|"manages catalog"| node_product_api
node_other_admin -.->|"uses management API"| node_product_api
node_auth_ui -->|"authenticates"| node_auth_api
node_device_api -.->|"device security"| node_device_guard
node_sync_api -->|"is protected by"| node_device_guard

click node_pos_ui "https://github.com/abdallahsaadelbasuoiny/cashier/blob/main/frontend/src/pages/POSPage.tsx"
click node_pos_cart "https://github.com/abdallahsaadelbasuoiny/cashier/blob/main/backend/resources/js/pos/cart.js"
click node_offline_db "https://github.com/abdallahsaadelbasuoiny/cashier/blob/main/backend/resources/js/offline/db.js"
click node_sync_engine "https://github.com/abdallahsaadelbasuoiny/cashier/blob/main/backend/resources/js/sync/sync-engine.js"
click node_service_worker "https://github.com/abdallahsaadelbasuoiny/cashier/blob/main/backend/public/service-worker.js"
click node_sync_api "https://github.com/abdallahsaadelbasuoiny/cashier/blob/main/backend/app/Http/Controllers/Api/V1/SyncController.php"
click node_sync_push "https://github.com/abdallahsaadelbasuoiny/cashier/blob/main/backend/app/Services/Sync/SyncPushService.php"
click node_sync_pull "https://github.com/abdallahsaadelbasuoiny/cashier/blob/main/backend/app/Services/Sync/SyncPullService.php"
click node_sale_api "https://github.com/abdallahsaadelbasuoiny/cashier/blob/main/backend/app/Http/Controllers/Api/V1/SaleController.php"
click node_checkout "https://github.com/abdallahsaadelbasuoiny/cashier/blob/main/backend/app/Services/POS/CheckoutService.php"
click node_inventory_ledger "https://github.com/abdallahsaadelbasuoiny/cashier/blob/main/backend/app/Services/Inventory/InventoryLedgerService.php"
click node_sales_data "https://github.com/abdallahsaadelbasuoiny/cashier/blob/main/backend/app/Models/Sale.php"
click node_inventory_data "https://github.com/abdallahsaadelbasuoiny/cashier/blob/main/backend/app/Models/InventoryBalance.php"
click node_sessions_api "https://github.com/abdallahsaadelbasuoiny/cashier/blob/main/backend/app/Http/Controllers/Api/V1/CashierSessionController.php"
click node_session_data "https://github.com/abdallahsaadelbasuoiny/cashier/blob/main/backend/app/Models/CashierSession.php"
click node_product_api "https://github.com/abdallahsaadelbasuoiny/cashier/blob/main/backend/app/Http/Controllers/Api/V1/ProductController.php"
click node_product_data "https://github.com/abdallahsaadelbasuoiny/cashier/blob/main/backend/app/Models/Product.php"
click node_admin_ui "https://github.com/abdallahsaadelbasuoiny/cashier/blob/main/frontend/src/pages/ProductsPage.tsx"
click node_other_admin "https://github.com/abdallahsaadelbasuoiny/cashier/blob/main/frontend/src/pages/CustomersPage.tsx"
click node_auth_ui "https://github.com/abdallahsaadelbasuoiny/cashier/blob/main/frontend/src/hooks/useAuth.tsx"
click node_auth_api "https://github.com/abdallahsaadelbasuoiny/cashier/blob/main/backend/app/Http/Controllers/Api/V1/AuthController.php"
click node_device_api "https://github.com/abdallahsaadelbasuoiny/cashier/blob/main/backend/app/Http/Controllers/Api/V1/DeviceController.php"
click node_device_guard "https://github.com/abdallahsaadelbasuoiny/cashier/blob/main/backend/app/Http/Middleware/VerifyDeviceAuthorization.php"

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_pos_ui,node_pos_cart toneBlue
class node_offline_db,node_sync_engine,node_service_worker,node_sync_api,node_sync_push,node_sync_pull toneAmber
class node_sale_api,node_checkout,node_inventory_ledger,node_sales_data,node_inventory_data,node_sessions_api,node_session_data toneMint
class node_product_api,node_product_data,node_admin_ui,node_other_admin toneRose
class node_auth_ui,node_auth_api,node_device_api,node_device_guard,node_cashier toneIndigo
```

## Components

### POS terminal

- [POS screen](https://github.com/abdallahsaadelbasuoiny/cashier/blob/main/frontend/src/pages/POSPage.tsx): `frontend/src/pages/POSPage.tsx`
- [Cart logic](https://github.com/abdallahsaadelbasuoiny/cashier/blob/main/backend/resources/js/pos/cart.js): `backend/resources/js/pos/cart.js`

### Offline synchronization

- [Offline storage](https://github.com/abdallahsaadelbasuoiny/cashier/blob/main/backend/resources/js/offline/db.js): `backend/resources/js/offline/db.js`
- [Sync engine](https://github.com/abdallahsaadelbasuoiny/cashier/blob/main/backend/resources/js/sync/sync-engine.js): `backend/resources/js/sync/sync-engine.js`
- [PWA worker](https://github.com/abdallahsaadelbasuoiny/cashier/blob/main/backend/public/service-worker.js): `backend/public/service-worker.js`
- [Sync API](https://github.com/abdallahsaadelbasuoiny/cashier/blob/main/backend/app/Http/Controllers/Api/V1/SyncController.php): `backend/app/Http/Controllers/Api/V1/SyncController.php`
- [Push processing](https://github.com/abdallahsaadelbasuoiny/cashier/blob/main/backend/app/Services/Sync/SyncPushService.php): `backend/app/Services/Sync/SyncPushService.php`
- [Pull processing](https://github.com/abdallahsaadelbasuoiny/cashier/blob/main/backend/app/Services/Sync/SyncPullService.php): `backend/app/Services/Sync/SyncPullService.php`

### Sales and inventory

- [Sale endpoint](https://github.com/abdallahsaadelbasuoiny/cashier/blob/main/backend/app/Http/Controllers/Api/V1/SaleController.php): `backend/app/Http/Controllers/Api/V1/SaleController.php`
- [Checkout service](https://github.com/abdallahsaadelbasuoiny/cashier/blob/main/backend/app/Services/POS/CheckoutService.php): `backend/app/Services/POS/CheckoutService.php`
- [Inventory ledger](https://github.com/abdallahsaadelbasuoiny/cashier/blob/main/backend/app/Services/Inventory/InventoryLedgerService.php): `backend/app/Services/Inventory/InventoryLedgerService.php`
- [Sales records](https://github.com/abdallahsaadelbasuoiny/cashier/blob/main/backend/app/Models/Sale.php): `backend/app/Models/Sale.php`
- [Inventory records](https://github.com/abdallahsaadelbasuoiny/cashier/blob/main/backend/app/Models/InventoryBalance.php): `backend/app/Models/InventoryBalance.php`
- [Session endpoint](https://github.com/abdallahsaadelbasuoiny/cashier/blob/main/backend/app/Http/Controllers/Api/V1/CashierSessionController.php): `backend/app/Http/Controllers/Api/V1/CashierSessionController.php`
- [Cashier sessions](https://github.com/abdallahsaadelbasuoiny/cashier/blob/main/backend/app/Models/CashierSession.php): `backend/app/Models/CashierSession.php`

### Business management

- [Product API](https://github.com/abdallahsaadelbasuoiny/cashier/blob/main/backend/app/Http/Controllers/Api/V1/ProductController.php): `backend/app/Http/Controllers/Api/V1/ProductController.php`
- [Product catalog](https://github.com/abdallahsaadelbasuoiny/cashier/blob/main/backend/app/Models/Product.php): `backend/app/Models/Product.php`
- [Management screens](https://github.com/abdallahsaadelbasuoiny/cashier/blob/main/frontend/src/pages/ProductsPage.tsx): `frontend/src/pages/ProductsPage.tsx`
- [Business operations](https://github.com/abdallahsaadelbasuoiny/cashier/blob/main/frontend/src/pages/CustomersPage.tsx): `frontend/src/pages/CustomersPage.tsx`

### Identity and devices

- [Sign-in state](https://github.com/abdallahsaadelbasuoiny/cashier/blob/main/frontend/src/hooks/useAuth.tsx): `frontend/src/hooks/useAuth.tsx`
- [Authentication API](https://github.com/abdallahsaadelbasuoiny/cashier/blob/main/backend/app/Http/Controllers/Api/V1/AuthController.php): `backend/app/Http/Controllers/Api/V1/AuthController.php`
- [Device management](https://github.com/abdallahsaadelbasuoiny/cashier/blob/main/backend/app/Http/Controllers/Api/V1/DeviceController.php): `backend/app/Http/Controllers/Api/V1/DeviceController.php`
- [Device authorization](https://github.com/abdallahsaadelbasuoiny/cashier/blob/main/backend/app/Http/Middleware/VerifyDeviceAuthorization.php): `backend/app/Http/Middleware/VerifyDeviceAuthorization.php`

### Other components

- **Cashier**

## Connections

- Cashier → POS screen: uses (evidence: `README.md`)
- POS screen → Cart logic: manages cart (evidence: `README.md`)
- POS screen → Offline storage: stores transactions (evidence: `README.md`)
- Sync engine → Offline storage: reads queued work (evidence: `README.md`)
- Sync engine → Sync API: pushes batches (evidence: `README.md`)
- PWA worker → Sync engine: supports reconnect
- Sync API → Push processing: dispatches push (evidence: `backend/app/Http/Controllers/Api/V1/SyncController.php`)
- Sync API → Pull processing: dispatches pull (evidence: `backend/app/Http/Controllers/Api/V1/SyncController.php`)
- Push processing → Checkout service: processes sales (evidence: `backend/app/Services/Sync/SyncPushService.php`)
- Sale endpoint → Checkout service: calls checkout (evidence: `backend/app/Http/Controllers/Api/V1/SaleController.php`)
- Checkout service → Inventory ledger: records movement (evidence: `backend/app/Services/POS/CheckoutService.php`)
- Checkout service → Sales records: creates sale (evidence: `backend/app/Services/POS/CheckoutService.php`)
- Inventory ledger → Inventory records: updates balance (evidence: `backend/app/Services/Inventory/InventoryLedgerService.php`)
- Checkout service → Cashier sessions: checks session (evidence: `backend/app/Services/POS/CheckoutService.php`)
- Session endpoint → Cashier sessions: opens and closes (evidence: `backend/app/Http/Controllers/Api/V1/CashierSessionController.php`)
- Session endpoint → Sales records: reconciles sales (evidence: `backend/app/Http/Controllers/Api/V1/CashierSessionController.php`)
- Product API → Product catalog: manages products (evidence: `backend/app/Http/Controllers/Api/V1/ProductController.php`)
- Management screens → Product API: manages catalog
- Business operations → Product API: uses management API
- Sign-in state → Authentication API: authenticates (evidence: `frontend/src/hooks/useAuth.tsx`)
- Device management → Device authorization: device security (evidence: `backend/routes/api.php`)
- Sync API → Device authorization: is protected by (evidence: `backend/routes/api.php`)
