# muhammadhyahya/retail_pos architecture

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

- Interactive diagram: https://gitdiagram.com/muhammadhyahya/retail_pos
- Repository: https://github.com/muhammadhyahya/retail_pos

## Overview

#### Purpose and Runtime
Desktop point-of-sale and shop-operations application: billing, inventory/products, purchases, returns, expenses, cash-day closure, reports, labels/receipts, administration, and audit history. It is an Electron Forge application with a Vite/React renderer.
- Electron main entry: `src/main.js`
- Renderer entry and root UI: `src/renderer/main.jsx`, `src/renderer/App.jsx`
- Packaging/runtime setup: `forge.config.js`

#### Process Boundary and Entry Flow
Electron’s main process owns privileged operations, database access, printing, filesystem-oriented backup/import-export, and authentication services. The React renderer presents pages and invokes approved capabilities through preload/IPC rather than directly accessing main-process resources.
- Preload boundary: `src/preload.js`
- Renderer IPC client: `src/renderer/lib/ipc.js`
- IPC registration surface: `src/main/ipc/authHandlers.js`, `src/main/ipc/saleHandlers.js`, `src/main/ipc/productHandlers.js`

#### Persistence and Schema Evolution
A local database is initialized and upgraded through ordered JavaScript migrations. The schema has evolved from bootstrap/user/session data into products, sales, discounts, backups, shop-loop policies, import/export, permissions, labels, and audit reliability.
- Database bootstrap/access: `src/main/database/db.js`
- Migration registry: `src/main/database/migrations/index.js`
- Representative domain migrations: `src/main/database/migrations/008_products.js`, `src/main/database/migrations/009_sales.js`, `src/main/database/migrations/020_audit_reliability.js`

#### Core Shop Transaction Domains
Main-process services implement the operational business layer behind IPC: product catalog and stock-related operations, purchases, sales, returns, expenses, and cash sessions. The renderer exposes corresponding workflow pages, with billing and day-close being key transaction endpoints.
- Services: `src/main/services/saleService.js`, `src/main/services/purchaseService.js`, `src/main/services/cashSessionService.js`
- Transaction IPC: `src/main/ipc/saleHandlers.js`, `src/main/ipc/returnHandlers.js`, `src/main/ipc/cashSessionHandlers.js`
- Principal UI workflows: `src/renderer/pages/Billing/BillingPage.jsx`, `src/renderer/pages/Cash/DayClosePage.jsx`, `src/renderer/pages/Returns/ReturnsPage.jsx`

#### Identity, Authorization, and Audit
Authentication, session handling, recovery/security questions, and permissions are main-process concerns; shared permission definitions allow consistent UI and backend decisions. Audit handlers/services provide a separate accountability path for operational events.
- Authentication/security: `src/main/services/authenticationService.js`, `src/main/lib/sessionAuth.js`, `src/main/lib/securityQuestions.js`
- Authorization contract: `src/shared/permissions.js`, `src/main/lib/permissions.js`
- Audit path: `src/main/services/auditService.js`, `src/main/ipc/auditHandlers.js`, `src/renderer/pages/Audit/AuditPage.jsx`

#### Renderer Composition and State
The React UI is organized around authentication/layout shells and role-oriented operational pages. Local renderer stores hold authentication, cart, and theme state; billing consumes cart state while server-backed actions cross IPC.
- Layout/root: `src/renderer/App.jsx`, `src/renderer/components/layout/AppShell.jsx`
- State: `src/renderer/store/authStore.js`, `src/renderer/store/cartStore.js`
- Administration/catalog surfaces: `src/renderer/pages/Dashboard/AdminDashboard.jsx`, `src/renderer/pages/Dashboard/products/ProductCatalogView.jsx`

#### Output, Data Portability, and Operational Resilience
Printing is delegated to main-process printer infrastructure, including ESC/POS and Windows raw-print support. Backup scheduling/archive verification and import/export are dedicated subsystems, exposed in Settings. Reports and labels are separate user-facing outputs.
- Printing: `src/main/services/printerService.js`, `src/main/lib/escposPort.js`, `src/main/lib/windowsRawPrint.js`
- Backup subsystem: `src/main/services/backup/index.js`, `src/main/services/backup/archiveVerifier.js`
- Import/export subsystem and UI: `src/main/services/importExport/index.js`, `src/renderer/pages/Settings/ImportExportPanel.jsx`

Main entry points: [`src/main/database/db.js`](https://github.com/muhammadhyahya/retail_pos/blob/master/src/main/database/db.js) (Local database), [`src/main/ipc/saleHandlers.js`](https://github.com/muhammadhyahya/retail_pos/blob/master/src/main/ipc/saleHandlers.js) (IPC handlers), [`src/main.js`](https://github.com/muhammadhyahya/retail_pos/blob/master/src/main.js) (Electron main), [`src/renderer/App.jsx`](https://github.com/muhammadhyahya/retail_pos/blob/master/src/renderer/App.jsx) (React app)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_electron["Electron boundary"]
  node_main{{"Electron main<br/>process entry<br/>[main.js]"}}
  node_preload["Preload bridge<br/>security boundary<br/>[preload.js]"]
end

subgraph group_data["Persistence"]
  node_database[("Local database<br/>embedded database<br/>[db.js]")]
  node_migrations["Migration registry<br/>schema evolution<br/>[index.js]"]
end

subgraph group_operations["Shop operations"]
  node_ipc_handlers["IPC handlers<br/>capability surface<br/>[saleHandlers.js]"]
  node_auth["Authentication<br/>identity service"]
  node_permissions["Permissions contract<br/>authorization<br/>[permissions.js]"]
  node_sales["Sales service<br/>transaction service<br/>[saleService.js]"]
  node_purchases["Purchase service<br/>inventory service<br/>[purchaseService.js]"]
  node_cash_sessions["Cash sessions<br/>cash service"]
  node_audit["Audit service<br/>accountability service<br/>[auditService.js]"]
end

subgraph group_renderer["React renderer"]
  node_ipc_client["IPC client<br/>renderer IPC<br/>[ipc.js]"]
  node_app["React app<br/>renderer root<br/>[App.jsx]"]
  node_auth_store["Auth store<br/>client state<br/>[authStore.js]"]
  node_cart_store["Cart store<br/>client state<br/>[cartStore.js]"]
  node_billing["Billing workflow<br/>transaction page<br/>[BillingPage.jsx]"]
  node_day_close["Day close<br/>cash workflow<br/>[DayClosePage.jsx]"]
end

subgraph group_resilience["Output &amp; portability"]
  node_printing["Printer service<br/>output service<br/>[printerService.js]"]
  node_backup["Backup subsystem<br/>resilience service<br/>[index.js]"]
  node_import_export["Import/export<br/>portability service<br/>[index.js]"]
end

node_main -->|"loads"| node_preload
node_main -->|"initializes"| node_database
node_database -->|"upgrades via"| node_migrations
node_main -->|"registers"| node_ipc_handlers
node_ipc_client -->|"invokes exposed API"| node_preload
node_preload -->|"bridges IPC"| node_ipc_handlers
node_ipc_handlers -->|"auth requests"| node_auth
node_ipc_handlers -->|"sale requests"| node_sales
node_ipc_handlers -->|"purchase requests"| node_purchases
node_ipc_handlers -->|"cash requests"| node_cash_sessions
node_ipc_handlers -->|"audit requests"| node_audit
node_auth -->|"authorizes with"| node_permissions
node_auth -->|"reads sessions"| node_database
node_sales -->|"persists sales"| node_database
node_purchases -->|"persists purchases"| node_database
node_cash_sessions -->|"persists closures"| node_database
node_audit -->|"records events"| node_database
node_app -->|"uses"| node_auth_store
node_app -->|"routes to"| node_billing
node_app -->|"routes to"| node_day_close
node_billing -->|"uses cart"| node_cart_store
node_billing -->|"submits sale"| node_ipc_client
node_day_close -->|"closes cash session"| node_ipc_client
node_sales -->|"prints receipts"| node_printing
node_main -->|"hosts"| node_backup
node_main -->|"hosts"| node_import_export
node_backup -.->|"archives"| node_database
node_import_export -.->|"transfers data"| node_database

click node_main "https://github.com/muhammadhyahya/retail_pos/blob/master/src/main.js"
click node_preload "https://github.com/muhammadhyahya/retail_pos/blob/master/src/preload.js"
click node_ipc_client "https://github.com/muhammadhyahya/retail_pos/blob/master/src/renderer/lib/ipc.js"
click node_ipc_handlers "https://github.com/muhammadhyahya/retail_pos/blob/master/src/main/ipc/saleHandlers.js"
click node_database "https://github.com/muhammadhyahya/retail_pos/blob/master/src/main/database/db.js"
click node_migrations "https://github.com/muhammadhyahya/retail_pos/blob/master/src/main/database/migrations/index.js"
click node_auth "https://github.com/muhammadhyahya/retail_pos/blob/master/src/main/services/authenticationService.js"
click node_permissions "https://github.com/muhammadhyahya/retail_pos/blob/master/src/shared/permissions.js"
click node_sales "https://github.com/muhammadhyahya/retail_pos/blob/master/src/main/services/saleService.js"
click node_purchases "https://github.com/muhammadhyahya/retail_pos/blob/master/src/main/services/purchaseService.js"
click node_cash_sessions "https://github.com/muhammadhyahya/retail_pos/blob/master/src/main/services/cashSessionService.js"
click node_audit "https://github.com/muhammadhyahya/retail_pos/blob/master/src/main/services/auditService.js"
click node_app "https://github.com/muhammadhyahya/retail_pos/blob/master/src/renderer/App.jsx"
click node_auth_store "https://github.com/muhammadhyahya/retail_pos/blob/master/src/renderer/store/authStore.js"
click node_cart_store "https://github.com/muhammadhyahya/retail_pos/blob/master/src/renderer/store/cartStore.js"
click node_billing "https://github.com/muhammadhyahya/retail_pos/blob/master/src/renderer/pages/Billing/BillingPage.jsx"
click node_day_close "https://github.com/muhammadhyahya/retail_pos/blob/master/src/renderer/pages/Cash/DayClosePage.jsx"
click node_printing "https://github.com/muhammadhyahya/retail_pos/blob/master/src/main/services/printerService.js"
click node_backup "https://github.com/muhammadhyahya/retail_pos/blob/master/src/main/services/backup/index.js"
click node_import_export "https://github.com/muhammadhyahya/retail_pos/blob/master/src/main/services/importExport/index.js"

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_main,node_preload toneBlue
class node_database,node_migrations toneAmber
class node_ipc_handlers,node_auth,node_permissions,node_sales,node_purchases,node_cash_sessions,node_audit toneMint
class node_ipc_client,node_app,node_auth_store,node_cart_store,node_billing,node_day_close toneRose
class node_printing,node_backup,node_import_export toneIndigo
```

## Components

### Electron boundary

Privileged main process and constrained renderer bridge.

- [Electron main](https://github.com/muhammadhyahya/retail_pos/blob/master/src/main.js): process entry · Owns privileged runtime startup. · `src/main.js`
- [Preload bridge](https://github.com/muhammadhyahya/retail_pos/blob/master/src/preload.js): security boundary · Exposes approved main-process capabilities. · `src/preload.js`

### Persistence

Local schema bootstrap and migration chain.

- [Local database](https://github.com/muhammadhyahya/retail_pos/blob/master/src/main/database/db.js): embedded database · `src/main/database/db.js`
- [Migration registry](https://github.com/muhammadhyahya/retail_pos/blob/master/src/main/database/migrations/index.js): schema evolution · Applies ordered domain migrations. · `src/main/database/migrations/index.js`

### Shop operations

Transaction, identity, and accountability services.

- [IPC handlers](https://github.com/muhammadhyahya/retail_pos/blob/master/src/main/ipc/saleHandlers.js): capability surface · Registers auth, sale, and product operations. · `src/main/ipc/saleHandlers.js`
- [Authentication](https://github.com/muhammadhyahya/retail_pos/blob/master/src/main/services/authenticationService.js): identity service · Manages sessions and recovery security. · `src/main/services/authenticationService.js`
- [Permissions contract](https://github.com/muhammadhyahya/retail_pos/blob/master/src/shared/permissions.js): authorization · Shared rules used by backend and UI. · `src/shared/permissions.js`
- [Sales service](https://github.com/muhammadhyahya/retail_pos/blob/master/src/main/services/saleService.js): transaction service · Executes billing and sale operations. · `src/main/services/saleService.js`
- [Purchase service](https://github.com/muhammadhyahya/retail_pos/blob/master/src/main/services/purchaseService.js): inventory service · Handles purchasing and stock-related flows. · `src/main/services/purchaseService.js`
- [Cash sessions](https://github.com/muhammadhyahya/retail_pos/blob/master/src/main/services/cashSessionService.js): cash service · Supports day-close operations. · `src/main/services/cashSessionService.js`
- [Audit service](https://github.com/muhammadhyahya/retail_pos/blob/master/src/main/services/auditService.js): accountability service · Records operational history. · `src/main/services/auditService.js`

### React renderer

Workflow UI and local client state.

- [IPC client](https://github.com/muhammadhyahya/retail_pos/blob/master/src/renderer/lib/ipc.js): renderer IPC · `src/renderer/lib/ipc.js`
- [React app](https://github.com/muhammadhyahya/retail_pos/blob/master/src/renderer/App.jsx): renderer root · Composes authenticated application UI. · `src/renderer/App.jsx`
- [Auth store](https://github.com/muhammadhyahya/retail_pos/blob/master/src/renderer/store/authStore.js): client state · `src/renderer/store/authStore.js`
- [Cart store](https://github.com/muhammadhyahya/retail_pos/blob/master/src/renderer/store/cartStore.js): client state · `src/renderer/store/cartStore.js`
- [Billing workflow](https://github.com/muhammadhyahya/retail_pos/blob/master/src/renderer/pages/Billing/BillingPage.jsx): transaction page · `src/renderer/pages/Billing/BillingPage.jsx`
- [Day close](https://github.com/muhammadhyahya/retail_pos/blob/master/src/renderer/pages/Cash/DayClosePage.jsx): cash workflow · `src/renderer/pages/Cash/DayClosePage.jsx`

### Output & portability

Printing, backup, and data transfer capabilities.

- [Printer service](https://github.com/muhammadhyahya/retail_pos/blob/master/src/main/services/printerService.js): output service · Provides ESC/POS and raw-print support. · `src/main/services/printerService.js`
- [Backup subsystem](https://github.com/muhammadhyahya/retail_pos/blob/master/src/main/services/backup/index.js): resilience service · Schedules and verifies backup archives. · `src/main/services/backup/index.js`
- [Import/export](https://github.com/muhammadhyahya/retail_pos/blob/master/src/main/services/importExport/index.js): portability service · Exposed through Settings workflows. · `src/main/services/importExport/index.js`

## Connections

- Electron main → Preload bridge: loads
- Electron main → Local database: initializes
- Local database → Migration registry: upgrades via
- Electron main → IPC handlers: registers
- IPC client → Preload bridge: invokes exposed API
- Preload bridge → IPC handlers: bridges IPC
- IPC handlers → Authentication: auth requests
- IPC handlers → Sales service: sale requests
- IPC handlers → Purchase service: purchase requests
- IPC handlers → Cash sessions: cash requests
- IPC handlers → Audit service: audit requests
- Authentication → Permissions contract: authorizes with
- Authentication → Local database: reads sessions
- Sales service → Local database: persists sales
- Purchase service → Local database: persists purchases
- Cash sessions → Local database: persists closures
- Audit service → Local database: records events
- React app → Auth store: uses
- React app → Billing workflow: routes to
- React app → Day close: routes to
- Billing workflow → Cart store: uses cart
- Billing workflow → IPC client: submits sale
- Day close → IPC client: closes cash session
- Sales service → Printer service: prints receipts
- Electron main → Backup subsystem: hosts
- Electron main → Import/export: hosts
- Backup subsystem → Local database: archives
- Import/export → Local database: transfers data
