A fully functional Ecommerce backend built using FastAPI and PostgreSQL, implementing core features like product management, cart system, and checkout flow.
- Backend Framework: FastAPI
- Database: PostgreSQL
- ORM: SQLAlchemy
- Validation: Pydantic
- Server: Uvicorn
ecommerce/
│
├── app/
│ ├── main.py # Entry point
│ ├── database.py # DB connection
│ │
│ ├── models.py # SQLAlchemy models
│ │
│ ├── schemas.py # Pydantic schemas
│ │
│ ├── routes/ # API routes
│ │ └── routes.py
│
├── .env
├── requirements.txt
├── .gitignore
└── README.md
git clone https://github.com/your-username/ecommerce-fastapi.git
cd ecommerce-fastapipython -m venv myvenv
source myvenv/bin/activate # Linux/Mac
myvenv\Scripts\activate # Windowspip install -r requirements.txtCreate .env file:
DATABASE_URL=postgresql://postgres:password@localhost:5432/EcommerceFastAPI_dbuvicorn app.main:app --reload- Create product
- Get all products
- Get single product
- Update product (PUT & PATCH)
- Delete product
- Add product to cart
- Remove product from cart
- View cart with total price
- Quantity management
- Create order from cart
- Auto calculate total amount
- Clear cart after checkout
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/products/ |
Get all products |
| POST | /api/products/ |
Create product |
| GET | /api/products/{id} |
Get single product |
| PUT | /api/products/{id} |
Update product |
| PATCH | /api/products/{id} |
Partial update |
| DELETE | /api/products/{id} |
Delete product |
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/cart/add/ |
Add item to cart |
| POST | /api/cart/remove/ |
Remove item |
| GET | /api/cart/{id} |
Get cart details |
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/checkout/ |
Checkout cart |
{
"product_id": 1,
"quantity": 2
}{
"cart_id": 1
}- FastAPI architecture
- SQLAlchemy ORM
- Pydantic validation
- REST API design
- Ecommerce flow (cart → checkout)
Karan Python Developer
If you like this project, give it a ⭐ on GitHub!