REST API for order management, with user authentication via JWT, developed using FastAPI, SQLAlchemy, and Pydantic, following backend development best practices, code organization, and standards adopted in professional projects.
This project demonstrates practical expertise in modern APIs with Python, including security, data validation, persistence, and automatic documentation.
- Python 3.10+
- FastAPI — modern, fast, and typed web framework
- SQLAlchemy — ORM for database access
- Pydantic — data validation and serialization
- JWT (JSON Web Token) — authentication and authorization
- Uvicorn — ASGI server
- SQLite / PostgreSQL (configurable)
- User registration
- Login with JWT token generation
- Protection of authenticated routes
- Permission control (user and administrator)
- Create orders
- List orders
- Retrieve order by ID
- Update orders
- Delete orders
- Association between users and orders
The project uses SQLAlchemy ORM to abstract the database.
- The Engine manages the connection pool
- The Session controls transactions (
commitandrollback) - The ORM models represent database tables
- All models inherit from a Declarative Base
class Order(Base):
__tablename__ = "orders"
id = Column(Integer, primary_key=True, autoincrement=True)
description = Column(String, nullable=False)
user_id = Column(Integer, ForeignKey("users.id"))
The API uses Pydantic to ensure security, predictability, and consistency in data exchanged between client and server.
With Pydantic, the application guarantees:
- Automatic validation of input data
- Strong typing
- Clear error messages
- Safe response serialization
- Reduction of bugs and invalid data
Pydantic Schema Example
from pydantic import BaseModel
class OrderCreate(BaseModel):
description: str
The system uses JWT (JSON Web Token) for authentication.
- The login returns an access token
- The token must be sent in the header of protected requests
- Invalid or expired tokens are automatically rejected
Authentication Header Example
Authorization: Bearer <token>
The authenticated user is obtained via Dependency Injection, ensuring security and decoupling.
git clone https://github.com/your-username/fastapi-order-service.git
cd fastapi-order-service
python -m venv .venv
Linux / macOS
source .venv/bin/activate
Windows
.venv\Scripts\activate
pip install -r requirements.txt
uvicorn app.main:app --reload
FastAPI generates documentation automatically:
Swagger UI
👉 http://localhost:8000/docs
ReDoc
👉 http://localhost:8000/redoc