This is an Inventory and Cart Management System built using Node.js and Express. It provides functionalities to manage customers, inventory items, discounts, and customer carts. The project utilizes JSON files to persist data and ensures consistent state management across different operations.
- Customer management (sign up, login, authentication)
- Inventory management (add, remove items)
- Cart management (add items to cart, view cart, get total value of cart)
- Discount management (create and apply discounts)
- JSON-based data storage
- Authentication using bearer tokens
├── controllers # Controller logic for different entities
│ ├── customerController.js # Handles customer authentication
│ ├── cartController.js # Manages cart operations
│ ├── discountController.js # Manages discount operations
│ └── inventoryController.js # Manages inventory operations
│
├── data # JSON files for data storage
│ ├── cart.json # Stores cart information
│ ├── customers.json # Stores customer information
│ ├── discounts.json # Stores discount information
│ └── inventory.json # Stores inventory information
│
├── models # Data models
│ ├── Cart.js # Cart model
│ ├── Customer.js # Customer model
│ ├── Discount.js # Discount model
│ └── Inventory.js # Inventory model
│
├── routes # API routes
│ ├── customerRoutes.js # Routes for authentication
│ ├── cartRoutes.js # Routes for cart operations
│ ├── discountRoutes.js # Routes for discount operations
│ └── inventoryRoutes.js # Routes for inventory operations
│
├── utils # Utility functions
│ ├── appError.js # Custom error handling
│ ├── catchAsync.js # Async error handling
│ ├── jsonOp.js # JSON file operations
│
├── app.js # Application setup
└── server.js # Server setup and configuration
- Node.js installed on your machine
- Clone the repository:
git clone <repository-url>
- Navigate to the project directory:
cd inventory-cart-management
- Install the dependencies:
npm install
- Start the server:
npm start
- The server will start on
http://localhost:3000
POST /customer
: Sign up a new customerPOST /customer/login
: Login an existing customer
POST /inventory
: Add a new inventory item - Name, type and quantity is requiredDELETE /inventory
: Remove an inventory item - productId and quantity is required
POST /cart
: Add an item to the cartGET /cart
: Get the current cart of the logged-in customer
POST /discount
: Create a new discountPOST /discount/apply
: Apply a discount to the cart
This project uses bearer tokens for authentication. Include the token in the Authorization
header as Bearer <token>
for protected routes.
cart.json
: Stores cart informationcustomers.json
: Stores customer informationdiscounts.json
: Stores discount informationinventory.json
: Stores inventory information
jsonOp.js
: Provides functions to read and write JSON filestokenUtils.js
: Provides functions to generate and verify JWT tokensappError.js
: Custom error handlingcatchAsync.js
: Utility to catch errors in async functions