StockFlow

Inventory & Order Management System

A database-driven inventory and order management application for products, categories, stock movements, and customer orders.

  • Python
  • Django
  • SQLite
  • Django ORM

Overview

StockFlow is a database-driven inventory and order management application designed to manage products, categories, stock movements, and customer orders. It is built with Django and the Django ORM, with SQLite as the development database.

The focus of the project is correctness of stock data: every change to a product's quantity is recorded as a stock movement, validated against business rules, and written inside a database transaction.

Problem statement

Small businesses that track inventory in spreadsheets lose accuracy quickly: stock counts drift from reality, orders are accepted for items that are not on the shelf, and there is no history of why a number changed.

StockFlow models inventory as a relational system so stock levels, orders, and the movements that connect them stay consistent with each other.

Technical architecture

StockFlow is a server-rendered Django application. URL patterns route requests to views, business rules are applied before data is saved, and Django templates render the result. The Django admin is configured as the back-office interface for managing records.

Inventory adjustments run inside transaction.atomic(), so a stock movement and the matching quantity change are committed together or not at all. If any step raises an exception, for example because an order would take stock below zero, the whole transaction is rolled back and the database is left unchanged.

Inside that transaction the product row is read with select_for_update(). On PostgreSQL this issues SELECT ... FOR UPDATE, which locks the row until the transaction ends so two concurrent orders cannot both read the same quantity and oversell. SQLite does not support row-level locking: Django omits the FOR UPDATE clause on SQLite, and SQLite instead serializes writers with a database-wide write lock. The code is written for the PostgreSQL behavior, and the guarantee under real concurrency should be verified on PostgreSQL rather than SQLite.

Database design

The schema is built around five related models: Category, Product, Order, OrderItem, and StockMovement.

Product has a foreign key to Category. Order has many OrderItems, and each OrderItem references both its Order and a Product, so an order line always points to a real product. StockMovement references a Product and records each change to its stock, which gives every quantity an audit trail.

Database constraints and ORM relationships enforce integrity at the database level, not only in forms, so invalid data is rejected no matter which code path writes it.

Key functionality

  • Product and category management
  • Product search and filtering
  • Stock movement tracking
  • Transactional inventory adjustments with transaction.atomic()
  • Stock quantity validation before changes are saved
  • Order and order item management
  • Order status management with business rules
  • Relational database models with foreign keys
  • Database constraints for data integrity
  • Configured Django administration
  • Automated tests

Technologies used

  • Python
  • Django
  • SQLite
  • Django ORM

Technical challenges

Keeping stock consistent

A quantity change and its stock movement record must never get out of sync. Wrapping both writes in one atomic transaction means a failure halfway through leaves no partial update behind.

Preventing overselling

Validation has to happen against the current quantity inside the transaction, not against a value read earlier. Locking the product row with select_for_update() addresses this on PostgreSQL; on SQLite the database-level write lock serializes writers instead, which is one reason PostgreSQL is the target for production.

Enforcing rules in more than one place

Validation in forms gives users clear errors, while database constraints are the last line of defense for any code path that writes data, including the admin and tests.

More projects

Developer Portfolio

Full-Stack Django Application

This website: a Django application with admin-managed projects, skills and resume, and a validated, rate-limited contact form.

  • Python
  • Django
  • HTML
  • JavaScript
  • CSS
  • Database-driven profile, skills, projects, and resume content
  • Django admin with search, filters, inline screenshots, and publish/unpublish actions
  • Project case-study pages with unpublished projects hidden from visitors