Library Service API is a Django REST Framework project for managing a library system: books, users, borrowings, payments, and notifications.
It replaces outdated paper-based tracking with a modern API-driven solution that supports inventory management, online payments, and automated notifications.
-
Books Service
- CRUD operations for books (admin only for create/update/delete)
- Automatic inventory updates on borrowing/returning
- Public access to view books (even unauthenticated users)
-
Users Service
- Custom user model with email as the unique identifier
- Registration, login, JWT authentication
- Profile management (
/users/me/)
-
Borrowings Service
- Borrow creation with inventory validation
- Automatic decrease/increase of inventory
- Prevents double returns
- Filtering by
is_active,user_id(for admins)
-
Payments Service (Stripe)
- Automatic Stripe Session creation on borrowing
- Endpoints for
/success/and/cancel/ - Fine calculation for overdue returns
-
Notifications Service (Telegram)
- Notifications on new borrowings
- Daily overdue checks
- Implemented with Celery or Django-Q
-
API Docs
- Auto-generated Swagger / OpenAPI schema
- Python 3.12
- Django 5.2
- Django REST Framework
- PostgreSQL
- Redis
- Celery
- Docker & Docker Compose
- drf-spectacular (OpenAPI schema)
- Simple JWT (authentication)
- Stripe (payments)
- python-dotenv
git clone https://github.com/<your-username>/drf-library-api.git
cd drf-library-apiThe project requires a .env file in the root directory.
You can create it manually or copy from the template:
cp .env.sample .envThen open .env and configure the following values:
DEBUG— setTruefor local development,Falsefor production.SECRET_KEY— generate your own Django secret key:python -c 'from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())'
POSTGRES_DB— name of the database (e.g.,library)POSTGRES_USER— database usernamePOSTGRES_PASSWORD— database passwordPOSTGRES_HOST— database host (usuallydbin Docker)POSTGRES_PORT— default is5432
STRIPE_SECRET_KEY— create a test API key in your Stripe DashboardSTRIPE_PUBLISHABLE_KEY— optional, for frontend usage
TELEGRAM_BOT_TOKEN— create a bot via BotFatherTELEGRAM_CHAT_ID— get your chat ID using @userinfobot or by adding the bot to a group
🔑 Keep
.envprivate and never commit it to GitHub.
docker-compose up --build📍 API will be available at:
http://localhost:8000
JWT-based authentication:
POST /users/token/— obtain access and refresh tokensPOST /users/token/refresh/— refresh the access token
Add the header to access protected endpoints:
Authorization: Bearer <your_access_token>
POST /users/register/— register a new userPOST /users/token/— obtain JWT tokensGET /users/me/— get profile infoPUT /users/me/— update profile
GET /books/— list booksPOST /books/— create a book (admin only)PUT/PATCH /books/{id}/— update a book (admin only)DELETE /books/{id}/— delete a book (admin only)
POST /borrowings/— create borrowingGET /borrowings/— list borrowings (filters:is_active,user_id)GET /borrowings/{id}/— get borrowing detailPOST /borrowings/{id}/return/— return a book
GET /payments/— list paymentsGET /payments/{id}/— payment detailsGET /payments/success/— confirm Stripe paymentGET /payments/cancel/— cancel payment
- Swagger UI: http://localhost:8000/api/docs/
- OpenAPI schema (JSON): http://localhost:8000/api/schema/
docker-compose exec app python manage.py test





