This is a simple Bookstore Management System built with FastAPI (Python) for the backend and a static HTML/CSS/JS frontend. It allows you to manage a collection of books, view statistics, and interact with a RESTful API.
- List, add, update, and delete books (with price and genre)
- Sort book collection by title, author, price, or genre
- Get random books
- View collection statistics
- Interactive API documentation (Swagger UI)
- Simple static frontend for demonstration
- Python 3.11+
- FastAPI
- Pydantic
- Uvicorn
- HTML, CSS, JavaScript (vanilla)
requirements.txt
backend/
main.py
database.py
models.py
utils.py
api/
routes.py
__init__.py
data/
books.json
frontend/
index.html
assets/
css/
styles.css
js/
app.js
data/
books.json
- Built with FastAPI.
- API routes are defined in
backend/api/routes.py. - Data is stored in
backend/data/books.json. - Utility functions and database logic are in their respective files.
- Static HTML, CSS, and JavaScript files in the
frontendfolder index.htmlis the main entry point- Book collection can be sorted by title, author, price, or genre using the sort feature
General
GET /— Welcome endpoint with API information
Books
GET /books— List all booksGET /books/random— Get a random bookGET /books/{book_id}— Get book by IDPOST /books— Add a new bookPUT /books/{book_id}— Update book infoDELETE /books/{book_id}— Delete book by ID
Statistics
GET /stats— Get book collection statistics
Docs
/docs— Interactive API documentation (Swagger UI)
-
Clone the repository
git clone <repo-url> cd bookstore-management-system-fastapi
-
Install dependencies
pip install -r requirements.txt -
Run the backend server
cd backend uvicorn main:app --reload -
Open the frontend
- Open
frontend/index.htmlin your browser
- Open
Add a Book
POST /books
{
"title": "The Pragmatic Programmer",
"author": "Andrew Hunt",
"price": 12.99,
"genre": "Programming"
}Get All Books
GET /booksUpdate a Book
PUT /books/1
{
"title": "The Pragmatic Programmer (Updated)",
"price": 13.99,
"genre": "Software Development"
}Delete a Book
DELETE /books/1Contributions are welcome! Please fork the repository and submit a pull request.
MIT License