Skip to content

SmartStockRFID/smartstock-backend

Repository files navigation

🌎 English | 🇧🇷 Português

Inventory Control API - (Smart Stock Project)

Python FastAPI PostgreSQL License

REST API for inventory management using RFID, developed as part of the EmbarcaTech Program. It allows real-time stock verification sessions, product catalog management, and report generation through a structured API with role-based access control.

Built with FastAPI, SQLAlchemy, and PostgreSQL.

Features

  • JWT Authentication with token rotation
  • Role-based access controladmin and stockist roles
  • Parts Management — Complete CRUD with filterable listing
  • Stock checking sessions — start, register RFID scans, register events, close, or cancel
  • Reports — inventory metrics and PDF generation
  • Database migrations via Alembic
  • Integration test suite with pytest and an in-memory SQLite database

🛠️ Technologies

Layer Technology
Framework FastAPI 0.116
ORM SQLAlchemy 2.0 + psycopg3
Database PostgreSQL 16
Migrations Alembic
Linting Ruff
Testing pytest + pytest-asyncio
Runtime Python 3.13

💻 Installation and Usage

Prerequisites

1. Clone the repository

git clone {smartstock-backend repository}
cd smartstock-backend

2. Configure environment variables

cp .env.example .env

Edit the .env file with the necessary configurations.

3. Start the project

# Start the services
docker compose -f local.yml up

# Start and force rebuild of images
docker compose -f local.yml up --build

To stop and remove containers:

docker compose -f local.yml down

The API will be available at http://localhost:8000. The interactive documentation is at http://localhost:8000/docs.

4. Create the admin user:

docker compose -f local.yml run --rm fastapi task cli createsuperuser

5. (Optional) Populate the products database with sample data:

docker compose -f local.yml run --rm fastapi task cli seed

📖 API Documentation

The API is divided into the following resource groups:

  • /auth — Login, token refresh, and authenticated user data
  • /produtos — Products CRUD (mutations restricted to admin)
  • /inventarios — Stock checking sessions with RFID scans and events
  • /relatorios — Inventory metrics and PDF export
  • /usuarios — User management (restricted to admin)

All endpoints require a Bearer token unless stated otherwise. Complete interactive documentation with request/response examples is available at /docs.

Tests

The project includes integration tests written with pytest. See tests/README.md for full documentation.

Available Commands

Task Command Description
up task up Starts the development server with reload
migrate task migrate Applies database migrations
makemigrations task makemigrations "msg" Generates a new migration
createsuperuser task createsuperuser Creates an admin user interactively
cli seed task cli seed Populates the database with sample products
test task test Runs the test suite
test-cov task test-cov Runs tests with an HTML coverage report
requirements task requirements Regenerates requirements.txt via uv

🏗️ Project Structure

app/
├── main.py              # FastAPI app and middleware configuration
├── auth.py              # JWT token creation and verification
├── database.py          # SQLAlchemy session management
├── settings.py          # Environment variable-based configuration
├── seed.py              # Sample data population
├── cli/                 # CLI with Typer (createsuperuser, seed)
├── core/                # Exception handlers and shared utilities
├── models/              # SQLAlchemy ORM models
├── schemas/             # Pydantic request/response schemas
├── crud/                # Database query functions
└── routers/             # FastAPI route handlers

tests/                   # Integration tests (pytest + in-memory SQLite)
tk_client/               # Optional Tkinter desktop client for local testing
migrations/              # Alembic migrations history

Desktop Client (Optional)

The tk_client/ directory contains a Tkinter interface for local API testing, without the need for tools like curl or Postman. To use it, set up a local Python environment and run:

python tk_client/main.py

Prerequisite: Python 3.13 installed locally with the dependencies for tk_client/.

📄 License

This project is licensed under the MIT License. See the LICENSE file for more details.

👨‍💻 Authors

This project was created and maintained by:


Developed for the Smart Stock project under the EmbarcaTech Program.

About

Backend API for inventory management with FastAPI and SQLAlchemy.

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages