Problem
A buyer needs a predictable path from catalogue to confirmed order, while a supplier needs control over products, stock, and incoming orders. Concurrent requests must not sell the same stock twice.
A backend application for procurement between buyers and suppliers. It combines a catalogue, cart, order placement, price-list imports, user roles, and background operations.
The core complexity sits at the boundary between the catalogue, cart, stock, permissions, and long-running background work.
A buyer needs a predictable path from catalogue to confirmed order, while a supplier needs control over products, stock, and incoming orders. Concurrent requests must not sell the same stock twice.
DRF accepts the request, a service layer owns the business transaction, PostgreSQL protects stock, and Redis with Celery handles caching and long-running tasks.
The service layer keeps validation and state changes together instead of turning the controller into a container for business logic.
The buyer filters the catalogue, adds products to a cart, and changes quantities. Catalogue reads can be served from Redis cache.
DRF validates authentication, the user role, cart contents, and request shape before starting the transaction.
The order service opens transaction.atomic and selects stock rows with select_for_update to prevent concurrent deduction.
After validation, stock is deducted and the order with its items is persisted as one consistent change.
Email, price-list imports, and image processing are delegated to Celery instead of extending API response time.
Each tool addresses a concrete risk: concurrent stock changes, long-running work, and reusable business rules.
Order placement is extracted from the view into one scenario that owns validation, locking, and related entity changes.
transaction.atomic and select_for_update protect stock while multiple carts are being confirmed.
YAML imports, email, and image processing run outside the request-response cycle.
Frequently read data is cached, with explicit invalidation when products or categories change.
The suite covers individual API areas and an integration purchase flow from authentication to order placement.
Authentication, throttling, catalogue, cart, order placement, and an end-to-end purchase scenario.
drf-spectacular generates the API schema and exposes two documentation views.
A containerised environment and automated checks make local execution reproducible.
The case separates implemented mechanisms from the next layer of product and operational work.
Operational traceability would benefit from explicit order transition history and user action logs.
Pricing is not yet extracted into an extensible rules and campaign module.
The next step is a reproducible benchmark for concurrent checkout and catalogue behaviour under load.
The main result is not endpoint count, but a clear separation between HTTP handling, transactional checkout, caching, and background tasks.
The README covers quick start, API workflows, project structure, and Docker Compose commands.