
- Set up project structure with FastAPI and SQLite - Created database models for users, categories, suppliers, items, and stock transactions - Implemented Alembic for database migrations with proper absolute paths - Built comprehensive CRUD operations for all entities - Added JWT-based authentication and authorization system - Created RESTful API endpoints for all inventory operations - Implemented search, filtering, and low stock alerts - Added health check endpoint and base URL response - Configured CORS for all origins - Set up Ruff for code linting and formatting - Updated README with comprehensive documentation and usage examples The system provides complete inventory management functionality for small businesses including product tracking, supplier management, stock transactions, and reporting. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
5.5 KiB
5.5 KiB
Small Business Inventory Management System
A comprehensive FastAPI-based inventory management system designed for small businesses to track products, manage suppliers, monitor stock levels, and handle inventory transactions.
Features
- Product Management: Add, update, and track inventory items with detailed information
- Category Management: Organize products into categories for better organization
- Supplier Management: Maintain supplier information and relationships
- Stock Tracking: Real-time stock level monitoring with low stock alerts
- Transaction History: Complete audit trail of all stock movements
- Authentication: Secure JWT-based authentication system
- Search & Filtering: Powerful search capabilities across inventory items
- RESTful API: Clean, well-documented API endpoints
Technology Stack
- Framework: FastAPI
- Database: SQLite with SQLAlchemy ORM
- Authentication: JWT tokens with PassLib for password hashing
- Migration: Alembic for database migrations
- Validation: Pydantic for data validation
- Documentation: Auto-generated OpenAPI/Swagger documentation
Installation
- Install dependencies:
pip install -r requirements.txt
- Run database migrations:
alembic upgrade head
- Start the application:
uvicorn main:app --host 0.0.0.0 --port 8000 --reload
Environment Variables
The following environment variables can be set to configure the application:
SECRET_KEY
: JWT secret key (default: "your-secret-key-change-this-in-production")FIRST_SUPERUSER_EMAIL
: Admin user email (default: "admin@inventory.com")FIRST_SUPERUSER_PASSWORD
: Admin user password (default: "admin123")
Important: Change the default SECRET_KEY and admin credentials in production!
API Documentation
Once the application is running, you can access:
- Interactive API Documentation: http://localhost:8000/docs
- Alternative Documentation: http://localhost:8000/redoc
- OpenAPI Schema: http://localhost:8000/openapi.json
API Endpoints
Authentication
POST /auth/login
- User login
Categories
GET /categories/
- List all categoriesPOST /categories/
- Create new categoryGET /categories/{id}
- Get category by IDPUT /categories/{id}
- Update categoryDELETE /categories/{id}
- Delete category
Suppliers
GET /suppliers/
- List all suppliersPOST /suppliers/
- Create new supplierGET /suppliers/{id}
- Get supplier by IDPUT /suppliers/{id}
- Update supplierDELETE /suppliers/{id}
- Delete supplier
Items
GET /items/
- List all itemsPOST /items/
- Create new itemGET /items/{id}
- Get item by IDPUT /items/{id}
- Update itemDELETE /items/{id}
- Delete itemGET /items/search?query={query}
- Search itemsGET /items/low-stock
- Get items with low stockGET /items/active
- Get active items only
Stock Transactions
GET /stock-transactions/
- List all transactionsPOST /stock-transactions/
- Create new transaction (updates stock automatically)GET /stock-transactions/{id}
- Get transaction by IDGET /stock-transactions/item/{item_id}
- Get transactions for specific itemGET /stock-transactions/type/{type}
- Get transactions by type (in/out/adjustment)
System
GET /
- API information and linksGET /health
- Health check endpoint
Database Schema
The system uses the following main entities:
- Users: System users with authentication
- Categories: Product categories for organization
- Suppliers: Supplier information and contacts
- Items: Inventory items with pricing and stock information
- StockTransactions: Record of all stock movements
Usage Examples
1. Login
curl -X POST "http://localhost:8000/auth/login" \
-H "Content-Type: application/json" \
-d '{"email": "admin@inventory.com", "password": "admin123"}'
2. Create a Category
curl -X POST "http://localhost:8000/categories/" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"name": "Electronics", "description": "Electronic devices and components"}'
3. Add an Item
curl -X POST "http://localhost:8000/items/" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "Laptop Computer",
"description": "High-performance laptop",
"sku": "LAP001",
"unit_price": 999.99,
"cost_price": 750.00,
"quantity_in_stock": 10,
"minimum_stock_level": 2,
"reorder_point": 5,
"category_id": 1
}'
4. Record Stock Transaction
curl -X POST "http://localhost:8000/stock-transactions/" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"item_id": 1,
"transaction_type": "out",
"quantity": 2,
"reference_number": "SALE001",
"notes": "Sale to customer"
}'
Development
Running with Auto-reload
uvicorn main:app --reload
Code Formatting
The project uses Ruff for linting and formatting:
ruff check .
ruff format .
Database Migrations
Create a new migration:
alembic revision --autogenerate -m "Description of changes"
Apply migrations:
alembic upgrade head
Production Deployment
- Set secure environment variables
- Use a production WSGI server like Gunicorn
- Configure proper SSL/TLS certificates
- Set up database backups
- Configure logging and monitoring
License
This project is open source and available under the MIT License.