A production-style E-Commerce REST API built with FastAPI, PostgreSQL, SQLAlchemy, Docker, and JWT Authentication.
This project demonstrates backend engineering concepts including authentication, role-based authorization, product management, shopping cart functionality, order processing, inventory management, and relational database design.
API Base URL:
https://e-commerce-api-dihq.onrender.com
Swagger Documentation:
https://e-commerce-api-dihq.onrender.com/docs
- User registration
- User login
- JWT-based authentication
- Protected routes
- Create products
- View products
- Update products
- Delete products
- Product search and filtering
- Create categories
- View categories
- Add products to cart
- View cart contents
- Remove cart items
- Checkout cart
- Create orders
- View orders
- View individual order details
- Automatic stock reduction during checkout
- Stock validation before purchases
- Role-based access control
- Admin-only product management
- Python
- FastAPI
- PostgreSQL
- SQLAlchemy
- JWT Authentication
- Docker
- Render
| Method | Endpoint | Description |
|---|---|---|
| POST | /auth/register | Register user |
| POST | /auth/login | Login user |
| Method | Endpoint | Description |
|---|---|---|
| GET | /categories | Get categories |
| POST | /categories | Create category |
| Method | Endpoint | Description |
|---|---|---|
| GET | /products | Get products |
| POST | /products | Create product |
| GET | /products/{product_id} | Get product |
| PUT | /products/{product_id} | Update product |
| DELETE | /products/{product_id} | Delete product |
| Method | Endpoint | Description |
|---|---|---|
| POST | /cart/add | Add to cart |
| GET | /cart | Get cart |
| DELETE | /cart/{cart_item_id} | Remove cart item |
| Method | Endpoint | Description |
|---|---|---|
| POST | /orders/checkout | Checkout |
| GET | /orders | Get orders |
| GET | /orders/{order_id} | Get order |
app/
├── api/
├── core/
├── models/
├── schemas/
├── main.py
Dockerfile
docker-compose.yml
requirements.txt
.env
Create a .env file:
DATABASE_URL=postgresql://postgres:password@localhost/ecommerce_db
SECRET_KEY=your_secret_key
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=60Clone the repository:
git clone https://github.com/rivondave/E-Commerce-API.git
cd E-Commerce-APICreate virtual environment:
python -m venv venvActivate virtual environment:
source venv/bin/activateInstall dependencies:
pip install -r requirements.txtRun the application:
uvicorn app.main:app --reloadSwagger documentation:
http://127.0.0.1:8000/docs
Build and run containers:
docker compose up --buildAccess API:
http://localhost:8000
Swagger:
http://localhost:8000/docs
- REST API design
- JWT Authentication
- Role-Based Access Control (RBAC)
- Relational Database Design
- Shopping Cart Architecture
- Order Processing Workflows
- Inventory Management
- Docker Containerization
- API Deployment with Render
This project uses Pytest for automated testing.
- User Registration
- User Login
- Product Creation
- Product Retrieval
- Cart Management
- Order Checkout
Run tests locally:
python -m pytest