This project is a scalable backend API for an e-commerce platform, built with Node.js and TypeScript. It provides a comprehensive set of RESTful endpoints to manage users, authentication, products, brands, categories, blogs, wishlists, ratings, coupons, orders, and more. It leverages technologies like JWT for authentication, MongoDB for data storage, and Cloudinary for file uploads. (Under Development...)
- Description
- Features
- Tech Stack
- Installation
- Usage
- Project Structure
- API Endpoints
- Contributing
- License
- Important Links
- Footer
- 🔐 Secure Authentication and Authorization: JWT-based authentication for users and administrators.
- 👤 User Management: Comprehensive endpoints for managing users, including registration, login, profile updates, and password management.
- 🛍️ Product Catalog: APIs to manage products, categories, and brands with advanced filtering capabilities.
- 🛒 Shopping Cart and Order Management: Functionality for managing shopping carts, applying coupons, and processing orders.
- ❤️ Wishlist and Ratings: Support for wishlists and product ratings to enhance the user experience.
- 📝 Blog Management: APIs for creating, updating, and managing blog posts and categories.
- 🎁 Coupon System: Implementation of coupons and discounts with usage limits and expiration dates.
- ☁️ File Uploads: Integration with Cloudinary for handling file uploads.
- ✉️ Email Sending: Email service for sending password reset links and other notifications.
- ⚙️ Query Features: Advanced filtering, sorting, pagination, and search capabilities.
- 🏛️ Modular Design: Well-organized code structure for maintainability and scalability.
- 🛡️ Error Handling: Centralized error handling for consistent error responses.
- TypeScript: Primary language for type safety and maintainability.
- Node.js: Runtime environment for the backend.
- Express: Web framework for building the API.
- Mongoose: ODM for MongoDB.
- JWT: For authentication and authorization.
- Cloudinary: Cloud storage for image uploads.
- bcrypt: For password hashing.
- nodemailer: For sending emails.
- express-validator: For request validation.
- dotenv: For managing environment variables.
- cors: For handling Cross-Origin Resource Sharing.
- morgan: For request logging.
- cookie-parser: For parsing cookies.
- sharp: For image processing.
- slugify: For generating URL-friendly slugs.
- Clone the repository:
git clone https://github.com/KariMuhammad/eCommerceTS.git
cd eCommerceTS- Install dependencies:
npm install
# or
yarn install- Configure environment variables:
Create a .env file based on .env.example and fill in the necessary values, such as:
SERVER_DOMAIN=http://localhost
SERVER_PORT=5000
DB_ATLAS_URI=mongodb+srv://<username>:<password>@<cluster>/<dbname>?retryWrites=true&w=majority
DB_NAME=ecommerce
SECRET_KEY=your-secret-key
REFRESH_TOKEN_KEY=your-refresh-token-key
MAIL_ACCOUNT=your-email@gmail.com
MAIL_PASSWORD_APP=your-email-app-password
CLOUDINARY_CLOUD_NAME=your-cloud-name
CLOUDINARY_API_KEY=your-api-key
CLOUDINARY_API_SECRET=your-api-secret
CLOUDINARY_RESOURCE_LINK=your-resource-link
CORS_ORIGIN=http://localhost:3000
- Set up the database:
Ensure MongoDB is running and the connection URI in .env is correct. You can use a local MongoDB instance or a cloud-based service like MongoDB Atlas.
- Run the development server:
npm run dev
# or
yarn dev- Build for production:
npm run build- Start the production server:
npm start-
Building an E-commerce Platform: This project provides a robust backend API for managing products, users, orders, and more, making it suitable for building a complete e-commerce solution.
-
Developing a Mobile Shopping App: The API can be used to power a mobile shopping app, allowing users to browse products, add items to their cart, and place orders.
-
Creating a Blog for an Online Store: The blog management feature can be used to create a blog for an online store, allowing you to share news, promotions, and other content with your customers.
-
Start the server: Run the development server using
npm run dev2or the production server usingnpm start. -
Access the API endpoints: Use tools like Postman or Insomnia to send requests to the API endpoints. The base URL will be something like
http://localhost:5000(depending on your.envconfiguration). -
Authentication:
- Register a new user:
POST /auth/register - Login a user:
POST /auth/login
After successful login, you will receive an access token. Include this token in the
Authorizationheader of subsequent requests. - Register a new user:
-
Product Management:
- Get all products:
GET /products - Create a new product (Admin only):
POST /products
- Get all products:
-
Cart Management:
- Add an item to the cart:
POST /cart/add - Apply a coupon to the cart:
POST /cart/apply-discount
- Add an item to the cart:
-
Password Reset
- Forgot Password:
POST /auth/forgot-password - Reset Password:
POST /auth/reset-password
- Forgot Password:
-
User Profile
- Accessing user profile:
GET /auth/profile
- Accessing user profile:
-
Coupon Management
- Creating a new coupon (Admin only):
POST /coupons
- Creating a new coupon (Admin only):
-
Product Ratings
- Adding a product rating:
POST /products/:productId/ratings
- Adding a product rating:
├── .env.example # Example environment variables
├── .vscode # VS Code configuration
├── config.ts # Configuration settings
├── database # Database connection
├── src
│ ├── @types # Custom TypeScript definitions
│ ├── common # Common utilities and middleware
│ ├── features # Feature modules
│ │ ├── auth # Authentication feature
│ │ ├── blogs # Blog feature
│ │ ├── brands # Brand feature
│ │ ├── carts # Cart feature
│ │ ├── category # Category feature
│ │ ├── colors # Color feature
│ │ ├── coupons # Coupon feature
│ │ ├── products # Product feature
│ │ ├── reviews # Reviews feature
│ │ ├── user # User feature
│ │ ├── wishlist # Wishlist feature
│ │ └── ... # Other features
│ ├── app.ts # Express application setup
│ └── server.ts # Server entry point
├── package.json # Project dependencies and scripts
├── tsconfig.json # TypeScript configuration
└── README.md # Project documentation
You can find the API documentation on Postman:
Here's a brief overview of the available endpoints:
| Method | Endpoint | Description |
|---|---|---|
| POST | /auth/register |
Register a new user |
| POST | /auth/login |
Log in an existing user |
| POST | /auth/logout |
Log out the current user |
| POST | /auth/refresh |
Refresh the access token |
| POST | /auth/forgot-password |
Request a password reset |
| POST | /auth/reset-password |
Reset the user's password |
| PATCH | /auth/change-password |
Change the user's password |
| GET | /auth/profile |
Get the user's profile |
| Method | Endpoint | Description |
|---|---|---|
| GET | /users |
Get all users |
| GET | /users/:id |
Get a specific user |
| PUT | /users/:id |
Update a user |
| DELETE | /users/:id |
Delete a user |
| Method | Endpoint | Description |
|---|---|---|
| GET | /brands |
Get all brands |
| GET | /brands/:id |
Get a specific brand |
| POST | /brands |
Create a new brand |
| PATCH | /brands/:id |
Update a brand |
| DELETE | /brands/:id |
Delete a brand |
| Method | Endpoint | Description |
|---|---|---|
| GET | /category |
Get all categories |
| GET | /category/:id |
Get a specific category |
| POST | /category |
Create a new category |
| PATCH | /category/:id |
Update a category |
| DELETE | /category/:id |
Delete a category |
| Method | Endpoint | Description |
|---|---|---|
| GET | /products |
Get all products |
| GET | /products/:id |
Get a specific product |
| POST | /products |
Create a new product |
| PATCH | /products/:id |
Update a product |
| DELETE | /products/:id |
Delete a product |
| POST | /products/:productId/ratings |
Add a product rating |
| Method | Endpoint | Description |
|---|---|---|
| GET | /blogs |
Get all blogs |
| GET | /blogs/:id |
Get a specific blog |
| POST | /blogs |
Create a new blog |
| PATCH | /blogs/:id |
Update a blog |
| DELETE | /blogs/:id |
Delete a blog |
| PATCH | /blogs/:id/like |
Like a blog |
| PATCH | /blogs/:id/unlike |
Unlike a blog |
| Method | Endpoint | Description |
|---|---|---|
| GET | /wishlist |
Get all wishlist items |
| POST | /wishlist/add |
Add product to wishlist |
| POST | /wishlist/remove |
Remove product from wishlist |
| Method | Endpoint | Description |
|---|---|---|
| GET | /coupons |
Get all coupons |
| GET | /coupons/:id |
Get a specific coupon |
| POST | /coupons |
Create a new coupon |
| PATCH | /coupons/:id |
Update a coupon |
| DELETE | /coupons/:id |
Delete a coupon |
| POST | /coupons/apply |
Apply a coupon |
| Method | Endpoint | Description |
|---|---|---|
| GET | /cart |
Get the user's cart |
| POST | /cart/add |
Add item to the cart |
| POST | /cart/remove |
Remove item from the cart |
| POST | /cart/clear |
Clear the cart |
| PATCH | /cart/increase |
Increase item quantity in cart |
| PATCH | /cart/decrease |
Decrease item quantity in cart |
| POST | /cart/apply-discount |
Apply a discount to cart |
| GET | /cart/checkout |
Checkout |
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Make your changes and commit them with descriptive messages.
- Push your changes to your fork.
- Submit a pull request to the main repository.
This project has no license.
- API Documentation: https://documenter.getpostman.com/view/23054100/2sAXqv61r7
- GitHub Repository: https://github.com/KariMuhammad/eCommerceTS
<div align="center">
<p>
<a href="https://github.com/KariMuhammad/eCommerceTS">eCommerceTS</a>
| Repository URL: <a href="https://github.com/KariMuhammad/eCommerceTS">https://github.com/KariMuhammad/eCommerceTS</a>
</p>
<p>
Author: Karim Muhammad
</p>
<p>
Contact: <a href="mailto:kimoomar005@gmail.com">kimoomar005@gmail.com</a>
</p>
<p>
⭐️ Consider giving the project a star on GitHub! ⭐️
</p>
<p>
Fork the project | Like the project | Raise issues
</p>
</div>