In today's digital age, online shopping has become an integral part of our lives. E-commerce platforms have revolutionized the way we purchase products, offering convenience, variety, and accessibility like never before. However, building a robust e-commerce application from scratch can be a complex task, involving various components such as user management, product listings, shopping carts, and order processing.
Imagine you are tasked with creating an e-commerce application that empowers both customers and administrators. The goal is to build a user-friendly platform where customers can effortlessly browse products, add them to their shopping carts, and place orders. Simultaneously, administrators should have tools to manage product inventory, track orders, and ensure a seamless shopping experience.
To tackle this challenge, we will leverage the power of Python and two essential libraries: Flask and Flask-SQLAlchemy. Flask is a lightweight web framework that simplifies web application development, while Flask-SQLAlchemy provides a robust toolkit for database interactions. Together, they form the perfect duo to craft our e-commerce solution.
To guarantee the scalability of our API, we will empower it by modularizing the code and adding cache and rate limit services to control the performance of our API. Additionally, we will guarantee the correct functioning of our endpoints by performing the necessary tests to ensure that the logic is working correctly.
In this project, we will guide you through the process of building an e-commerce application that closely mimics real-world scenarios.
Project Requirements
<aside> š” Note: We've already developed key functionalities for our e-commerce project in "Module 6: API REST Development" and āModule 13: Advanced API REST Developmentā, including models, schemas, and endpoints for Customers and Products. To save time and maintain consistency, consider reusing the Flask-SQLAlchemy project as a foundation for Orders and Shopping Cart components. This approach ensures a unified and efficient codebase, making it easier to integrate new features into the existing solution.
</aside>
Customers: Create the CRUD (Create, Read, Update, Delete) endpoints for managing Customers and their associated CustomerAccounts:
Create Customer: Implement an endpoint to add a new customer to the database. Ensure that you capture essential customer information, including name, email, phone number, unique username and a secure password
Read Customer: Develop an endpoint to retrieve customer details based on their unique identifier (ID). Provide functionality to query and display customer information.
Update Customer: Create an endpoint for updating customer details, allowing modifications to the customer's name, email, and phone number.
Delete Customer: Implement an endpoint to delete a customer from the system based on their ID.
Product Catalog: Create the CRUD (Create, Read, Update, Delete) endpoints for managing Products:
Create Product: Implement an endpoint to add a new product to the e-commerce database. Capture essential product details, such as the product name and price.
Read Product: Develop an endpoint to retrieve product details based on the product's unique identifier (ID). Provide functionality to query and display product information.
Update Product: Create an endpoint for updating product details, allowing modifications to the product name and price.
Delete Product: Implement an endpoint to delete a product from the system based on its unique ID.
List Products: Develop an endpoint to list all available products in the e-commerce platform. Ensure that the list provides essential product information.
View and Manage Product Stock Levels (Bonus): Create an endpoint that allows to view and manage the stock levels of each product in the catalog. Administrators should be able to see the current stock level and make adjustments as needed.
Restock Products When Low (Bonus): Develop an endpoint that monitors product stock levels and triggers restocking when they fall below a specified threshold. Ensure that stock replenishment is efficient and timely.
Order Processing: Develop comprehensive Orders Management functionality to efficiently handle customer orders, ensuring that customers can place, track, and manage their orders seamlessly.
Place Order: Create an endpoint for customers to place new orders, specifying the products they wish to purchase and providing essential order details. Each order should capture the order date and the associated customer.
Retrieve Order: Implement an endpoint that allows customers to retrieve details of a specific order based on its unique identifier (ID). Provide a clear overview of the order, including the order date and associated products.
Track Order: Develop functionality that enables customers to track the status and progress of their orders. Customers should be able to access information such as order dates and expected delivery dates.
Manage Order History (Bonus): Create an endpoint that allows customers to access their order history, listing all previous orders placed. Each order entry should provide comprehensive information, including the order date and associated products.
Cancel Order (Bonus): Implement an order cancellation feature, allowing customers to cancel an order if it hasn't been shipped or completed. Ensure that canceled orders are appropriately reflected in the system.
Calculate Order Total Price (Bonus): Include an endpoint that calculates the total price of items in a specific order, considering the prices of the products included in the order. This calculation should be specific to each customer and each order, providing accurate pricing information.
Shopping cart: The Shopping Cart functionality is a crucial component of any e-commerce platform, allowing customers to add, remove, and manage items they wish to purchase. Here's how you can develop a comprehensive Shopping Cart feature: Add Items to Cart:
Create an endpoint that allows customers to add items to their shopping cart. Customers should be able to specify the quantity of each item they want to add.
Ensure that the item's details, such as name, price, and quantity, are saved in the cart.
Implement functionality that enables customers to remove items from their shopping cart.
Ensure that the cart's total price is updated accordingly after removing an item.
Develop a feature that allows customers to update the quantity of items in their shopping cart.
Ensure that the cart's total price is updated based on the updated quantity.
Create an endpoint that allows customers to view their shopping cart, displaying a list of items, quantities, and the total price.
Ensure that the cart's content is displayed clearly and that customers can easily navigate the cart.
Implement functionality that allows customers to clear their shopping cart, removing all items.
Provide a confirmation prompt before emptying the cart to prevent accidental deletions.
Develop a feature that allows customers to proceed to the checkout process from their shopping cart.
Ensure that the items in the cart are transferred to the checkout process seamlessly.
Create functionality that allows customers to save their shopping cart for later.
Ensure that the saved cart is accessible from the customer's account.
Implement a feature that allows customers to share their shopping cart with others, such as friends or family.
Ensure that the shared cart can be accessed via a unique link.
Include functionality that calculates the estimated shipping costs based on the items in the shopping cart and the customer's location.
Ensure that customers can see the estimated shipping costs before proceeding to checkout.
Database Integration:
Utilize Flask-SQLAlchemy to integrate a MySQL database into the application.
Design and create the necessary Model to represent customers, orders, products, customer management, and any additional features.
Establish relationships between tables to model the application's core functionality.
Ensure proper database connections and interactions for data storage and retrieval.
Modularization code:
The code must be modularized using a layered architecture. The organization of the project must be composed as follows: Controllers, Models, Routes, Services, Utils, Test
The code must have a configuration file to configure all database connections, cache, etc.
Performance improvement with cache and limit implementation:
Use the cache logic only to get requests using the flask-caching library.
Use flask-limiter to limit request consumption to 100 per day for all endpoints generated.
Implement JWT Security
Use the jwt library and implement a token that has a time limit of 1 hour. Additionally, all endpoints except login should require the JWT.
Customer and CustomerAccount endpoints must have the administrator role to be consumed.
Unit test implementation with unittest:
Implement at least 1 test for each endpoint created. Use the unittest and mock library to be able to consider multiple scenarios.
Only implement tests at the service layer
Implementing integration tests from the driver layer using pytest (bonus)
Document API with Swagger library:
Use the Swagger library to be able to generate project documentation
Generate the swagger.yaml file with the documentation of each of the generated endpoints.
The Swagger documentation must have the security implementation by jwt.
GitHub Repository:
Create a GitHub repository for the project and commit code regularly.
Maintain a clean and interactive
README.md
file in the GitHub repository, providing clear instructions on how to run the application and explanations of its features.Include a link to the GitHub repository in the project documentation.
Submission
Upon completing the project, submit your code and video, including all source code files, and the
README.md
file in your GitHub repository to your instructor or designated platform.
Project tips
Python Programming:
Utilize a code generator like
Flask-RESTful
to simplify endpoint creation and API documentation simultaneously.Implement data validation using libraries like
Marshmallow
to ensure input data meets certain criteria.Use Flask's recommended folder structure to organize models, views, and controllers clearly and legibly.
Database Integration:
Use Flask-SQLAlchemy to define database models and establish relationships between them.
Implement pagination in database queries to enhance performance and prevent server overload.
Design and create necessary models to represent customers, orders, products, customer account, and any additional features.
Modularization code:
Break down the code into smaller, manageable modules following a layered architecture.
Use meaningful names for modules, classes, and functions to enhance readability and maintainability.
Consider employing Python's built-in logging module for effective error handling and debugging.
Performance improvement with cache and limit implementation:
Utilize Flask-Caching for caching GET requests to improve performance.
Implement rate limiting with Flask-Limiter to control request consumption and prevent abuse.
Implement JWT Security:
Use the jwt library to handle JWT token generation, validation, and authentication.
Secure endpoints requiring authentication by verifying JWT tokens and extracting user information from them.
Unit test implementation with unittest:
Write concise and focused unit tests for each endpoint and functionality.
Utilize the unittest and mock libraries to isolate components for testing and simulate different scenarios.
Document API with Swagger library:
Employ Flask-Swagger to generate comprehensive API documentation automatically.
Ensure that API documentation is kept up-to-date with changes to endpoints and functionalities.
Include information on authentication requirements, request parameters, and response formats in the documentation.
GitHub Repository:
Commit code regularly to the GitHub repository to track changes and facilitate collaboration.
Follow best practices for version control, such as branching and merging, to manage code changes effectively.