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
- Host: GitHub
- URL: https://github.com/trhgatu/e-commerce-backend
- Owner: trhgatu
- Created: 2025-04-25T06:53:08.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-06-25T10:45:56.000Z (12 months ago)
- Last Synced: 2025-06-25T11:45:21.789Z (12 months ago)
- Topics: backend, ci-cd, docker, ecommerce, express, github-actions, modular-architecture, mongodb, nodejs, redis, render, socket-io, typescript, vnpay-api, zod
- Language: TypeScript
- Homepage:
- Size: 407 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ๐ ๏ธ E-Commerce Backend โ Modular, Scalable, Production-Ready
[](https://e-commerce-backend-develop.onrender.com/api-docs)
[](https://opensource.org/licenses/MIT)
[](https://www.typescriptlang.org/)
[](https://nodejs.org/)
[](https://www.mongodb.com/atlas)
[](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."*