DEV Community

David Kljajo
David Kljajo

Posted on

Mini E-Commerce API (FastAPI + JWT) - project 1

πŸš€ Project: Mini E-Commerce API (FastAPI + JWT)
🎯 What you’re building

A backend system with:

Users (auth system)
Products (CRUD)
Orders (user purchases)
JWT authentication
Clean architecture (like real production APIs)
🧱 Tech Stack
Python 3.11+
FastAPI
SQLAlchemy (ORM)
SQLite (start) β†’ PostgreSQL later
JWT (python-jose)
Passlib (password hashing)
πŸ“ Clean Project Structure (IMPORTANT)
app/
β”œβ”€β”€ main.py
β”œβ”€β”€ core/
β”‚ β”œβ”€β”€ config.py
β”‚ β”œβ”€β”€ security.py
β”‚
β”œβ”€β”€ database/
β”‚ β”œβ”€β”€ db.py
β”‚
β”œβ”€β”€ models/
β”‚ β”œβ”€β”€ user.py
β”‚ β”œβ”€β”€ product.py
β”‚ β”œβ”€β”€ order.py
β”‚
β”œβ”€β”€ schemas/
β”‚ β”œβ”€β”€ user.py
β”‚ β”œβ”€β”€ product.py
β”‚ β”œβ”€β”€ order.py
β”‚
β”œβ”€β”€ routes/
β”‚ β”œβ”€β”€ auth.py
β”‚ β”œβ”€β”€ users.py
β”‚ β”œβ”€β”€ products.py
β”‚ β”œβ”€β”€ orders.py
β”‚
β”œβ”€β”€ services/
β”‚ β”œβ”€β”€ user_service.py
β”‚ β”œβ”€β”€ product_service.py
β”‚ β”œβ”€β”€ order_service.py
β”‚
β”œβ”€β”€ dependencies/
β”‚ β”œβ”€β”€ auth.py

This structure alone already makes your project look β€œproduction-grade”.

πŸ” Features Breakdown
πŸ‘€ Auth System
Register user
Login user
Password hashing (bcrypt)
JWT token generation
Protected routes
πŸ›οΈ Products (CRUD)
Create product (admin only)
Get all products (public)
Get single product
Update product (admin only)
Delete product (admin only)
🧾 Orders
Create order (user)
View own orders
Admin sees all orders
πŸ”‘ Core Learning Flow (build in this order)
STEP 1 β€” Setup
pip install fastapi uvicorn sqlalchemy passlib python-jose
STEP 2 β€” Run FastAPI

app/main.py

from fastapi import FastAPI

app = FastAPI()

@app.get("/")
def root():
return {"message": "API is running"}

Run:

uvicorn app.main:app --reload
STEP 3 β€” Add Database

Create SQLAlchemy models first (User, Product, Order)

STEP 4 β€” Auth (MOST IMPORTANT)
Register endpoint
Login endpoint
JWT token creation
Middleware to protect routes
STEP 5 β€” Products CRUD

Build full CRUD using:

routes
services layer (important for clean code)
STEP 6 β€” Orders System
User creates order from product
Reduce stock
Save order history

Top comments (0)