Skip to content

harpreet-2146/FM-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

179 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🏭 Food Manufacturing SaaS Platform

Enterprise Supply Chain Platform for Food Manufacturing

Developed for Skantha Technology Solutions

TypeScript NestJS React PostgreSQL

Role-Based Access | Production Tracking | GST-Compliant Invoicing | Commission Management


πŸ“‹ Table of Contents


🌟 Overview

🌟 Overview

The Food Manufacturing SaaS Platform is an enterprise-grade application designed to manage the complete supply chain workflow for food manufacturing businesses.

This platform was developed as part of an AI development project for Skantha Technology Solutions, focusing on building scalable systems for manufacturing operations, inventory management, and financial tracking.

It provides role-specific dashboards for Admins, Manufacturers, and Retailers, enabling seamless tracking from production to point-of-sale with built-in GST compliance and commission management.

✨ Features

🎯 Core Functionality

  • Multi-Role System: Separate dashboards and permissions for Admin, Manufacturer, and Retailer roles
  • Production Management: Track production batches, recipes, raw materials, and finished goods
  • Inventory Control: Real-time stock tracking with SRN (Stock Requisition Note) and GRN (Goods Receipt Note)
  • Material Catalog: Comprehensive catalog management for raw materials and finished products
  • Dispatch Management: Order fulfillment and dispatch execution with tracking
  • Invoice Generation: GST-compliant invoice creation with automatic tax calculations
  • Commission Tracking: Multi-tier commission management for retailers and distributors
  • Financial Reports: Comprehensive reporting for admins with revenue and sales analytics
  • Authentication & Authorization: JWT-based secure authentication with role-based access control

πŸ“Š Business Features

  • B2B & B2C Sales: Support for both business-to-business and direct consumer sales
  • Stock Movements: Complete audit trail of all inventory movements
  • Batch Tracking: Production batch recording with expiry date management
  • Purchase Orders: End-to-end purchase order management
  • Sales Analytics: Real-time dashboards with key performance indicators
  • Commission Calculation: Automated commission calculations based on sales

πŸ› οΈ Tech Stack

Backend

  • Framework: NestJS (Node.js framework)
  • Language: TypeScript
  • Database: PostgreSQL 16
  • ORM: Prisma
  • Authentication: JWT (JSON Web Tokens)
  • Validation: class-validator, class-transformer
  • API Documentation: Swagger/OpenAPI

Frontend

  • Framework: React 18
  • Language: TypeScript
  • Build Tool: Vite
  • Styling: Tailwind CSS
  • State Management: React Query (TanStack Query)
  • Routing: React Router v6
  • HTTP Client: Axios
  • UI Components: Custom components with Tailwind

DevOps & Tools

  • Version Control: Git
  • Package Manager: npm
  • Database Management: PostgreSQL with Prisma Migrate
  • Development: Hot reload for both frontend and backend

πŸ—οΈ System Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     Client Layer (Browser)                   β”‚
β”‚              React + TypeScript + Tailwind CSS               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                       β”‚ HTTP/REST API
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   API Gateway Layer                          β”‚
β”‚                NestJS Controllers + Guards                   β”‚
β”‚         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”           β”‚
β”‚         β”‚   Admin    β”‚Manufacturerβ”‚  Retailer   β”‚           β”‚
β”‚         β”‚  Routes    β”‚   Routes   β”‚   Routes    β”‚           β”‚
β”‚         β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜           β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                β”‚             β”‚            β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   Service Layer                              β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚Productionβ”‚ β”‚Inventory β”‚ β”‚ Invoice  β”‚ β”‚ Commission  β”‚   β”‚
β”‚  β”‚ Service  β”‚ β”‚ Service  β”‚ β”‚ Service  β”‚ β”‚   Service   β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
        β”‚            β”‚            β”‚               β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                  Data Access Layer                          β”‚
β”‚                   Prisma ORM                                β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                       β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                PostgreSQL Database                          β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚  β”‚  Users  β”‚ β”‚Products β”‚ β”‚Productionβ”‚ β”‚ Transactions β”‚    β”‚
β”‚  β”‚  Roles  β”‚ β”‚Inventoryβ”‚ β”‚  Batches β”‚ β”‚   Invoices   β”‚    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

βš™οΈ Prerequisites

Before setting up the project, ensure you have the following installed on your system:

Required Software

Software Version Download Link Purpose
Node.js 18.x or 20.x nodejs.org Runtime for backend and build tools
npm 9.x or higher Comes with Node.js Package manager
PostgreSQL 16.x postgresql.org Database server
Git Latest git-scm.com Version control

Optional but Recommended

Tool Purpose
pgAdmin 4 PostgreSQL database GUI management
Postman API testing
VS Code Code editor with TypeScript support

System Requirements

  • OS: Windows 10/11, macOS 10.15+, or Linux
  • RAM: Minimum 4GB (8GB recommended)
  • Storage: At least 2GB free space
  • Network: Internet connection for package installation

πŸ“₯ Installation & Setup

Step 1: Clone the Repository

git clone https://github.com/harpreet-2146/FM-demo.git
cd FM-demo

Step 2: Backend Setup

# Navigate to backend directory
cd backend

# Install dependencies
npm install

# Generate Prisma Client
npx prisma generate

# Run database migrations
npx prisma migrate dev

Step 3: Frontend Setup

# Navigate to frontend directory (from project root)
cd ../frontend

# Install dependencies
npm install

πŸ”§ Environment Configuration

Backend Environment Variables

Create a .env file in the backend directory:

# Database Configuration
DATABASE_URL="postgresql://postgres:your_password@localhost:5432/food_manufacturing_saas?schema=public"

# JWT Configuration
JWT_SECRET="my-super-secret-jwt-key-for-food-manufacturing-saas-2026"
JWT_EXPIRES_IN="24h"

# Server Configuration
PORT=3000
NODE_ENV=development

# CORS Configuration
CORS_ORIGIN="http://localhost:5173"

Configuration Details:

Variable Description Example Value
DATABASE_URL PostgreSQL connection string postgresql://user:pass@host:port/db
JWT_SECRET Secret key for JWT token signing Any strong random string (min 32 chars)
JWT_EXPIRES_IN Token expiration time 24h, 7d, 30d
PORT Backend server port 3000
NODE_ENV Environment mode development, production
CORS_ORIGIN Allowed frontend origin http://localhost:5173

⚠️ IMPORTANT: Replace your_password with your actual PostgreSQL password that you set during installation.

Frontend Environment Variables

Create a .env file in the frontend directory:

# API Configuration
VITE_API_URL=http://localhost:3000

πŸ—„οΈ Database Setup

Step 1: Install PostgreSQL

Windows

  1. Download PostgreSQL 16 from postgresql.org
  2. Run the installer
  3. Set a password for the postgres user (remember this!)
  4. Default port is 5432 (keep this unless you have conflicts)
  5. Install pgAdmin 4 (included in the installer)
  6. Complete the installation and ensure PostgreSQL service is running

macOS

# Using Homebrew
brew install postgresql@16
brew services start postgresql@16

# Create postgres user if needed
createuser -s postgres

Linux (Ubuntu/Debian)

sudo apt update
sudo apt install postgresql-16 postgresql-contrib-16
sudo systemctl start postgresql
sudo systemctl enable postgresql

# Set password for postgres user
sudo -u postgres psql
\password postgres
# Enter your password twice
\q

Step 2: Create Database

# Connect to PostgreSQL
# Windows (from Command Prompt or PowerShell)
psql -U postgres

# macOS/Linux
psql -U postgres

# Once connected, create the database
CREATE DATABASE food_manufacturing_saas;

# Verify database was created
\l

# Exit psql
\q

Step 3: Run Migrations

# From backend directory
cd backend

# Ensure DATABASE_URL in .env is correct
# Run Prisma migrations
npx prisma migrate dev

# This will:
# 1. Create all tables
# 2. Set up relationships
# 3. Apply indexes and constraints

# Seed database (if seed file exists)
npx prisma db seed

Step 4: Verify Database

# Open Prisma Studio to view database
npx prisma studio

This will open Prisma Studio at http://localhost:5555 where you can view and edit database records.


πŸš€ Running the Application

Development Mode

Terminal 1: Start Backend

cd backend
npm run start:dev

Expected Output:

[Nest] 12345  - 02/08/2026, 10:30:00 AM     LOG [NestFactory] Starting Nest application...
[Nest] 12345  - 02/08/2026, 10:30:01 AM     LOG [InstanceLoader] AppModule dependencies initialized
[Nest] 12345  - 02/08/2026, 10:30:01 AM     LOG [RoutesResolver] AuthController {/auth}:
[Nest] 12345  - 02/08/2026, 10:30:01 AM     LOG [NestApplication] Nest application successfully started
[Nest] 12345  - 02/08/2026, 10:30:01 AM     LOG Application is running on: http://localhost:3000

The backend will start on http://localhost:3000

Terminal 2: Start Frontend

cd frontend
npm run dev

Expected Output:

VITE v5.x.x  ready in 500 ms

  ➜  Local:   http://localhost:5173/
  ➜  Network: use --host to expose
  ➜  press h to show help

The frontend will start on http://localhost:5173

Production Mode

Build Backend

cd backend
npm run build
npm run start:prod

Build Frontend

cd frontend
npm run build

# Preview production build
npm run preview

Verify Everything is Running

  1. Backend API: Visit http://localhost:3000/api (Swagger documentation)
  2. Frontend: Visit http://localhost:5173
  3. Database: Check with npx prisma studio from backend directory

πŸ“ Project Structure

FM-demo/
β”œβ”€β”€ backend/                      # NestJS Backend Application
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ auth/                # Authentication module
β”‚   β”‚   β”‚   β”œβ”€β”€ guards/          # JWT guards, role guards
β”‚   β”‚   β”‚   β”œβ”€β”€ decorators/      # Custom decorators (Roles, Public)
β”‚   β”‚   β”‚   β”œβ”€β”€ auth.controller.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ auth.service.ts
β”‚   β”‚   β”‚   └── auth.module.ts
β”‚   β”‚   β”œβ”€β”€ admin/               # Admin module
β”‚   β”‚   β”‚   β”œβ”€β”€ admin.controller.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ admin.service.ts
β”‚   β”‚   β”‚   └── admin.module.ts
β”‚   β”‚   β”œβ”€β”€ manufacturer/        # Manufacturer module
β”‚   β”‚   β”‚   β”œβ”€β”€ manufacturer-inventory.controller.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ manufacturer-inventory.service.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ manufacturer-production.controller.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ manufacturer-production.service.ts
β”‚   β”‚   β”‚   └── manufacturer.module.ts
β”‚   β”‚   β”œβ”€β”€ retailer/            # Retailer module
β”‚   β”‚   β”‚   β”œβ”€β”€ retailer-inventory.controller.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ retailer-inventory.service.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ retailer-sales.controller.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ retailer-sales.service.ts
β”‚   β”‚   β”‚   └── retailer.module.ts
β”‚   β”‚   β”œβ”€β”€ shared/              # Shared utilities
β”‚   β”‚   β”‚   β”œβ”€β”€ dtos/            # Data Transfer Objects
β”‚   β”‚   β”‚   └── interfaces/      # TypeScript interfaces
β”‚   β”‚   β”œβ”€β”€ prisma/              # Prisma configuration
β”‚   β”‚   β”‚   β”œβ”€β”€ prisma.service.ts
β”‚   β”‚   β”‚   └── schema.prisma    # Database schema
β”‚   β”‚   β”œβ”€β”€ app.module.ts        # Root module
β”‚   β”‚   └── main.ts              # Application entry point
β”‚   β”œβ”€β”€ .env                     # Environment variables
β”‚   β”œβ”€β”€ package.json
β”‚   └── tsconfig.json
β”‚
β”œβ”€β”€ frontend/                     # React Frontend Application
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/          # Reusable UI components
β”‚   β”‚   β”‚   β”œβ”€β”€ layout/         # Layout components (Header, Sidebar)
β”‚   β”‚   β”‚   β”œβ”€β”€ common/         # Common components (Button, Card, Table)
β”‚   β”‚   β”‚   └── forms/          # Form components
β”‚   β”‚   β”œβ”€β”€ pages/              # Page components
β”‚   β”‚   β”‚   β”œβ”€β”€ auth/           # Login, Register
β”‚   β”‚   β”‚   β”œβ”€β”€ admin/          # Admin dashboard & reports
β”‚   β”‚   β”‚   β”œβ”€β”€ manufacturer/   # Manufacturer dashboard
β”‚   β”‚   β”‚   └── retailer/       # Retailer dashboard
β”‚   β”‚   β”œβ”€β”€ services/           # API service layer
β”‚   β”‚   β”‚   β”œβ”€β”€ api.ts          # Axios configuration
β”‚   β”‚   β”‚   β”œβ”€β”€ auth.service.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ admin.service.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ manufacturer.service.ts
β”‚   β”‚   β”‚   └── retailer.service.ts
β”‚   β”‚   β”œβ”€β”€ hooks/              # Custom React hooks
β”‚   β”‚   β”‚   β”œβ”€β”€ useAuth.ts
β”‚   β”‚   β”‚   └── useApi.ts
β”‚   β”‚   β”œβ”€β”€ context/            # React Context
β”‚   β”‚   β”‚   └── AuthContext.tsx
β”‚   β”‚   β”œβ”€β”€ types/              # TypeScript type definitions
β”‚   β”‚   β”œβ”€β”€ utils/              # Utility functions
β”‚   β”‚   β”œβ”€β”€ App.tsx             # Root component
β”‚   β”‚   β”œβ”€β”€ main.tsx            # Application entry point
β”‚   β”‚   └── index.css           # Global styles
β”‚   β”œβ”€β”€ .env                    # Environment variables
β”‚   β”œβ”€β”€ index.html
β”‚   β”œβ”€β”€ package.json
β”‚   β”œβ”€β”€ tailwind.config.js
β”‚   β”œβ”€β”€ tsconfig.json
β”‚   └── vite.config.ts
β”‚
β”œβ”€β”€ .gitignore
└── README.md                    # This file

πŸ“š API Documentation

Access Swagger Documentation

Once the backend is running, visit: http://localhost:3000/api

The Swagger UI provides:

  • Complete API endpoint documentation
  • Request/response schemas
  • Interactive API testing
  • Authentication flow testing

Key API Endpoints

Authentication

Method Endpoint Description Auth Required
POST /auth/login User login ❌
POST /auth/register User registration ❌
GET /auth/profile Get current user profile βœ…

Admin Endpoints

Method Endpoint Description Role
GET /admin/reports/sales Sales reports Admin
GET /admin/reports/inventory Inventory reports Admin
GET /admin/reports/commissions Commission reports Admin
GET /admin/users List all users Admin
POST /admin/users Create new user Admin

Manufacturer Endpoints

Method Endpoint Description Role
GET /manufacturer/inventory Get inventory list Manufacturer
POST /manufacturer/inventory/srn Create Stock Requisition Note Manufacturer
POST /manufacturer/inventory/grn Create Goods Receipt Note Manufacturer
GET /manufacturer/production/batches List production batches Manufacturer
POST /manufacturer/production/batch Record production batch Manufacturer

Retailer Endpoints

Method Endpoint Description Role
GET /retailer/inventory Get retailer inventory Retailer
GET /retailer/invoices List invoices Retailer
POST /retailer/sales/invoice Create sales invoice Retailer
GET /retailer/commissions View commissions Retailer

πŸ‘₯ User Roles & Permissions

Admin

Full system access with oversight capabilities

βœ… Can Do:

  • View all system reports (sales, inventory, commissions)
  • Manage users and assign roles
  • View complete financial data
  • Access analytics dashboards
  • Configure system settings
  • Approve/reject transactions
  • Audit all system activities

❌ Cannot Do:

  • Execute production batches (view only)
  • Create invoices directly (oversight only)

Dashboard Components:

  • Sales overview
  • Revenue analytics
  • Commission summaries
  • User management
  • System health monitoring

Manufacturer

Production and inventory management

βœ… Can Do:

  • Create and manage production batches
  • Track raw materials and finished goods
  • Create SRN (Stock Requisition Notes)
  • Create GRN (Goods Receipt Notes)
  • View their own inventory levels
  • Dispatch orders to retailers
  • Record material consumption
  • Track production costs

❌ Cannot Do:

  • View financial data (commissions, profit margins)
  • Access retailer sales data
  • View system-wide reports
  • Modify commission structures
  • Access other manufacturers' data

Dashboard Components:

  • Production batch overview
  • Inventory status
  • Material requisitions
  • Dispatch tracking
  • Production efficiency metrics

Retailer

Sales and inventory for retail operations

βœ… Can Do:

  • View their assigned inventory
  • Create sales invoices (B2C sales)
  • View their own invoices
  • Track their commissions
  • Place orders with manufacturers
  • View order history
  • Generate sales reports (own data)

❌ Cannot Do:

  • View other retailers' data
  • Access production information
  • View manufacturer inventory
  • Access admin reports
  • Modify commission rates
  • View system-wide analytics

Dashboard Components:

  • Inventory overview
  • Sales summary
  • Commission tracking
  • Invoice history
  • Order management

πŸ”‘ Key Modules

1. Production Management

Features:

  • Production batch recording with unique batch numbers
  • Recipe management with BOM (Bill of Materials)
  • Raw material consumption tracking
  • Finished goods production
  • Expiry date tracking and alerts
  • Batch costing and profitability analysis

Workflow:

1. Create Production Batch
   ↓
2. Record Raw Materials Used
   ↓
3. Process Production
   ↓
4. Update Finished Goods Inventory
   ↓
5. Calculate Production Costs
   ↓
6. Generate Batch Report

Key Fields:

  • Batch Number (auto-generated)
  • Production Date
  • Raw Materials (with quantities)
  • Finished Product
  • Quantity Produced
  • Manufacturing Cost
  • Expiry Date

2. Inventory Control

Features:

  • Real-time stock tracking
  • SRN (Stock Requisition Note) for material requests
  • GRN (Goods Receipt Note) for material receipts
  • Stock movement audit trail
  • Low stock alerts and notifications
  • Multi-location inventory support
  • FIFO/LIFO stock valuation

Stock Movement Types:

  • Purchase (IN) - Goods received from suppliers
  • Production (IN/OUT) - Materials consumed, products created
  • Sales (OUT) - Products sold to customers
  • Dispatch (OUT) - Goods sent to retailers
  • Adjustment (IN/OUT) - Stock corrections
  • Return (IN) - Returned goods

SRN Workflow:

Manufacturer Creates SRN β†’ Approval β†’ Material Procurement β†’ GRN Creation

GRN Workflow:

Goods Received β†’ Quality Check β†’ GRN Creation β†’ Inventory Update

3. Invoice Generation

Features:

  • GST-compliant invoice creation
  • Automatic tax calculations (CGST, SGST, IGST)
  • Invoice numbering system (sequential)
  • PDF generation
  • Invoice history tracking
  • Payment status tracking
  • Multi-currency support

GST Calculation:

Base Amount:            β‚Ή10,000.00
CGST @ 9%:             β‚Ή   900.00
SGST @ 9%:             β‚Ή   900.00
─────────────────────────────────
Total Invoice Amount:   β‚Ή11,800.00

Invoice Structure:

  • Invoice Number (auto-generated)
  • Invoice Date
  • Buyer Details (GST Number, Address)
  • Seller Details (GST Number, Address)
  • Line Items (Product, Quantity, Rate, Amount)
  • Tax Breakdown (CGST, SGST, IGST)
  • Total Amount
  • Payment Terms
  • Due Date

GST Types:

  • Intrastate: CGST + SGST (9% + 9% = 18%)
  • Interstate: IGST (18%)

4. Commission Management

Features:

  • Multi-tier commission structure
  • Automatic commission calculation
  • Commission reports by period
  • Payment tracking
  • Commission history
  • Commission rate management
  • Performance-based bonuses

Commission Tiers:

Role Commission % Calculation Base
Primary Retailer 10% Sales Amount
Distributor 5% Sales Amount
Referral Partner 2% Sales Amount
Regional Manager 3% Regional Sales

Calculation Example:

Sale Amount: β‚Ή100,000
Primary Retailer (10%): β‚Ή10,000
Distributor (5%): β‚Ή5,000
Referral (2%): β‚Ή2,000
─────────────────────────
Total Commissions: β‚Ή17,000

Commission Reports:

  • Monthly commission summary
  • Individual retailer performance
  • Commission payment status
  • Historical commission data
  • Commission forecasting

5. Dispatch Management

Features:

  • Order fulfillment tracking
  • Dispatch note generation
  • Delivery status tracking
  • Vehicle assignment
  • Proof of delivery
  • Route optimization
  • Delivery scheduling

Dispatch Workflow:

Order Placed
    ↓
Inventory Check
    ↓
Packing & Quality Check
    ↓
Dispatch Note Generated
    ↓
Vehicle Assignment
    ↓
In-Transit Tracking
    ↓
Delivered & POD Collected

Dispatch Statuses:

  • Pending
  • Packed
  • Dispatched
  • In Transit
  • Out for Delivery
  • Delivered
  • Returned

πŸ› Troubleshooting

Common Issues & Solutions

1. Database Connection Failed

Error:

Can't reach database server at localhost:5432

Solutions:

Check PostgreSQL Service:

# Windows
services.msc
# Look for "postgresql-x64-16" and ensure it's running

# macOS
brew services list | grep postgresql

# Linux
sudo systemctl status postgresql

Verify Connection:

# Test if PostgreSQL is accepting connections
pg_isready -h localhost -p 5432

# Expected output: localhost:5432 - accepting connections

Check .env Configuration:

# Ensure this matches your PostgreSQL setup
DATABASE_URL="postgresql://postgres:YOUR_ACTUAL_PASSWORD@localhost:5432/food_manufacturing_saas?schema=public"

Test Direct Connection:

psql -U postgres -d food_manufacturing_saas

# If this works, your credentials are correct

Common Mistakes:

  • Wrong password in DATABASE_URL
  • PostgreSQL service not running
  • Firewall blocking port 5432
  • Database name misspelled

2. Port Already in Use

Error:

Error: listen EADDRINUSE: address already in use :::3000

Solutions:

Windows:

# Find process using port 3000
netstat -ano | findstr :3000

# Kill the process (replace <PID> with actual process ID)
taskkill /PID <PID> /F

macOS/Linux:

# Find and kill process using port 3000
lsof -ti:3000 | xargs kill -9

# Or for port 5173 (frontend)
lsof -ti:5173 | xargs kill -9

Alternative Solution: Change the port in .env file:

# Backend
PORT=3001

# Frontend (.env in frontend folder)
VITE_PORT=5174

3. Prisma Client Not Generated

Error:

Cannot find module '@prisma/client'
or
PrismaClient is unable to be run in the browser

Solutions:

# Navigate to backend directory
cd backend

# Generate Prisma Client
npx prisma generate

# If schema has changed, migrate first
npx prisma migrate dev

# Then generate
npx prisma generate

# Restart the backend server
npm run start:dev

Clear Prisma Cache (if still having issues):

# Delete node_modules and reinstall
rm -rf node_modules package-lock.json
npm install
npx prisma generate

4. Frontend Build Fails

Error:

TypeScript compilation errors
or
Module not found errors

Solutions:

# Clear cache and reinstall
rm -rf node_modules package-lock.json
npm install

# Clear Vite cache
rm -rf node_modules/.vite

# Update dependencies
npm update

# If still failing, check TypeScript errors
npm run type-check

Common TypeScript Errors:

  • Missing type definitions: npm install --save-dev @types/node
  • Import path errors: Check tsconfig.json paths configuration
  • Version conflicts: Ensure React and React-DOM versions match

5. CORS Errors

Error:

Access to XMLHttpRequest has been blocked by CORS policy:
No 'Access-Control-Allow-Origin' header is present

Solutions:

Check Backend .env:

# Must match your frontend URL exactly
CORS_ORIGIN="http://localhost:5173"

# For multiple origins (production):
CORS_ORIGIN="http://localhost:5173,https://yourdomain.com"

Verify Backend main.ts:

// Should have CORS enabled
app.enableCors({
  origin: process.env.CORS_ORIGIN || 'http://localhost:5173',
  credentials: true,
});

Check Frontend API URL:

# Frontend .env
VITE_API_URL=http://localhost:3000
# No trailing slash!

Restart Both Servers:

# Backend
cd backend
npm run start:dev

# Frontend (new terminal)
cd frontend
npm run dev

6. JWT Token Invalid

Error:

Unauthorized
or
Invalid token
or
jwt malformed

Solutions:

Clear Browser Storage:

// Open browser console (F12) and run:
localStorage.clear();
sessionStorage.clear();
// Then refresh page

Verify JWT_SECRET:

# Backend .env - this should NEVER change
JWT_SECRET="my-super-secret-jwt-key-for-food-manufacturing-saas-2026"

# If you change this, all existing tokens become invalid

Check Token Expiration:

# Default is 24 hours
JWT_EXPIRES_IN="24h"

# For development, you might want longer:
JWT_EXPIRES_IN="7d"

Re-login:

  • Logout from the application
  • Clear browser storage
  • Login again with credentials

7. npm Install Fails

Error:

npm ERR! code ENOENT
or
npm ERR! network issues

Solutions:

# Clear npm cache
npm cache clean --force

# Delete lock file and node_modules
rm -rf node_modules package-lock.json

# Reinstall
npm install

# If still failing, try updating npm
npm install -g npm@latest

Network Issues:

# Use a different registry
npm config set registry https://registry.npmjs.org/

# Check your internet connection
ping registry.npmjs.org

8. Prisma Migration Fails

Error:

Migration failed
or
Database schema is out of sync

Solutions:

# Reset database (WARNING: Deletes all data)
npx prisma migrate reset

# Create a new migration
npx prisma migrate dev --name fix_schema

# Force push schema (development only)
npx prisma db push

If Migration History is Broken:

# Delete migrations folder
rm -rf prisma/migrations

# Recreate initial migration
npx prisma migrate dev --name init

9. Build Production Fails

Error:

Build fails with various errors

Solutions:

Backend:

# Clean build
rm -rf dist
npm run build

# Check for TypeScript errors
npm run build

Frontend:

# Clean build
rm -rf dist
npm run build

# Test build locally
npm run preview

Environment Variables for Production:

# Backend .env
NODE_ENV=production
DATABASE_URL="your_production_database_url"

# Frontend .env
VITE_API_URL=https://your-api-domain.com

10. Database Connection Pool Exhausted

Error:

Can't create new connection: pool is exhausted

Solution:

Add to prisma.service.ts:

export class PrismaService extends PrismaClient {
  constructor() {
    super({
      datasources: {
        db: {
          url: process.env.DATABASE_URL,
        },
      },
      // Add connection pool settings
      connection: {
        pool: {
          min: 2,
          max: 10,
        },
      },
    });
  }
}

πŸ’‘ Development Guidelines

Code Style & Standards

TypeScript Configuration

{
  "compilerOptions": {
    "strict": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "esModuleInterop": true
  }
}

Naming Conventions

Type Convention Example
Variables camelCase productName, userId
Constants UPPER_SNAKE_CASE MAX_ITEMS, API_URL
Functions camelCase getUserById(), calculateTotal()
Classes PascalCase ProductService, UserController
Interfaces PascalCase (prefix I) IProduct, IUserResponse
Components PascalCase ProductCard, LoginForm
Files kebab-case user-service.ts, auth-guard.ts

No Hardcoding Rule

❌ Wrong:

const apiUrl = 'http://localhost:3000';
const taxRate = 0.18;

βœ… Correct:

const apiUrl = process.env.VITE_API_URL;
const taxRate = parseFloat(process.env.TAX_RATE || '0.18');

CRITICAL: If a value has no source, FAIL LOUDLY

const apiUrl = process.env.VITE_API_URL;
if (!apiUrl) {
  throw new Error('VITE_API_URL is not defined in environment variables');
}

Error Handling

Backend (NestJS):

@Get(':id')
async getProduct(@Param('id') id: string) {
  try {
    const product = await this.productService.findOne(id);
    if (!product) {
      throw new NotFoundException(`Product with ID ${id} not found`);
    }
    return product;
  } catch (error) {
    this.logger.error(`Error fetching product: ${error.message}`);
    throw error;
  }
}

Frontend (React):

try {
  const response = await api.get(`/products/${id}`);
  setProduct(response.data);
} catch (error) {
  if (axios.isAxiosError(error)) {
    toast.error(error.response?.data?.message || 'Failed to fetch product');
  } else {
    toast.error('An unexpected error occurred');
  }
}

Git Workflow

# Create feature branch from main
git checkout main
git pull origin main
git checkout -b feature/add-invoice-module

# Make changes and commit
git add .
git commit -m "feat: add invoice generation module"

# Push to remote
git push origin feature/add-invoice-module

# Create Pull Request on GitHub

Commit Message Convention

Follow Conventional Commits:

<type>(<scope>): <subject>

<body>

<footer>

Types:

  • feat: New feature
  • fix: Bug fix
  • docs: Documentation changes
  • style: Code style changes (formatting, no logic change)
  • refactor: Code refactoring
  • test: Adding or updating tests
  • chore: Build process or auxiliary tool changes
  • perf: Performance improvements

Examples:

git commit -m "feat(auth): add password reset functionality"
git commit -m "fix(invoice): correct GST calculation for interstate sales"
git commit -m "docs: update README with database setup instructions"
git commit -m "refactor(inventory): optimize stock movement queries"
git commit -m "test(production): add unit tests for batch creation"

Testing

Backend Tests

# Run all tests
npm run test

# Run tests in watch mode
npm run test:watch

# Run test coverage
npm run test:cov

# Run e2e tests
npm run test:e2e

Example Test:

describe('ProductService', () => {
  it('should create a product', async () => {
    const productDto = {
      name: 'Test Product',
      price: 100,
    };
    
    const result = await service.create(productDto);
    
    expect(result).toBeDefined();
    expect(result.name).toBe(productDto.name);
  });
});

Frontend Tests

# Run all tests
npm run test

# Run with coverage
npm run test:coverage

Database Migrations

Creating Migrations

# Create a migration after schema changes
npx prisma migrate dev --name add_expiry_date_to_products

# This will:
# 1. Create a new migration file
# 2. Apply it to the database
# 3. Regenerate Prisma Client

Migration Naming Conventions

  • init - Initial database setup
  • add_<table>_table - New table
  • add_<column>_to_<table> - New column
  • rename_<old>_to_<new> - Rename operation
  • remove_<column>_from_<table> - Delete column
  • update_<table>_indexes - Index changes

Applying Migrations

# Development
npx prisma migrate dev

# Production
npx prisma migrate deploy

# Reset database (CAUTION: Deletes all data)
npx prisma migrate reset

Code Review Checklist

Before submitting a PR, ensure:

  • Code follows naming conventions
  • No hardcoded values (all in .env)
  • Proper error handling implemented
  • TypeScript types properly defined
  • No console.logs in production code
  • API endpoints use proper HTTP methods
  • Role-based authorization implemented
  • Database queries optimized
  • Comments added for complex logic
  • Tests added for new features
  • README updated if needed
  • Commit messages follow convention

🀝 Contributing

We welcome contributions! Here's how you can help:

Getting Started

  1. Fork the repository

    # Click "Fork" on GitHub
  2. Clone your fork

    git clone https://github.com/YOUR-USERNAME/FM-demo.git
    cd FM-demo
  3. Add upstream remote

    git remote add upstream https://github.com/harpreet-2146/FM-demo.git
  4. Create a feature branch

    git checkout -b feature/amazing-feature

Making Changes

  1. Make your changes

  2. Test your changes

    # Backend
    cd backend
    npm run test
    npm run start:dev
    
    # Frontend
    cd frontend
    npm run test
    npm run dev
  3. Commit your changes

    git add .
    git commit -m "feat: add amazing feature"
  4. Push to your fork

    git push origin feature/amazing-feature
  5. Create Pull Request

    • Go to your fork on GitHub
    • Click "Pull Request"
    • Fill in the PR template
    • Link related issues

Pull Request Guidelines

  • Title: Use conventional commit format
  • Description: Clearly describe changes and motivation
  • Screenshots: Add for UI changes
  • Testing: Describe how you tested
  • Breaking Changes: Clearly document any breaking changes

Code Review Process

  1. Maintainer reviews your PR
  2. Address any requested changes
  3. Once approved, PR will be merged
  4. Your contribution is live! πŸŽ‰

πŸ“ License

This project is proprietary software developed for food manufacturing businesses.

All Rights Reserved Β© 2026

For licensing inquiries, please contact the repository owner.


πŸ“ž Support & Contact

Getting Help

Reporting Issues

When reporting bugs, please include:

  1. Environment: OS, Node version, PostgreSQL version
  2. Steps to reproduce: Clear steps to recreate the issue
  3. Expected behavior: What should happen
  4. Actual behavior: What actually happens
  5. Screenshots: If applicable
  6. Error logs: Console output, server logs

Feature Requests

We love hearing your ideas! When requesting features:

  1. Describe the feature: What should it do?
  2. Use case: Why is this needed?
  3. Examples: Similar features in other apps
  4. Impact: Who would benefit from this?

πŸ™ Acknowledgments

Built With

Special Thanks

  • Open-source community for amazing tools
  • All contributors who help improve this project
  • Food manufacturing industry for inspiration

πŸ“ˆ Project Status

Current Version: 1.0.0
Status: Active Development
Built: 2026
Last Updated: February 2026

Roadmap

  • Core authentication & authorization
  • Role-based dashboards
  • Production management
  • Inventory control (SRN/GRN)
  • GST-compliant invoicing
  • Commission tracking
  • Mobile app (React Native)
  • Advanced analytics & ML
  • Multi-warehouse support
  • Integration with accounting software
  • Automated email notifications
  • QR code for batch tracking

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages