A scalable Node.js-based backend for managing an e-commerce platform. This project includes authentication, product and category management, a blog system, user support through a ticketing system, newsletters, and more. It’s designed with a service-based architecture, following best practices for maintainability and scalability.
- Features
- Project Structure
- Installation
- Environment Variables
- Usage
- API Documentation
- API Endpoints
- Contributing
- License
- Authentication & Authorization: Secure login, registration, and role-based access control (RBAC).
- Product Management: Manage products with categories and discounts.
- Blog System: Blog management with categories and comments.
- Support System: Manage user tickets for customer support.
- Notifications: Real-time notifications for users.
- Newsletter: Send newsletters to users.
- Contact Form: Handle user queries through a contact form.
- Validation: Request validation with comprehensive error handling.
The project is organized into multiple layers for better separation of concerns:
src/
|-- configs/
| |-- db.config.js # Database connection configuration
| |-- swagger.config.js # Swagger configuration for API documentation
|-- constants/
| |-- constants.js # Application-wide constants
|-- controllers/ # Route handlers for different modules
| |-- auth.controller.js
| |-- blog.controller.js
| |-- categories.controller.js
| |-- ... # Other controllers
|-- middlewares/
| |-- guard/
| |-- authenticate.guard.js # JWT authentication guard
| |-- permission.guard.js # Role-based access control guard
| |-- tags.middleware.js # Middleware for managing tags
| |-- uploader.middleware.js # File upload handling
|-- models/ # Mongoose models for database schemas
| |-- ban.model.js
| |-- blog.model.js
| |-- ... # Other models
|-- routes/ # Define routes for each module
| |-- swagger/ # Swagger documentation for APIs
| |-- auth.routes.js
| |-- blog.routes.js
| |-- ... # Other routes
|-- services/ # Business logic for each module
| |-- auth.service.js
| |-- blog.service.js
| |-- ... # Other services
|-- utils/ # Utility functions
| |-- function.utils.js
| |-- hash.utils.js # Password hashing utilities
| |-- token.utils.js # Token generation and verification
|-- validations/ # Input validation schemas
| |-- auth.validation.js
| |-- blog.validation.js
| |-- ... # Other validations
|-- server.js # Server setup and entry point
|-- .env # Environment variables
|-- .gitignore # Files and folders to be ignored by Git
|-- app.js # Express app setup
|-- package.json # Dependencies and scripts
|-- package-lock.json # Locked dependency versions
- Clone the repository:
git clone https://github.com/your-username/store-project.git
cd store-project
- Install dependencies:
npm install
- Set up environment variables:
- Create a .env file in the root directory.
- Add the following variables:
BASE_URL=http://localhost:5000
PORT=5000
MONGO_URL=mongodb://localhost:27017/shop
ACCESS_TOKEN_SECRET_KEY=""
REFRESH_TOKEN_SECRET_KEY=""
RESET_PASSWORD_SECRET_KEY=""
EMAIL="your-email@gmail.com"
EMAIL_PASSWORD="your passwod in app password"
- Run the server:
npm start
The server will be running at http://localhost:5000.
http://localhost:5000/api-document/
A brief description of the project and what it does.
Here’s a brief overview of the available endpoints:
- POST
/auth/register
- Register a new user. - POST
/auth/login
- Log in with email and password. - POST
/auth/logout
- Log out the user.
- GET
/users
- Retrieve a list of all users. - GET
/users/:id
- Get user details by ID. - PUT
/users/:id
- Update user information. - DELETE
/users/:id
- Delete a user.
- POST
/products
- Create a new product. - GET
/products
- Retrieve all products. - GET
/products/:id
- Get product details by ID. - PUT
/products/:id
- Update product information. - DELETE
/products/:id
- Delete a product.
- POST
/categories
- Create a new category. - GET
/categories
- Get a list of all categories. - GET
/categories/:id
- Get a specific category. - PUT
/categories/:id
- Update category details. - DELETE
/categories/:id
- Delete a category.
- POST
/discounts
- Create a discount code. - GET
/discounts
- Retrieve all discounts. - PUT
/discounts/:id
- Update a discount. - DELETE
/discounts/:id
- Remove a discount.
- POST
/blogs
- Create a new blog post. - GET
/blogs
- Get a list of all blog posts. - GET
/blogs/:id
- Retrieve details of a specific blog post. - PUT
/blogs/:id
- Update blog post. - DELETE
/blogs/:id
- Delete a blog post.
- POST
/comments
- Add a comment to a post. - GET
/comments/:postId
- Get all comments for a specific post. - DELETE
/comments/:id
- Delete a comment.
- POST
/newsletter
- Send a newsletter to users. - GET
/newsletter
- Retrieve a list of all sent newsletters.
- GET
/notifications
- Retrieve user notifications. - PUT
/notifications/mark-seen
- Mark notifications as seen.
- POST
/tickets
- Create a support ticket. - GET
/tickets
- Retrieve all user tickets. - PUT
/tickets/:id
- Respond to a support ticket. - DELETE
/tickets/:id
- Remove a support ticket.
- POST
/roles
- Create a new role. - GET
/roles
- List all roles. - PUT
/roles/:id
- Update a role. - DELETE
/roles/:id
- Delete a role. - POST
/permissions
- Add a permission. - GET
/permissions
- Get all permissions. - PUT
/permissions/:id
- Update a permission. - DELETE
/permissions/:id
- Delete a permission.
Contributions are welcome! To contribute, follow these steps:
- Fork the repository.
- Create a new branch:
git checkout -b feature/YourFeature
- Make your changes.
- Commit your changes:
git commit -m 'Add some feature'
- Push your changes:
git push origin feature/YourFeature
- Open a pull request. After your pull request is reviewed and approved, it will be merged into the main branch.
This project is licensed under the MIT License. See the LICENSE file for more information.
This section provides clear instructions on how to contribute to the project and includes licensing information.