- The Backend API uses Django Rest Framework with a PostgreSQL database to store admin data and user information.
- The Frontend API is built with FastAPI and uses MongoDB to store book data for quick access by users.
- RabbitMQ is used to communicate changes (like adding or removing books) between the two services.
- Docker is used to containerize and orchestrate the services.
- Backend: Django, Django REST Framework, PostgreSQL
- Frontend: FastAPI, Pydantic, MongoDB
- Messaging Queue: RabbitMQ
- Containerization: Docker, Docker Compose
- Testing: Pytest, Django's TestCase, REST framework test client, RabbitMQ
- Other Tools: HTTPX (for testing FastAPI routes)
- Add new books to the library catalog.
- Remove books from the catalog.
- Fetch list of users and their borrowing history.
- Fetch list of books that are currently borrowed and unavailable for lending.
- Enroll users in the library system.
- Browse and filter books by publisher and category.
- Borrow books by specifying how many days you want them.
- Get book details by its ID.
.
├── backend # Django app for the backend/admin API
├── frontend_api # FastAPI app for the frontend API
├── docker-compose.yml # Docker Compose file to orchestrate services
└── README.md # Project README file
- Docker
- Docker Compose
- Python 3.9+
-
Clone the repository:
git clone https://github.com/t0yosi/cowry-library.git cd cowry-library
-
Create a .env file in the project root with the following content:
POSTGRES_DB=library_db POSTGRES_USER=postgres POSTGRES_PASSWORD=password POSTGRES_HOST=db
MONGODB_URL=mongodb://mongo:27017
-
Start the docker container
docker-compose up --build
-
Access the services:
Frontend API (FastAPI): http://localhost:8000 Backend API (Django): http://localhost:8001/api
Base URL: http://localhost:8000
Method | Endpoint | Description | Parameters |
---|---|---|---|
POST |
/users/ |
Enroll a new user | email , first_name , last_name |
GET |
/books/ |
List all available books | None |
GET |
/books/{book_id} |
Get details of a single book by its ID | book_id |
POST |
/borrow/{book_id} |
Borrow a book | book_id , days |
GET |
/books/filter/ |
Filter books by publisher or category | publisher , category |
Payloads:
## Enroll a user:
curl -X POST "http://localhost:8080/api/enroll_user/" -H "Content-Type: application/json" -d '{"email": "[email protected]", "firstname": "John", "lastname": "Doe"}'
## Get list of all books:
curl -X POST "http://127.0.0.1:8000/books/{book_id}"
## Fetch by Publisher:
curl -X GET "http://127.0.0.1:8000/books/filter/?publisher=Ada%20Bane"
## Fetch by Category:
curl -X GET "http://127.0.0.1:8000/books/filter/?category=Fiction"
## Borrow a book::
curl -X POST "http://127.0.0.1:8000/books/{book_id}/borrow" -H "Content-Type: application/json" -d '{"days": 14}'
Base URL: http://localhost:8001
Method | Endpoint | Description | Parameters |
---|---|---|---|
POST |
/api/books/ |
Add a new book to the catalog | title , publisher , category |
GET |
/api/books/{book_id} |
Add a book to the catalog | book_id |
DELETE |
/api/books/{book_id} |
Remove a book from the catalog | book_id |
GET |
/api/users/ |
List all enrolled users | None |
GET |
/api/borrowed/ |
List all users and their borrowed books | None |
Unit tests cover the core logic of the models, API endpoints, and services.
Run unit tests for the Django backend:
docker-compose exec backend-api python manage.py test
Run unit tests for the FastAPI frontend-api:
docker-compose exec frontend-api pytest