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

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.
git clone https://github.com/Ahmed-Alabadla/Ecommerce-TrendHub-Backend.git
cd Ecommerce-TrendHub-Backendnpm installnpm run start:devnpm run buildStart the NestJS server and use the API endpoints for e-commerce operations. The API provides authentication, product management, order processing, and payment handling.
| Variable | Description | Example |
|---|---|---|
| DB_USERNAME | Local database username | postgres |
| DB_PASSWORD | Local database password | password123 |
| DB_DATABASE | Local database name | trendhub |
| DB_PORT | Local database port | 5432 |
| DB_HOST | Local database host | localhost |
| DATABASE_URL | Remote PostgreSQL connection string (NEON) | postgresql://username:password@host/database |
| JWT_SECRET_ACCESS | Secret key for access token generation | your-access-token-secret |
| JWT_SECRET_REFRESH | Secret key for refresh token generation | your-refresh-token-secret |
| JWT_EXPIRES_IN_ACCESS | Access token expiration time | 15m |
| JWT_EXPIRES_IN_REFRESH | Refresh token expiration time | 7d |
| DOMAIN | API domain | localhost:3000 |
| APP_FRONTEND_URL | Frontend application URL | http://localhost:3001 |
| DASHBOARD_FRONTEND_URL | Dashboard frontend URL | http://localhost:3002 |
| MAIL_USERNAME | Email service username | your-email@gmail.com |
| MAIL_PASSWORD | Email service password | app-password |
| CLOUDINARY_NAME | Cloudinary cloud name | your-cloud-name |
| CLOUDINARY_API_KEY | Cloudinary API key | 123456789012345 |
| CLOUDINARY_API_SECRET | Cloudinary API secret | your-api-secret |
| STRIPE_SECRET_KEY | Stripe secret key for payments | sk_test_... |
| STRIPE_WEBHOOK_SECRET | Stripe webhook secret for event verification | whsec_... |
| GOOGLE_CLIENT_ID | Google OAuth client ID | your-google-client-id |
| GOOGLE_CLIENT_SECRET | Google OAuth client secret | your-google-client-secret |
| GOOGLE_CALLBACK_URL | Google OAuth callback URL | http://localhost:3000/auth/google/callback |
| Method | Route | Description | Auth Required | Access |
|---|---|---|---|---|
| POST | /api/admin/users | Create a new user (Admin only) | Yes | Private [Admin] |
| GET | /api/admin/users | Get all users (Admin only) | Yes | Private [Admin] |
| GET | /api/admin/users/role/:role | Get users by role (Admin only) | Yes | Private [Admin] |
| GET | /api/admin/users/:id | Get user by ID (Admin only) | Yes | Private [Admin] |
| PATCH | /api/admin/users/:id | Update user by ID (Admin only) | Yes | Private [Admin] |
| DELETE | /api/admin/users/:id | Delete user by ID (Admin only) | Yes | Private [Admin] |
| GET | /api/users/profile | Get current user profile | Yes | Private [Admin, Customer] |
| PATCH | /api/users/profile | Update current user profile | Yes | Private [Admin, Customer] |
| DELETE | /api/users/profile | Delete current user account | Yes | Private [Admin, Customer] |
| Method | Route | Description | Auth Required | Access |
|---|---|---|---|---|
| POST | /api/auth/register | Register a new user | No | Public |
| POST | /api/auth/login | Login user and get JWT tokens | No | Public |
| POST | /api/auth/forgot-password | Send password reset email | No | Public |
| POST | /api/auth/reset-password | Reset user password with token | No | Public |
| GET | /api/auth/verify-email/:id/:verificationToken | Verify user email address | No | Public |
| PATCH | /api/auth/change-password | Change user password | Yes | Private [Admin, Customer] |
| GET | /api/auth/google | Redirect to Google OAuth login page | No | Public |
| GET | /api/auth/google/callback | Google OAuth callback handler | No | Public |
| POST | /api/auth/refresh-token/:refresh-token | Refresh access token using refresh token | Yes | Private [Refresh Token Required] |
| Method | Route | Description | Auth Required | Access |
|---|---|---|---|---|
| GET | /api/dashboard/stats | Get dashboard statistics | Yes | Private [Admin] |
| GET | /api/dashboard/monthly-sales | Get monthly sales data | Yes | Private [Admin] |
| GET | /api/dashboard/recent-orders | Get recent orders | Yes | Private [Admin] |
| Method | Route | Description | Auth Required | Access |
|---|---|---|---|---|
| POST | /api/order/checkout/:paymentMethod | Create order with payment method | Yes | Private [Customer] |
| PATCH | /api/order/checkout/:orderId | Update order status | Yes | Private [Admin] |
| POST | /api/order/checkout/stripe/webhook | Stripe webhook handler | No | Public |
| GET | /api/order/checkout/user | Get current user's orders | Yes | Private [Customer] |
| GET | /api/order/checkout/:userId | Get orders by user ID | Yes | Private [Admin] |
| GET | /api/order/checkout/:id/user | Get specific order details | Yes | Private [Customer] |
| Method | Route | Description | Auth Required | Access |
|---|---|---|---|---|
| POST | /api/products | Create a new product | Yes | Private [Admin] |
| GET | /api/products | Get all products | No | Public |
| GET | /api/products/:id | Get product by ID | No | Public |
| PATCH | /api/products/:id | Update product by ID | Yes | Private [Admin] |
| DELETE | /api/products/:id | Delete product by ID | Yes | Private [Admin] |
| Method | Route | Description | Auth Required | Access |
|---|---|---|---|---|
| POST | /api/cart/:productId | Add product to cart | Yes | Private [Customer] |
| GET | /api/cart/all | Get all carts (Admin only) | Yes | Private [Admin] |
| GET | /api/cart | Get user's cart | Yes | Private [Customer] |
| DELETE | /api/cart/item/:productId | Remove item from cart | Yes | Private [Customer] |
| DELETE | /api/cart | Clear user's cart | Yes | Private [Customer] |
| POST | /api/cart/apply-coupon/:code | Apply coupon to cart | Yes | Private [Customer] |
| DELETE | /api/cart/remove-coupon | Remove coupon from cart | Yes | Private [Customer] |
| Method | Route | Description | Auth Required | Access |
|---|---|---|---|---|
| POST | /api/coupons | Create a new coupon | Yes | Private [Admin] |
| GET | /api/coupons | Get all coupons | Yes | Private [Admin] |
| GET | /api/coupons/:id | Get coupon by ID | Yes | Private [Admin] |
| PATCH | /api/coupons/:id | Update coupon by ID | Yes | Private [Admin] |
| DELETE | /api/coupons/:id | Delete coupon by ID | Yes | Private [Admin] |
| Method | Route | Description | Auth Required | Access |
|---|---|---|---|---|
| POST | /api/categories | Create a new category | Yes | Private [Admin] |
| GET | /api/categories | Get all categories | No | Public |
| GET | /api/categories/:id | Get category by ID | No | Public |
| PATCH | /api/categories/:id | Update category by ID | Yes | Private [Admin] |
| DELETE | /api/categories/:id | Delete category by ID | Yes | Private [Admin] |
| Method | Route | Description | Auth Required | Access |
|---|---|---|---|---|
| POST | /api/sub-categories | Create a new subcategory | Yes | Private [Admin] |
| GET | /api/sub-categories | Get all subcategories | No | Public |
| GET | /api/sub-categories/:id | Get subcategory by ID | No | Public |
| PATCH | /api/sub-categories/:id | Update subcategory by ID | Yes | Private [Admin] |
| DELETE | /api/sub-categories/:id | Delete subcategory by ID | Yes | Private [Admin] |
| Method | Route | Description | Auth Required | Access |
|---|---|---|---|---|
| POST | /api/brands | Create a new brand | Yes | Private [Admin] |
| GET | /api/brands | Get all brands | No | Public |
| GET | /api/brands/:id | Get brand by ID | No | Public |
| PATCH | /api/brands/:id | Update brand by ID | Yes | Private [Admin] |
| DELETE | /api/brands/:id | Delete brand by ID | Yes | Private [Admin] |
| Method | Route | Description | Auth Required | Access |
|---|---|---|---|---|
| POST | /api/reviews/:productId | Create a review for product | Yes | Private [Admin, Customer] |
| GET | /api/reviews | Get all reviews | No | Public |
| GET | /api/reviews/:id | Get review by ID | No | Public |
| PATCH | /api/reviews/:id | Update review by ID | Yes | Private [User who created it] |
| DELETE | /api/reviews/:id | Delete review by ID | Yes | Private [Admin, Customer] |
| Method | Route | Description | Auth Required | Access |
|---|---|---|---|---|
| POST | /api/settings | Create or update settings | Yes | Private [Admin] |
| GET | /api/settings | Get application settings | Yes | Private [Admin] |
| Method | Route | Description | Auth Required | Access |
|---|---|---|---|---|
| POST | /api/suppliers | Create a new supplier | Yes | Private [Admin] |
| GET | /api/suppliers | Get all suppliers | No | Public |
| GET | /api/suppliers/:id | Get supplier by ID | No | Public |
| PATCH | /api/suppliers/:id | Update supplier by ID | Yes | Private [Admin] |
| DELETE | /api/suppliers/:id | Delete supplier by ID | Yes | Private [Admin] |