
- 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
126 lines
3.5 KiB
Markdown
126 lines
3.5 KiB
Markdown
# 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:
|
|
```bash
|
|
pip install -r requirements.txt
|
|
```
|
|
|
|
2. Run database migrations:
|
|
```bash
|
|
alembic upgrade head
|
|
```
|
|
|
|
3. Start the development server:
|
|
```bash
|
|
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
|
|
```json
|
|
{
|
|
"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:
|
|
```bash
|
|
ruff check .
|
|
ruff format .
|
|
```
|
|
|
|
### Database Migrations
|
|
To create a new migration after model changes:
|
|
```bash
|
|
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`.
|