Skip to content

sabiransari1/safar-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Server introduction:

Our E-Commerce Website Backend is the backbone of our application, handling critical operations and ensuring smooth functionality. It serves as the engine that powers product management, user authentication, order processing, and more. With its robust architecture and scalable design, our backend ensures a seamless experience for both customers and administrators. The Backend API is designed to manage the Product and User. It allows clients to read the products through HTTP requests.

Architecture:

The backend follows a three-tier architecture:

Presentation Layer: Accepts HTTP requests and communicates with the Application Layer.

Application Layer: Handles business logic and interacts with the Data Access Layer.

Data Access Layer: Manages interactions with the database.

Key Features:

  • Product Management: Effortlessly add, update, and remove products from the catalog. Categorize and organize products for easy discovery.

  • User Authentication: Secure user registration and authentication to ensure a safe environment. Allow customers to manage their profiles and track their produc history.

  • Favorite and Checkout: Enable customers to add products to their favorite list, proceed to checkout, and complete their purchases securely.

  • Order Processing: Efficiently handle order fulfillment, and payment processing for a seamless customer experience.

  • Inventory Management: Track product availability, stock levels, and handle restocking processes.

  • Discounts and Promotions: Implement special offers, discounts, and promotional campaigns to attract and retain customers.

  • Reporting and Analytics: Generate valuable insights through data-driven reports, helping administrators make informed decisions and optimize business strategies.

Technologies:

Our backend leverages cutting-edge technologies to deliver exceptional performance and maintainability:

  • Node.js: A versatile and efficient JavaScript runtime that powers our server-side logic.

  • Express.js: A flexible and lightweight web application framework that facilitates the development of robust APIs.

  • MongoDB: A powerful NoSQL database for efficient data storage and retrieval.

  • Mongoose: An elegant MongoDB object modeling tool that simplifies data manipulation and validation.

  • JSON Web Tokens (JWT): Securely manage user authentication and authorization.

  • Bcrypt: Securely manage user-sensitive data.

  • RESTful API: We follow REST principles to build an intuitive and predictable API.

  • Custom middleware: A user authentication middleware for Node.js that ensures secure and customizable authentication.

Installation and Setup:

To get started with our E-Commerce Website Backend, follow our easy installation instructions.

  • Install Node.js and npm.

  • Clone the repository from the URL.

  • Run npm install to install the required dependencies.

  • Create a PostgreSQL database named your choose.

  • Set environment variables for database connection: PORT, MONGODB_URL, SECRET_KEY.

  • Run npm start to start the backend server.

Configuration:

  • Environment variables

API Documentation:

For detailed information on the available endpoints, request parameters, and responses, refer to our API Documentation.

PORT: The port on which the server listens (default: 8080).

Base URL: http://localhost:8080/

Endpoints:

These Endpoints are for the user.

  • POST:- /user/register

Note:- Now while registration you have to check that password should contain all the following things, otherwise user cannot register.

At least one uppercase character.

At least one number.

At least a special character.

The length of password should be at least 8 characters long.

  • Description: Create a new user.

  • Request Body: JSON object with properties firstname, lastname, email & password.

  • Response: JSON object with the newly registered user & success message.

  • POST:- /user/login

  • Description: Log in to the registered user.

  • Request Body: JSON object with properties email & password.

  • Response: JSON object with the username, token & success message.

  • POST:- /user/logout

  • Description: Logged out the user.

  • Request Body: Need token to be Logged.

  • Response: Success message.

These Endpoints are for products.

  • GET:- /product/getproducts

Note:- You can use this route also for search based on title, sort based on price, and pagination. Please use these keys to access these functionality title, sortbyprice, pageno, pagelimit.

Please use these category & type key-value pair to perform any operation on these fields.

  1. category: gardening_inputs, type: fertilizers
  2. category: gardening_inputs, type: grow_bags
  3. category: gardening_inputs, type: grow_beds
  4. category: gardening_inputs, type: pots
  5. category: gardening_inputs, type: potting_medium
  6. category: hydroponics, type: accessorie_hydroponics
  7. category: hydroponics, type: diy_kits_hydroponics
  8. category: hydroponics, type: growing_media_hydroponics
  9. category: hydroponics, type: instrument_hydroponics
  10. category: hydroponics, type: nutrient_hydroponics
  11. category: organic_farming,type: bio_fertilizers
  12. category: organic_farming,type: bio_pesticides
  13. category: organic_farming,type: organic_fertilizers
  14. category: seeds, type: flower_seeds
  15. category: seeds, type: fruit_seeds
  16. category: seeds, type: herb_seeds
  17. category: seeds, type: microgreens_seeds
  18. category: seeds, type: vegetable_seeds
  • Description: Get a list of all products or according to params.

  • Response: Array of task objects with properties _id, primary_image, alternative_image, title, price, description, old_price, category & type.

  • GET:- /product/getproduct/:productID

  • Description: Get details of a specific product by its _id.

  • Request Body: Product _id as a string.

  • Response: JSON object with the specific product.

  • POST:- /product/addproduct

  • Description: Create a new product.

  • Request Body: JSON object with properties _id, primary_image, alternative_image, title, price, description, old_price, category & type.

  • Response: JSON object with the newly created product & success message.

  • PATCH:- /product/update/:productID

  • Description: Update the propertie of a product by its _id.

  • Request Body: JSON object with properties _id, primary_image, alternative_image, title, price, description, old_price, category & type.

  • Response: JSON object with the updated product & success message.

  • DELETE:- /product/delete/:productID

  • Description: Delete a product by its _id.

  • Response: Success message.

These Endpoints are for cart.

  • GET:- /cart/cartproducts

  • Description: Get a list of logging user cart products.

  • Response: Array of task objects with properties _id, primary_image, alternative_image, title, price, description, old_price, category & type.

  • POST:- /cart/addtocart/:_id

  • Description: Add a new cart product in the logging user cart lists.

  • Request Body: JSON object with properties _id, primary_image, alternative_image, title, price, description, old_price, category & type.

  • Response: JSON object with the newly created cart product in the logging user cart lists & success message.

  • DELETE:- /cart/delete/:_id

  • Description: Delete a cart product in the logging user cart lists by its _id.

  • Response: Success message.

Data Models:

  • User example:- { firstname: { type: String, required: true }, lastname: { type: String, required: true }, email: { type: String, required: true }, password: { type: String, required: true }, },
  • Product & cart example:- { primary_image: { type: String, required: true }, alternative_image: { type: String, required: true }, title: { type: String, required: true }, price: { type: Number, required: true }, description: { type: String, required: true }, old_price: { type: String, required: false }, category: { type: String, required: true }, type: { type: String, required: true }, },

Error Handling:

  • HTTP status codes 400, 404, and 500 are used for error responses.
  • Error responses include a message field with a description of the error.

Security Considerations:

  • Authentication is implemented in this backend.
  • Do not use this backend in a production environment without proper security measures.