
- Set up project structure for FastAPI application - Create database models for items, categories, suppliers, and transactions - Set up Alembic for database migrations - Implement API endpoints for all entities - Add authentication with JWT tokens - Add health check endpoint - Create comprehensive README with documentation
Small Business Inventory System
A comprehensive inventory management system built with FastAPI and SQLite, designed for small businesses.
Features
- User Authentication: Secure login and user management system
- Item Management: Create, read, update, and delete inventory items
- Category Management: Organize items by categories
- Supplier Management: Keep track of item suppliers
- Transaction Management: Record stock movements (in/out/adjustments)
- API Documentation: Interactive API documentation with Swagger UI
Technology Stack
- Backend: FastAPI (Python)
- Database: SQLite with SQLAlchemy ORM
- Migration: Alembic for database migrations
- Authentication: JWT token-based authentication
- Documentation: Swagger UI and ReDoc
Project Structure
.
├── app/
│ ├── api/
│ │ ├── deps.py # API dependencies
│ │ └── v1/ # API v1 endpoints
│ │ ├── endpoints/ # Individual endpoint modules
│ │ └── api.py # API router
│ ├── core/ # Core modules
│ │ ├── config.py # Settings and configuration
│ │ └── security.py # Security utilities
│ ├── db/ # Database utilities
│ │ ├── base.py # SQLAlchemy declarative base
│ │ └── session.py # Database session management
│ ├── models/ # SQLAlchemy models
│ └── schemas/ # Pydantic schemas
├── migrations/ # Alembic migrations
├── alembic.ini # Alembic configuration
├── main.py # Application entry point
└── requirements.txt # Project dependencies
Setup and Installation
Prerequisites
- Python 3.8 or higher
Installation
-
Clone the repository:
git clone https://github.com/yourusername/smallbusinessinventorysystem.git cd smallbusinessinventorysystem
-
Install dependencies:
pip install -r requirements.txt
-
Set up environment variables:
# Create a .env file with the following variables (optional) SECRET_KEY=your-secret-key
-
Initialize the database:
alembic upgrade head
-
Run the application:
uvicorn main:app --reload
API Documentation
Once the application is running, you can access:
- Interactive API documentation: http://localhost:8000/docs
- Alternative documentation: http://localhost:8000/redoc
Environment Variables
Variable | Description | Default |
---|---|---|
PROJECT_NAME | Name of the project | Small Business Inventory System |
SECRET_KEY | Secret key for JWT encoding | supersecretkey (change in production!) |
ACCESS_TOKEN_EXPIRE_MINUTES | JWT token expiration time | 30 |
Database
The application uses SQLite as the database, stored at /app/storage/db/db.sqlite
. This location can be configured through environment variables if needed.
API Endpoints
Authentication
POST /api/v1/login/access-token
- Get access token
Users
GET /api/v1/users/
- List users (admin only)POST /api/v1/users/
- Create user (admin only)GET /api/v1/users/me
- Get current userPUT /api/v1/users/me
- Update current userGET /api/v1/users/{user_id}
- Get user by IDPUT /api/v1/users/{user_id}
- Update user (admin only)
Categories
GET /api/v1/categories/
- List categoriesPOST /api/v1/categories/
- Create categoryGET /api/v1/categories/{category_id}
- Get category by IDPUT /api/v1/categories/{category_id}
- Update categoryDELETE /api/v1/categories/{category_id}
- Delete category
Suppliers
GET /api/v1/suppliers/
- List suppliersPOST /api/v1/suppliers/
- Create supplierGET /api/v1/suppliers/{supplier_id}
- Get supplier by IDPUT /api/v1/suppliers/{supplier_id}
- Update supplierDELETE /api/v1/suppliers/{supplier_id}
- Delete supplier
Items
GET /api/v1/items/
- List itemsPOST /api/v1/items/
- Create itemGET /api/v1/items/{item_id}
- Get item by IDPUT /api/v1/items/{item_id}
- Update itemDELETE /api/v1/items/{item_id}
- Delete item
Transactions
GET /api/v1/transactions/
- List transactionsPOST /api/v1/transactions/
- Create transactionGET /api/v1/transactions/{transaction_id}
- Get transaction by ID
Health Check
GET /health
- Check system healthGET /
- Basic service information
Description
Languages
Python
98.8%
Mako
1.2%