A comprehensive NestJS backend API for the Aura Commerce e-commerce platform, featuring multi-vendor support, complete order management, payment processing with Stripe, and advanced analytics.
- JWT-based authentication with refresh token rotation
- Role-based access control (USER, VENDOR, ADMIN)
- Email verification with 6-digit PIN
- Password reset functionality
- Session management with refresh tokens
- User profiles with avatar support
- Address management (multiple addresses per user)
- Email and SMS notification preferences
- User status management (ACTIVE, SUSPENDED, PENDING)
- Vendor registration and shop creation
- Shop approval workflow (PENDING, APPROVED, SUSPENDED, REJECTED)
- Shop profiles with logo, banner, and business information
- Shop ratings and reviews
- Shop followers system
- Featured shops
- Complete product CRUD operations
- Product variants (size, color, etc.)
- Multiple product images with primary image selection
- Category hierarchy (parent-child relationships)
- Brand management
- Inventory tracking with low stock alerts
- Product status (DRAFT, PUBLISHED, OUT_OF_STOCK, DISCONTINUED)
- SEO metadata (meta title, description, keywords)
- Product ratings and reviews
- View count and sold count tracking
- Persistent cart per user
- Cart item management with variant support
- Wishlist functionality
- Complete order lifecycle (PENDING β CONFIRMED β PROCESSING β SHIPPED β DELIVERED)
- Order tracking with carrier and tracking number
- Multiple payment methods (CARD, CASH_ON_DELIVERY, MOBILE_BANKING)
- Payment status tracking (PENDING, PAID, FAILED, REFUNDED)
- Order notes (customer and admin)
- Coupon support with discount calculation
- Stripe integration for card payments
- Payment intent creation
- Webhook handling for payment confirmation
- Refund support
- Return request system (REQUESTED, APPROVED, REJECTED, RECEIVED, REFUNDED)
- Return item tracking
- Refund processing
- Product reviews with 1-5 star ratings
- Review images support
- Verified purchase badges
- Helpful count tracking
- Flexible coupon types (PERCENTAGE, FIXED_AMOUNT, FREE_SHIPPING)
- Usage limits (total and per user)
- Date-based validity
- Minimum purchase requirements
- Category and product restrictions
- Coupon usage tracking
- Real-time notifications for order updates
- Multiple notification types (ORDER_PLACED, ORDER_SHIPPED, PRICE_DROP, etc.)
- Read/unread status
- Page view tracking
- Audit logs for all critical actions
- Sales analytics
- User activity tracking
- Newsletter subscription management
- File uploads with Cloudinary integration
- Store settings (shipping costs, tax rates, return policies)
- Email notifications with Nodemailer
- Rate limiting for API protection
- Swagger API documentation
- Framework: NestJS 11
- Database: PostgreSQL with Prisma ORM
- Authentication: JWT with Passport
- Payment: Stripe
- File Storage: Cloudinary
- Email: Nodemailer
- Validation: class-validator & class-transformer
- Documentation: Swagger/OpenAPI
- Security: bcryptjs, cookie-parser, rate limiting
- Node.js 18+ or higher
- PostgreSQL 14+ or higher
- npm or yarn package manager
- Stripe account (for payments)
- Cloudinary account (for image uploads)
- SMTP server credentials (for emails)
-
Clone the repository
cd aura-commerce-backend -
Install dependencies
npm install
-
Set up environment variables
Create a
.envfile in the root directory with the following variables:# Server Configuration NODE_ENV=development PORT=4000 # Database DATABASE_URL="postgresql://username:password@localhost:5432/aura_commerce?schema=public" # JWT Authentication JWT_SECRET=your-super-secret-jwt-key-change-this-in-production JWT_REFRESH_SECRET=your-super-secret-refresh-key-change-this-in-production JWT_EXPIRES_IN=15m JWT_REFRESH_EXPIRES_IN=7d # Frontend URL (for CORS) FRONTEND_URL=http://localhost:3000 # Stripe STRIPE_SECRET_KEY=sk_test_your_stripe_secret_key STRIPE_WEBHOOK_SECRET=whsec_your_webhook_secret # Cloudinary CLOUDINARY_CLOUD_NAME=your_cloud_name CLOUDINARY_API_KEY=your_api_key CLOUDINARY_API_SECRET=your_api_secret # Email (SMTP) SMTP_HOST=smtp.gmail.com SMTP_PORT=587 SMTP_USER=your-email@gmail.com SMTP_PASS=your-app-password SMTP_FROM=Aura Commerce <noreply@auracommerce.com>
-
Set up the database
# Generate Prisma Client npx prisma generate # Run migrations npx prisma migrate dev # (Optional) Seed the database npm run seed
npm run start:devThe API will be available at http://localhost:4000
# Build the application
npm run build
# Start the production server
npm run start:prodnpm run start:debugWhen running in development mode, Swagger documentation is available at:
http://localhost:4000/docs
# Generate Prisma Client
npx prisma generate
# Create a new migration
npx prisma migrate dev --name migration_name
# Apply migrations in production
npx prisma migrate deploy
# Open Prisma Studio (Database GUI)
npx prisma studio
# Reset database (WARNING: Deletes all data)
npx prisma migrate resetPOST /auth/register- Register new userPOST /auth/login- Login userPOST /auth/logout- Logout userPOST /auth/refresh- Refresh access tokenPOST /auth/verify-email- Verify email with PINPOST /auth/forgot-password- Request password resetPOST /auth/reset-password- Reset passwordGET /auth/me- Get current user
GET /products- List products (with filters, pagination)GET /products/:id- Get product detailsPOST /products- Create product (VENDOR/ADMIN)PATCH /products/:id- Update product (VENDOR/ADMIN)DELETE /products/:id- Delete product (VENDOR/ADMIN)
GET /cart- Get user's cartPOST /cart/items- Add item to cartPATCH /cart/items/:id- Update cart itemDELETE /cart/items/:id- Remove cart itemDELETE /cart- Clear cart
GET /orders- List user's ordersGET /orders/:id- Get order detailsPOST /orders- Create orderPATCH /orders/:id/status- Update order status (VENDOR/ADMIN)PATCH /orders/:id/cancel- Cancel order
POST /payments/create-intent- Create Stripe payment intentPOST /payments/webhook- Stripe webhook handler
GET /shops- List shopsGET /shops/:slug- Get shop detailsPOST /shops- Create shop (VENDOR)PATCH /shops/:id- Update shop (VENDOR)PATCH /shops/:id/approve- Approve shop (ADMIN)
GET /reviews- List reviewsPOST /reviews- Create reviewPATCH /reviews/:id- Update reviewDELETE /reviews/:id- Delete review
GET /coupons- List coupons (ADMIN)POST /coupons- Create coupon (ADMIN)POST /coupons/validate- Validate coupon codePATCH /coupons/:id- Update coupon (ADMIN)DELETE /coupons/:id- Delete coupon (ADMIN)
GET /analytics/dashboard- Get dashboard stats (ADMIN)GET /analytics/sales- Get sales analytics (ADMIN/VENDOR)
# Run unit tests
npm run test
# Run e2e tests
npm run test:e2e
# Run tests with coverage
npm run test:cov- JWT Authentication with access and refresh tokens
- Password hashing with bcryptjs
- Rate limiting to prevent abuse
- CORS configuration for frontend access
- Input validation with class-validator
- SQL injection protection via Prisma
- XSS protection via input sanitization
src/
βββ addresses/ # Address management
βββ analytics/ # Analytics and reporting
βββ auth/ # Authentication & authorization
βββ brands/ # Brand management
βββ cart/ # Shopping cart
βββ categories/ # Product categories
βββ common/ # Shared utilities, filters, interceptors
βββ config/ # Configuration files
βββ coupons/ # Coupon management
βββ database/ # Database module
βββ newsletter/ # Newsletter subscriptions
βββ notifications/ # User notifications
βββ orders/ # Order management
βββ payments/ # Payment processing
βββ products/ # Product management
βββ returns/ # Return requests
βββ reviews/ # Product reviews
βββ settings/ # Store settings
βββ shops/ # Vendor shops
βββ uploads/ # File uploads
βββ users/ # User management
βββ utils/ # Utility functions
βββ wishlist/ # Wishlist functionality
βββ app.module.ts # Root module
βββ main.ts # Application entry point
This backend is configured for Vercel serverless deployment:
-
Install Vercel CLI:
npm i -g vercel
-
Deploy:
vercel
-
Set environment variables in Vercel dashboard
-
Build the application:
npm run build
-
Set environment variables on your server
-
Run migrations:
npx prisma migrate deploy
-
Start the server:
npm run start:prod
-
Install Stripe CLI for local testing:
stripe listen --forward-to localhost:4000/payments/webhook
-
For production, configure webhook in Stripe Dashboard:
- URL:
https://your-domain.com/payments/webhook - Events:
payment_intent.succeeded,payment_intent.payment_failed
- URL:
Email templates are located in the auth service. Customize them for:
- Email verification
- Password reset
- Order confirmations
- Shipping notifications
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the UNLICENSED License.
For support, email mahade.adib45@gmail.com or open an issue in the repository.
Built with β€οΈ using NestJS and Prisma