Automated Action 667ac548e1 Build complete FastAPI inventory management application
- 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
2025-07-21 19:29:24 +00:00

3.5 KiB

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

  1. Install dependencies:
pip install -r requirements.txt
  1. Run database migrations:
alembic upgrade head
  1. 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 links
  • GET /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 item
  • POST /api/v1/inventory/ - Create new inventory item
  • PUT /api/v1/inventory/{item_id} - Update inventory item
  • DELETE /api/v1/inventory/{item_id} - Delete inventory item
  • PATCH /api/v1/inventory/{item_id}/quantity - Update item quantity

Query Parameters

  • skip - Number of records to skip (pagination)
  • limit - Maximum number of records to return
  • category - Filter by category
  • search - 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.