This project implements a FastAPI-based REST API for managing warehouse processes. The API allows you to manage products, inventory, and orders. It was built with ease of local development in mind and includes configurations for production deployment.
- Database with SQLAlchemy (v2)
- Designed entities:
Product,Order, andOrderItem - Async SQLAlchemy engine with pessimistic connection pooling
- Migration setup using Alembic with migrations formatted for easy sorting (
YYYY-MM-DD_slug) - Global Pydantic model with explicit timezone setting during JSON export
- Designed entities:
- Business Logic
- Stock checks during order creation to ensure sufficient stock
- Automatic inventory updates when orders are placed
- Error handling for insufficient stock
- API Endpoints
- Product Management
- Create Product (POST
/products) - Get List of Products (GET
/products) - Get Product by ID (GET
/products/{id}) - Update Product (PUT
/products/{id}) - Delete Product (DELETE
/products/{id})
- Create Product (POST
- Order Management
- Create Order (POST
/orders) - Get List of Orders (GET
/orders) - Get Order by ID (GET
/orders/{id}) - Update Order Status (PATCH
/orders/{id}/status)
- Create Order (POST
- Product Management
- Production-Ready
- Configured with Gunicorn and Docker
- JSON logs, Sentry for error reporting
- Dockerfile optimized for fast builds and small size
- Dynamic Gunicorn worker configuration
- Install dependencies:
- MacOS:
brew install just - Debian/Ubuntu:
apt install just - Others: link
- MacOS:
- Install
poetry:Or follow other installation methods here.pip install poetry
- Set up PostgreSQL (16.3) and start containers:
just up
- Copy the environment file and install dependencies:
cp .env.example .env poetry install
- Run the server:
just run
- With custom logging:
just run --log-config logging.ini
- Format code with
ruff:just lint
- Create migrations:
just mm *migration_name*
- Apply migrations:
just migrate
- Downgrade migrations:
just downgrade -1
Deployment is managed via Docker and Gunicorn. The Dockerfile is optimized for small size and fast builds with a non-root user. The number of workers is dynamically set based on CPU cores.
Run the app in production:
docker compose -f docker-compose.prod.yml up -d --buildFastAPI provides built-in interactive API documentation with Swagger/OpenAPI, which can be accessed at /docs once the server is running.