E-commerce REST

A extendable-ready, modular REST API for e-commerce platforms with JWT authentication, product management, order workflows, and Razorpay integration.

ecommercerestexpressmongodbmongoosejwtrazorpaybackendapi
v1.0.0bundles

Overview

A full-stack ready e-commerce backend built on Express and MongoDB. Implements authentication, product catalog management, order processing, and Razorpay payment verification. Follows clean MVC patterns with dedicated models, controllers, routes, and middleware. Designed for reuse across storefronts, admin dashboards, or mobile commerce apps.

Installation

CLI
npx backternity add ecommerce-rest-api

What This Does

Installs a complete e-commerce backend foundation with authentication, product CRUD, order flow, Razorpay integration, and secure middleware.

Files & Folders Created

File / PathDescription
/src/models/userModel.jsUser schema with hashed passwords.
/src/models/productModel.jsProduct schema with categories, images, stock.
/src/models/orderModel.jsOrder, order items, status, payment metadata.
/src/controllers/authController.jsRegister, login, profile logic.
/src/controllers/productController.jsProduct search, CRUD, pagination.
/src/controllers/orderController.jsOrder creation, Razorpay order, payment verification.
/src/routes/authRoutes.jsUser auth endpoints.
/src/routes/productRoutes.jsPublic + admin product operations.
/src/routes/orderRoutes.jsOrder/checkout/payment APIs.
/src/middleware/authMiddleware.jsJWT verification + admin guard.
/src/middleware/errorMiddleware.jsCentralized error formatting.
/src/config/db.jsMongoDB connection.
/src/config/razorpay.jsRazorpay instance.
/src/utils/generateToken.jsHelper for JWT access tokens.
server.jsMain Express bootstrap with security middleware.

Files to be modified

File / PathDescription
.envAdds JWT secret, MongoDB URI, Razorpay keys, rate limits.
package.jsonAdds required production dependencies.

Configuration

# Database
MONGODB_URI=mongodb://localhost:27017/backternity-ecom

# Server
PORT=3001
NODE_ENV=development

# JWT
JWT_SECRET=your_32_char_or_longer_secret
JWT_EXPIRES_IN=7d

# Razorpay
RAZORPAY_KEY_ID=your_razorpay_key_id
RAZORPAY_KEY_SECRET=your_razorpay_key_secret

# Misc
API_PREFIX=/api/v1
RATE_LIMIT_WINDOW_MS=60000
RATE_LIMIT_MAX=100

Frontend Integration

These endpoints allow seamless integration with any storefront—Next.js, React, Vue, mobile apps, or server-side frameworks. A typical frontend workflow includes user authentication, product listing, and Razorpay checkout.

POST/api/v1/users/register

Registers a new user account.

POST/api/v1/users/login

Authenticates user credentials and returns JWT token.

GET/api/v1/products

Fetches products with search, filtering, and pagination.

POST/api/v1/orders

Creates an order and a corresponding Razorpay order on the server.

POST/api/v1/orders/:id/payment/verify

Verifies the Razorpay signature and marks the order as paid.

Example

1// Example React flow for Razorpay Checkout 2import { useState } from 'react'; 3 4export default function CheckoutButton() { 5 const [loading, setLoading] = useState(false); 6 7 async function createOrder() { 8 setLoading(true); 9 10 // Step 1: Create server order 11 const res = await fetch('/api/v1/orders', { 12 method: 'POST', 13 headers: { 'Content-Type': 'application/json', 14 Authorization: 'Bearer ' + localStorage.getItem('token') }, 15 body: JSON.stringify({ 16 orderItems: [...], 17 shippingAddress: {...}, 18 paymentMethod: 'razorpay', 19 totalPrice: 1200 20 }) 21 }); 22 23 const data = await res.json(); 24 25 // Step 2: Open Razorpay checkout 26 const rzp = new window.Razorpay({ 27 key: data.razorpay.key, 28 amount: data.razorpay.amount, 29 currency: 'INR', 30 order_id: data.razorpay.id, 31 handler: async function (paymentResponse) { 32 // Step 3: Verify payment 33 await fetch('/api/v1/orders/' + data.orderId + '/payment/verify', { 34 method: 'POST', 35 headers: { 'Content-Type': 'application/json', 36 Authorization: 'Bearer ' + localStorage.getItem('token') }, 37 body: JSON.stringify(paymentResponse) 38 }); 39 } 40 }); 41 42 rzp.open(); 43 setLoading(false); 44 } 45 46 return ( 47 <button onClick={createOrder} disabled={loading}> 48 {loading ? 'Processing…' : 'Checkout with Razorpay'} 49 </button> 50 ); 51}

Usage

1// Protect admin routes 2const express = require('express'); 3const { protect, admin } = require('./src/middleware/authMiddleware'); 4 5const router = express.Router(); 6 7router.post('/products', protect, admin, (req, res) => { 8 res.json({ message: 'Admin access granted' }); 9});

Get in Touch

For partnerships, collaborations, or custom backend components - let’s build something powerful together.

Send us a message

Reach us directly

Email

team@backternity.dev

Quick Answers

Are components free?

Yes, they’re absolutely free to use.

Do you offer custom work?

Absolutely, we build scalable backend systems tailored to your stack.

How often are updates released?

Monthly, with new components, optimizations, and features.

E-commerce REST – Bundles Component | Backternity