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.
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.
- π 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
- 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
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)
- Node.js (v14 or higher)
- npm or yarn
- MongoDB Atlas account or local MongoDB installation
-
Clone the repository
git clone https://github.com/MERN-Assignment/backend.git cd backend
-
Install dependencies
npm install
-
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
-
Start the development server
npm start
The server will start on http://localhost:3001
(or your specified PORT).
GET /
- Get all employees (protected)POST /
- Create new employeePOST /verify
- Employee login verificationGET /:id
- Get employee by ID (protected)PUT /:id
- Update employee (protected)DELETE /:id
- Delete employee (protected)
GET /
- Get all productsPOST /
- Create or update productPOST /add-sellingprice-date
- Create inventory entryGET /:id
- Get product by IDPUT /:id
- Update productDELETE /:id
- Delete productPUT /update-inventory/:id
- Update product inventoryGET /check/:productName/:quantity
- Check product availability
GET /
- Get all customersPOST /
- Create new customerGET /:id
- Get customer by IDPUT /:id
- Update customerDELETE /:id
- Delete customerGET /by-customID/:customID
- Get customer by custom ID
GET /
- Get all ordersPOST /
- Create new orderGET /:id
- Get order by IDPUT /:id
- Update orderDELETE /:id
- Delete orderGET /:id/details
- Get order with detailsPOST /with-details
- Create order with details
- Standard CRUD operations for product categories
- Employee Registration: Create account via
POST /api/employees
- Login: Authenticate via
POST /api/employees/verify
- Token Usage: Include JWT token in Authorization header:
Bearer <token>
- Protected Routes: Most routes require valid JWT token
// 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..."
}
username
: Unique employee identifierpassword
: Hashed password for authentication
productID
: Unique product identifierproductName
: Product namesellingPrice
: Current selling pricequantity
: Available stock quantitydate
: Date of inventory entrycategoryID
: Reference to product category
customer_ID
: Unique customer identifierfName
: First namelName
: Last nameemail
: Customer email addressaddress
: Customer addresscontact_number
: Contact phone number
orderID
: Unique order identifierorderDate
: Date of order creationtotalPrice
: Total order amountcustomer_ID
: Reference to customerorderDetails
: Array of order items with product details
categoryID
: Unique category identifiercategoryName
: Category name
npm start
- Start development server with nodemonnpm test
- Run tests (currently not configured)
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
This backend is designed to be deployed with the corresponding frontend React application to complete the full-stack TechSL inventory management system.
Ensure the following environment variables are set in your production environment:
MONGODB_URI
: Production MongoDB connection stringPORT
: 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.