
- 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
141 lines
4.6 KiB
Markdown
141 lines
4.6 KiB
Markdown
# 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
|
|
|
|
1. Clone the repository:
|
|
```
|
|
git clone https://github.com/yourusername/smallbusinessinventorysystem.git
|
|
cd smallbusinessinventorysystem
|
|
```
|
|
|
|
2. Install dependencies:
|
|
```
|
|
pip install -r requirements.txt
|
|
```
|
|
|
|
3. Set up environment variables:
|
|
```
|
|
# Create a .env file with the following variables (optional)
|
|
SECRET_KEY=your-secret-key
|
|
```
|
|
|
|
4. Initialize the database:
|
|
```
|
|
alembic upgrade head
|
|
```
|
|
|
|
5. Run the application:
|
|
```
|
|
uvicorn main:app --reload
|
|
```
|
|
|
|
## API Documentation
|
|
|
|
Once the application is running, you can access:
|
|
|
|
- Interactive API documentation: [http://localhost:8000/docs](http://localhost:8000/docs)
|
|
- Alternative documentation: [http://localhost:8000/redoc](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 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)
|
|
|
|
### 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
|
|
|
|
### Items
|
|
- `GET /api/v1/items/` - List items
|
|
- `POST /api/v1/items/` - Create item
|
|
- `GET /api/v1/items/{item_id}` - Get item by ID
|
|
- `PUT /api/v1/items/{item_id}` - Update item
|
|
- `DELETE /api/v1/items/{item_id}` - Delete item
|
|
|
|
### Transactions
|
|
- `GET /api/v1/transactions/` - List transactions
|
|
- `POST /api/v1/transactions/` - Create transaction
|
|
- `GET /api/v1/transactions/{transaction_id}` - Get transaction by ID
|
|
|
|
## Health Check
|
|
- `GET /health` - Check system health
|
|
- `GET /` - Basic service information |