Manga Inventory API
A FastAPI-based RESTful API for managing a manga book inventory.
Features
- Complete CRUD operations for manga books, authors, publishers, and genres
- Search and filtering capabilities for manga inventory
- SQLite database with SQLAlchemy ORM
- Alembic for database migrations
- Pydantic for data validation
- Comprehensive logging with Loguru
Tech Stack
- Python 3.10+
- FastAPI
- SQLAlchemy
- Alembic
- Pydantic
- SQLite
- Loguru
Project Structure
manga-inventory-api/
├── alembic.ini
├── app/
│ ├── api/
│ │ ├── deps.py
│ │ └── v1/
│ │ ├── api.py
│ │ └── endpoints/
│ │ ├── author.py
│ │ ├── genre.py
│ │ ├── manga.py
│ │ └── publisher.py
│ ├── core/
│ │ ├── config.py
│ │ └── logging.py
│ ├── crud/
│ │ ├── author.py
│ │ ├── base.py
│ │ ├── genre.py
│ │ ├── manga.py
│ │ └── publisher.py
│ ├── db/
│ │ ├── base.py
│ │ ├── base_class.py
│ │ └── session.py
│ ├── models/
│ │ └── manga.py
│ └── schemas/
│ ├── author.py
│ ├── genre.py
│ ├── manga.py
│ └── publisher.py
├── main.py
├── migrations/
│ ├── env.py
│ ├── README
│ ├── script.py.mako
│ └── versions/
│ └── 01_initial_tables.py
├── pyproject.toml
└── requirements.txt
Setup and Installation
-
Clone the repository:
git clone <repository-url> cd manga-inventory-api
-
Create a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install the dependencies:
pip install -r requirements.txt
-
Run the database migrations:
alembic upgrade head
-
Start the development server:
uvicorn main:app --reload
-
The API will be available at http://localhost:8000
API Endpoints
Health Check
GET /health
- Check if the API is running
Manga
GET /api/v1/manga
- List all mangaPOST /api/v1/manga
- Create a new mangaGET /api/v1/manga/{manga_id}
- Get a specific mangaPUT /api/v1/manga/{manga_id}
- Update a mangaDELETE /api/v1/manga/{manga_id}
- Delete a manga
Authors
GET /api/v1/authors
- List all authorsPOST /api/v1/authors
- Create a new authorGET /api/v1/authors/{author_id}
- Get a specific authorPUT /api/v1/authors/{author_id}
- Update an authorDELETE /api/v1/authors/{author_id}
- Delete an author
Publishers
GET /api/v1/publishers
- List all publishersPOST /api/v1/publishers
- Create a new publisherGET /api/v1/publishers/{publisher_id}
- Get a specific publisherPUT /api/v1/publishers/{publisher_id}
- Update a publisherDELETE /api/v1/publishers/{publisher_id}
- Delete a publisher
Genres
GET /api/v1/genres
- List all genresPOST /api/v1/genres
- Create a new genreGET /api/v1/genres/{genre_id}
- Get a specific genrePUT /api/v1/genres/{genre_id}
- Update a genreDELETE /api/v1/genres/{genre_id}
- Delete a genre
Filtering and Searching
You can filter manga using query parameters:
GET /api/v1/manga?title=Naruto&in_stock=true
Available filters:
title
- Filter by title (partial match)author_id
- Filter by author IDpublisher_id
- Filter by publisher IDgenre_id
- Filter by genre IDin_stock
- Filter by stock availability (true/false)
Documentation
Interactive API documentation is available at:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
Development
Code Formatting and Linting
The project uses Ruff for linting and formatting:
# Format code
ruff format .
# Lint code
ruff check .
# Fix auto-fixable linting issues
ruff check --fix .
Description
Languages
Python
99.1%
Mako
0.9%