An open API service indexing awesome lists of open source software.

https://github.com/trhgatu/e-commerce-backend

Production-ready E-Commerce Backend โ€“ Modular Node.js + TypeScript + MongoDB + VNPAY IPN + Redis + Docker + CI/CD
https://github.com/trhgatu/e-commerce-backend

backend ci-cd docker ecommerce express github-actions modular-architecture mongodb nodejs redis render socket-io typescript vnpay-api zod

Last synced: 3 months ago
JSON representation

Production-ready E-Commerce Backend โ€“ Modular Node.js + TypeScript + MongoDB + VNPAY IPN + Redis + Docker + CI/CD

Awesome Lists containing this project

README

          

# ๐Ÿ› ๏ธ E-Commerce Backend โ€“ Modular, Scalable, Production-Ready

[![Render](https://img.shields.io/badge/render-live-success?logo=render&style=flat-square)](https://e-commerce-backend-develop.onrender.com/api-docs)
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](https://opensource.org/licenses/MIT)
[![TypeScript](https://img.shields.io/badge/code-typescript-blue?style=flat-square&logo=typescript)](https://www.typescriptlang.org/)
[![Node.js](https://img.shields.io/badge/node.js-18+-brightgreen?style=flat-square&logo=node.js)](https://nodejs.org/)
[![MongoDB](https://img.shields.io/badge/mongoDB-atlas-success?style=flat-square&logo=mongodb)](https://www.mongodb.com/atlas)
[![Swagger](https://img.shields.io/badge/docs-swagger-yellow?style=flat-square&logo=swagger)](https://e-commerce-backend-develop.onrender.com/api-docs)

> A backend system for modern e-commerce platforms, built with **Node.js**, **TypeScript**, **MongoDB**, **Redis**, **Zod**, and **Swagger**, following **modular architecture** for long-term scalability.

---

## ๐Ÿš€ Features

- ๐Ÿ” JWT Authentication with refresh token
- ๐Ÿง‘โ€โš–๏ธ RBAC โ€“ Role & Permission-based access
- ๐Ÿ“ฆ Inventory-aware Cart & Order management
- ๐Ÿ’ฐ Payment via **VNPAY** (IPN webhook supported)
- ๐Ÿท๏ธ Voucher support & discount logic
- โ˜๏ธ Image uploads via **Supabase Storage**
- โšก Redis caching for performance
- ๐Ÿ”Ž Full Swagger API documentation
- ๐Ÿงพ Audit logs via middleware

---

## โš™๏ธ Tech Stack

| Layer | Technology |
|---------------|--------------------------------------|
| Language | Node.js (v18+) + TypeScript |
| Framework | Express.js |
| Database | MongoDB (Mongoose ODM) |
| Auth | JWT + RBAC |
| Caching | Redis Cloud |
| Validation | Zod |
| Docs | Swagger (OpenAPI 3.0) |
| Storage | Supabase |
| Deployment | Docker + Render |

---

## ๐Ÿงฑ Folder Structure

```
src/
โ”œโ”€โ”€ config/ # DB, Redis, Swagger, env
โ”œโ”€โ”€ routes/ # App route entrypoints
โ”œโ”€โ”€ middlewares/ # Auth, logger, validation, etc
โ”œโ”€โ”€ common/ # Utils, base models
โ”œโ”€โ”€ shared/ # Services: redis, upload, usecases
โ”œโ”€โ”€ modules/ # Feature-based modules (DDD)
โ”‚ โ””โ”€โ”€ /
โ”‚ โ”œโ”€โ”€ controller.ts
โ”‚ โ”œโ”€โ”€ service.ts
โ”‚ โ”œโ”€โ”€ route.ts
โ”‚ โ”œโ”€โ”€ model.ts
โ”‚ โ”œโ”€โ”€ validator.ts
โ”‚ โ”œโ”€โ”€ dtos/
โ”‚ โ””โ”€โ”€ docs/
โ”œโ”€โ”€ types/ # Global type declarations
โ””โ”€โ”€ server.ts # App entry
```

---

## ๐Ÿงช Development Setup

```bash
# Clone repo
git clone https://github.com/trhgatu/e-commerce-backend.git
cd e-commerce-backend

# Install deps
npm install

# Setup env
cp .env.example .env
```

Start dev server:

```bash
npm run dev
```

Build & run production:

```bash
npm run build
npm start
```

---

## ๐Ÿ” Authentication & Security

- Access & Refresh token via JWT
- Secure route middleware with `requireAuth`, `requireRole`
- All inputs validated via `Zod`
- Middleware logging for audit & actions
- Redis prevents brute-force login (rate-limit ready)

---

## ๐Ÿ’ผ Major Modules

- **Core:** `auth`, `user`, `role`, `permission`, `log`
- **Product-related:** `product`, `category`, `brand`, `color`, `inventory`
- **Order-related:** `cart`, `order`, `voucher`, `payment (VNPAY)`
- **UX-enhancement:** `wishlist`, `notification`, `address`, `upload-image`

---

## ๐Ÿง  Design Guidelines

- Controller: thin layer to receive & respond
- Service: business logic lives here
- Zod Validator: input check before logic
- Middleware: logging, access control
- Redis: used for pagination cache, single-object cache, and invalidation by pattern

---

## ๐Ÿ› ๏ธ CI/CD โ€“ Render Deployment

- ๐ŸŽฏ Push to GitHub โ†’ auto build & deploy via Render
- ๐Ÿงฑ Docker containerized (multi-env ready)
- ๐Ÿงฉ Supports environment secrets (via Render dashboard)
- ๐Ÿ”„ Auto restart on crash (PM2 inside Docker optional)

---

## ๐Ÿ“˜ API Documentation

- Develop: [`/api-docs`](https://e-commerce-backend-develop.onrender.com/api-docs)
- Production: [`/api-docs`](https://e-commerce-backend-prod-v1.onrender.com/api-docs)
- Built with `swagger-jsdoc` + `swagger-ui-express`
- Each module has `.swagger.ts` for documentation

---

## ๐ŸŒ Environment Variables

.env setup

```env
# Server
PORT=5000
NODE_ENV=development
API_URL=http://localhost:5000/api/v1

# MongoDB
MONGODB_URI=mongodb://localhost:27017/ecommerce

# Redis
REDIS_USERNAME=default
REDIS_HOST=your.redis.host
REDIS_PORT=12345
REDIS_PASSWORD=your_password

# JWT
JWT_SECRET=your_jwt_secret

# Supabase
SUPABASE_URL=https://xyz.supabase.co
SUPABASE_SERVICE_ROLE_KEY=your_supabase_key

# VNPAY
VNP_TMNCODE=your_code
VNP_HASH_SECRET=your_secret
VNP_URL=https://sandbox.vnpayment.vn/paymentv2/vpcpay.html
VNP_RETURN_URL=https://yourdomain.com/api/v1/payments/vnpay/return
```

---

## ๐Ÿ“œ License

MIT License โ€“ feel free to fork, learn, extend, and build your own system on top of it.

---

## โœจ Author

> Built with passion by [**@trhgatu**](https://github.com/trhgatu) โ€“
> *"Coding isn't just solving problems. It's telling the world who I am."*