Node, Mongo, Connect. This slogan captures the essence of the backend use of Node.js, MongoDB, and connections to external services to facilitate commerce operations. It's catchy, memorable, and doesn't include the project name.
Table of Contents
The AmazonCloneNodeJS-backend is a robust Node.js solution powering an e-commerce application. It manages user authentication, handles product creation and CRUD operations, routes payment transactions through Stripe, and supports cart functionality. The project initializes with crucial dependencies like Express, Mongoose, and MongoDB, providing a foundation for server setup, CORS, routing, and database interactions. Connections to external services like payment gateways are centralized, ensuring seamless communication between components. This comprehensive backend infrastructure facilitates user registration, product listing, cart manipulation, order processing, and secure access control.
└── AmazonCloneNodeJS-backend/
├── LICENSE
├── README.md
├── baseUrlsPort.js
├── certificates
│ └── X509-cert-2381793436636801278.pem
├── connections.js
├── controllers
│ ├── authController.js
│ ├── cartController.js
│ ├── orderController.js
│ ├── paymentController.js
│ └── productController.js
├── install_package_notes
├── middlewares
│ └── authMiddleWares.js
├── models
│ ├── cartModel.js
│ ├── couponModel.js
│ ├── orderModel.js
│ ├── productModel.js
│ └── userModel.js
├── new.js
├── package-lock.json
├── package.json
├── products.js
├── routes
│ ├── authRouter.js
│ ├── cartRouter.js
│ ├── index.js
│ ├── orderRouter.js
│ ├── paymentRouter.js
│ ├── productRouter.js
│ └── staticRouter.js
├── server.js
├── service
│ └── auth.js
└── views
└── signup.ejs.
| File | Summary |
|---|---|
| baseUrlsPort.js | Export configurable base URL and API endpoint for adding products in this Node.JS backend project. |
| package.json | Initiates Node.js backend project amazonclonebackend with defined dependencies like Express, Mongoose, Stripe, and more in the package.json file. This configuration enables server setup, CORS support, routing, and authentication services within the larger AmazonClone repository framework. |
| products.js | Create and manage product data by exporting a Mongoose model based on a schema, defining title, image URL, price, and rating fields in the repositorys backend architecture. |
| package-lock.json | The connections.js file in the given AmazonCloneNodeJS-backend repository is a crucial component of the projects architecture, which focuses on handling various connections between different services and modules within the system.By analyzing the repository structure, this file can be found under the root directory among other files like controllers and certificates. Its primary purpose lies in managing and establishing links to external services such as payment gateways or databases, enabling seamless data exchange and functionality between components. This centralized approach ensures a consistent and efficient methodology for making external connections throughout the application. |
| server.js | Initialize Express server with CORS and cookie-parser middleware. Configure view engine, content security policy, and error handling. Connect to MongoDB. Import routes for authentication, products, payment, and cart, protecting some with access level restrictions. Listen on defined port. |
| connections.js | Initiates database connection using Mongoose and config data in parent repository. Establishes a connection to MongoDB via the provided URL and optional SSL options upon server startup. |
| install_package_notes | Express for routing, CORS for cross-origin requests, development dependency Nodemon, MongoDB database and connector Mongoose, authentication tokens, user validation (bcrypt, uuid), ELK stack, and payment processor Stripe. |
| new.js | Establishes MongoDB connection for the application using Mongoose and X.509 certificate-based authentication. Configures TestModel schema, retrieves document count from testDB database, and eventually disconnects after operation completion. |
service
| File | Summary |
|---|---|
| auth.js | Generates JSON web tokens for user sessions in this Node.js backend, using the provided secret key. Implements functions to set and get session data from tokens. |
middlewares
| File | Summary |
|---|---|
| authMiddleWares.js | This middleware module handles user session verification by decoding and checking tokens using the auth service. Additionally, it restricts access based on given roles, ensuring secure routes for specific user types. |
models
| File | Summary |
|---|---|
| userModel.js | Model user data with Mongoose in this file, defining schema for fields like username, email, role, and password. Instantiate Mongoose model User and export it for database operations. |
| orderModel.js | Model order schema for an e-commerce platform using Mongoose in Node.js, defining schema for user id, product list with product Id and quantity, shipping address, status, updated at, and payment Id. Creates an Order model to export for further application usage. |
| cartModel.js | Create a Mongoose schema for the cart model in this backend project, defining an email property and an array of products with productId, name, price, total, and quantity properties, as well as subTotalPrice. Exports the Cart model. |
| productModel.js | Model product data by defining its schema using Mongoose in this file. The schema includes essential attributes like name, price, description, and tags for each product. Mongoose converts the schema into a model named Product which is exported for usage within the application. |
| couponModel.js | Creates a Mongoose model, Coupon, for managing coupons within the application, defining schema properties for code, discount type, value, expiration date, usage limit, used count, and product restrictions. |
views
| File | Summary |
|---|---|
| signup.ejs | Create visually engaging sign-up pages for users in this Node.JS application. The views/signup.ejs file is responsible for rendering the HTML structure and content for the sign-up route, enhancing user experience and registration functionality within the backend architecture. |
controllers
| File | Summary |
|---|---|
| paymentController.js | Processes Stripe payments in this Node.JS backend by creating and confirming payment intents. Calculates total price from request items and communicates with the Stripe API to facilitate transactions. |
| productController.js | Create an engaging product controller that handles CRUD operations efficiently using Express and MongoDB. Design routes for adding, getting, editing price, deleting products, and searching with queries. Ensure each action returns appropriate status codes and JSON responses to enable seamless interaction between front-end applications and the back-end server. |
| authController.js | The authController.js file handles user registration and login operations in the application by validating provided email and password inputs against existing records, hashing passwords, creating new users if necessary, and generating session tokens for authentication. |
| cartController.js | Retrieve product details with id.2. Update product quantity.3. Add a new product to cart.4. Delete a product from cart.5. Delete the entire cart.6. View the contents of a cart and total price.7. Calculate the price in real-time. (optional)8. Use coupons and apply discounts (optional).9. Finalize order by checking out and clearing cart. |
| orderController.js | The orderController.js file processes requests for placing single orders, cart orders, getting order details, and retrieving order status. It interacts with the Order model in the cartModel.js for handling various order-related operations. |
routes
| File | Summary |
|---|---|
| orderRouter.js | Routes the incoming requests for order-related functionality in this Amazon clone Node.js backend. Imports orderController functions to handle getting orders, order details, and order status. Exports express router as default. |
| productRouter.js | Define and handle HTTP requests. This file exports Express routers for adding, editing, deleting, getting product details by ID or name, fetching all products, and searching them. (routes/productRouter.js) |
| paymentRouter.js | Manage and process payment transactions by routing requests to appropriate controllers. Routes for creating payment intents and confirming payments using paymentController. |
| staticRouter.js | It exports an Express router handling GET requests for the /signup endpoint, rendering the signup view. Integral to displaying the sign-up page within this backend application. |
| index.js | Navigate through the Express application by handling base URL routes in this file. Routes for homepage, API documentation, and error handling are defined, ensuring seamless interaction with the AmazonCloneNodeJS-backend. |
| cartRouter.js | Route newcomer, cartRouter.js facilitates interactions with the shopping cart. It processes additions, checkout, calculates totals, handles edits, and offers cart viewing, removal, and deletion utilizing linked cartController. |
| authRouter.js | Route file for handling user authentication in express-based backend application. Contains post routes for registration, login, and logout, each dispatching respective functions from authController to process the requests. |
System Requirements:
- JavaScript:
version x.y.z
- Clone the AmazonCloneNodeJS-backend repository:
$ git clone https://github.com/ansumandas441/AmazonCloneNodeJS-backend
- Change to the project directory:
$ cd AmazonCloneNodeJS-backend
- Install the dependencies:
$ npm install
Run AmazonCloneNodeJS-backend using the command below:
$ node app.js
Or:
$ nodemon
Run the test suite using the command below:
$ npm test
-
► INSERT-TASK-1 -
► INSERT-TASK-2 -
► ...
Contributions are welcome! Here are several ways you can contribute:
- Report Issues: Submit bugs found or log feature requests for the
AmazonCloneNodeJS-backendproject. - Submit Pull Requests: Review open PRs, and submit your own PRs.
- Join the Discussions: Share your insights, provide feedback, or ask questions.
Contributing Guidelines
- Fork the Repository: Start by forking the project repository to your github account.
- Clone Locally: Clone the forked repository to your local machine using a git client.
git clone https://github.com/ansumandas441/AmazonCloneNodeJS-backend
- Create a New Branch: Always work on a new branch, giving it a descriptive name.
git checkout -b new-feature-x
- Make Your Changes: Develop and test your changes locally.
- Commit Your Changes: Commit with a clear message describing your updates.
git commit -m 'Implemented new feature x.' - Push to github: Push the changes to your forked repository.
git push origin new-feature-x
- Submit a Pull Request: Create a PR against the original project repository. Clearly describe the changes and their motivations.
- Review: Once your PR is reviewed and approved, it will be merged into the main branch. Congratulations on your contribution!
This project is protected under the LICENSE License. For more details, refer to the LICENSE CATALOG file.
- List any resources, contributors, inspiration, etc. here.