
- Created complete RESTful API for inventory management - Set up database models for items, categories, suppliers, and transactions - Implemented user authentication with JWT tokens - Added transaction tracking for inventory movements - Created comprehensive API endpoints for all CRUD operations - Set up Alembic for database migrations - Added input validation and error handling - Created detailed documentation in README
Small Business Inventory Management System
A RESTful API built with FastAPI and SQLite to help small businesses manage their inventory, track stock levels, and handle inventory transactions.
Features
- User authentication with JWT tokens
- Inventory items management with categories and suppliers
- Stock level monitoring and low-stock alerts
- Transaction tracking (purchases, sales, adjustments, returns)
- Comprehensive reporting endpoints
- Role-based access control
Technology Stack
- Framework: FastAPI
- Database: SQLite with SQLAlchemy ORM
- Migrations: Alembic
- Authentication: JWT tokens with password hashing
- Validation: Pydantic
- Code Quality: Ruff
Getting Started
Prerequisites
- Python 3.8+
- Virtual environment (recommended)
Installation
-
Clone the repository:
git clone <repository-url> cd smallbusinessinventorymanagementsystem
-
Create and activate a virtual environment:
python -m venv venv source venv/bin/activate # On Windows, use: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Set up environment variables:
export SECRET_KEY="your-secret-key-here" # For production, use a strong random key
-
Run database migrations:
alembic upgrade head
-
Start the application:
uvicorn main:app --reload
The API will be available at http://localhost:8000. The interactive API documentation is available at http://localhost:8000/docs.
API Endpoints
Authentication
POST /api/v1/login/access-token
- Get an access tokenPOST /api/v1/login/test-token
- Test an access token
Users
GET /api/v1/users/
- Get all users (admin only)POST /api/v1/users/
- Create a new user (admin only)GET /api/v1/users/me
- Get current userPUT /api/v1/users/me
- Update current userGET /api/v1/users/{user_id}
- Get a specific userPUT /api/v1/users/{user_id}
- Update a specific user (admin only)
Items
GET /api/v1/items/
- Get all itemsPOST /api/v1/items/
- Create a new itemGET /api/v1/items/{id}
- Get an item by IDPUT /api/v1/items/{id}
- Update an itemDELETE /api/v1/items/{id}
- Delete an itemGET /api/v1/items/by-category/{category_id}
- Get items by categoryGET /api/v1/items/by-supplier/{supplier_id}
- Get items by supplierGET /api/v1/items/low-stock/
- Get items with low stock
Categories
GET /api/v1/categories/
- Get all categoriesPOST /api/v1/categories/
- Create a new categoryGET /api/v1/categories/{id}
- Get a category by IDPUT /api/v1/categories/{id}
- Update a categoryDELETE /api/v1/categories/{id}
- Delete a category
Suppliers
GET /api/v1/suppliers/
- Get all suppliersPOST /api/v1/suppliers/
- Create a new supplierGET /api/v1/suppliers/{id}
- Get a supplier by IDPUT /api/v1/suppliers/{id}
- Update a supplierDELETE /api/v1/suppliers/{id}
- Delete a supplier
Transactions
GET /api/v1/transactions/
- Get all transactionsPOST /api/v1/transactions/
- Create a new transactionGET /api/v1/transactions/{id}
- Get a transaction by IDGET /api/v1/transactions/by-item/{item_id}
- Get transactions by itemGET /api/v1/transactions/by-user/{user_id}
- Get transactions by user (admin only)GET /api/v1/transactions/by-type/{transaction_type}
- Get transactions by typeGET /api/v1/transactions/by-date-range/
- Get transactions by date range
Environment Variables
Variable | Description | Default Value |
---|---|---|
SECRET_KEY | Key used for JWT token generation | "your-secret-key-here-make-sure-to-change-in-production" |
ACCESS_TOKEN_EXPIRE_MINUTES | Token expiration time in minutes | 11520 (8 days) |
Development
Running Tests
pytest
Linting with Ruff
ruff check .
ruff format .
License
This project is licensed under the MIT License - see the LICENSE file for details.
Description
Languages
Python
99.1%
Mako
0.9%