A production-grade e-commerce backend for selling products. Built with Node.js, Express, TypeScript, Supabase, and Stripe integration.
- User Authentication: Registration, login, password recovery with Supabase Auth
- Product Management: Categories, products, images, inventory management
- Shopping Cart: Cart management with user and guest session support
- Order Processing: Comprehensive order management workflow
- Payment Integration: Secure checkout with Stripe
- Shipping: Shipping calculation, address validation, and tracking
- User Management: User profiles and address book
- Admin Panel: Admin-specific endpoints for managing products, orders, and users
- Security: Input validation, error handling, CORS, and JWT authentication
- Language: TypeScript
- Runtime: Node.js
- Framework: Express.js
- Database: PostgreSQL (via Supabase)
- Authentication: Supabase Auth
- Payment Processing: Stripe
- Validation: Express Validator & Joi
- Error Handling: Custom error classes and middleware
- Logging: Custom logger implementation
├── src/
│ ├── config/ # Configuration files
│ ├── controllers/ # Route controllers
│ ├── middlewares/ # Express middlewares
│ ├── models/ # Data models
│ ├── routes/ # API routes
│ ├── services/ # Business logic
│ ├── types/ # TypeScript type definitions
│ ├── utils/ # Utility functions
│ │ ├── validators/ # Input validation schemas
│ ├── app.ts # Express app setup
│ └── server.ts # Server entry point
├── dist/ # Compiled JavaScript
├── .env # Environment variables
├── .env.example # Example environment variables
├── tsconfig.json # TypeScript configuration
└── package.json # Dependencies
POST /api/auth/register- Register new userPOST /api/auth/login- User loginPOST /api/auth/forgot-password- Password reset requestPOST /api/auth/reset-password- Reset password with tokenGET /api/auth/me- Get current user profile
GET /api/products- List all products (with pagination, filtering, sorting)GET /api/products/search- Search productsGET /api/products/:id- Get product detailsPOST /api/products- Create product (admin only)PUT /api/products/:id- Update product (admin only)DELETE /api/products/:id- Delete product (admin only)GET /api/products/categories- List all categoriesGET /api/products/categories/:id- Get category detailsGET /api/products/categories/:id/products- Get products by category
GET /api/users/me- Get current user profilePUT /api/users/me- Update current user profileGET /api/users/me/addresses- Get user addressesPOST /api/users/me/addresses- Add new addressPUT /api/users/me/addresses/:id- Update addressDELETE /api/users/me/addresses/:id- Delete address
GET /api/cart- Get cart contentsPOST /api/cart/items- Add item to cartPUT /api/cart/items/:id- Update cart itemDELETE /api/cart/items/:id- Remove item from cartDELETE /api/cart- Clear cartGET /api/orders/my-orders- List user ordersGET /api/orders/my-orders/:id- Get order detailsPOST /api/orders/my-orders/:id/cancel- Cancel order
POST /api/shipping/calculate- Calculate shipping ratesPOST /api/shipping/validate-address- Validate shipping addressGET /api/shipping/tracking/:trackingNumber- Get tracking information
POST /api/payment/create-payment-intent- Create payment intentGET /api/payment/payment-status/:paymentIntentId- Check payment statusPOST /api/payment/webhook- Handle Stripe webhook events
GET /api/admin/dashboard- Get dashboard statisticsGET /api/admin/orders- List all ordersGET /api/admin/orders/:id- Get order detailsPUT /api/admin/orders/:id/status- Update order statusGET /api/admin/users- List all usersGET /api/admin/users/:id- Get user details
- Node.js (v16+)
- npm or yarn
- Supabase account
- Stripe account
-
Clone the repository
git clone https://github.com/yourusername/e-commerce-backend.git cd e-commerce-backend -
Install dependencies
npm install
-
Create a
.envfile based on.env.examplecp .env.example .env
-
Set up your Supabase database
- Create a new Supabase project
- Run the database schema SQL from
supabase-schema.sqlin the Supabase SQL editor - Update your
.envfile with your Supabase credentials
-
Set up Stripe
- Create a Stripe account
- Get your API keys and update your
.envfile - Set up webhooks to point to your
/api/payment/webhookendpoint
-
Build the project
npm run build
-
Start the server
npm start
For development:
npm run dev