A complete library management application, featuring a FastAPI backend and a React + TypeScript frontend, is provided in this repository. This project was developed to be straightforward, easily extensible, and simple to run locally. An overview of the project structure and setup instructions is included below.
What's included
- Backend: FastAPI app (entry:
api.py) with endpoints to add, list, fetch and delete books, plus health and system endpoints. - Database layer: SQLModel + PostgreSQL integration under
app/with models, repositories and services. - Frontend: A small React + TypeScript app in
frontend/that can add books (by ISBN) and browse the library. .
- Book metadata is fetched from OpenLibrary when adding by ISBN.
- Books are stored in a PostgreSQL database using SQLModel.
- A JSON REST API is served and consumed by a Vite + React frontend.
- Basic tests are included, some of which mock external HTTP calls so they are run offline.
- Python 3.10+, FastAPI, SQLModel (SQLAlchemy under the hood)
- PostgreSQL (local or Docker)
- Frontend: React + TypeScript, Vite
- Tests: pytest
The minimal steps to be followed to run both backend and frontend on your machine are presented below.
- Install Python dependencies
pip install -r requirements.txt- Start a PostgreSQL instance
Option A — Docker (recommended):
docker run --name library-postgres -e POSTGRES_PASSWORD=postgres -e POSTGRES_USER=postgres -e POSTGRES_DB=library_db -p 5432:5432 -d postgres:15Option B — Local PostgreSQL: a database named library_db should be created and credentials should be ensured to match your .env.
- Create a
.envfile in the project root with these values (example):
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_HOST=localhost
POSTGRES_PORT=5432
POSTGRES_DB=library_db- Start the backend (from project root)
uvicorn api:app --reloadOpenAPI docs: http://127.0.0.1:8000/docs
- Start the frontend (in a new terminal)
cd frontend
npm install
npm run devFrontend default URL: http://localhost:5173
- Add a book: an ISBN (10 or 13 digits) should be pasted into the frontend "Add Book" form. OpenLibrary will be queried by the backend for metadata, then the book will be stored.
- Browse books: the UI filters should be used to search by author, title or status.
- Delete: a book should be removed from the library via the UI (or the API).
GET /books— list books (supports pagination and filters)POST /books— add a book by sending{ "isbn": "9780451524935" }GET /books/{isbn}— get details for an ISBNDELETE /books/{isbn}— delete a bookGET /health— health check and book count
For a complete reference, see info/API_ENDPOINTS.md.
The test suite may be run with:
pytest -qOpenLibrary is mocked by some tests so network access is not required. If tests that hit real services are to be run, network connectivity should be ensured.
- The backend code is located in
app/—models.py,db_models.py,repositories.py,services.pyanddatabase.pyare intentionally kept separated for clarity. - Database tables are created automatically on app startup by the
init_db()logic. - Frontend API calls are found in
frontend/src/api.tsand components are found infrontend/src/components.
Start backend (project root):
uvicorn api:app --reloadStart frontend (frontend folder):
cd frontend
npm run devRun tests:
pytest -q- Add member management and borrowing flows to the frontend.
- Add authentication (JWT) to the API.
- Add CI (GitHub Actions) to run tests on PRs.
- API docs: [info/API_ENDPOINTS.md]
- Run instructions & troubleshooting: [info/HOW_TO_RUN.md] and [info/QUICK_START.md]
- Database guide: [info/README_DATABASE.md]
- Frontend notes: [frontend/README_FRONTEND.md]