Skip to content

About

Order management system built with FastAPI, SQLAlchemy and Alembic, following modern backend best practices.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

24 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🚀 FastAPI Order Management System

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.


🛠 Technologies Used

  • 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)

✨ Features

🔐 Authentication and Users

  • User registration
  • Login with JWT token generation
  • Protection of authenticated routes
  • Permission control (user and administrator)

📦 Order Management

  • Create orders
  • List orders
  • Retrieve order by ID
  • Update orders
  • Delete orders
  • Association between users and orders

🗄 Database and ORM

The project uses SQLAlchemy ORM to abstract the database.

  • The Engine manages the connection pool
  • The Session controls transactions (commit and rollback)
  • The ORM models represent database tables
  • All models inherit from a Declarative Base

ORM Model Example

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"))

✅ Data Validation with Pydantic

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

🔑 Authentication with JWT

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.


▶️ How to Run the Project

1️⃣ Clone the repository

git clone https://github.com/your-username/fastapi-order-service.git
cd fastapi-order-service 

2️⃣ Create and activate the virtual environment

python -m venv .venv
Linux / macOS

source .venv/bin/activate
Windows

.venv\Scripts\activate

3️⃣ Install dependencies

pip install -r requirements.txt 

4️⃣ Run the application

uvicorn app.main:app --reload

📚 Automatic API Documentation

FastAPI generates documentation automatically:

Swagger UI
👉 http://localhost:8000/docs

ReDoc
👉 http://localhost:8000/redoc

About

Order management system built with FastAPI, SQLAlchemy and Alembic, following modern backend best practices.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages