
- Set up project structure with FastAPI and SQLite - Created database models for users, categories, suppliers, items, and stock transactions - Implemented Alembic for database migrations with proper absolute paths - Built comprehensive CRUD operations for all entities - Added JWT-based authentication and authorization system - Created RESTful API endpoints for all inventory operations - Implemented search, filtering, and low stock alerts - Added health check endpoint and base URL response - Configured CORS for all origins - Set up Ruff for code linting and formatting - Updated README with comprehensive documentation and usage examples The system provides complete inventory management functionality for small businesses including product tracking, supplier management, stock transactions, and reporting. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
79 lines
2.2 KiB
Python
79 lines
2.2 KiB
Python
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from app.core.config import settings
|
|
from app.db.session import get_db, engine
|
|
from app.db.base import Base
|
|
from app.api import auth, categories, suppliers, items, stock_transactions
|
|
from app.crud import user as user_crud
|
|
from app.schemas.user import UserCreate
|
|
|
|
# Create database tables
|
|
Base.metadata.create_all(bind=engine)
|
|
|
|
app = FastAPI(
|
|
title=settings.PROJECT_NAME,
|
|
version=settings.PROJECT_VERSION,
|
|
openapi_url="/openapi.json",
|
|
)
|
|
|
|
# Set up CORS
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=settings.BACKEND_CORS_ORIGINS,
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
# Include routers
|
|
app.include_router(auth.router, prefix="/auth", tags=["authentication"])
|
|
app.include_router(categories.router, prefix="/categories", tags=["categories"])
|
|
app.include_router(suppliers.router, prefix="/suppliers", tags=["suppliers"])
|
|
app.include_router(items.router, prefix="/items", tags=["items"])
|
|
app.include_router(
|
|
stock_transactions.router, prefix="/stock-transactions", tags=["stock-transactions"]
|
|
)
|
|
|
|
|
|
@app.get("/")
|
|
async def root():
|
|
return {
|
|
"title": settings.PROJECT_NAME,
|
|
"version": settings.PROJECT_VERSION,
|
|
"description": "API for managing inventory in small businesses",
|
|
"documentation": "/docs",
|
|
"health_check": "/health",
|
|
}
|
|
|
|
|
|
@app.get("/health")
|
|
async def health_check():
|
|
return {
|
|
"status": "healthy",
|
|
"service": settings.PROJECT_NAME,
|
|
"version": settings.PROJECT_VERSION,
|
|
}
|
|
|
|
|
|
@app.on_event("startup")
|
|
async def startup_event():
|
|
# Create first superuser if it doesn't exist
|
|
db = next(get_db())
|
|
user = user_crud.get_by_email(db, email=settings.FIRST_SUPERUSER_EMAIL)
|
|
if not user:
|
|
user_in = UserCreate(
|
|
email=settings.FIRST_SUPERUSER_EMAIL,
|
|
password=settings.FIRST_SUPERUSER_PASSWORD,
|
|
full_name="System Administrator",
|
|
)
|
|
user = user_crud.create(db, obj_in=user_in)
|
|
user.is_superuser = True
|
|
db.add(user)
|
|
db.commit()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
import uvicorn
|
|
|
|
uvicorn.run(app, host="0.0.0.0", port=8000)
|