
- Set up FastAPI project structure - Configure SQLite database with SQLAlchemy - Create Item model and schemas - Implement CRUD endpoints for inventory items - Set up Alembic for database migrations - Add comprehensive documentation
Simple Inventory App
A FastAPI-based inventory management application that provides CRUD operations for managing inventory items.
Features
- Create, read, update, and delete inventory items
- Filter items by category
- Pagination support
- SQLite database for data persistence
- Alembic for database migrations
- Health check endpoint
API Endpoints
GET /
: Root endpoint with basic app informationGET /health
: Health check endpointGET /api/v1/items
: List all items (with optional filtering and pagination)POST /api/v1/items
: Create a new itemGET /api/v1/items/{item_id}
: Get a specific item by IDPUT /api/v1/items/{item_id}
: Update an existing itemDELETE /api/v1/items/{item_id}
: Delete an item
Project Structure
.
├── alembic.ini # Alembic configuration
├── app # Application package
│ ├── api # API module
│ │ ├── v1 # API version 1
│ │ │ ├── api.py # API router
│ │ │ └── endpoints # API endpoints
│ │ │ └── items.py # Items endpoints
│ ├── core # Core application code
│ │ └── config.py # Configuration settings
│ ├── db # Database module
│ │ ├── base.py # SQLAlchemy Base
│ │ ├── base_model.py # Models import for Alembic
│ │ └── session.py # DB session
│ ├── models # SQLAlchemy models
│ │ └── item.py # Item model
│ └── schemas # Pydantic schemas
│ └── item.py # Item schemas
├── main.py # FastAPI application
├── migrations # Alembic migrations
│ ├── env.py # Alembic environment
│ ├── README # Migrations readme
│ ├── script.py.mako # Migration script template
│ └── versions # Migration versions
│ └── 20240512_initial_tables.py # Initial migration
└── requirements.txt # Project dependencies
Setup and Installation
-
Install the dependencies:
pip install -r requirements.txt
-
Apply database migrations:
alembic upgrade head
-
Run the application:
uvicorn main:app --reload
-
Access the application:
- API documentation: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
- API root: http://localhost:8000
- Health check: http://localhost:8000/health
Environment Variables
The application uses the following environment variables:
PROJECT_NAME
: Name of the project (default: "Simple Inventory App")BACKEND_CORS_ORIGINS
: List of allowed CORS origins (default: ["*"])
Inventory Item Model
Each inventory item has the following attributes:
id
: Unique identifier (integer)name
: Item name (string, required)description
: Item description (string, optional)quantity
: Available quantity (integer, default: 0)price
: Item price (float, optional)category
: Item category (string, optional)created_at
: Creation timestamp (datetime)updated_at
: Last update timestamp (datetime)
Development
Linting
To lint the code with Ruff:
ruff check .
To automatically fix linting issues:
ruff check --fix .
Description
Languages
Python
95.3%
Mako
4.7%