Flask patterns -- application factory, blueprints, error handlers, extensions, request lifecycle, configuration, logging, CLI commands
98
98%
Does it follow best practices?
Impact
98%
1.28xAverage score across 5 eval scenarios
Passed
No known issues
A local bookstore wants a Flask API to manage their inventory. They currently track everything in spreadsheets and want to move to a simple web service. The API should manage books (title, author, isbn, price, quantity_in_stock) and categories (name, description). A book belongs to one category.
Requirements:
GET /api/books?category=fiction&in_stock=true endpoint with optional filtering.POST /api/books/<id>/restock endpoint that increases a book's quantity.The bookstore owner is not technical, so error messages should be clear and the API should never show Python tracebacks.
Produce Python source files in a bookstore/ directory:
app/__init__.py -- application factoryapp/extensions.py -- CORS, rate limiter instancesapp/errors.py -- custom exceptions and error handlersapp/db.py -- SQLite setup, init_db(), get_db()app/routes/books.py -- books blueprintapp/routes/categories.py -- categories blueprinttests/conftest.py -- test fixtures with in-memory SQLiterun.py -- entry pointrequirements.txtDo not run pip install or start the server.