Go back to projects

TrendHub Backend

A robust e-commerce backend API built with NestJS, featuring advanced authentication, payment processing, and cloud storage.

FrameworkNestJS
Use CaseE-commerce
DeploymentVercel
TrendHub Backend

📋 Overview

TrendHub Backend is a comprehensive e-commerce API built with NestJS and TypeScript. Features include JWT authentication, OAuth integration, PostgreSQL database with TypeORM, Stripe payment processing, Cloudinary image uploads, and email notifications.

✨ Features

  • JWT & OAuth authentication (Google)
  • User management with role-based access
  • Product CRUD operations
  • Order management system
  • Stripe payment integration
  • Cloudinary image upload
  • Email notifications
  • PostgreSQL database with TypeORM
  • API documentation with Swagger
  • Environment-based configuration
  • Error handling and validation
  • CORS enabled for frontend integration

🛠️ Technologies Used

NestJSTypeScriptPostgreSQLTypeORMJWT (jsonwebtoken)bcryptStripeCloudinaryOAuth (Google)Nodemailer

📋 Prerequisites

  • Node.js (v18+)
  • PostgreSQL database
  • Stripe account
  • Cloudinary account
  • Google OAuth credentials
  • npm or yarn

🚀 Getting Started

Clone the repository

git clone https://github.com/Ahmed-Alabadla/Ecommerce-TrendHub-Backend.git
cd Ecommerce-TrendHub-Backend

Install dependencies

npm install

Run the development server

npm run start:dev

Build for production

npm run build

💡 Usage

Start the NestJS server and use the API endpoints for e-commerce operations. The API provides authentication, product management, order processing, and payment handling.

🚀 Deployment

  1. Connect repository to Vercel
  2. Configure all environment variables
  3. Deploy automatically on push to main branch

🔐 Environment Variables

VariableDescriptionExample
DB_USERNAMELocal database usernamepostgres
DB_PASSWORDLocal database passwordpassword123
DB_DATABASELocal database nametrendhub
DB_PORTLocal database port5432
DB_HOSTLocal database hostlocalhost
DATABASE_URLRemote PostgreSQL connection string (NEON)postgresql://username:password@host/database
JWT_SECRET_ACCESSSecret key for access token generationyour-access-token-secret
JWT_SECRET_REFRESHSecret key for refresh token generationyour-refresh-token-secret
JWT_EXPIRES_IN_ACCESSAccess token expiration time15m
JWT_EXPIRES_IN_REFRESHRefresh token expiration time7d
DOMAINAPI domainlocalhost:3000
APP_FRONTEND_URLFrontend application URLhttp://localhost:3001
DASHBOARD_FRONTEND_URLDashboard frontend URLhttp://localhost:3002
MAIL_USERNAMEEmail service usernameyour-email@gmail.com
MAIL_PASSWORDEmail service passwordapp-password
CLOUDINARY_NAMECloudinary cloud nameyour-cloud-name
CLOUDINARY_API_KEYCloudinary API key123456789012345
CLOUDINARY_API_SECRETCloudinary API secretyour-api-secret
STRIPE_SECRET_KEYStripe secret key for paymentssk_test_...
STRIPE_WEBHOOK_SECRETStripe webhook secret for event verificationwhsec_...
GOOGLE_CLIENT_IDGoogle OAuth client IDyour-google-client-id
GOOGLE_CLIENT_SECRETGoogle OAuth client secretyour-google-client-secret
GOOGLE_CALLBACK_URLGoogle OAuth callback URLhttp://localhost:3000/auth/google/callback

🛣️ API Routes

USERS ENDPOINT

MethodRouteDescriptionAuth RequiredAccess
POST/api/admin/usersCreate a new user (Admin only)YesPrivate [Admin]
GET/api/admin/usersGet all users (Admin only)YesPrivate [Admin]
GET/api/admin/users/role/:roleGet users by role (Admin only)YesPrivate [Admin]
GET/api/admin/users/:idGet user by ID (Admin only)YesPrivate [Admin]
PATCH/api/admin/users/:idUpdate user by ID (Admin only)YesPrivate [Admin]
DELETE/api/admin/users/:idDelete user by ID (Admin only)YesPrivate [Admin]
GET/api/users/profileGet current user profileYesPrivate [Admin, Customer]
PATCH/api/users/profileUpdate current user profileYesPrivate [Admin, Customer]
DELETE/api/users/profileDelete current user accountYesPrivate [Admin, Customer]

AUTH ENDPOINT

MethodRouteDescriptionAuth RequiredAccess
POST/api/auth/registerRegister a new userNoPublic
POST/api/auth/loginLogin user and get JWT tokensNoPublic
POST/api/auth/forgot-passwordSend password reset emailNoPublic
POST/api/auth/reset-passwordReset user password with tokenNoPublic
GET/api/auth/verify-email/:id/:verificationTokenVerify user email addressNoPublic
PATCH/api/auth/change-passwordChange user passwordYesPrivate [Admin, Customer]
GET/api/auth/googleRedirect to Google OAuth login pageNoPublic
GET/api/auth/google/callbackGoogle OAuth callback handlerNoPublic
POST/api/auth/refresh-token/:refresh-tokenRefresh access token using refresh tokenYesPrivate [Refresh Token Required]

DASHBOARD ENDPOINT

MethodRouteDescriptionAuth RequiredAccess
GET/api/dashboard/statsGet dashboard statisticsYesPrivate [Admin]
GET/api/dashboard/monthly-salesGet monthly sales dataYesPrivate [Admin]
GET/api/dashboard/recent-ordersGet recent ordersYesPrivate [Admin]

ORDER ENDPOINT

MethodRouteDescriptionAuth RequiredAccess
POST/api/order/checkout/:paymentMethodCreate order with payment methodYesPrivate [Customer]
PATCH/api/order/checkout/:orderIdUpdate order statusYesPrivate [Admin]
POST/api/order/checkout/stripe/webhookStripe webhook handlerNoPublic
GET/api/order/checkout/userGet current user's ordersYesPrivate [Customer]
GET/api/order/checkout/:userIdGet orders by user IDYesPrivate [Admin]
GET/api/order/checkout/:id/userGet specific order detailsYesPrivate [Customer]

PRODUCTS ENDPOINT

MethodRouteDescriptionAuth RequiredAccess
POST/api/productsCreate a new productYesPrivate [Admin]
GET/api/productsGet all productsNoPublic
GET/api/products/:idGet product by IDNoPublic
PATCH/api/products/:idUpdate product by IDYesPrivate [Admin]
DELETE/api/products/:idDelete product by IDYesPrivate [Admin]

CART ENDPOINT

MethodRouteDescriptionAuth RequiredAccess
POST/api/cart/:productIdAdd product to cartYesPrivate [Customer]
GET/api/cart/allGet all carts (Admin only)YesPrivate [Admin]
GET/api/cartGet user's cartYesPrivate [Customer]
DELETE/api/cart/item/:productIdRemove item from cartYesPrivate [Customer]
DELETE/api/cartClear user's cartYesPrivate [Customer]
POST/api/cart/apply-coupon/:codeApply coupon to cartYesPrivate [Customer]
DELETE/api/cart/remove-couponRemove coupon from cartYesPrivate [Customer]

COUPON ENDPOINT

MethodRouteDescriptionAuth RequiredAccess
POST/api/couponsCreate a new couponYesPrivate [Admin]
GET/api/couponsGet all couponsYesPrivate [Admin]
GET/api/coupons/:idGet coupon by IDYesPrivate [Admin]
PATCH/api/coupons/:idUpdate coupon by IDYesPrivate [Admin]
DELETE/api/coupons/:idDelete coupon by IDYesPrivate [Admin]

CATEGORIES ENDPOINT

MethodRouteDescriptionAuth RequiredAccess
POST/api/categoriesCreate a new categoryYesPrivate [Admin]
GET/api/categoriesGet all categoriesNoPublic
GET/api/categories/:idGet category by IDNoPublic
PATCH/api/categories/:idUpdate category by IDYesPrivate [Admin]
DELETE/api/categories/:idDelete category by IDYesPrivate [Admin]

SUBCATEGORIES ENDPOINT

MethodRouteDescriptionAuth RequiredAccess
POST/api/sub-categoriesCreate a new subcategoryYesPrivate [Admin]
GET/api/sub-categoriesGet all subcategoriesNoPublic
GET/api/sub-categories/:idGet subcategory by IDNoPublic
PATCH/api/sub-categories/:idUpdate subcategory by IDYesPrivate [Admin]
DELETE/api/sub-categories/:idDelete subcategory by IDYesPrivate [Admin]

BRANDS ENDPOINT

MethodRouteDescriptionAuth RequiredAccess
POST/api/brandsCreate a new brandYesPrivate [Admin]
GET/api/brandsGet all brandsNoPublic
GET/api/brands/:idGet brand by IDNoPublic
PATCH/api/brands/:idUpdate brand by IDYesPrivate [Admin]
DELETE/api/brands/:idDelete brand by IDYesPrivate [Admin]

REVIEWS ENDPOINT

MethodRouteDescriptionAuth RequiredAccess
POST/api/reviews/:productIdCreate a review for productYesPrivate [Admin, Customer]
GET/api/reviewsGet all reviewsNoPublic
GET/api/reviews/:idGet review by IDNoPublic
PATCH/api/reviews/:idUpdate review by IDYesPrivate [User who created it]
DELETE/api/reviews/:idDelete review by IDYesPrivate [Admin, Customer]

SETTINGS ENDPOINT

MethodRouteDescriptionAuth RequiredAccess
POST/api/settingsCreate or update settingsYesPrivate [Admin]
GET/api/settingsGet application settingsYesPrivate [Admin]

SUPPLIERS ENDPOINT

MethodRouteDescriptionAuth RequiredAccess
POST/api/suppliersCreate a new supplierYesPrivate [Admin]
GET/api/suppliersGet all suppliersNoPublic
GET/api/suppliers/:idGet supplier by IDNoPublic
PATCH/api/suppliers/:idUpdate supplier by IDYesPrivate [Admin]
DELETE/api/suppliers/:idDelete supplier by IDYesPrivate [Admin]