
- Created FastAPI application structure with SQLAlchemy and Alembic - Implemented full CRUD operations for inventory items - Added search, filtering, and pagination capabilities - Configured CORS, API documentation, and health endpoints - Set up SQLite database with proper migrations - Added comprehensive API documentation and README
Inventory Management API
A comprehensive FastAPI-based inventory management system for tracking and managing inventory items.
Features
- CRUD Operations: Create, read, update, and delete inventory items
- Search & Filter: Search by name, description, or SKU and filter by category
- Quantity Management: Update item quantities with dedicated endpoint
- RESTful API: Clean REST API endpoints with proper HTTP status codes
- Data Validation: Pydantic models for request/response validation
- Database Migrations: Alembic integration for database schema management
- API Documentation: Auto-generated OpenAPI/Swagger documentation
Technology Stack
- Framework: FastAPI
- Database: SQLite with SQLAlchemy ORM
- Migrations: Alembic
- Validation: Pydantic
- Code Quality: Ruff for linting and formatting
Project Structure
├── app/
│ ├── api/
│ │ └── inventory.py # Inventory API endpoints
│ ├── db/
│ │ ├── base.py # SQLAlchemy base model
│ │ └── session.py # Database session configuration
│ ├── models/
│ │ └── inventory.py # SQLAlchemy models
│ └── schemas/
│ └── inventory.py # Pydantic schemas
├── migrations/ # Alembic migration files
├── main.py # FastAPI application entry point
├── requirements.txt # Python dependencies
└── alembic.ini # Alembic configuration
Installation
- Install dependencies:
pip install -r requirements.txt
- Run database migrations:
alembic upgrade head
- Start the development server:
uvicorn main:app --reload
The API will be available at http://localhost:8000
API Endpoints
Base Endpoints
GET /
- API information and linksGET /health
- Health check endpoint
Inventory Management
GET /api/v1/inventory/
- List all inventory items (with pagination, search, and filtering)GET /api/v1/inventory/{item_id}
- Get specific inventory itemPOST /api/v1/inventory/
- Create new inventory itemPUT /api/v1/inventory/{item_id}
- Update inventory itemDELETE /api/v1/inventory/{item_id}
- Delete inventory itemPATCH /api/v1/inventory/{item_id}/quantity
- Update item quantity
Query Parameters
skip
- Number of records to skip (pagination)limit
- Maximum number of records to returncategory
- Filter by categorysearch
- Search in name, description, or SKU
API Documentation
Once the server is running, you can access:
- Swagger UI:
http://localhost:8000/docs
- ReDoc:
http://localhost:8000/redoc
- OpenAPI JSON:
http://localhost:8000/openapi.json
Data Model
Inventory Item
{
"id": 1,
"name": "Product Name",
"description": "Product description",
"sku": "UNIQUE-SKU-123",
"quantity": 50,
"price": 29.99,
"category": "Electronics",
"supplier": "Supplier Name",
"location": "Warehouse A",
"created_at": "2024-01-01T00:00:00Z",
"updated_at": "2024-01-01T00:00:00Z"
}
Development
Code Quality
The project uses Ruff for code formatting and linting:
ruff check .
ruff format .
Database Migrations
To create a new migration after model changes:
alembic revision --autogenerate -m "Description of changes"
alembic upgrade head
Storage
The application uses /app/storage/db/
as the database storage directory with SQLite. The database file will be created automatically at /app/storage/db/db.sqlite
.
Description
Languages
Python
95.9%
Mako
4.1%