This repository contains the back-end API for an e-commerce application. The API is designed to power a web admin dashboard for e-commerce managers, providing detailed insights into sales, revenue, and inventory status, as well as allowing the registration of new products. The implementation is done using Python and FastAPI.
To run the API using Docker Compose, follow these steps:
-
Clone the Repository:
git clone https://github.com/Archer0071/e-commerce.git cd e-commerce
-
Create Environment File:
Create a
.env
file in the root directory and define the required environment variables. For example:DATABASE_URL=mysql+mysqlconnector://user:password@mysql/dbname MYSQL_DATABASE=mydatabase MYSQL_USER=myuser MYSQL_PASSWORD=mypassword MYSQL_ROOT_PASSWORD=myrootpassword 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 e-commerce_web_1 python app/init_database.py
-
Access the API:
The API will be accessible at
http://localhost:8000
.
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 schema includes the following tables:
- products: Represents products in the inventory.
- inventory: Tracks the current state of inventory for each product.
- inventory_history: Logs historical changes in inventory.
- sales: Records sales 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:
POST /products/create_product
: Create a new product.DELETE /products/delete/{product_id}
: Delete a product.POST /products/upload/product_image
: Upload an image for a product.GET /products
: Get all products.
-
Sales Endpoints:
POST /sales/
: Create a new sale record.GET /sales
: Get sales data based on date range, product, and category filters.GET /sales/revenue/daily
: Analyze daily revenue.GET /sales/revenue/weekly
: Analyze weekly revenue.GET /sales/revenue/monthly
: Analyze monthly revenue.GET /sales/revenue/annual
: Analyze annual revenue.
-
Inventory Endpoints:
POST /inventory/create_inventory
: Create a new inventory record.GET /inventory
: Get all inventory records.GET /inventory/history/{inventory_id}
: Get the history of inventory changes for a specific product.
Feel free to explore and use these endpoints to manage your e-commerce-inventory application efficiently.
For any issues or inquiries, please contact [[email protected]]. ๐ง