Enterprise-grade REST API for modern e-commerce platforms
Features β’ Quick Start β’ Documentation β’ API Reference β’ Contributing
Digital E-Commerce Backend is a production-ready, scalable, and secure REST API built with Node.js, Express, and MongoDB. It provides comprehensive features for user management, payment processing, digital wallets, and multi-language support.
- π JWT Authentication with refresh token rotation
- π° PayOS Payment Integration with webhook support
- π³ Digital Wallet System with atomic transactions
- π i18n Support (English, Vietnamese)
- π‘οΈ Enterprise Security (rate limiting, input validation, CORS, Helmet)
- π§ Email Notifications with template system
- ποΈ Clean Architecture (Repository pattern, service layer)
- π§ͺ Test Coverage (unit, integration, e2e)
- User registration with email verification
- JWT-based authentication (access + refresh tokens)
- Role-based access control (User, Staff, Manager, Admin)
- Password reset with secure tokens
- Session management
- PayOS payment gateway integration
- Digital wallet with real-time balance
- Transaction history with audit trail
- Webhook processing for payment updates
- Multi-currency support (VND default)
- Profile management with avatar upload
- Email verification workflow
- Password change and recovery
- User preferences and settings
- Activity tracking
- Transactional emails (Nodemailer)
- Template-based email system
- Multi-language email support
- Background job processing
- Rate limiting (100 req/15min per IP)
- Input validation and sanitization
- XSS and SQL injection protection
- CORS configuration
- Secure HTTP headers (Helmet)
- Environment-based configuration
| Tool | Version | Purpose |
|---|---|---|
| Node.js | β₯ 14.0.0 | Runtime |
| npm/yarn | Latest | Package manager |
| MongoDB | β₯ 4.4 | Database |
| Redis | β₯ 6.0 | Cache & queues (optional) |
# 1. Clone the repository
git clone https://github.com/devnguyen0111/Digital-Ecommerce-BE.git
cd Digital-Ecommerce-BE
# 2. Install dependencies
npm install
# 3. Configure environment
cp .env.example .env
# Edit .env with your configuration
# 4. Start MongoDB
# Windows: net start MongoDB
# macOS/Linux: mongod
# 5. Start the server
npm run dev # Development with hot reload
npm start # Production# Health check
curl http://localhost:5000/health
# Expected response:
# {
# "status": "healthy",
# "timestamp": "2026-02-07T10:30:00.000Z",
# "uptime": 125
# }| Document | Description |
|---|---|
| Architecture | System design and patterns |
| Codebase Overview | Code organization |
| API Reference | Complete API documentation |
| Environment Setup | Configuration guide |
| Coding Conventions | Code standards |
| Contributing | Contribution guidelines |
| Deployment | Production deployment |
| Folder Structure | Directory organization |
| Changelog | Version history |
graph TB
Client[Client Apps]
API[Express Server]
Auth[Auth Middleware]
Routes[Routes Layer]
Controllers[Controllers]
Services[Services]
Repos[Repositories]
DB[(MongoDB)]
Redis[(Redis)]
PayOS[PayOS API]
Email[Email Service]
Client -->|HTTPS| API
API --> Auth
Auth --> Routes
Routes --> Controllers
Controllers --> Services
Services --> Repos
Repos --> DB
Services --> Redis
Services --> PayOS
Services --> Email
| Layer | Purpose | Location |
|---|---|---|
| Routes | API endpoint definition | src/routes/ |
| Middleware | Auth, validation, logging | src/middleware/ |
| Controllers | Request/response handling | src/controllers/ |
| Services | Business logic | src/services/ |
| Repositories | Data access abstraction | src/repositories/ |
| Models | Database schemas | src/models/ |
| Utils | Helper functions | src/utils/ |
Development: http://localhost:5000
Production: https://your-domain.com
Include JWT token in requests:
Authorization: Bearer <your_jwt_token>Request:
POST /api/auth/register
Content-Type: application/json
{
"username": "johndoe",
"email": "john@example.com",
"password": "SecurePass123!",
"preferredLanguage": "en"
}Response:
{
"success": true,
"message": "User registered successfully",
"data": {
"user": {
"id": "507f1f77bcf86cd799439011",
"username": "johndoe",
"email": "john@example.com"
},
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}
}| Category | Endpoint | Method | Auth |
|---|---|---|---|
| Health | /health |
GET | β |
| Auth | /api/auth/register |
POST | β |
| Auth | /api/auth/login |
POST | β |
| Auth | /api/auth/me |
GET | β |
| User | /api/users/profile |
GET | β |
| Wallet | /api/wallet |
GET | β |
| Wallet | /api/wallet/add-funds |
POST | β |
π Full API Documentation: API_REFERENCE.md
- β JWT with refresh token rotation
- β bcrypt password hashing (10 rounds)
- β Rate limiting (100 req/15min)
- β Input validation (express-validator)
- β CORS with origin whitelist
- β Helmet for secure HTTP headers
- β Environment variable protection
- β SQL injection prevention (Mongoose)
- β XSS protection
- Never commit
.envfiles - Use strong JWT secrets (32+ chars)
- Rotate secrets regularly
- Enable HTTPS in production
- Keep dependencies updated
- Run security audits:
npm audit
# Run all tests
npm test
# Run with coverage
npm run test:coverage
# Run specific test suite
npm test -- auth.test.js
# Watch mode
npm test -- --watchWe welcome contributions! Please read our Contributing Guide.
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Commit changes:
git commit -m 'feat: add amazing feature' - Push to branch:
git push origin feature/amazing-feature - Open a Pull Request
We follow Conventional Commits:
feat: add new feature
fix: fix bug
docs: update documentation
style: format code
refactor: restructure code
test: add tests
chore: maintenance tasks
This project is licensed under the ISC License.
Copyright (c) 2026 devnguyen0111
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- GraphQL API support
- WebSocket for real-time updates
- Redis caching layer
- Elasticsearch integration
- Unit & integration tests (Jest)
- CI/CD with GitHub Actions
- Microservices architecture
- Message queue (RabbitMQ/Kafka)
- Advanced analytics
- Multi-vendor support
- Inventory management
- Order tracking system
- Mobile app optimization
- Social authentication
- AI-powered recommendations
- Fraud detection
- Blockchain payments
Built with amazing open-source technologies:
- Express.js - Web framework
- MongoDB - Database
- Mongoose - ODM
- JWT - Authentication
- Nodemailer - Email
- PayOS - Payment gateway
- π Documentation: /docs
- π Issues: GitHub Issues
- π¬ Discussions: GitHub Discussions
devnguyen0111
- GitHub: @devnguyen0111
- Repository: Digital-Ecommerce-BE