Skip to main content

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.x or 20.x LTS
  • npm: 9.x+
  • PostgreSQL: 14.x or 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.key
  • backend/config.enc
  • backend/sysConfig.enc
  • backend/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 GuideTarget Subsystem & Covered Architecture
Backend GuideDeep dive into Node.js, Express, Sequelize, Middleware pipeline, Caching, and Security.
Frontend GuideDeep dive into Flutter Provider state management, responsive UI, printing engine, and caching.
Restaurant & Hospitality GuideFloor plan JSON, Table state machines, KOT lifecycle, real-time KDS, and Captain tablets.
Accounting & Financial EngineDouble-entry ledger invariants, COA tree, Trial Balance, P&L, Balance Sheet, and Loan EMI algorithms.
HRMS & Payroll ArchitectureHRMS schema, attendance punch logic, shift rules, monthly payroll calculation, and payslips.
POS, Inventory & BOM EnginePOS transaction atomicity, Stock Ledger FIFO/Average, Barcode rendering, and BOM assembly.
AI Intelligence & Autonomous AgentsLynx AI tool calling schemas, autonomous replenishment background agents, and Smart Upsell engine.
Plugins, Workflows & AutomationPlugin sandboxing (VM2), event bus triggers, WhatsApp BullMQ queue, and Webhook dispatch.
Developer Security, Cache & Load BalancerHigh-concurrency clustering, Redis caching, AES encryption, and distributed locks.
M-Pesa Mobile Money Integration ArchitectureSafaricom Daraja STK push lifecycle, OAuth token caching, and webhook callback processing.
Multi-Outlet Hierarchy & Scoping ArchitectureMulti-tenant database routing, outlet scoping middleware, warehouse tree data models, and sequence numbering.
Reports, Analytics & BI Engine ArchitectureSQL aggregations, Redis dashboard cache warming, read-replica queries, and vector PDF rendering.
Payment Gateways & Virtual SimulatorMulti-gateway credential store, secret masking, and Flutter Virtual Payment Simulator state machine.
Plugin Dev Studio & Sandbox ArchitectureIn-app IDE, safe TypeScript runner, sandbox lifecycle hooks, and marketplace publishing.
Third-Party Orders & Outlet OTP ArchitectureDelivery aggregator order normalization, commission calculation, and cryptographic outlet onboarding OTP.
Operations Document Modifications & Differential LedgerDifferential stock adjustments (delta_in, delta_out), concurrency row locking, and tax group recalculation.
Enterprise SaaS Control Plane & Data DoctorMaster 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 PortalSplit-bill session engine, seat-level tagging, combined vs per-seat totals, and standalone dining app (main_dining.dart).
Clinic Management & Digital Prescription ArchitectureAppointment state machine, doctor desk vitals JSONB, direct pharmacy billing bridge, vector prescription PDF generation, and public email OTP portal.
System Maintenance & Lockout Middleware EngineMaintenance middleware, atomic JSON state storage, role-based bypass rules, and non-dismissible Flutter lockout interceptor dialog.
Delivery Challan, Fleet Vehicles & Transport ArchitectureVehicle & driver entities, trip assignment manifest, delivery OTP verification, and POS sales conversion pipeline.
Multi-Tiered Storage & Enterprise Backup ArchitecturePartitioned root volume (storage/), dedicated enterprise tier, multi-tenant outlet sandboxing, .fambak / .posbak archive internals, and quota services.
Model Context Protocol (MCP) & AI Gateway ArchitectureSSE 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 ArchitectureGSTR-1/3B tax calculation, ITR statement mapping, Haversine GPS geofencing, device binding, and fleet driver OTP verification.
Full REST API Endpoint Reference100% 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 ArchitectureAES-256 cloud backup pipeline, write-ahead sync tracker, and 1-click bare-metal system rebuild.
Node.js Backend Windows EXE Compilation GuideStep-by-step compilation using pkg, obfuscation, native module handling (bcryptjs), and launcher scripts.
PostgreSQL Complete Removal & Clean Reinstall GuideComplete Windows service removal, registry cleanup, data directory deletion, and Inno Setup automation.
Windows Installer & Packaging GuideComplete 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!