A comprehensive, production-ready e-commerce REST API built with FastAPI that provides complete online shopping functionality. This API serves as a robust backend solution for e-commerce applications, featuring secure user authentication, comprehensive product management, intelligent shopping cart operations, streamlined order processing, and integrated review systems. Designed with modern Python best practices, it offers high performance, automatic API documentation, and scalable architecture suitable for both small businesses and enterprise-level applications.
- User registration and authentication
- JWT-based authorization
- Profile management
- Email validation
- CRUD operations for products
- Product categorization
- Image upload support
- Search and filtering
- Add/remove items from cart
- Update quantities
- Persistent cart storage
- Order creation and tracking
- Order history
- Status updates
- Product reviews and ratings
- User feedback management
- Framework: FastAPI
- Database: PostgreSQL / SQLite
- Authentication: JWT tokens
- Validation: Pydantic v2
- ORM: SQLAlchemy
- Password Hashing: Passlib with bcrypt
- API Documentation: Swagger UI (auto-generated)
- Python 3.8+
- pip or pipenv
- PostgreSQL (optional) or SQLite (for development)
git clone https://github.com/Ktrimalrao/ecommerce-backend-fastapi
cd ecommerce-backend-fastapi
python -m venv venv
# On Windows
venv\Scripts\activate
# On macOS/Linux
source venv/bin/activate
pip install -r requirements.txt
uvicorn app.main:app --reload
The API will be available at:
π http://127.0.0.1:8000
π API Documentation
Swagger UI: http://127.0.0.1:8000/docs
ReDoc: http://127.0.0.1:8000/redoc
E-COMMERCE/
βββ app/
β βββ auth/ # Handles authentication (JWT)
β β βββ init.py
β β βββ jwt_bearer.py # Defines JWTBearer dependency for protected routes
β β βββ jwt_handler.py # Creates and decodes JWT tokens
β βββ crud/ # All CRUD operations for each module
β β βββ init.py
β β βββ carts.py
β β βββ orders.py
β β βββ products.py
β β βββ reviews.py
β β βββ users.py
β βββ models/ # SQLAlchemy models for DB tables
β β βββ init.py
β β βββ cart.py
β β βββ order.py
β β βββ product.py
β β βββ review.py
β β βββ user.py
β βββ routers/ # API endpoints/route definitions
β β βββ init.py
β β βββ carts.py
β β βββ orders.py
β β βββ products.py
β β βββ reviews.py
β β βββ users.py
β βββ schemas/ # Pydantic schemas for request/response validation
β β βββ init.py
β β βββ cart.py
β β βββ order.py
β β βββ product.py
β β βββ review.py
β β βββ users.py
β βββ init.py
β βββ config.py # Configuration and settings (e.g., secret key, DB URL)
β βββ database.py # DB connection using SQLAlchemy
β βββ main.py # FastAPI app entry point
βββ ecomerce.db # SQLite database file (can be replaced with other DB)
βββ README.md # Project documentation
βββ requirements.txt # Python dependencies
βββ venv/ # Python virtual environment (optional - not pushed to Git)
POST /users/register
β Register a new userPOST /users/login
β Login userGET /users/me
β Get current user profile
GET /products/
β List all productsGET /products/{id}
β Get product by IDPOST /products/
β Create a product (admin only)PUT /products/{id}
β Update product (admin only)DELETE /products/{id}
β Delete product (admin only)
GET /cart/
β Retrieve user cartPOST /cart/items
β Add item to cartPUT /cart/items/{id}
β Update cart item quantityDELETE /cart/items/{id}
β Remove cart item
GET /orders/
β Get all user ordersPOST /orders/
β Create a new orderGET /orders/{id}
β Get specific order details
GET /products/{id}/reviews
β Get product reviewsPOST /products/{id}/reviews
β Submit a product review
If you have any questions or need help:
- π Check the documentation
- π Open an issue
- π¬ Contact: trimalrao2004@gmail.com
- Payment gateway integration
- Email notifications
- Product image uploads
- Advanced search with Elasticsearch
- Rate limiting
- API versioning
- Admin dashboard
- Mobile app API enhancements
Your Name
GitHub: Ktrimalrao
Email: trimalrao2004@gmail.com
LinkedIn: K Trimal Rao
- FastAPI β for the amazing framework
- Pydantic β for elegant data validation
- SQLAlchemy β for ORM capabilities
Made with β€οΈ using FastAPI