How muhammadhyahya/retail_pos works
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: db.js Local database · saleHandlers.js IPC handlers · main.js Electron main · App.jsx React app
Components 20
Electron boundary
Privileged main process and constrained renderer bridge.
- Electron main · Owns privileged runtime startup.
src/main.js - Preload bridge · Exposes approved main-process capabilities.
src/preload.js
Persistence
Local schema bootstrap and migration chain.
- Local database
src/main/database/db.js - Migration registry · Applies ordered domain migrations.
src/main/database/migrations/index.js
Shop operations
Transaction, identity, and accountability services.
- IPC handlers · Registers auth, sale, and product operations.
src/main/ipc/saleHandlers.js - Authentication · Manages sessions and recovery security.
src/main/services/authenticationService.js - Permissions contract · Shared rules used by backend and UI.
src/shared/permissions.js - Sales service · Executes billing and sale operations.
src/main/services/saleService.js - Purchase service · Handles purchasing and stock-related flows.
src/main/services/purchaseService.js - Cash sessions · Supports day-close operations.
src/main/services/cashSessionService.js - Audit service · Records operational history.
src/main/services/auditService.js
React renderer
Workflow UI and local client state.
- IPC client
src/renderer/lib/ipc.js - React app · Composes authenticated application UI.
src/renderer/App.jsx - Auth store
src/renderer/store/authStore.js - Cart store
src/renderer/store/cartStore.js - Billing workflow
src/renderer/pages/Billing/BillingPage.jsx - Day close
src/renderer/pages/Cash/DayClosePage.jsx
Output & portability
Printing, backup, and data transfer capabilities.
- Printer service · Provides ESC/POS and raw-print support.
src/main/services/printerService.js - Backup subsystem · Schedules and verifies backup archives.
src/main/services/backup/index.js - Import/export · Exposed through Settings workflows.
src/main/services/importExport/index.js
Connections 28
- 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