This project showcases the backend of a product inventory management system built using FastAPI as the framework and MySQL as the database, followed by a Layered Architecture.
- Project Overview and Features
- Setup Instructions
- Dependencies
- Database
- API Endpoints
- Examples Using
- Conclusion
This repository contains a robust backend API for managing a product inventory. This API will be designed to be easily integrated with any future front-end application. The API is designed to power a web admin dashboard for e-commerce managers, providing detailed insights into inventory status and allowing the registration of new products.
To run the API using Docker Compose, follow these steps:
-
Clone the Repository:
git clone https://github.com/LamThanhNguyen/Managing-Product-Inventory.git cd Managing-Product-Inventory
-
Create Environment File:
Create a
.env
file in the root directory and define the required environment variables. For example:DATABASE_URL=mysql+mysqlconnector://admin_x:letdoit123@mysql/managing_product_inventory MYSQL_DATABASE=managing_product_inventory MYSQL_USER=admin_x MYSQL_PASSWORD=letdoit123 MYSQL_ROOT_PASSWORD=root_secure_345@ ENVIRONMENT=development
Update the values based on your database setup.
-
Build and Run with Docker Compose:
docker-compose up --build -d
This command will build the Docker images and start the containers in detached mode.
-
Optional: Initialize Database:
If you want to fill the database with test entries, run the
init_database.py
script inside theapp
folder.docker exec -it managing-product-inventory-webapp-1 python init_database.py
The API uses the following libraries and frameworks:
- FastAPI: A modern, fast (high-performance), web framework for building APIs with Python.
- SQLAlchemy: A SQL toolkit and Object-Relational Mapping (ORM) library for Python.
- MySQL Connector/Python: A MySQL database connector for Python.
- Pydantic: A data validation and settings management library using Python type hints.
- Uvicorn: An ASGI server implementation for running FastAPI applications.
The database includes the following tables:
- products: Represents products in the inventory.
- inventory: Tracks the current state of inventory for each product.
- orders: Records orders transactions.
The relationships between these tables are defined using foreign keys and are crucial for maintaining data integrity.
The API provides the following endpoints:
-
Product Endpoints:
GET /products
: Get a list of all products with pagination and filtering(name, category) options.GET /products/{id}
: Get details of a specific product.POST /products
: Create a new product.PUT /products/{id}
: Update an existing product.DELETE /products/{id}
: Delete a product.
-
Inventory Endpoints:
GET /inventory
: Get inventory levels for all products.GET /inventory/{id}
: Get inventory level for a specific product.
-
Order Endpoints:
POST /orders/
: Create a new order (updating inventory).
- Get a list of all products with pagination and filtering by name and category.
- Get details of a specific product.
- Create a new product.
- Update an existing product.
- Delete a product.
- Get inventory levels for all products.
- Get inventory level for a specific product.
- Create a new order (updating inventory).
Feel free to explore and use these endpoints to manage your e-commerce inventory application efficiently.