How mohammedbetkaoui/khayati-manager works
Purpose and Runtime Topology
This is a workshop/business-management desktop application covering sales, customers, inventory/production, suppliers, workers/payroll, expenses, invoices, analytics, reports, and settings. It combines a React frontend, NestJS backend, and Electron desktop host.
Entry points:
• Electron process and backend lifecycle: electron/main.js, electron/backend-runtime.js, electron/preload.js
• Backend HTTP application: backend/src/main.ts, backend/src/app.module.ts
• Frontend SPA bootstrap: frontend/src/main.tsx, frontend/src/app/App.tsx
Desktop Host and Process Boundary
Electron owns the native desktop window, splash/launcher behavior, update handling, and starting/stopping the bundled backend runtime. The preload layer is the security boundary for renderer-to-native APIs; the frontend should not directly depend on Node/Electron internals.
Key paths:
• electron/main.js
• electron/preload.js
• electron/updater.js
Control flow is Electron main process → local backend runtime → React renderer, with environment-specific frontend configuration in frontend/.env.development and frontend/.env.production.
Backend API and Domain Composition
The backend is a modular NestJS application. Controllers expose domain APIs, services implement workflows, DTOs define request/query boundaries, and entity directories model persisted business records. AppModule is the composition root.
Key paths:
• backend/src/app.module.ts
• backend/src/analytics/analytics.controller.ts
• backend/src/common/enums/index.ts
Shared enums and money handling establish cross-domain status/category/value conventions. API clients should submit DTO-shaped data and treat service-owned state transitions—such as cancellations, payments, and stock adjustments—as backend authority.
Sales, Orders, and Invoicing Flow
Customer and sales records support measurements, notes, sales invoices, line items, and payments. A separate orders domain supplies order/order-item records. The invoicing domain adds document sequencing, calculation, draft updates, cancellation, payment recording, invoice creation from orders, and PDF output.
Key paths:
• backend/src/sales/sales.service.ts
• backend/src/orders/entities/order.entity.ts
• backend/src/invoices/invoices.service.ts
• backend/src/invoices/invoice-pdf.service.ts
Typical flow: customer/order inputs → invoice creation and line calculation → persistent document number/payment state → optional PDF generation. Invoice-specific database preparation utilities indicate that invoice and invoice-payment persistence need normalization before calculations or output.
Inventory, Supply, and Production Flow
Inventory is the operational core for materials and finished goods. It models inventory items, suppliers, purchases, supplier advances/payments, stock movements, product variants, production batches, production materials, and material consumption. Finished products are handled through a dedicated service alongside general inventory workflows.
Key paths:
• backend/src/inventory/inventory.service.ts
• backend/src/inventory/finished-products.service.ts
• backend/src/inventory/entities/production-batch.entity.ts
Primary control flow: supplier purchase or stock adjustment changes inventory → production batch consumes materials → finished-product/product stock movements record output. Stock changes and production consumption should be treated as auditable domain operations, not independent frontend mutations.
Workforce, Payroll, Expenses, and Configuration
Workers have roles, attendance, and production records; payroll combines salary payments with advances, loans, and repayment/deduction records. Expenses are an independent financial ledger domain. Settings centralize workshop settings, piece prices, and production stages, making them upstream reference data for operations and compensation.
Key paths:
• backend/src/workers/workers.service.ts
• backend/src/payroll/payroll.service.ts
• backend/src/expenses/expenses.service.ts
• backend/src/settings/settings.service.ts
Payroll preparation routines suggest calculated payroll data is assembled from related worker-finance records before persistence or presentation.
Frontend Application and Reporting
The React renderer is organized around page-level operational screens and reusable feature components. Its API adapter is the frontend/backend boundary; page state should derive from backend records rather than duplicated local domain logic. Analytics and reports consume operational data for summaries and saved reporting.
Key paths:
• frontend/src/app/lib/api.ts
• frontend/src/app/pages/stock-page.tsx
• frontend/src/app/pages/new-sale-page.tsx
• backend/src/analytics/analytics.service.ts
• backend/src/reports/reports.service.ts
Material user workflows include new sales, stock/production operations, workers/payroll, expenses, and archival/profile views. The UI includes language and theme contexts, but business state remains centered in the NestJS domain services.
Main entry points: app.module.ts Application composition · analytics.service.ts Analytics and reports · api.ts API adapter · invoices.service.ts Invoicing
Components 20
Desktop host
- Electron main process · Owns windows, launcher behavior, and backend lifecycle.
electron/main.js - Bundled backend runtime · Local API process started and stopped by Electron.
electron/backend-runtime.js - Preload bridge · Exposes approved native APIs to the renderer.
electron/preload.js - Update handler
electron/updater.js
React renderer
- React application · Renderer bootstrap and page composition.
frontend/src/app/App.tsx - API adapter · Maps page actions to backend API requests.
frontend/src/app/lib/api.ts - Sales workflow UI
frontend/src/app/pages/new-sale-page.tsx - Stock workflow UI
frontend/src/app/pages/stock-page.tsx
NestJS backend
- Application composition · Composes controllers and domain modules.
backend/src/app.module.ts - Analytics and reports · Builds operational summaries and reports.
backend/src/analytics/analytics.service.ts
Operational domains
- Sales and customers · Owns sales, customer records, and payments.
backend/src/sales/sales.service.ts - Orders · Order and order-item source records for invoicing.
backend/src/orders/entities/order.entity.ts - Invoicing · Calculates, sequences, cancels, and records invoice payments.
backend/src/invoices/invoices.service.ts - Invoice PDF output
backend/src/invoices/invoice-pdf.service.ts - Inventory and supply · Audits purchases, supplier finance, and stock movements.
backend/src/inventory/inventory.service.ts - Production batches · Consumes materials and records batch output.
backend/src/inventory/entities/production-batch.entity.ts - Finished products · Records finished-product stock operations.
backend/src/inventory/finished-products.service.ts - Workers and payroll · Combines worker records with pay, advances, loans, and deductions.
backend/src/payroll/payroll.service.ts - Expenses ledger
backend/src/expenses/expenses.service.ts - Workshop settings · Maintains piece prices and production stages.
backend/src/settings/settings.service.ts
Connections 28
- Electron main process → Bundled backend runtime: starts and stops
- Electron main process → Preload bridge: loads
- Electron main process → Update handler: uses
- Preload bridge → React application: approved native APIs
- React application → API adapter: uses
- Sales workflow UI → API adapter: submits sales
- Stock workflow UI → API adapter: submits stock operations
- API adapter → Bundled backend runtime: local HTTP
- Bundled backend runtime → Application composition: runs API
- Application composition → Sales and customers: composes
- Application composition → Orders: composes
- Application composition → Invoicing: composes
- Application composition → Inventory and supply: composes
- Application composition → Workers and payroll: composes
- Application composition → Expenses ledger: composes
- Application composition → Workshop settings: composes
- Application composition → Analytics and reports: composes
- Sales and customers → Invoicing: sales invoice inputs
- Orders → Invoicing: create invoice from order
- Invoicing → Invoice PDF output: generates
- Inventory and supply → Production batches: material availability and movements
- Production batches → Finished products: records output stock
- Workshop settings → Production batches: production stages
- Workshop settings → Workers and payroll: piece-price inputs
- Sales and customers → Analytics and reports: operational data
- Inventory and supply → Analytics and reports: operational data
- Workers and payroll → Analytics and reports: operational data
- Expenses ledger → Analytics and reports: operational data