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: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:Order Schema
Orders contain product references with quantities and totals:Security Features
StockAPI implements multiple security layers:- Password Hashing: User passwords are securely hashed using bcryptjs before storage
- JWT Tokens: Authentication via JSON Web Tokens with 4-hour expiration
- Protected Routes: Most endpoints require valid JWT in Authorization header
- Role-based Access: Users have roles (vendor, developer) that define permissions
- CORS Configuration: Cross-origin requests are properly configured
API Endpoint Categories
Products
POST /products- Create new productGET /products- List all products (public)GET /products/:id- Get single productGET /search?q=query- Search productsPUT /products/:id- Update productDELETE /products/:id- Delete product
Orders
POST /orders- Create new order (auto-deducts stock)GET /orders- List all ordersDELETE /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.