A RESTful API for managing product inventory with real-time stock tracking, low stock alerts, and CRUD operations for products.
This inventory management system provides:
- Product Management: Create, read, update, and delete products
- Stock Management: Increase/decrease stock quantities with transaction safety
- Low Stock Monitoring: Track products below threshold levels
- Data Validation: Input validation using Zod schemas
- Error Handling: Comprehensive error handling and logging
- API Testing: Complete test suite with Jest and Supertest
| Technology | Version | Use Case |
|---|---|---|
| Node.js | Latest | Runtime environment |
| TypeScript | ^5.9.2 | Type-safe JavaScript development |
| Express.js | ^5.1.0 | Web framework for REST API |
| Prisma | ^6.16.2 | Database ORM and migrations |
| PostgreSQL | Latest | Primary database |
| Zod | ^4.1.11 | Runtime type validation |
| Winston | ^3.17.0 | Logging and monitoring |
| Jest | ^29.7.0 | Testing framework |
| Supertest | ^7.1.4 | HTTP assertion testing |
| CORS | ^2.8.5 | Cross-origin resource sharing |
| Swagger JSDoc | ^6.2.8 | API documentation generation |
| Swagger UI Express | ^5.0.1 | Interactive API documentation |
- Node.js (v18 or higher)
- PostgreSQL database
- npm or yarn package manager
model Product {
id Int @id @default(autoincrement())
name String
description String
stock_quantity Int
low_stock_threshold Int
created_at DateTime @default(now())
updated_at DateTime @updatedAt
}-
Clone the repository
git clone https://github.com/manikanta5827/inventory_management.git cd inventory_management -
Install dependencies
npm install
-
Environment Setup Create a
.envfile in the root directory:DATABASE_URL="postgresql://username:password@localhost:5432/inventory" PORT=8080
-
Database Migration
# Generate Prisma client npx prisma generate # Run database migrations npx prisma migrate deploy
-
Start the application
# Development mode npm run dev # Production mode npm run build npm start
-
Access Swagger Documentation Once the server is running, visit:
http://localhost:8080/api-docs
The project includes comprehensive Swagger/OpenAPI documentation:
- Swagger UI: Visit
http://localhost:8080/api-docswhen the server is running - Interactive Testing: Test all endpoints directly from the Swagger UI
- Schema Validation: Complete request/response schemas with validation rules
- Error Codes: Detailed error response documentation
- Complete API endpoint documentation
- Request/response examples
- Schema definitions with validation rules
- Interactive API testing interface
- Organized by tags (Products, Inventory)
# Run all tests
npm test| Method | Endpoint | Description |
|---|---|---|
POST |
/api/v1/products |
Create a new product |
GET |
/api/v1/products |
Get all products |
GET |
/api/v1/products/:id |
Get product by ID |
PUT |
/api/v1/products/:id |
Update product |
DELETE |
/api/v1/products/:id |
Delete product |
| Method | Endpoint | Description |
|---|---|---|
PUT |
/api/v1/inventory/:id/stock/increase |
Increase stock quantity |
PUT |
/api/v1/inventory/:id/stock/decrease |
Decrease stock quantity |
GET |
/api/v1/inventory/low-stock |
Get low stock products |
Create Product
POST /api/v1/products
Content-Type: application/json
{
"name": "Samsung Galaxy S25",
"description": "Latest smartphone with advanced features",
"stock_quantity": 100,
"low_stock_threshold": 10
}Increase Stock
PUT /api/v1/inventory/1/stock/increase
Content-Type: application/json
{
"amount": 50
}Get Low Stock Products
GET /api/v1/inventory/low-stocksrc/
├── controllers/ # Business logic handlers
├── middlewares/ # Express middleware
├── routes/ # API route definitions
├── schemas/ # Zod validation schemas
├── utils/ # Utility functions (logging)
├── app.ts # Express app configuration
└── server.ts # Server startup