BookNest is a digital library designed to let users explore and borrow books effortlessly. With smart filters, it makes browsing through a wide range of categories—from fiction to technology—a breeze. On the admin side, managing the library is just as simple, with tools to easily add new titles, track borrowed books, and monitor availability.
Development of an application to manage books in a library. With this application, users can browse through the catalogue of books and borrow them. Build 2 independent API services for this application.
This API will be used to:
- Enroll users into the library using their email, firstname and lastname.
- List all available books
- Get a single book by its ID
- Filter books
- by publishers e.g Wiley, Apress, Manning
- by category e.g fiction, technology, science
- Borrow books by id (specify how long you want it for in days)
This API will be used by an admin to:
- Add new books to the catalogue
- Remove a book from the catalogue.
- Fetch / List users enrolled in the library.
- Fetch/List users and the books they have borrowed
- Fetch/List the books that are not available for borrowing (showing the day it will be available)
Before running the application, ensure you have the following installed:
- Python 3.10+
- PostgreSQL
- Docker and Docker Compose (optional, for containerized deployment)
-
Clone the repository:
git clone git@github.com:Timothy-py/BookNest.git cd BookNest
-
Create a virtual environment and activate it:
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install the dependencies:
pip install -r requirements.txt
-
Configure environment variables in a
.env
file using the .env.example provided:DATABASE_URL=postgresql+asyncpg://user:password@localhost:5432/library_db
-
Start the FastAPI server:
fastapi dev main.py --reload
-
Access the API documentation:
- Frontend Swagger UI: http://127.0.0.1:8080/docs
- Admin Swagger UI: http://127.0.0.1:8081/docs
-
Ensure you have Docker and Docker Compose installed.
-
Create a
.env
in the root directory of the project using the .env.example file: -
Start the application with Docker Compose:
docker-compose up --build
-
The APIs will be accessible at
http://localhost:8080
andhttp://localhost:8081
.
The database module automatically handles:
- Connection management
- Database creation (if it does not exist)
- Table creation on startup
For managing migrations, consider using Alembic:
pip install alembic
alembic init migrations
Run the tests using:
pytest
Ensure the test database is configured in your environment variables.
I welcome contributions! Feel free to open issues or submit pull requests.