A production-ready, scalable e-commerce backend API built with modern TypeScript, Express, and MongoDB
Features β’ API Documentation β’ Tech Stack β’ Getting Started β’ Project Structure
TechStore Backend is a full-featured REST API designed to power modern e-commerce applications. It provides comprehensive functionality for product management, order processing, user authentication, analytics, and more. Built with industry-standard technologies and following best practices for security, scalability, and maintainability.
- π Secure Authentication - JWT-based auth with refresh tokens and role-based access control
- β Input Validation - Comprehensive Zod schemas for all endpoints
- ποΈ Modular Architecture - Clean MVC pattern with separated business logic
- π Analytics Dashboard - Built-in analytics for business insights
- π Complete Order Management - Full order lifecycle with status tracking
- π¦ Product Catalog - Categories, subcategories, and rich product management
- π₯ User Management - Admin/user roles with profile management
- User Registration - Secure signup with email validation
- JWT Authentication - Access and refresh token mechanism
- Role-Based Access Control - Admin and user roles with granular permissions
- Password Security - Bcrypt hashing with configurable salt rounds
- Token Refresh - Seamless token renewal without re-login
- CRUD Operations - Create, read, update, delete products
- Category System - Hierarchical categories and subcategories
- Rich Product Data - Support for images, specifications, features
- Pricing - Regular price and discount price support
- Search & Filter - Pagination and search capabilities
- Order Creation - Cash on delivery support
- Order Status Updates - Admin can update order statuses
- Order History - Users can view their order history
- Order Validation - Complete input validation for order data
- Sales Analytics - Revenue and order statistics
- User Analytics - User growth and engagement metrics
- Product Analytics - Popular products and inventory insights
- Profile Management - Update user profiles
- Admin Operations - User CRUD by admin
- Password Reset - Secure password reset functionality
- Soft Delete - Safe user deletion with recovery option
- Subscribe/Unsubscribe - Email subscription management
- Status Updates - Manage subscriber status
- Delete Subscribers - Clean subscriber list
| Technology | Version | Purpose |
|---|---|---|
| TypeScript | 5.7 | Type-safe development |
| Node.js | 18+ | Runtime environment |
| Express.js | 4.21 | Web framework |
| MongoDB | Latest | NoSQL database |
| Mongoose | 8.10 | ODM for MongoDB |
| Zod | 3.24 | Schema validation |
| JWT | 9.0 | Authentication tokens |
| Bcrypt | 5.1 | Password hashing |
| date-fns | 4.1 | Date utilities |
http://localhost:5000/api/v1
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| POST | /signup |
Register new user | β No |
| POST | /login |
Login user | β No |
| POST | /refresh-token |
Get new access token | β No |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| POST | /create-product |
Create new product | β Admin |
| PATCH | /edit-product/:id |
Update product | β Admin |
| DELETE | /delete-product/:id |
Delete product | β Admin |
| GET | /get-all-product |
Get all products | β No |
| GET | /:id |
Get product by ID | β No |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| POST | /create-category |
Create category | β Admin |
| GET | /get-all-category |
Get all categories (paginated) | β No |
| GET | /:id |
Get category by ID | β No |
| PATCH | /update-category/:id |
Update category | β Admin |
| DELETE | /delete-category/:id |
Delete category | β Admin |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| POST | /create-subcategory |
Create subcategory | β Admin |
| GET | /get-all-subcategory |
Get all subcategories | β No |
| GET | /:id |
Get subcategory by ID | β No |
| PATCH | /update-subcategory/:id |
Update subcategory | β Admin |
| DELETE | /delete-subcategory/:id |
Delete subcategory | β Admin |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| POST | /create-order |
Create new order | β User/Admin |
| GET | /get-orders |
Get user orders | β User/Admin |
| PATCH | /update-status/:id |
Update order status | β Admin |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| POST | /create-user |
Create user | β Admin |
| GET | /get-all-user |
Get all users | β Admin |
| GET | /get-single-user/:id |
Get user by ID | β Admin |
| PATCH | /update-user/:id |
Update user | β Admin |
| DELETE | /delete-user/:id |
Delete user | β Admin |
| PATCH | /reset-user |
Reset user password | β Admin |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| GET | /get-analytics |
Get analytics data | β User/Admin |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| POST | /create-subscriber |
Add subscriber | β No |
| GET | /get-all-subscriber |
Get all subscribers | β Admin |
| DELETE | /delete-subscriber/:id |
Delete subscriber | β Admin |
| PATCH | /update-status/:id |
Update status | β Admin |
TechStore-Server/
βββ src/
β βββ app.ts # Express app configuration
β βββ server.ts # Server entry point
β βββ app/
β βββ config/
β β βββ index.ts # Environment configuration
β βββ middlewares/
β β βββ authMiddleware.ts # JWT authentication
β β βββ validateRequest.ts # Request validation
β βββ modules/ # Feature modules (MVC)
β β βββ analytics/ # Analytics controller, service, routes
β β βββ auth/ # Authentication logic
β β βββ category/ # Category management
β β βββ order/ # Order processing
β β βββ product/ # Product CRUD
β β βββ subcategory/ # Subcategory management
β β βββ subscriber/ # Newsletter subscriptions
β β βββ user/ # User management
β βββ routes/
β β βββ index.ts # Main router
β βββ utils/
β β βββ parseDate.ts # Utility functions
β βββ validation/ # Zod schemas
β βββ interfaces/ # TypeScript declarations
βββ .env # Environment variables
βββ package.json # Dependencies
βββ tsconfig.json # TypeScript config
βββ README.md # This file
Each module follows a clean, scalable architecture:
module/
βββ module.model.ts # Mongoose schema & model
βββ module.interface.ts # TypeScript interfaces
βββ module.service.ts # Business logic layer
βββ module.controller.ts # Request handlers
βββ module.route.ts # Route definitions
- Node.js 18 or higher
- MongoDB (local or cloud instance)
- npm or yarn package manager
-
Clone the repository
git clone https://github.com/ahad1033/TechStore-Server cd TechStore-Server -
Install dependencies
npm install
-
Environment setup
Create a
.envfile in the root directory:PORT=5000 DATABASE_URL=mongodb://localhost:27017/techstore BCRYPT_SALT_ROUNDS=3 JWT_ACCESS_SECRET=your-super-secret-access-key JWT_ACCESS_EXPIRES_IN=10d JWT_REFRESH_SECRET=your-super-secret-refresh-key JWT_REFRESH_EXPIRES_IN=10d SUPER_ADMIN_PASSWORD=your-admin-password NODE_ENV=development
-
Start the server
# Development mode (with hot reload) npm run start:dev # Production mode npm run build npm start
-
Verify the server
The server will start on
http://localhost:5000
| Variable | Description | Default |
|---|---|---|
PORT |
Server port | 5000 |
DATABASE_URL |
MongoDB connection string | - |
BCRYPT_SALT_ROUNDS |
Password hashing rounds | 9 |
JWT_ACCESS_SECRET |
Access token secret | - |
JWT_ACCESS_EXPIRES_IN |
Access token expiry | 10d |
JWT_REFRESH_SECRET |
Refresh token secret | - |
JWT_REFRESH_EXPIRES_IN |
Refresh token expiry | 10d |
SUPER_ADMIN_PASSWORD |
Default admin password | - |
NODE_ENV |
Environment (dev/prod) | development |
-
Sign Up
POST /api/v1/auth/signup { "name": "John Doe", "email": "john@example.com", "password": "securePassword123", "gender": "male", "phone": "1234567890", "address": "123 Main St" } -
Login
POST /api/v1/auth/login { "email": "john@example.com", "password": "securePassword123" } -
Access Protected Routes
GET /api/v1/orders/get-orders Authorization: Bearer <access_token>
-
Refresh Token
POST /api/v1/auth/refresh-token Cookie: refreshToken=<refresh_token>
- Type Safety - Full TypeScript coverage with strict mode
- Validation - Zod schemas for all input validation
- Error Handling - Consistent error response format
- Security - Bcrypt password hashing, JWT tokens, CORS configured
- Clean Code - Modular architecture, separated concerns
- Scalability - Ready for horizontal scaling
- Maintainability - Clear code structure and documentation
This project is licensed under the MIT License.
Ahad Ahammad Akash
- GitHub: @ahad1033
Contributions, issues, and feature requests are welcome!
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
For support, email ahadahamedakash@gmail.com or open an issue in the repository.
Built with β€οΈ for the e-commerce community
β Star this repo if it helped you!