Skip to content

vignesh-kumar-v/FreshCart

Repository files navigation

FreshCart API

A distributed inventory management system built with Express.js and CockroachDB, designed to handle multi-region product inventory with high availability and fault tolerance.

Features

  • 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

Tech Stack

  • Backend: Node.js, Express.js
  • Database: CockroachDB (distributed SQL database)
  • Dependencies:
    • pg - PostgreSQL client for CockroachDB
    • cors - Cross-origin resource sharing
    • dotenv - Environment variable management

Prerequisites

  • Node.js (v14 or higher)
  • CockroachDB cluster (local or cloud)
  • npm or yarn package manager

Installation

  1. Clone the repository:
git clone <your-repo-url>
cd FreshCart
  1. Install dependencies:
npm install
  1. Create a .env file in the root directory:
DB_HOST=localhost
DB_PORT=26257
DB_USER=root
DB_PASSWORD=
DB_NAME=freshcart
PORT=5000
NODE_ENV=development
  1. Test the database connection:
npm test
  1. Import sample products (optional):
npm run import

Usage

Start the server:

npm start

The server will be available at http://localhost:5000

API Endpoints

Health & Monitoring

  • GET /health - Server health check
  • GET /api/cluster/status - CockroachDB cluster status

Products

  • GET /api/products - List products (with pagination & filters)
  • GET /api/products/:id - Get product by ID
  • GET /api/products/region/:region - Get products by region
  • GET /api/products/warehouse/:warehouse - Get products by warehouse
  • POST /api/products - Create new product
  • PUT /api/products/:id - Update product
  • PATCH /api/products/:id/stock - Update stock quantity
  • DELETE /api/products/:id - Delete product

Analytics

  • GET /api/analytics/inventory - Inventory analytics by region
  • GET /api/analytics/warehouse - Warehouse analytics
  • GET /api/analytics/category - Category analytics

Query Parameters

GET /api/products

  • page - Page number (default: 1)
  • limit - Items per page (max: 100, default: 20)
  • region - Filter by region
  • warehouse - Filter by warehouse
  • category - Filter by category
  • search - Search in name, description, or category

Project Structure

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

Development

Testing Database Connection

npm test

Running Performance Tests

node performance-test.js

Fault Tolerance Testing

node fault-tolerance.js

Environment Variables

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

License

ISC

Author

Your Name

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors