A distributed inventory management system built with Express.js and CockroachDB, designed to handle multi-region product inventory with high availability and fault tolerance.
- Product Management: Full CRUD operations for inventory items
- Multi-Region Support: Track products across different regions and warehouses
- Real-time Analytics: Inventory analytics by region, warehouse, and category
- Cluster Monitoring: Health checks and cluster status endpoints
- Stock Management: Advanced stock operations (add, subtract, set)
- Pagination & Filtering: Efficient product queries with search and filtering
- Performance Tracking: Query time monitoring for all endpoints
- Backend: Node.js, Express.js
- Database: CockroachDB (distributed SQL database)
- Dependencies:
pg- PostgreSQL client for CockroachDBcors- Cross-origin resource sharingdotenv- Environment variable management
- Node.js (v14 or higher)
- CockroachDB cluster (local or cloud)
- npm or yarn package manager
- Clone the repository:
git clone <your-repo-url>
cd FreshCart- Install dependencies:
npm install- Create a
.envfile in the root directory:
DB_HOST=localhost
DB_PORT=26257
DB_USER=root
DB_PASSWORD=
DB_NAME=freshcart
PORT=5000
NODE_ENV=development- Test the database connection:
npm test- Import sample products (optional):
npm run importStart the server:
npm startThe server will be available at http://localhost:5000
GET /health- Server health checkGET /api/cluster/status- CockroachDB cluster status
GET /api/products- List products (with pagination & filters)GET /api/products/:id- Get product by IDGET /api/products/region/:region- Get products by regionGET /api/products/warehouse/:warehouse- Get products by warehousePOST /api/products- Create new productPUT /api/products/:id- Update productPATCH /api/products/:id/stock- Update stock quantityDELETE /api/products/:id- Delete product
GET /api/analytics/inventory- Inventory analytics by regionGET /api/analytics/warehouse- Warehouse analyticsGET /api/analytics/category- Category analytics
page- Page number (default: 1)limit- Items per page (max: 100, default: 20)region- Filter by regionwarehouse- Filter by warehousecategory- Filter by categorysearch- Search in name, description, or category
FreshCart/
├── server.js # Main Express server
├── db.js # Database configuration
├── import-products.js # Product import utility
├── test-connection.js # Database connection test
├── performance-test.js # Performance testing
├── fault-tolerance.js # Fault tolerance testing
├── index.html # Frontend interface
├── package.json # Dependencies
└── .env # Environment variables
npm testnode performance-test.jsnode fault-tolerance.js| Variable | Description | Default |
|---|---|---|
DB_HOST |
Database host | localhost |
DB_PORT |
Database port | 26257 |
DB_USER |
Database user | root |
DB_PASSWORD |
Database password | (empty) |
DB_NAME |
Database name | freshcart |
PORT |
Server port | 5000 |
NODE_ENV |
Environment | development |
ISC
Your Name