Skip to content

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Streamoid Product Catalog API

[cite_start]This project is a backend service built for the Streamoid Backend Intern/Fresher take-home exercise[cite: 1, 2]. [cite_start]It simulates a system for online sellers to upload, validate, and manage their product catalogs from a CSV file before listing them on marketplaces[cite: 6, 14].

The application is built with Node.js, Express.js, and SQLite.


Features

  • [cite_start]CSV Upload: Upload a product catalog via a multipart/form-data request[cite: 16].
  • [cite_start]Data Validation: Each row of the CSV is validated against a set of rules (e.g., price <= mrp, required fields)[cite: 17, 33].
  • [cite_start]Database Storage: Valid products are parsed and stored in an SQLite database[cite: 17, 37].
  • [cite_start]Product Listing: An endpoint to list all stored products with pagination support[cite: 18, 40].
  • [cite_start]Product Search: An endpoint to search and filter products by brand, color, and price range[cite: 18, 43].

Setup and Installation

To run this project locally, follow these steps:

  1. Clone the repository:

    git clone <your-github-repository-url>
  2. Navigate to the project directory:

    cd streamoid-backend
  3. Install dependencies:

    npm install
  4. Create the uploads directory: The application requires an uploads folder in the root directory to temporarily store CSV files.

    mkdir uploads
  5. Run the server:

    node src/app.js

    The server will start and be available at http://localhost:8000.


Running with Docker

This application can be built and run using Docker, with no local setup required other than Docker itself.

  1. Build the Docker image:

    docker build -t streamoid-backend .
  2. Run the Docker container:

    docker run -p 8000:8000 streamoid-backend

    The application will be available at http://localhost:8000.

API Documentation

The API provides three main endpoints to manage products.

1. Welcome Route

  • Endpoint: GET /
  • Description: A simple welcome route to confirm that the API is running.
  • Sample Request:
    curl http://localhost:8000/
  • Success Response:
    {
      "status": "success",
      "message": "Streamoid Product API is running."
    }

2. Upload Products CSV

  • [cite_start]Endpoint: POST /upload [cite: 31]
  • Description: Uploads a CSV file of products. [cite_start]The file is parsed, each row is validated, and valid products are stored in the database[cite: 16, 17, 37].
  • Request Body: multipart/form-data with a key file holding the CSV file.
  • Sample Request:
    curl -X POST -F "file=@products.csv" http://localhost:8000/upload
  • Success Response:
    {
      "stored": 3,
      "failed": [
        {
          "row": {
            "sku": "INVALID-ROW",
            "name": "Test Product",
            "brand": "Test Brand",
            "color": "Black",
            "size": "L",
            "mrp": "500",
            "price": "600",
            "quantity": "5"
          },
          "reason": "Price cannot be greater than MRP."
        }
      ]
    }

3. List All Products

  • [cite_start]Endpoint: GET /products [cite: 39]
  • [cite_start]Description: Returns a paginated list of all products stored in the database[cite: 40].
  • Query Parameters:
    • page (optional): The page number to retrieve (default: 1).
    • limit (optional): The number of items per page (default: 10).
  • Sample Request:
    curl "http://localhost:8000/products?page=1&limit=5"
  • Success Response:
    {
      "totalItems": 3,
      "totalPages": 1,
      "currentPage": 1,
      "products": [
        {
          "sku": "TSHIRT-RED-001",
          "name": "Classic Cotton T-Shirt",
          "brand": "Stream Threads",
          "color": "Red",
          "size": "M",
          "mrp": 799,
          "price": 499,
          "quantity": 20,
          "createdAt": "2025-10-13T09:19:50.725Z",
          "updatedAt": "2025-10-13T09:19:50.725Z"
        }
      ]
    }

4. Search Products

  • [cite_start]Endpoint: GET /products/search [cite: 42]
  • [cite_start]Description: Searches for products based on various filter criteria[cite: 43].
  • Query Parameters:
    • [cite_start]brand (optional): Filter by brand name (e.g., ?brand=DenimWorks)[cite: 44].
    • [cite_start]color (optional): Filter by color (e.g., ?color=Red)[cite: 45].
    • [cite_start]minPrice & maxPrice (optional): Filter by a price range (e.g., ?minPrice=500&maxPrice=2000)[cite: 46].
  • Sample Request:
    curl "http://localhost:8000/products/search?brand=Stream+Threads"
  • Success Response:
    [
      {
        "sku": "TSHIRT-RED-001",
        "name": "Classic Cotton T-Shirt",
        "brand": "Stream Threads",
        "color": "Red",
        "size": "M",
        "mrp": 799,
        "price": 499,
        "quantity": 20,
        "createdAt": "2025-10-13T09:19:50.725Z",
        "updatedAt": "2025-10-13T09:19:50.725Z"
      }
    ]

About

This project is a backend service for managing a product catalog. It allows a user to upload a CSV file of products, validates each entry, and stores the valid items in an SQLite database. The service also provides REST APIs to list all products with pagination and to search for products using filters like brand, color, and price.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages