Famalth Lynx Master Developer Guide
This document is the comprehensive technical architecture, development, build, and deployment manualfor the complete enterprise Famalth Lynx Retail & Hospitality Management System.
System Architecture Overview
The system is engineered as a modern, high-performance, multi-tenant POS, ERP, and Hospitality suite consisting of:
Enterprise Architecture
├── Client Tier (Flutter Desktop / Web / Mobile in `lib/`)
│ ├── State Management: Provider + ChangeNotifiers
│ ├── Network & Cache: HTTP Client + Local SQLite / SharedPreferences
│ ├── Printing Engine: ESC/POS Thermal 80mm/58mm + PDF Vector Engine
│ └── UI Layer: Responsive Adaptive Layout (Desktop, Tablet, Mobile)
│
├── Backend API Tier (Node.js + Express + TypeScript in `backend/`)
│ ├── Middleware Stack: Auth, License, Rate Limiter, Security, Idempotency, Timezone
│ ├── Background Engine: BullMQ Redis Queue, Node-Cron, Distributed Locks
│ ├── Extensibility: Plugin Sandboxing (VM2), Webhooks, Automation Engine
│ └── AI & ML: Famalth Lynx AI Tool Calling, Association Rules Upselling
│
└── Persistence Tier
├── Relational Database: PostgreSQL 14+ via Sequelize ORM
├── Encryption & Licensing: AES-256-GCM Config Encryption & RSA License Keys
└── File Storage: Local Assets, Uploads, and Cloud Migration Snapshots
Prerequisites & Developer Setup
1. Toolchain Requirements
- Flutter SDK:
>= 3.4.0(Supports Windows Desktop, Web, Android, iOS) - Dart SDK: Compatible with Flutter toolchain
- Node.js:
18.xor20.x LTS - npm:
9.x+ - PostgreSQL:
14.xor higher - Git:
2.x+
2. Initial Setup Step-by-Step
Step 1: Clone Repository
git clone <repository_url>
cd RetailSale
Step 2: Setup Backend Dependencies & Environment
cd backend
npm install
Ensure the runtime license and encryption configuration files are present:
backend/license.keybackend/config.encbackend/sysConfig.encbackend/client.json
Step 3: Start PostgreSQL & Run Database Migrations
Start your local or cloud PostgreSQL instance:
# In backend directory
npm run migrate
Step 4: Start the Backend Development Server
# In backend directory
npm start
The server binds to port 3000 by default (configurable via environment or encrypted config).
Step 5: Setup & Run Flutter Client
# In project root
flutter pub get
flutter run -d windows # Or -d chrome for web, -d <android-device> for mobile
Project Directory Structure
RetailSale/
├── backend/ # Node.js + Express + TypeScript Backend
│ ├── config/ # Database & security configurations
│ ├── controllers/ # REST endpoint business logic
│ │ ├── finance/ # Accounting, COA, Loans, Vouchers
│ │ ├── hrms/ # HRMS, Attendance, Payroll
│ │ ├── restaurant/ # Tables, Floors, KOTs, KDS, Delivery
│ │ ├── sales/ # Sales, POS, Lucky Draw, Subscriptions
│ │ └── ...
│ ├── middlewares/ # Auth, License, RateLimit, AuditAuto, Context
│ ├── models/ # Sequelize ORM Relational Models
│ ├── routes/ # 32 modular Express route files
│ ├── services/ # Business services, AI, TaxEngine, WhatsApp
│ ├── utils/ # Crypto, distributed locks, timezone, backup
│ └── jobs/ # Background queue workers & cron jobs
│
├── lib/ # Flutter Client Source Code
│ ├── controllers/ # Provider state management controllers
│ ├── core/ # AppConfig, theme, constants, API client
│ ├── models/ # Dart data models & serialization
│ ├── screens/ # 75+ UI screens organized by feature domain
│ │ ├── accounting/ # Chart of Accounts, Vouchers, Balance Sheet
│ │ ├── auth/ # Login, User Management, Customer/Rider Auth
│ │ ├── community/ # B2B Trade Chat & Marketplace Hub
│ │ ├── dashboard/ # Main POS, Autonomous Agent, Cloud Migration
│ │ ├── hrms/ # Attendance, Employees, Payroll
│ │ ├── inventory/ # POS, BOM Assembly, Barcode Manager, GRN, Transfers
│ │ ├── modify/ # Audit reprints, sales modifications
│ │ ├── recovery/ # Disaster recovery, auto-reinstall
│ │ ├── reports/ # 26+ financial, stock, tax, and sales reports
│ │ ├── restaurant/ # Floors, Tables, KDS, Captain Tablet, KOTs
│ │ └── settings/ # Hardware, Tax Groups, WhatsApp, Plugins, Workflows
│ ├── services/ # Printing service, local storage, notifications
│ ├── utils/ # Formatters, dialog helpers, sound effects
│ └── widgets/ # Reusable UI widgets & smart upsell components
│
├── Docs/ # Complete Technical & User Documentation
└── installer/ # InnoSetup & Windows packaging scripts
Feature-by-Feature Dedicated Developer Guides
For in-depth implementation details of each individual subsystem, consult the dedicated technical guides:
| Technical Guide | Target Subsystem & Covered Architecture |
|---|---|
| Backend Guide | Deep dive into Node.js, Express, Sequelize, Middleware pipeline, Caching, and Security. |
| Frontend Guide | Deep dive into Flutter Provider state management, responsive UI, printing engine, and caching. |
| Restaurant & Hospitality Guide | Floor plan JSON, Table state machines, KOT lifecycle, real-time KDS, and Captain tablets. |
| Accounting & Financial Engine | Double-entry ledger invariants, COA tree, Trial Balance, P&L, Balance Sheet, and Loan EMI algorithms. |
| HRMS & Payroll Architecture | HRMS schema, attendance punch logic, shift rules, monthly payroll calculation, and payslips. |
| POS, Inventory & BOM Engine | POS transaction atomicity, Stock Ledger FIFO/Average, Barcode rendering, and BOM assembly. |
| AI Intelligence & Autonomous Agents | Lynx AI tool calling schemas, autonomous replenishment background agents, and Smart Upsell engine. |
| Plugins, Workflows & Automation | Plugin sandboxing (VM2), event bus triggers, WhatsApp BullMQ queue, and Webhook dispatch. |
| Developer Security, Cache & Load Balancer | High-concurrency clustering, Redis caching, AES encryption, and distributed locks. |
| M-Pesa Mobile Money Integration Architecture | Safaricom Daraja STK push lifecycle, OAuth token caching, and webhook callback processing. |
| Multi-Outlet Hierarchy & Scoping Architecture | Multi-tenant database routing, outlet scoping middleware, warehouse tree data models, and sequence numbering. |
| Reports, Analytics & BI Engine Architecture | SQL aggregations, Redis dashboard cache warming, read-replica queries, and vector PDF rendering. |
| Payment Gateways & Virtual Simulator | Multi-gateway credential store, secret masking, and Flutter Virtual Payment Simulator state machine. |
| Plugin Dev Studio & Sandbox Architecture | In-app IDE, safe TypeScript runner, sandbox lifecycle hooks, and marketplace publishing. |
| Third-Party Orders & Outlet OTP Architecture | Delivery aggregator order normalization, commission calculation, and cryptographic outlet onboarding OTP. |
| Operations Document Modifications & Differential Ledger | Differential stock adjustments (delta_in, delta_out), concurrency row locking, and tax group recalculation. |
| Enterprise SaaS Control Plane & Data Doctor | Master IAM, multi-tenant fleet governance, 30-day quota guard, sandboxed Data Doctor SQL runner, vector PDF invoicing, and Inno Setup packaging. |
| QR Table Dining & Multi-Seat Portal | Split-bill session engine, seat-level tagging, combined vs per-seat totals, and standalone dining app (main_dining.dart). |
| Clinic Management & Digital Prescription Architecture | Appointment state machine, doctor desk vitals JSONB, direct pharmacy billing bridge, vector prescription PDF generation, and public email OTP portal. |
| System Maintenance & Lockout Middleware Engine | Maintenance middleware, atomic JSON state storage, role-based bypass rules, and non-dismissible Flutter lockout interceptor dialog. |
| Delivery Challan, Fleet Vehicles & Transport Architecture | Vehicle & driver entities, trip assignment manifest, delivery OTP verification, and POS sales conversion pipeline. |
| Multi-Tiered Storage & Enterprise Backup Architecture | Partitioned root volume (storage/), dedicated enterprise tier, multi-tenant outlet sandboxing, .fambak / .posbak archive internals, and quota services. |
| Model Context Protocol (MCP) & AI Gateway Architecture | SSE and JSON-RPC transports, dynamic ChatGPT Action OpenAPI 3.0 spec, Gemini function calling, and RFC 6749/7636 OAuth 2.0 PKCE server. |
| Tax Compliance, Employee Portal & Driver Fleet Architecture | GSTR-1/3B tax calculation, ITR statement mapping, Haversine GPS geofencing, device binding, and fleet driver OTP verification. |
| Full REST API Endpoint Reference | 100% complete REST API reference for all 41 backend route modules (53 API sections) with request/response schemas. |
| Bug Fixes & Resolutions Changelog (Month-Wise) | Chronological month-by-month record of resolved bugs, concurrency fixes, and security patches. |
| Disaster Recovery & Bare-Metal Restore Architecture | AES-256 cloud backup pipeline, write-ahead sync tracker, and 1-click bare-metal system rebuild. |
| Node.js Backend Windows EXE Compilation Guide | Step-by-step compilation using pkg, obfuscation, native module handling (bcryptjs), and launcher scripts. |
| PostgreSQL Complete Removal & Clean Reinstall Guide | Complete Windows service removal, registry cleanup, data directory deletion, and Inno Setup automation. |
| Windows Installer & Packaging Guide | Complete InnoSetup packaging, bundling PostgreSQL runtime, Node binary, and Flutter executables. |
Testing & Code Quality Guidelines
1. Flutter Code Analysis & Tests
flutter analyze
flutter test
2. Backend TypeScript Compilation & Verification
cd backend
npm run build # Compiles TypeScript to dist/
npm test # Runs automated Jest test suites
Maintain code quality, ensure double-entry invariants, and preserve clean separation of concerns across all modules!