Skip to content

Node.js REST API for importing Excel product data and managing categories, subcategories, warranties, and filters in MongoDB.

Notifications You must be signed in to change notification settings

SobhanHaghverdi/backend-task

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

38 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ“ฆ Product Import & Management API

A robust RESTful service built with Node.js, Express, and MongoDB (Mongoose) โ€” designed to import, manage, filter, and query products from Excel at scale.


๐Ÿš€ Overview

This project is a RESTful backend service that imports product data from Excel (.xlsx) into MongoDB and offers powerful querying, filtering, and pagination capabilities.

It is designed with clean data modeling, duplicate prevention, and scalable query patterns for real-world usage such as e-commerce platforms or large inventory systems.

Core Features:

  • Excel-based data ingestion
  • Duplicate prevention based on unique productCode
  • Structured relationships:
    • Category โ†’ Subcategory โ†’ Product
  • Advanced filtering
  • Full-text multi-field search
  • Pagination & sorting
  • Date-based warranty analysis

๐Ÿงฉ Tech Stack

Layer Technology
Runtime Node.js
Framework Express.js
ODM Mongoose
Database MongoDB
File Parser ExcelJS
Validation VineJS
Logging Console
Docs Swagger
Uploader Multer

๐Ÿ“ฆ Installed Packages & Their Usage

This project uses the following core dependencies to support validation, security, file handling, database operations, documentation, and Excel processing:

  1. @vinejs/vine: Used for schema-based validation, especially for validating environment variables and request payloads.

  2. express: Core web framework used to build the REST API.

  3. helmet: Used to improve HTTP security by setting secure response headers.

  4. cors: Manages cross-origin requests for your API.

  5. express-rate-limit: Protects the server from abuse by limiting repeated requests from the same IP.

  6. multer: Handles file uploads, used mainly for importing Excel files..

  7. exceljs: Used to read and process Excel files.

  8. moment-jalaali: Handles Jalali (Persian) dates and converts them to UTC/ISO for MongoDB.

  9. mongoose: ODM (Object Data Mapper) for MongoDB.

  10. swagger-jsdoc: Generates Swagger/OpenAPI specification from JSDoc comments.

  11. swagger-ui-express: Provides Swagger UI to visualize and test API routes.


๐Ÿงฑ Architecture Diagram

flowchart TD
    A[Client / Postman / Frontend]
    B[Express API]

    subgraph Database
        C[(Category)]
        D[(Subcategory)]
        E[(Product)]
    end

    A --> B
    B --> C
    B --> D
    B --> E

    D --> C
    E --> D
Loading

๐Ÿง  Design Highlights

  • โœ… Duplicate-safe import
    Uses productCode as a strict unique identifier
  • ๐Ÿงฉ Normalized data model
    Category โ†’ Subcategory โ†’ Product
  • ๐Ÿ” Multi-field search
    name, productCode, category, subcategory
  • โšก Optimized aggregation pipeline
  • ๐Ÿงฎ Advanced filtering (AND-based)
  • ๐Ÿ—“๏ธ Warranty analysis (active / range filters)
  • ๐Ÿ“„ Detailed import report generation

๐Ÿงฑ Project Structure

backend-task/
โ”œโ”€โ”€ env/
โ”‚   โ”œโ”€โ”€ .env.example
โ”‚   โ”œโ”€โ”€ .env.development
โ”‚   โ”œโ”€โ”€ .env.production
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ common/
โ”‚   โ”‚   โ”œโ”€โ”€ constant
โ”‚   โ”‚   โ”œโ”€โ”€ middlewares
โ”‚   โ”‚   โ”œโ”€โ”€ utils
โ”‚   โ”œโ”€โ”€ config
โ”‚   โ”œโ”€โ”€ modules/
โ”‚   โ”‚   โ”œโ”€โ”€ category
โ”‚   โ”‚   โ””โ”€โ”€ product
โ”‚   โ”‚   โ””โ”€โ”€ index.js
โ”‚   โ”œโ”€โ”€ app.js
โ”‚   โ”œโ”€โ”€ main.js
โ”œโ”€โ”€ .gitignore
โ”œโ”€โ”€ package.json
โ”œโ”€โ”€ pnpm-lock.yaml
โ”œโ”€โ”€ pnpm-workspace.yaml
โ””โ”€โ”€ README.md

๐Ÿงช Sample .env

PORT = 3000
CORS_ORIGIN = "*"
NODE_ENV = "development"
MONGODB_MIN_POOL_SIZE = 5
MONGODB_MAX_POOL_SIZE = 30
MULTER_MAX_FILE_SIZE = 10485760
MONGODB_READ_PREFERENCE = "primaryPreferred"
MONGODB_URI = mongodb://localhost:27017/products

๐Ÿงฐ Development Setup

# 1๏ธโƒฃ Clone the repo
git clone https://github.com/SobhanHaghverdi/backend-task.git

# 2๏ธโƒฃ Install dependencies
pnpm install

# 3๏ธโƒฃ Set up environment
cp env/.env.example env/.env.development

# 4๏ธโƒฃ Start development
pnpm run dev

๐Ÿงฐ Production Setup

# 1๏ธโƒฃ Clone the repo
git clone https://github.com/SobhanHaghverdi/backend-task.git

# 2๏ธโƒฃ Install dependencies
pnpm install

# 3๏ธโƒฃ Set up environment
cp env/.env.example env/.env.production

# 4๏ธโƒฃ Start production
pnpm run start

๐ŸŒ Live Demo

Backend API:
https://backend-task-production-9e5d.up.railway.app/

Swagger:
https://backend-task-production-9e5d.up.railway.app/docs

Example Endpoint:

GET /docs.json (Access to generated definition by swagger)
GET /api/products
POST /api/products/import

๐Ÿงช Test Flow

1. Download sample Excel (https://github.com/SobhanHaghverdi/backend-task/blob/develop/reports/test-import.xlsx)
2. Open Swagger `/products/import`
3. Upload the file
4. Check `/products`

About

Node.js REST API for importing Excel product data and managing categories, subcategories, warranties, and filters in MongoDB.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published