A REST API backend for an e-commerce application built with FastAPI, MongoDB, and MinIO. This API enables product management, user authentication, product reviews, role-based access control, and more.
- Product Management: Endpoints to create, read, update, and delete products with support for variants (e.g., color, size).
- Review System: Users can submit reviews and ratings (up to 5 points) for products, and the API calculates average ratings.
- Role-Based Access Control (RBAC): Role-specific access for
Customer,Seller, andAdminroles. - User Authentication and OTP Verification: Secure user authentication with JWT, including OTP-based email verification and password reset.
- Refresh Tokens: Support for refresh tokens to renew access tokens without requiring the user to log in again.
- Categories: Organize products into categories to improve discoverability.
- Order Management: Basic order handling for checkout and order history.
- Object Storage: Media uploads and storage with MinIO, compatible with Amazon S3.
- Integrated Wallet: Built-in wallet system to manage user balances, process payments, and handle refunds directly within the platform.
Other payment methods and top-up methods are coming soon.
- Framework: FastAPI
- Database: MongoDB
- Object Storage: MinIO (for media and file storage)
- Authentication: JWT & OTP for email verification, password reset, and refresh token
- Figma Design: https://www.figma.com/community/file/1282297701057617450
- Mobile Client Repository: https://github.com/ericwidhiantara/QuickMart-KMP
-
Clone the repository:
git clone https://github.com/sakku116/fastapi-ecommerce-restapi.git cd fastapi-ecommerce-restapi -
Configure environment variables:
Create a
.envfile. see ./.env.example file for env variable examples. -
Run docker compose Run docker compose command:
docker compose up -dThe API will be accessible at
http://localhost:8000(if use default port)
- Python 3.9+
- MongoDB server
- MinIO server or S3-compatible storage
-
Clone the repository:
git clone https://github.com/sakku116/fastapi-ecommerce-restapi.git cd fastapi-ecommerce-restapi -
Install dependencies:
pip install -r requirements.txt
I recommend to use virtualenv or docker.
-
Configure environment variables:
Create a
.envfile. see ./.env.example file for env variable examples. -
Run the application:
python main.py
The API will be accessible at
http://localhost:8000(if use default port) -
Run the application with specific options:
To run the app with specific options, you can use the following command-line arguments:
python main.py [arguments]
Available Arguments:
--ensure-indexes: Ensures that the necessary indexes are created in the MongoDB database.--ensure-buckets: Ensures that the necessary MinIO buckets are created for file storage.--seed-initial-users: Seeds the database with initial users (e.g., admin, sellers, and customers) if these envs is filled up in.envfile:INITIAL_CUSTOMER_USER_USERNAMEINITIAL_CUSTOMER_USER_PASSWORDINITIAL_SELLER_USER_USERNAMEINITIAL_SELLER_USER_PASSWORDINITIAL_ADMIN_USER_USERNAMEINITIAL_ADMIN_USER_PASSWORD
--seed-initial-categories: Seeds the database with initial product categories.--seed-initial-products: Seeds the database with initial products and product variants.