MFG Lite - [Plan & Implementation]

MFG Lite - [Plan & Implementation]

MFG Lite

  • Note : Some modules should be accessible to Admin System only and not Admin Users. Pending to be implemented.

๐Ÿง  Executive Overview

  • MFG Lite is a mobile-first + desktop-friendly ERP application designed to perform essential business operations in a simple way.
  • It serves as a lightweight version to the existing ErpCrystal MFG system, enabling users to perform essential transactions without prior training.
  • The system is fully self-contained (Node.js-based) with no external ERP dependency.
  • Supports multi-company (multi-tenant) architecture using a single database.

๐ŸŽฏ Key Goals

  • ๐Ÿ“ฑ Works on mobile + laptop
  • โšก Fast and simple UI
  • ๐Ÿง  No training required
  • ๐Ÿข Multi-company support (single DB)
  • ๐Ÿ” Role + permission-based access

๐Ÿ› ๏ธ Technology Stack

Category Technology
Framework Next.js 16
Language TypeScript
Styling Tailwind CSS + shadcn/ui
Backend Node.js (Server Actions only)
Database SQL Server (Prisma)
Auth JWT + OTP
PWA next-pwa (UI caching only)
Notifications Firebase (optional)

๐Ÿ“‚ Project Structure

/mfg-lite
โ”œโ”€โ”€ app
โ”‚   โ”œโ”€โ”€ (auth) # Login, OTP verification
โ”‚   โ”œโ”€โ”€ (main) # Protected routes
โ”‚   โ”‚   โ”œโ”€โ”€ dashboard
โ”‚   โ”‚   โ”œโ”€โ”€ manufacturing
โ”‚   โ”‚   โ”œโ”€โ”€ supply chain
โ”‚   โ”‚   โ”œโ”€โ”€ sales
โ”‚   โ”‚   โ”œโ”€โ”€ finance
โ”‚   โ”‚   โ”œโ”€โ”€ hr
โ”‚   โ”‚   โ”œโ”€โ”€ system
โ”‚   โ”‚   โ””โ”€โ”€ settings
โ”‚   โ”œโ”€โ”€ actions # Server Actions (all backend logic)
โ”œโ”€โ”€ components
โ”œโ”€โ”€ lib
โ”œโ”€โ”€ prisma
โ””โ”€โ”€ public

๐Ÿงพ Database Design

๐Ÿ“ฆ Module Table
model module {
  id          String @id @default(cuid())

  code        String @unique // MFG, SCM, SALES, FINANCE, HR, SYS
  name        String

  sort_order  Int?

  is_active   Boolean @default(true)
}
๐Ÿ“ฆ Subscription Plan
  • Subscription Plan defines only user limits.
  • Modules are linked separately to clients.
model subscription_plan {
  id          String @id @default(cuid())

  code        String @unique // BASIC, SILVER, GOLD, PLATINUM, BLACK
  name        String

  max_users   Int

  is_active   Boolean @default(true)
}
๐Ÿข Client Table
model client {
  id          String @id  // A0001

  name        String

  plan_id     String

  is_active   Boolean @default(true)
}
๐Ÿ“ฆ Client Module Mapping
model client_module {
  id          String @id @default(cuid())

  client_id   String
  module_id   String

  is_active   Boolean @default(true)
}
๐Ÿ‘ค Users Table
model user {
  id        String   @id @default(cuid())

  name      String

  mobile    String? @unique
  email     String? @unique

  role      UserRole

  client_id String

  is_active Boolean @default(true)

  telegram_id       String?
  telegram_linked   Boolean @default(false)

  current_session_id    String?
  otp_code              String?
  otp_expires_at        DateTime?
}

enum UserRole {
  SYSTEM
  ADMIN
  MANAGER
  STAFF
  READ_ONLY
}

๐Ÿ” Authentication & Authorization

Login Flow
  1. User enters mobile/email
  2. System sends OTP via:
    • Email
    • SMS (optional)
  3. User enters OTP
  4. System validates + generates JWT
  5. Session created with:
    • userId
    • role
    • clientId

๐Ÿ”„ Client Handling

ClientId Format
A0001, A0002, A0003...
Rules
  • All tables must include client_id
  • All queries must filter by client_id
  • Prevent cross-company data access
  • client_id should be stored in HTTP Cookie
  • Frontend should never manually send client_id
  • client_id should be automatically injected from session/cookie

๐Ÿ‘ค Role Behavior

Role Description
SYSTEM Access to multiple companies (one at a time)
ADMIN Full access within assigned company
MANAGER No delete access
STAFF Limited create access
READ_ONLY View-only access

๐Ÿ” SYSTEM User Special Behavior

  • SYSTEM users login through Crystal Account
  • Can switch between companies
  • Works on one client at a time
  • Session stores active clientId
  • Modules shown based on selected client

๐Ÿ“ฆ Module Access Logic

A module is accessible and shown in UI only if:

  • module is active
  • module linked to client
  • user has permission

๐Ÿ” Permissions List

Each module supports:

  • VIEW
  • CREATE
  • MODIFY
  • DELETE
  • PRINT

๐Ÿ” Permission Check

const isSystem = user?.role === "SYSTEM";
const isAdmin = user?.role === "ADMIN";
const isManager = user?.role === "MANAGER";
const isStaff = user?.role === "STAFF";
const isReadOnly = user?.role === "READ_ONLY";
const canDelete = isSystem || isAdmin;

๐Ÿ“ฑ UI / UX Design

Mobile
  • Bottom navigation bar
  • Card-based UI
Desktop
  • Sidebar navigation
  • Table view
  • Centered layout

๐Ÿ“ฒ Communication Features

๐Ÿ“ž Call
  • Tap to call customer/vendor
๐Ÿ’ฌ Message
  • SMS / WhatsApp quick actions
โœ‰๏ธ Email
  • Send invoice PDF
  • Share reports
๐Ÿ“ท Camera
  • Capture documents
  • Upload directly

๐Ÿ”” Notifications

  • Payment received
  • New entries

๐ŸŒ Offline Behavior

  • App UI may load using PWA caching
  • All data operations require internet connection
  • No offline data storage or sync

๐Ÿš€ Performance Strategy

  • Use Server Actions
  • Cache user session
  • Lazy load modules
  • Index client_id in all tables
  • Enforce client_id filtering in all queries

๐Ÿ“ฆ Modules

Sales
Menus Features
Sales Order View
Create
Modify
Delete
Item Details View
Item Create
Item Modify
Item Delete
Print
Upload PO No
Sales Invoice View
Create
Modify
Delete
Create From Order
Print
Sales Enquries View
Create
Modify
Delete
Collection Status View
Create
Modify
Marketing Activity View
Create
Modify
Delete
Sales Rejection View
Create
Modify
Delete
Sales Officer View
Create
Modify
Delete
Sales Order Analysis Report Order Register
Pending Order
Order Delivery
Sales Analysis Report Sales By Invoice
Sales By Product
SRN (Sales Rejection Note) Report
Supply Chain Management
Menus Features
Purchase Indent View
Create
Modify
Delete
Item Details View
Item Create
Item Modify
Item Delete
Print
GRN View
Create
Modify
Delete
Create From Indent
Print
Purchase Bill View
Create
Modify
Delete
Create With Grn
Create Without Grn
Print
Opening / Closing Inventory View
Create
In / Out Register View
Create
Debit Credit Notes View
Create
Modify
Delete
Print
Indent Analysis Report Pending Indent
Indent Register
GRN Analysis Report Peding GRN
GRN Register
QA Report
Purchase Analysis Report Purchase By Bill
Purchase By Product
Bill Wise QA Analysis
Inventory Aging Report Qty
Value
Inventory Valuation Report Valuation
WAR
Manufacturing
Menus Features
Bill Of Materials (BOM) View
Create
Modify
Delete
Item Details View
Item Create
Item Modify
Item Delete
Production Plan View
Create
Modify
Delete
Item Details View
Item Create
Daily Production Monitor View
Create
Modify
Delete
IIRS View
Create
Modify
Delete
JobWork View
Create
In Stock
Out Stock
Modify
Delete
BOM Reports Report BOM Analysis
MRP Report Report Production Plan
Procurement Plan
Consumption of Material Report Consumption of Material (with BOM scan)
Job Analysis Report Job Work In
Job Work Out
Job Work In+Out (combined)
Finance
Menus Features
Voucher View
Create
Modify
Delete
Upload Document
Journal Voucher View
Create
Modify
Delete
Cash / Bank Book Report Cash Bank
RTGS Register Report NEFT
Payment
Journal Register Report Journal Register
Financial Reports Report Ledger
Cheque Register Report Cheque Register
HR
Menus Features
Pay Details View
Time / Day Details View
Create
Modify
Delete
Loan Details View
Create
Modify
Delete
Approve Loan
Leave Details View
Create
Modify
Delete
Approve Leave
Employee View
Create
Modify
Delete
Holiday Mst View
System Tools
Menus Features
Company View
Create
Modify
Delete
Division View
Party View
Create
Modify
Delete
Item View
Create
Modify
Delete
Transporter View
Create
Modify
Delete