Skip to main content

What is StockAPI?

StockAPI is a RESTful API built with Node.js, Express, and MongoDB that enables market sellers to efficiently manage their product inventory and customer orders. Designed exclusively for vendor use, it provides a secure, centralized system for tracking stock levels, processing orders, and managing product catalogs.

Who is it for?

StockAPI is built specifically for:
  • Market sellers who need to track inventory across multiple products
  • Small business owners managing orders and stock levels
  • Vendors who want to automate stock deductions when orders are placed
  • Store managers who need real-time inventory visibility
This API is designed for internal vendor use only and includes role-based authentication to control access.

Key Capabilities

Product Management

Complete CRUD operations for products including stock updates, pricing, and inventory tracking

Order Processing

Create orders with automatic stock deduction and calculate totals with optional discounts

JWT Authentication

Secure token-based authentication with role-based access control for vendors and developers

Contact Forms

Built-in email functionality using Resend for customer communication

Architecture Overview

StockAPI follows a clean, service-oriented architecture:
stockapi/
├── models/           # MongoDB schemas (Product, Order, User)
├── controllers/      # Request handlers and response logic
├── services/         # Business logic layer
├── routes/           # API endpoint definitions
├── middlewares/      # JWT authentication middleware
└── utils/            # Helper functions and scripts

Technology Stack

  • Runtime: Node.js
  • Framework: Express.js 5.x
  • Database: MongoDB (Atlas)
  • Authentication: JWT with bcryptjs password hashing
  • Email: Resend API
  • Deployment: Docker support with GitHub Packages

Data Models

Product Schema

Products are the core inventory items tracked by the system:
{
  brand: String,
  name: String,
  stock: Number,
  price: Number,
  normalizedName: String
}

Order Schema

Orders contain product references with quantities and totals:
{
  products: [
    {
      product: ObjectId,      // Reference to Product
      quantity: Number,        // Min: 1
      customName: String       // Optional
    }
  ],
  total: Number,             // Min: 0
  createdAt: Date,           // Auto-generated
  updatedAt: Date            // Auto-generated
}
When an order is created, stock is automatically deducted from the referenced products. Ensure sufficient inventory before order placement.

Security Features

StockAPI implements multiple security layers:
  1. Password Hashing: User passwords are securely hashed using bcryptjs before storage
  2. JWT Tokens: Authentication via JSON Web Tokens with 4-hour expiration
  3. Protected Routes: Most endpoints require valid JWT in Authorization header
  4. Role-based Access: Users have roles (vendor, developer) that define permissions
  5. CORS Configuration: Cross-origin requests are properly configured

API Endpoint Categories

Products

  • POST /products - Create new product
  • GET /products - List all products (public)
  • GET /products/:id - Get single product
  • GET /search?q=query - Search products
  • PUT /products/:id - Update product
  • DELETE /products/:id - Delete product

Orders

  • POST /orders - Create new order (auto-deducts stock)
  • GET /orders - List all orders
  • DELETE /orders/:id - Delete order

Authentication

  • POST /login - Authenticate and receive JWT token

Contact

  • POST /contact - Send contact form email
All routes except GET /products, POST /login, and POST /contact require authentication via JWT token.

Next Steps

Ready to get started? Head over to the Quickstart guide to set up your development environment and make your first API call.

Build docs developers (and LLMs) love