This repository contains an event-driven architecture with FastAPI. The project implements a furniture retailer MADE from the book Architecture Patterns with Python by Harry J.W Percival & Bob Gregory.
- (the first time) setup Python 3.13.5 with pyenv:
pyenv local 3.13.5to create the .python-version file - (the first time) create venv:
python3 -m venv .venv - activate venv:
source .venv/bin/activate - install the development mode:
pip install -e .[dev]
- Execute containers:
docker compose up -d - Start FastAPI project:
fastapi dev made/entrypoints/main.py - Start the event consumer:
python3 -m made.entrypoints.redis_eventconsumer - Stop containers:
docker compose down
Documentation at http://127.0.0.1:8000/docs
curl -X 'GET' \
'http://127.0.0.1:8000/health' \
-H 'Content-Type: application/json'
curl -X 'POST' \
'http://127.0.0.1:8000/batches' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"reference": "batch-001",
"sku": "CHAIR",
"quantity": 100
}'
curl -X 'POST' \
'http://localhost:8000/allocate' \
-H "Content-Type: application/json" \
-d '{
"orderid": "order-001",
"sku": "CHAIR",
"qty": 10
}'
Publish a message on change_batch_quantity Redis channel. The event will be processed by the redis_eventconsumer.
redis-cli -p 63791 PUBLISH change_batch_quantity '{"batchref": "batch-001", "qty": 200}'
- test (all):
pytest
