Skip to content

MERN-Assignment/backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

49 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

TechSL Inventory Management System - Backend

This repository contains the backend implementation of the TechSL Inventory Management System, developed as part of a Rapid Application Development (RAD) group assignment using the MERN stack.

πŸ“‹ Project Overview

TechSL is a comprehensive inventory management system designed to help manage their products, customers, and orders efficiently. This backend provides a robust REST API that handles authentication, inventory tracking, order processing, and customer management.

Key Features

  • πŸ” Authentication & Authorization: JWT-based authentication system for employees and managers
  • πŸ“¦ Product Management: Complete CRUD operations for inventory items with category organization
  • πŸ‘₯ Customer Management: Customer data management and tracking
  • πŸ“Š Order Management: Order processing with detailed order tracking
  • 🏷️ Category Management: Product categorization system
  • πŸ”’ Secure API: Protected routes with middleware authentication
  • πŸ“± CORS Enabled: Ready for frontend integration

πŸ› οΈ Technology Stack

  • Runtime: Node.js
  • Framework: Express.js
  • Database: MongoDB with Mongoose ODM
  • Authentication: JSON Web Tokens (JWT)
  • Password Hashing: bcrypt
  • Environment Management: dotenv
  • Development: nodemon for hot reloading
  • Cross-Origin: CORS enabled for frontend communication

πŸ“ Project Structure

backend/
β”œβ”€β”€ controllers/           # Business logic controllers
β”‚   β”œβ”€β”€ authController.js     # Authentication logic
β”‚   β”œβ”€β”€ productController.js  # Product management
β”‚   β”œβ”€β”€ customerController.js # Customer management
β”‚   β”œβ”€β”€ orderController.js    # Order processing
β”‚   └── categoryController.js # Category management
β”œβ”€β”€ models/               # MongoDB data models
β”‚   β”œβ”€β”€ Employee-Manager.js   # User authentication model
β”‚   β”œβ”€β”€ Products.js          # Product inventory model
β”‚   β”œβ”€β”€ Customers.js         # Customer data model
β”‚   β”œβ”€β”€ Order.js            # Order management model
β”‚   β”œβ”€β”€ Category.js         # Product category model
β”‚   └── middleware/         # Custom middleware
β”‚       └── authMiddleware.js # JWT authentication middleware
β”œβ”€β”€ routes/               # API route definitions
β”‚   β”œβ”€β”€ Employee-ManagerRoutes.js # Authentication routes
β”‚   β”œβ”€β”€ productRoutes.js         # Product API routes
β”‚   β”œβ”€β”€ customerRoutes.js        # Customer API routes
β”‚   β”œβ”€β”€ orderRoutes.js          # Order API routes
β”‚   └── categoryRoutes.js       # Category API routes
β”œβ”€β”€ index.js              # Main application entry point
β”œβ”€β”€ package.json          # Project dependencies and scripts
└── .env                  # Environment variables (not in repo)

πŸš€ Getting Started

Prerequisites

  • Node.js (v14 or higher)
  • npm or yarn
  • MongoDB Atlas account or local MongoDB installation

Installation

  1. Clone the repository

    git clone https://github.com/MERN-Assignment/backend.git
    cd backend
  2. Install dependencies

    npm install
  3. Environment Setup Create a .env file in the root directory with the following variables:

    MONGODB_URI=your_mongodb_connection_string
    PORT=3001
    JWT_SECRET=your_jwt_secret_key
  4. Start the development server

    npm start

The server will start on http://localhost:3001 (or your specified PORT).

πŸ”Œ API Endpoints

Authentication (/api/employees)

  • GET / - Get all employees (protected)
  • POST / - Create new employee
  • POST /verify - Employee login verification
  • GET /:id - Get employee by ID (protected)
  • PUT /:id - Update employee (protected)
  • DELETE /:id - Delete employee (protected)

Products (/api/products)

  • GET / - Get all products
  • POST / - Create or update product
  • POST /add-sellingprice-date - Create inventory entry
  • GET /:id - Get product by ID
  • PUT /:id - Update product
  • DELETE /:id - Delete product
  • PUT /update-inventory/:id - Update product inventory
  • GET /check/:productName/:quantity - Check product availability

Customers (/api/customers)

  • GET / - Get all customers
  • POST / - Create new customer
  • GET /:id - Get customer by ID
  • PUT /:id - Update customer
  • DELETE /:id - Delete customer
  • GET /by-customID/:customID - Get customer by custom ID

Orders (/api/orders)

  • GET / - Get all orders
  • POST / - Create new order
  • GET /:id - Get order by ID
  • PUT /:id - Update order
  • DELETE /:id - Delete order
  • GET /:id/details - Get order with details
  • POST /with-details - Create order with details

Categories (/api/categories)

  • Standard CRUD operations for product categories

πŸ” Authentication Flow

  1. Employee Registration: Create account via POST /api/employees
  2. Login: Authenticate via POST /api/employees/verify
  3. Token Usage: Include JWT token in Authorization header: Bearer <token>
  4. Protected Routes: Most routes require valid JWT token

Example Authentication

// Login
POST /api/employees/verify
{
  "username": "employee_username",
  "password": "employee_password"
}

// Response
{
  "status": "success",
  "message": "Login successful",
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}

// Using token in subsequent requests
Headers: {
  "Authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}

πŸ’Ύ Database Models

Employee-Manager

  • username: Unique employee identifier
  • password: Hashed password for authentication

Product

  • productID: Unique product identifier
  • productName: Product name
  • sellingPrice: Current selling price
  • quantity: Available stock quantity
  • date: Date of inventory entry
  • categoryID: Reference to product category

Customer

  • customer_ID: Unique customer identifier
  • fName: First name
  • lName: Last name
  • email: Customer email address
  • address: Customer address
  • contact_number: Contact phone number

Order

  • orderID: Unique order identifier
  • orderDate: Date of order creation
  • totalPrice: Total order amount
  • customer_ID: Reference to customer
  • orderDetails: Array of order items with product details

Category

  • categoryID: Unique category identifier
  • categoryName: Category name

πŸ”§ Development

Scripts

  • npm start - Start development server with nodemon
  • npm test - Run tests (currently not configured)

Code Style

The project follows standard JavaScript conventions with:

  • Consistent async/await usage
  • Proper error handling with try-catch blocks
  • RESTful API design principles
  • Modular architecture with separation of concerns

πŸš€ Deployment

This backend is designed to be deployed with the corresponding frontend React application to complete the full-stack TechSL inventory management system.

Environment Variables for Production

Ensure the following environment variables are set in your production environment:

  • MONGODB_URI: Production MongoDB connection string
  • PORT: Server port (defaults to 3001)
  • JWT_SECRET: Strong secret key for JWT signing

Note: This is the backend repository only. The complete MERN stack application requires the corresponding React frontend for full functionality.

About

React-based inventory management system backend for techSL - RAD group assignment

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •