A Flask-based Inventory Management System designed for small retail companies. This application allows employees to manage product inventory with full CRUD operations and real-time product data fetching from the OpenFoodFacts API.
- Complete CRUD operations: Create, Read, Update, and Delete inventory items
- External API integration: Fetch product details automatically from OpenFoodFacts by product name
- CLI interface: Command-line tool for easy inventory management
- Flask Shell: Interactive shell for direct database interaction
- Database: SQLite for lightweight, file-based data storage
- Unit Testing: pytest suite for reliability
flaskSammative/
│
├── app.py # Flask application, routes, and database models
├── models.py # Database model definitions
├── cli.py # CLI interface for API interaction
├── tests/
│ └── test_app.py # Unit tests
├── requirements.txt # Python dependencies
├── README.md # Project documentation
└── .gitignore # Git ignore rules
- Python 3.7 or higher
- Git
- Clone the repository
git clone https://github.com/devbysamcloudy/flaskSammative
cd flaskSammative- Create a virtual environment (recommended)
python -m venv venv
source venv/bin/activate # Linux/macOS
# or
venv\Scripts\activate # Windows- Install dependencies
pip install -r requirements.txt- Run the Flask application
python app.pyThe application will start at http://127.0.0.1:5000
| Method | Endpoint | Description |
|---|---|---|
| POST | /items |
Add a new inventory item |
| GET | /items |
Get all inventory items |
| PATCH | /items/<id> |
Update an item by ID |
| DELETE | /items/<id> |
Delete an item by ID |
| GET | /fetch/<product_name> |
Fetch product from OpenFoodFacts and add to inventory |
Add an item
curl -X POST http://127.0.0.1:5000/items \
-H "Content-Type: application/json" \
-d '{"name": "Milk", "quantity": 10, "price": 1.99, "barcode": "123456"}'Get all items
curl http://127.0.0.1:5000/itemsUpdate an item
curl -X PATCH http://127.0.0.1:5000/items/1 \
-H "Content-Type: application/json" \
-d '{"quantity": 20, "price": 2.49}'Delete an item
curl -X DELETE http://127.0.0.1:5000/items/1Fetch from OpenFoodFacts
curl http://127.0.0.1:5000/fetch/nutellaMake sure the Flask app is running first, then in a separate terminal:
python cli.py1- View all items2- Add a new item3- Delete an item by ID4- Fetch a product from OpenFoodFacts by name
Follow the interactive prompts to manage your inventory.
Use the Flask shell to interact with the database directly:
export FLASK_APP=app.py
flask shellInside the shell:
from app import db, Item
# Create tables
db.create_all()
# Add an item
item = Item(name="Milk", quantity=10, price=1.99, barcode="123456")
db.session.add(item)
db.session.commit()
# Query all items
Item.query.all()
# Query one item
Item.query.get(1)
# Delete an item
item = Item.query.get(1)
db.session.delete(item)
db.session.commit()Execute the test suite:
pytestNote: Ensure the Flask app is not running when executing tests to avoid port conflicts.
This project was developed using feature branches:
feature-crud- CRUD operations implementationfeature-api- OpenFoodFacts API integrationfeature-cli- Command-line interface development
All pull requests were merged before final submission.
- The database file (
inventory.db) will be automatically created inside theinstance/folder on first run - An active internet connection is required when fetching data from OpenFoodFacts
- Product prices and quantities can be modified via PATCH requests or the CLI
- The system uses SQLite, so no separate database server is needed
Issue: Database not found
- Solution: The system will create
inventory.dbautomatically on first run
Issue: API fetch failing
- Solution: Check your internet connection and verify the product name exists in OpenFoodFacts
Issue: Port 5000 already in use
- Solution: Change the port in
app.pyor stop the application using that port
Issue: CLI not connecting
- Solution: Make sure the Flask app is running before starting the CLI
Samuel Nganga
- Email: snganga685@gmail.com
- GitHub: devbysamcloudy/flaskSammative
This project is for educational purposes as part of a software development assessment.