A RESTful API for managing books, orders, and users built with Django REST Framework (DRF).
Supports JWT authentication, role-based access control, Redis caching, and PostgreSQL for production.
- User authentication (JWT / DRF token authentication)
- CRUD operations:
- Books
- Authors
- Categories
- Orders
- Place orders with multiple items
- Update order status (admin only)
- Email notifications for order placement
- Throttling to limit API requests
- Swagger API documentation with
drf_yasg - Role-based access control (Admin / Regular user)
- Dockerized for local development & production
- Supports Redis for caching & async tasks
- Python 3.12
- Django 5.2
- Django REST Framework
- PostgreSQL (production) / SQLite (development)
- Redis (caching, async tasks)
drf_yasgfor API documentation- Docker & Docker Compose
- Django email backend for notifications
git clone https://github.com/talibraath/BookStore
cd BookStoreSECRET_KEY=<your-django-secret-key>
DEBUG=True
DATABASE_URL=postgres://user:password@db:5432/bookstore
REDIS_URL=redis://redis:6379/0
EMAIL_HOST=<smtp-host>
EMAIL_PORT=<smtp-port>
EMAIL_HOST_USER=<email>
EMAIL_HOST_PASSWORD=<password>
EMAIL_USE_TLS=True
⚠️ In local development with Docker Compose,dbandredisrefer to the service names indocker-compose.yml.
docker compose build
docker compose up -dThis starts:
- Web (Django)
- Postgres
- Redis
docker compose exec web python manage.py migratedocker compose exec web python manage.py createsuperuserdocker compose exec web python manage.py seed-
Create virtual environment & install requirements:
python -m venv venv source venv/bin/activate pip install -r requirements.txt -
Configure
.envfile with SQLite or Postgres. -
Run migrations & server:
python manage.py migrate python manage.py runserver
Swagger documentation available at:
http://127.0.0.1:8000/documentation/
- User places an order with multiple books.
- Stock is verified before order creation.
- Total amount is calculated automatically.
- Email notification is sent to user and admin.
- Admin can update order status:
pendingshippeddeliveredcanceled
Default DRF throttling:
- Anonymous users: 20 requests/day
- Authenticated users: 50 requests/day
Can be customized per role.
- Build & run the Django app container.
- Use managed Postgres and Redis services (instead of Docker Compose).
- Set environment variables (
DATABASE_URL,REDIS_URL,SECRET_KEY, etc.) in the dashboard. - Run migrations once:
python manage.py migrate
- Fork the repository
- Create a branch:
git checkout -b feature-name - Commit changes:
git commit -m "Add feature" - Push:
git push origin feature-name - Create a Pull Request