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