Skip to content

sakku116/fastapi-ecommerce-restapi

Repository files navigation

E-Commerce REST API (Under Development)

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.

Features

  • 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, and Admin roles.
  • 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.

Tech Stack

  • Framework: FastAPI
  • Database: MongoDB
  • Object Storage: MinIO (for media and file storage)
  • Authentication: JWT & OTP for email verification, password reset, and refresh token

Design and Client

Getting Started

How to run with Docker (bundled with minio & mongodb)

  1. Clone the repository:

    git clone https://github.com/sakku116/fastapi-ecommerce-restapi.git
    cd fastapi-ecommerce-restapi
  2. Configure environment variables:

    Create a .env file. see ./.env.example file for env variable examples.

  3. Run docker compose Run docker compose command:

    docker compose up -d
    

    The API will be accessible at http://localhost:8000 (if use default port)

How to run manually

Prerequisites

  • Python 3.9+
  • MongoDB server
  • MinIO server or S3-compatible storage
  1. Clone the repository:

    git clone https://github.com/sakku116/fastapi-ecommerce-restapi.git
    cd fastapi-ecommerce-restapi
  2. Install dependencies:

    pip install -r requirements.txt

    I recommend to use virtualenv or docker.

  3. Configure environment variables:

    Create a .env file. see ./.env.example file for env variable examples.

  4. Run the application:

    python main.py

    The API will be accessible at http://localhost:8000 (if use default port)

  5. 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 .env file:
      • INITIAL_CUSTOMER_USER_USERNAME
      • INITIAL_CUSTOMER_USER_PASSWORD
      • INITIAL_SELLER_USER_USERNAME
      • INITIAL_SELLER_USER_PASSWORD
      • INITIAL_ADMIN_USER_USERNAME
      • INITIAL_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.

About

E-commerce app backend - FastAPI with Clean Architecture

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages