Library API Service is a comprehensive RESTful API designed to streamline library operations, from inventory management to automated borrowing flows and payment processing.
Built with Django REST Framework, this project focuses on scalability and data integrity, featuring asynchronous background tasks for real-time status updates and notifications.
- 📖 Book Inventory: Complete CRUD operations for managing books and tracking stock availability.
- 🔄 Smart Borrowing System:
- Automated stock validation.
- Debt Control: Prevents users with pending payments from borrowing new books.
- 💸 Advanced Stripe Payments:
- Integration with Stripe Checkout Sessions.
- Automated Expiration Tracking: Celery tasks monitor Stripe sessions every minute to mark unpaid transactions as
EXPIRED. - Payment Renewal: Dedicated endpoint to regenerate valid payment links for expired sessions.
- 🤖 Asynchronous Tasks (Celery + Redis):
- Daily checks for overdue borrowings.
- Real-time payment status synchronization.
- 📢 Notifications: Integrated Telegram Bot for instant alerts on overdue books.
- 🐳 Containerization: Fully Dockerized environment for easy deployment (App, DB, Redis, Celery Worker/Beat).
- Docker
- Docker Compose
git clone https://github.com/Psychox1k/library_service_api
cd library_service_apiCreate a .env file in the project root directory and add the following variables:
# Django
DJANGO_SECRET_KEY=your_secret_key
DEBUG=True
ALLOWED_HOSTS=127.0.0.1,localhost,0.0.0.0
# Telegram
TELEGRAM_BOT_TOKEN=your_bot_token
TELEGRAM_CHAT_ID=your_chat_id
# Stripe
STRIPE_SECRET_KEY=your_stripe_key
# Database
POSTGRES_DB=library_db
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_HOST=db
POSTGRES_PORT=5432
Start the application with Docker Compose:
docker compose up --buildOnce the containers are running, open a new terminal window to perform these steps.
(Usually applied automatically via entrypoint, but if needed manually):
docker compose exec app python manage.py migrateTo access the Django Admin panel:
docker compose exec app python manage.py createsuperuserPopulate the database with initial book inventory:
docker compose exec app python manage.py loaddata library_data.jsonThe project includes auto-generated API documentation. Once the server is running, you can access it here:
Swagger UI: http://127.0.0.1:8000/api/schema/swagger-ui/
Redoc: http://127.0.0.1:8000/api/schema/redoc/
The API root will be available at: http://127.0.0.1:8000/api/
To run the test suite inside the Docker container:
docker compose exec app python manage.py test