
- Fix unused imports in API endpoints - Add proper __all__ exports in model and schema modules - Add proper TYPE_CHECKING imports in models to prevent circular imports - Fix import order in migrations - Fix long lines in migration scripts - All ruff checks passing
4.7 KiB
4.7 KiB
Small Business Inventory Management System
Overview
This project is a comprehensive inventory management system designed for small businesses. It provides a robust REST API for managing products, categories, suppliers, and inventory transactions, along with analytics for business insights.
Features
- User Authentication: Secure login and user management
- Product Management: CRUD operations for products with SKU, pricing, and stock levels
- Category Management: Organize products into categories
- Supplier Management: Track and manage your suppliers
- Inventory Transactions: Record purchases, sales, returns, and adjustments
- Inventory Analytics: Get insights into your inventory performance
- Stock Alerts: Identify low stock and out-of-stock products
Tech Stack
- Framework: FastAPI
- Database: SQLite
- ORM: SQLAlchemy
- Authentication: JWT (JSON Web Tokens)
- Migrations: Alembic
API Endpoints
Authentication
POST /api/v1/auth/login
- Login to get access tokenPOST /api/v1/auth/test-token
- Verify access token
Users
GET /api/v1/users/
- List all users (admin only)POST /api/v1/users/
- Create a new user (admin only)GET /api/v1/users/me
- Get current user infoPUT /api/v1/users/me
- Update current user infoGET /api/v1/users/{user_id}
- Get user by IDPUT /api/v1/users/{user_id}
- Update user (admin only)
Categories
GET /api/v1/categories/
- List all categoriesPOST /api/v1/categories/
- Create a new categoryGET /api/v1/categories/{id}
- Get category by IDPUT /api/v1/categories/{id}
- Update categoryDELETE /api/v1/categories/{id}
- Delete category (admin only)
Suppliers
GET /api/v1/suppliers/
- List all suppliersPOST /api/v1/suppliers/
- Create a new supplierGET /api/v1/suppliers/{id}
- Get supplier by IDPUT /api/v1/suppliers/{id}
- Update supplierDELETE /api/v1/suppliers/{id}
- Delete supplier (admin only)
Products
GET /api/v1/products/
- List all productsPOST /api/v1/products/
- Create a new productGET /api/v1/products/{id}
- Get product by IDPUT /api/v1/products/{id}
- Update productDELETE /api/v1/products/{id}
- Delete productGET /api/v1/products/by-category/{category_id}
- Get products by categoryGET /api/v1/products/by-supplier/{supplier_id}
- Get products by supplierGET /api/v1/products/low-stock
- Get low stock productsGET /api/v1/products/out-of-stock
- Get out of stock products
Inventory Transactions
POST /api/v1/inventory-transactions/
- Create a new transactionGET /api/v1/inventory-transactions/
- List all transactionsGET /api/v1/inventory-transactions/{id}
- Get transaction by IDGET /api/v1/inventory-transactions/by-product/{product_id}
- Get transactions by productGET /api/v1/inventory-transactions/by-type/{transaction_type}
- Get transactions by type
Analytics
GET /api/v1/analytics/inventory-summary
- Get inventory summaryGET /api/v1/analytics/transaction-history
- Get transaction historyGET /api/v1/analytics/product-performance
- Get product performanceGET /api/v1/analytics/category-performance
- Get category performance
Installation and Setup
Prerequisites
- Python 3.8+
- pip
Setting Up the Environment
-
Clone the repository:
git clone <repository-url> cd smallbusinessinventorymanagementsystem
-
Install the required packages:
pip install -r requirements.txt
-
Create a
.env
file in the root directory (optional):SECRET_KEY=your_secret_key_here ACCESS_TOKEN_EXPIRE_MINUTES=43200 # 30 days
Database Setup
-
The application uses SQLite by default, stored at
/app/storage/db/db.sqlite
. -
Run the database migrations:
alembic upgrade head
Running the Application
-
Start the FastAPI server:
uvicorn main:app --reload
-
Access the API documentation at:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
Environment Variables
Variable | Description | Default |
---|---|---|
SECRET_KEY | Secret key for JWT encoding | "CHANGE_ME_IN_PRODUCTION" |
ACCESS_TOKEN_EXPIRE_MINUTES | Token expiration time in minutes | 10080 (7 days) |
SQLALCHEMY_DATABASE_URL | Database connection URL | "sqlite:///app/storage/db/db.sqlite" |
Development
Creating a Superuser
To create a superuser account, you can use the API or add a user directly to the database with the is_superuser
flag set to True
.
Running Tests
pytest
License
This project is licensed under the MIT License - see the LICENSE file for details.