This project consists of two independent API services to manage a library's collection of books. The APIs enable users to browse books and borrow them, while providing administrators the ability to manage the book catalogue and monitor library users.
- Frontend API: Allows library users to enroll, browse books, filter by category or publisher, and borrow books.
- Backend/Admin API: Allows library administrators to add or remove books, manage users, and view unavailable books.
Both services use separate data stores and communicate changes (like adding new books) between the APIs. The services are containerized using Docker for ease of deployment.
The Frontend API provides the following endpoints for users:
-
Enroll Users
- Endpoint:
POST /users/enroll/
- Description: Enroll a new user by providing their first name, last name, and email.
- Endpoint:
-
List All Available Books
- Endpoint:
GET /books/
- Description: Retrieve all books currently available for borrowing.
- Endpoint:
-
Get Single Book by ID
- Endpoint:
GET /books/{book_id}
- Description: Get details about a specific book using its ID.
- Endpoint:
-
Filter Books
- Endpoint:
GET /books/filter/
- Description: Filter books by publisher or category (e.g., fiction, technology, science).
- Endpoint:
-
Borrow a Book
- Endpoint:
POST /books/borrow/{book_id}
- Description: Borrow a book by its ID, specifying the number of days to borrow it.
- Endpoint:
The Admin API provides the following endpoints for administrators:
-
Add New Books
- Endpoint:
POST /admin/books/add/
- Description: Add new books to the library's catalogue.
- Endpoint:
-
Remove a Book
- Endpoint:
DELETE /admin/books/{book_id}
- Description: Remove a book from the catalogue by its ID.
- Endpoint:
-
List All Users
- Endpoint:
GET /admin/users/
- Description: Retrieve a list of all enrolled users.
- Endpoint:
-
List Users and Their Borrowed Books
- Endpoint:
GET /admin/users/borrowed-books/
- Description: Retrieve a list of users and the books they have borrowed.
- Endpoint:
-
List Unavailable Books
- Endpoint:
GET /admin/books/unavailable/
- Description: List all books currently borrowed and unavailable for lending, along with the date they will be available.
- Endpoint:
When an admin adds a new book via the backend API, the frontend API must be updated to reflect this change. This is achieved through communication between the services, ensuring both databases stay in sync.
id
(int): Unique identifierfirstname
(string): User's first namelastname
(string): User's last nameemail
(string): User's email (unique)
id
(int): Unique identifiertitle
(string): Book titleauthor
(string): Book authorpublisher
(string): Book publishercategory
(string): Book category (e.g., fiction, technology)is_available
(bool): Availability status of the bookavailable_on
(date): When the book will become available again if currently borrowed
id
(int): Unique identifieruser_id
(int): ID of the user borrowing the bookbook_id
(int): ID of the borrowed bookborrow_date
(date): Date of borrowingreturn_date
(date): Expected return date
Each service has its own data store:
- The frontend API uses a SQLite database (
library.db
). - The backend API uses a PostgreSQL database (configured in
docker-compose.yml
).
The application is containerized with Docker and can be easily deployed using the provided docker-compose.yml
file. The setup defines services for both the frontend and backend APIs, along with a PostgreSQL database for the backend.
- Ensure Docker and Docker Compose are installed on your system.
- Clone the repository and navigate to the project directory.
- Build and start the services:
docker-compose up --build
- The frontend API will be accessible at http://localhost:8000.
- The backend/admin API will be accessible at http://localhost:8001.
Unit and integration tests are provided using pytest. Run the tests with the following command:
pytest
The project dependencies are listed in requirements.txt and include:
- FastAPI
- SQLAlchemy
- Uvicorn
- Pydantic
- Pytest
This project is licensed under the MIT License.