Automated Action 4aac37bc90 Implement inventory management system with FastAPI and SQLite
- Setup project structure with FastAPI application
- Create database models with SQLAlchemy
- Configure Alembic for database migrations
- Implement CRUD operations for products, categories, suppliers
- Add inventory transaction functionality
- Implement user authentication with JWT
- Add health check endpoint
- Create comprehensive documentation
2025-06-05 11:43:07 +00:00
2025-06-05 11:28:29 +00:00

Small Business Inventory Management System

A comprehensive inventory management system built with FastAPI and SQLite, designed for small businesses to track products, manage inventory transactions, suppliers, and categories.

Features

  • Product Management: Create, update, view, and delete products with details like SKU, barcode, pricing, and stock levels
  • Inventory Transactions: Track inventory movements (purchases, sales, adjustments, returns)
  • Supplier Management: Maintain supplier information and track products by supplier
  • Category Organization: Organize products into categories
  • User Authentication: Secure JWT-based authentication system
  • Role-Based Access Control: Regular users and superusers with different permissions
  • API Documentation: Auto-generated interactive documentation

Technology Stack

  • Backend: FastAPI (Python)
  • Database: SQLite with SQLAlchemy ORM
  • Authentication: JWT tokens
  • Migration System: Alembic
  • Validation: Pydantic

Project Structure

.
├── alembic/              # Database migration scripts
├── app/                  # Main application
│   ├── api/              # API endpoints
│   │   ├── deps.py       # Dependencies (auth, db session)
│   │   └── routes/       # API route modules
│   ├── core/             # Core modules (config, security)
│   ├── crud/             # CRUD operations
│   ├── db/               # Database setup and base classes
│   ├── models/           # SQLAlchemy models
│   └── schemas/          # Pydantic schemas for validation
├── storage/              # Storage directories
│   └── db/               # SQLite database location
├── main.py               # Application entry point
├── alembic.ini           # Alembic configuration
└── requirements.txt      # Python dependencies

Environment Variables

The application uses the following environment variables:

Variable Description Default
SECRET_KEY JWT secret key for token generation "generate_a_secure_secret_key_here"
ADMIN_PASSWORD Password for initial admin user "admin"
ACCESS_TOKEN_EXPIRE_MINUTES JWT token expiration time in minutes 11520 (8 days)

Getting Started

Prerequisites

  • Python 3.8 or higher

Installation

  1. Clone the repository:

    git clone <repository-url>
    cd smallbusinessinventorymanagementsystem
    
  2. Install dependencies:

    pip install -r requirements.txt
    
  3. Set up environment variables (recommended):

    export SECRET_KEY="your-secure-secret-key"
    export ADMIN_PASSWORD="your-admin-password"
    
  4. Apply database migrations:

    alembic upgrade head
    
  5. Initialize the database with initial data (creates admin user):

    python -m app.initial_data
    
  6. Start the application:

    uvicorn main:app --host 0.0.0.0 --port 8000 --reload
    

API Documentation

Once the application is running, you can access:

Authentication

The API uses JWT tokens for authentication. To obtain a token:

  1. Make a POST request to /api/v1/login/access-token with form data:

    • username: your username
    • password: your password
  2. Use the returned access token in the Authorization header for protected endpoints:

    Authorization: Bearer <your-token>
    

Initial User

An admin user is automatically created when running the initial_data script:

  • Username: admin
  • Password: The value of ADMIN_PASSWORD env variable (default: "admin")
  • Email: admin@example.com

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 user
  • PUT /api/v1/users/me - Update current user
  • GET /api/v1/users/{user_id} - Get user by ID
  • PUT /api/v1/users/{user_id} - Update user (admin only)
  • DELETE /api/v1/users/{user_id} - Delete user (admin only)

Products

  • GET /api/v1/products/ - List products
  • POST /api/v1/products/ - Create product
  • GET /api/v1/products/{product_id} - Get product by ID
  • PUT /api/v1/products/{product_id} - Update product
  • DELETE /api/v1/products/{product_id} - Delete product
  • POST /api/v1/products/{product_id}/adjust - Adjust product quantity

Categories

  • GET /api/v1/categories/ - List categories
  • POST /api/v1/categories/ - Create category
  • GET /api/v1/categories/{category_id} - Get category by ID
  • PUT /api/v1/categories/{category_id} - Update category
  • DELETE /api/v1/categories/{category_id} - Delete category

Suppliers

  • GET /api/v1/suppliers/ - List suppliers
  • POST /api/v1/suppliers/ - Create supplier
  • GET /api/v1/suppliers/{supplier_id} - Get supplier by ID
  • PUT /api/v1/suppliers/{supplier_id} - Update supplier
  • DELETE /api/v1/suppliers/{supplier_id} - Delete supplier

Inventory Transactions

  • GET /api/v1/inventory/transactions/ - List transactions
  • POST /api/v1/inventory/transactions/ - Create transaction
  • GET /api/v1/inventory/transactions/{transaction_id} - Get transaction by ID
  • DELETE /api/v1/inventory/transactions/{transaction_id} - Delete transaction (admin only)

Health Check

  • GET /health - Check system health

License

MIT License

Description
Project: Small Business Inventory Management System
Readme 56 KiB
Languages
Python 99%
Mako 1%