A production-style REST API for managing a modern digital library system.
The application replaces a fully manual, paper-based process for tracking books, borrowings, users, and payments with a structured, scalable backend system.
The system exposes a fully documented API and integrates external services for payments and notifications.
The Library Service API provides functionality for:
- Managing book inventory
- Handling user registration and authentication
- Creating and tracking borrowings
- Processing online payments
- Calculating overdue fines
- Sending asynchronous notifications
The project is designed as a modular backend system with clearly separated responsibilities between services. There is no frontend layer. The system is fully operable via REST API and Swagger UI.
The system follows a modular Django app architecture:
- books/
- users/
- borrowings/
- payments/
- notifications/
Core principles:
- Separation of concerns
- Clear domain boundaries
- Explicit business logic
- Transaction-safe operations
- External integrations abstracted behind service layers
- Asynchronous event handling
erDiagram
USER {
int id PK
string email
string first_name
string last_name
string password
bool is_staff
bool is_active
datetime date_joined
}
BOOK {
int id PK
string title
string author
string cover
int inventory
decimal daily_fee
}
BORROWING {
int id PK
date borrow_date
date expected_return_date
date actual_return_date
int user_id FK
int book_id FK
}
PAYMENT {
int id PK
string status
string type
decimal money_to_pay
string session_id
string session_url
datetime created_at
int borrowing_id FK
}
USER ||--o{ BORROWING : "creates"
BOOK ||--o{ BORROWING : "borrowed in"
BORROWING ||--o{ PAYMENT : "generates"
- JWT authentication via djangorestframework-simplejwt
- Email-based login
- Access & refresh tokens
- Role-based access control (admin vs regular user)
Security model:
- Users can access only their own borrowings and payments
- Admin users can access all records
- Public endpoints limited to registration and token generation
Payments are processed using Stripe Checkout.
Flow:
- Borrowing created
- Stripe Checkout session generated
- Payment record created (PENDING)
- User completes payment
- Stripe webhook updates status to PAID
- Success endpoint confirms payment state
- Fine payments are generated automatically for overdue returns:
fine = overdue_days * daily_fee * FINE_MULTIPLIER| Endpoint | Method | Description |
|---|---|---|
/api/user/register/ |
POST | Register a new user |
/api/user/token/ |
POST | Get access and refresh tokens |
/api/user/token/refresh/ |
POST | Refresh access token |
/api/user/me/ |
GET, PUT, PATCH | Retrieve or update authenticated user's profile |
/api/books/ |
GET | List all books |
/api/books/ |
POST | Create a new book (admin only) |
/api/books/{id}/ |
GET | Retrieve book details |
/api/books/{id}/ |
PUT, PATCH | Update book (admin only) |
/api/books/{id}/ |
DELETE | Delete book (admin only) |
/api/borrowings/ |
GET | List borrowings (filtered by user / active status) |
/api/borrowings/ |
POST | Create a new borrowing |
/api/borrowings/{id}/ |
GET | Retrieve borrowing details |
/api/borrowings/{id}/return/ |
POST | Return a borrowed book |
/api/payments/ |
GET | List payments |
/api/payments/{id}/ |
GET | Retrieve payment details |
/api/payments/success/ |
GET | Check payment status after Stripe redirect |
/api/payments/cancel/ |
GET | Stripe cancel callback |
/api/payments/webhooks/stripe/ |
POST | Stripe webhook for payment confirmation |
- Unit tests for models and business logic
- API endpoint tests
- Stripe session mocked in tests
- Celery tasks mocked
Tests coverage: 96%
- Borrowings: 100%
- Payments (incl. webhook): 100%
- Notifications tasks: 92%
- Overall branch-safe transactional logic covered
- Python 3.11
- Django
- Django REST Framework
- drf-spectacular
- Celery
- Redis
- PostgreSQL
- Stripe SDK
🚀 Running the Project
- Build containers
docker-compose build- Start services
docker-compose up- Run migrations
docker-compose exec web python manage.py migrate- Create superuser
docker-compose exec web python manage.py createsuperuser| Service | URL |
|---|---|
| API | http://localhost:8000 |
| Swagger | http://localhost:8000/api/docs/ |
| ReDoc | http://localhost:8000/api/redoc/ |