Skip to content

Latest commit

ย 

History

19 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ“ฆ StockMate - Inventory & Sales Management System

FastAPI Python MySQL SQLAlchemy Bootstrap Railway

Manage Stock. Track Sales. Grow Business.

StockMate is a modern, high-performance, transaction-safe Inventory and Sales Management System built to streamline daily business operations. Developed primarily to demonstrate core backend engineering proficiency in Python, RESTful API design, database normalization, and robust concurrency handling.

Whether you run a single retail storefront or coordinate a multi-channel operation, StockMate provides business owners and counter employees with a secure, responsive, and visually stunning tool to control stock levels, log sales, track procurement, and analyze financial performance.

Ideal For:

  • Retail Stores & Shop Owners โ€“ Fast invoice generation and real-time stock deductions.
  • Wholesalers & Distributors โ€“ Track bulk purchasing lists and vendor relations.
  • Warehouses & Small Businesses โ€“ Automated alerts for low stock levels and expiring products.

๐Ÿ“‹ Table of Contents

  1. ๐ŸŒ Live Demo
  2. ๐Ÿ“ธ Screenshots
  3. ๐Ÿš€ Features
  4. ๐Ÿ› ๏ธ Technology Stack
  5. ๐Ÿ“‚ Project Structure
  6. ๐Ÿ—„๏ธ Database Schema
  7. ๐Ÿ”„ Application Workflow
  8. ๐Ÿ’ป Installation Guide
  9. ๐Ÿ”‘ Environment Variables
  10. ๐Ÿ“– API Documentation
  11. โ˜๏ธ Deployment
  12. ๐Ÿ”ฎ Future Improvements
  13. ๐ŸŽฏ Why This Project
  14. โœ๏ธ Author

๐ŸŒ Live Demo

Explore the live application and interactive API documentation:

Service Endpoint / Link Description
Frontend / Web App (Render) https://stockmate-vlpq.onrender.com/ Access the dashboards and UI screens.
Frontend / Web App (Railway) https://stock-mate.up.railway.app/ Access the dashboards and UI screens.
API Documentation https://stock-mate.up.railway.app//docs Interactive Swagger UI for REST endpoint testing.

๐Ÿ“ธ Screenshots

๐Ÿ”‘ Login Page

Login Page Provides secure, session-managed entry points for Owners and Employees.

๐Ÿ“Š Owner Dashboard

Owner Dashboard Provides Owner-only financial analytics including daily sales, monthly revenue trend charts, and alert summaries.

๐Ÿ‘ค Employee Dashboard

Employee Dashboard A clean workspace for sales agents to record sales and check products.

๐Ÿ“ฆ Product Management

Product Management Real-time product grid with automated visual warnings for Expired, Low Stock, and Expiring Soon items.

๐Ÿ‘ฅ Customer Management

Customer Management Maintains a registry of customer contact details and transaction history.

๐Ÿญ Supplier Management

Supplier Management Tracks contact information and purchase history for replenishment vendors.

๐Ÿ›๏ธ Purchase Module (Replenishments)

Purchase Module Enables employees to draft restocking orders, awaiting owner approval before updating inventory.

๐Ÿ›’ Sales Module (Point of Sale)

Sales Module Interactive multi-item checkout builder that dynamically computes prices, sub-totals, and GST.

๐Ÿ“„ Dynamic Invoice PDF

Invoice PDF Sample dynamic invoice generated programmatically with full business branding and GST calculations.

๐Ÿ“ˆ Reports & Analytics

Reports Page Provides customized date filters for profit analysis and data exporting.

๐Ÿ“‰ Analytical Charts

Charts View Chart.js graphics representing revenue flow, category distributions, and top product metrics.

๐Ÿ”” System Notifications

Notifications Screen Displays warning notifications for low stock thresholds and approaching expiry dates.

โš™๏ธ Audit Logs

Settings Page Security Audit Logs


๐Ÿš€ Features

๐Ÿ” Authentication & Security

  • Secure Login / Logout: Uses HTTP-Only secure cookies to manage state and session tokens.
  • Role-Based Access Control (RBAC): Restricts administrative modules (Audit Logs, Reports, Employee registers) strictly to Owner accounts, while permitting counter checkout processes to Employee credentials.
  • Password Hashing: Implements secure one-way hashing algorithms (bcrypt) to safely store credentials.
  • Route Protection: Validates JWT payloads on every requests to prevent session hijacking.

๐Ÿ“ฆ Inventory Control

  • Product Catalog: Full CRUD capabilities for recording product cost prices, selling prices, stock levels, and expiry alerts.
  • Nested Categories: Standardizes hierarchical categorization with cascading validations.
  • Low Stock Warnings: Computes dynamic warnings whenever product levels drop below their minimum threshold.
  • Expiry Tracking: Flags items automatically as "Expired" or "Expiring Soon" (within 30 days) to prevent waste.
  • Search & Filters: Multi-parameter search by keyword, category, and alert status.

๐Ÿ›’ Sales & Billing

  • Customer Ledger: Integrates customer contact numbers and emails with their historical purchases.
  • Multi-Product Checkout: Point-of-sale interface to build, adjust, and submit sales with live price updates.
  • Atomic Deductions: Utilizes database-level locking (.with_for_update()) to prevent race conditions during concurrent checkouts, rolling back transactions completely if any item check fails.
  • Profit Calculations: Calculates revenue margins per line item and stores aggregates for financial reporting.

๐Ÿญ Purchases & Restocking

  • Supplier Directory: Manages vendor contacts and logs previous procurement transactions.
  • Purchase Orders: Standardizes replenishment drafts. Stock levels and average unit cost prices are only updated upon Owner approval.

๐Ÿ“Š Business Intelligence & Exports

  • Live Dashboards: High-impact dashboards rendering charts for Daily Sales, Monthly Trends, Category distribution, and Top-Selling inventory.
  • Financial Reports: Custom interval queries (Today, Yesterday, Last 7 Days, Month, Year, Custom Range) compiling net revenues and margins.
  • Data Streams: Streams large datasets directly into CSV files for Excel importing.
  • PDF Billing: Instantly generates clean PDF invoice sheets formatted with client and server information using ReportLab.

๐Ÿ› ๏ธ Technology Stack

Component Technology Description
Backend Python Core application runtime.
FastAPI High-performance, asynchronous REST framework.
Frontend HTML5 & CSS3 Dynamic page structures.
Bootstrap 5 Responsive layout styling and dark custom glassmorphic overrides.
Vanilla JavaScript Asynchronous fetches, dynamic form rows, and modal interactions.
Database MySQL / SQLite Relational transactional databases.
SQLAlchemy Database Object Relational Mapper (ORM) with transaction manager.
Validation Pydantic Strict runtime schema parsing and request verification.
Visualizations Chart.js Renders HTML5 Canvas dashboards.
Reporting ReportLab Generates dynamic PDF invoice streams.
Deployment Railway Cloud hosting with automated continuous deployment.
VCS Git & GitHub Source code management.

๐Ÿ“‚ Project Structure

StockMate/
โ”‚
โ”œโ”€โ”€ app/
โ”‚   โ”œโ”€โ”€ auth/              # Security dependencies, role tokens, and bcrypt hashing
โ”‚   โ”œโ”€โ”€ models/            # SQLAlchemy Database structures (User, Sale, Product, etc.)
โ”‚   โ”œโ”€โ”€ routers/           # REST Endpoints and HTML controllers
โ”‚   โ”œโ”€โ”€ schemas/           # Pydantic schemas for payload validation
โ”‚   โ”œโ”€โ”€ static/            # Frontend assets (CSS styles, JS modules, logo images)
โ”‚   โ”œโ”€โ”€ templates/         # Jinja2 templates (dashboard layouts, invoices, modals)
โ”‚   โ”œโ”€โ”€ utils/             # Business helpers (PDF builder, CSV exporter, logger)
โ”‚   โ”œโ”€โ”€ config.py          # Settings parser with environment variables
โ”‚   โ”œโ”€โ”€ database.py        # Database engine setup and local session getters
โ”‚   โ””โ”€โ”€ main.py            # Main ASGI app init, middleware, and startup triggers
โ”‚
โ”œโ”€โ”€ tests/                 # Unit and integration test suites (Pytest)
โ”œโ”€โ”€ screenshots/           # UI image walkthrough files
โ”œโ”€โ”€ Procfile               # Railway process commands
โ”œโ”€โ”€ runtime.txt            # Python compiler instructions
โ”œโ”€โ”€ requirements.txt       # Python dependency package manifests
โ””โ”€โ”€ stockmate.db           # SQLite database for local development

๐Ÿ—„๏ธ Database Schema

StockMate uses a normalized, relational database schema configured with foreign key constraints, indexes for rapid querying, and cascade rules.

                   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                   โ”‚ Categories โ”‚
                   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜
                          โ”‚ 1
                          โ”‚
                          โ”‚ *
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Suppliers โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”ค Products โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”ค Sale_Items โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜ 1    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ *    โ””โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜
      โ”‚                                    โ”‚ *
      โ”‚ 1                                  โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”                              โ”‚ 1
โ”‚ Purchases โ”‚                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜ 1                            โ”‚
      โ”‚                                    โ”‚
      โ”‚ *                                  โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”             โ”Œโ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”
โ”‚ Purchase_Order_Items โ”‚             โ”‚  Sales  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜             โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”˜
                                          โ”‚ *
                                          โ”‚
                                          โ”‚ 1
                                     โ”Œโ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”
                                     โ”‚ Customers โ”‚
                                     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Table Definitions & Relationships:

  1. users
    • Stores credential hashes and system designations (Owner or Employee).
    • Relationships: Has a one-to-many relationship with sales (employee who processed the sale) and audit_logs (user who triggered the event).
  2. categories
    • Manages classifications for products (e.g., Electronics, Groceries).
    • Relationships: One-to-many relationship with products. Removing a category cascades validation to prevent orphaned products.
  3. products
    • Stores core inventory specifications, pricing structures, stock counts, and expiry thresholds.
    • Relationships: Belongs to a single category. Linked to sale_items and purchase_order_items.
  4. suppliers
    • Stores procurement vendor profiles.
    • Relationships: Has a one-to-many relationship with purchases orders.
  5. purchases
    • Tracks restocking requests. Statuses include Pending and Completed.
    • Relationships: Belongs to a supplier. Has many purchase_order_items.
  6. purchase_order_items
    • Stores the breakdown details of a purchase order (product quantities, unit costs).
    • Relationships: Connects purchases to the specific products being restocked.
  7. customers
    • Records retail and corporate clients.
    • Relationships: One-to-many relationship with sales invoices.
  8. sales
    • Represents transactions. Compiles revenue totals, profit aggregates, and GST.
    • Relationships: Linked to a customer and the processing employee (from users). Has many sale_items.
  9. sale_items
    • Individual invoice lines storing historical transaction pricing and counts.
    • Relationships: Pairs each sales record to products.
  10. company_profile / business_settings
    • Stores meta details like Business Name, Address, GST Registration Number, and Tax rates used in PDF headers.
  11. notifications
    • Caches warnings for products with low stock levels or expiring dates.
  12. audit_logs
    • Records security-sensitive operations. Tracks timestamps, actions, target descriptions, and IP addresses.

๐Ÿ”„ Application Workflow

[Login Screen] โ”€โ”€> [Verify Credentials] โ”€โ”€> [Check Role: Owner or Employee?]
                                                     โ”‚
       โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
       โ–ผ                                                                                           โ–ผ
[Owner Dashboard]                                                                         [Employee Dashboard]
* Visual Analytics & Charts                                                               * Personal Sales Counter
* View Full Audit Logs & Reports                                                           * Quick POS Access
* Manage Employee Accounts & CRUD Controls                                                * Search Inventory Details
       โ”‚                                                                                           โ”‚
       โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                              โ–ผ
                                      [Billing/POS Screen]
                                              โ”‚
                                              โ–ผ
                                 [Select Customer & Products]
                                              โ”‚
                                              โ–ผ
                               [Atomic Stock & Inventory Checks]
                                              โ”‚
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ–ผ (Success)                                         โ–ผ (Insufficent Stock)
        [Update Stock Quantities]                                [Rollback Transaction]
                    โ”‚                                                   โ”‚
                    โ–ผ                                                   โ–ผ
       [Commit Sale & Log Actions]                               [Display Error Banner]
                    โ”‚
                    โ–ผ
     [Generate Dynamic PDF Invoice]

๐Ÿ’ป Installation Guide

Prerequisites

  • Python 3.9 or higher.
  • MySQL Server (optional, defaults to SQLite local developer database).

Step 1: Clone Repository

Clone this repository to your local directory:

git clone https://github.com/YOUR_GITHUB_REPOSITORY/StockMate.git
cd StockMate

Step 2: Create Virtual Environment

Initialize a local python virtual environment to isolate package dependencies:

python -m venv .venv

Step 3: Activate Virtual Environment

Activate the environment:

  • Windows (Command Prompt / PowerShell):
    .venv\Scripts\activate
  • macOS / Linux:
    source .venv/bin/activate

Step 4: Install Requirements

Install all dependencies using pip:

pip install -r requirements.txt

Step 5: Configure Environment Variables

Copy the environment variables template and configure your parameters:

cp .env.example .env

(On Windows cmd: copy .env.example .env)

Update the values inside .env (such as changing the Database URL to point to SQLite or your MySQL Server instance).

Step 6: Start Server

Run the FastAPI development server:

uvicorn app.main:app --port 8000 --reload

On startup, StockMate automatically sets up all database tables and seeds default user roles.

Step 7: Open Browser

Navigate to: http://127.0.0.1:8000 Log in with the default credentials:

  • Owner Dashboard: owner@stockmate.com (password: owner123)
  • Employee Dashboard: employee@stockmate.com (password: employee123)

๐Ÿ”‘ Environment Variables

Create a .env file in the project root directory:

# Application Settings
APP_ENV=development # Options: development, production
SECRET_KEY=yoursecretkey123!@# # Used for signing cookie sessions

# Database Configuration
# For SQLite (default development):
DATABASE_URL=sqlite:///./stockmate.db

# For MySQL (production):
# DATABASE_URL=mysql+pymysql://username:password@localhost:3306/stockmate_db

๐Ÿ“– API Documentation

StockMate exposes standard OpenAPI documentation, allowing developers to explore and interact with backend REST APIs:


โ˜๏ธ Deployment

Deploying to Railway

StockMate is pre-configured for instant deployment on Railway:

  1. Procfile: Tells Railway to launch Uvicorn and bind to the correct host and port:
    web: uvicorn app.main:app --host 0.0.0.0 --port $PORT
    
  2. Environment Configuration: Add these variables in the Railway console:
    • APP_ENV = production
    • SECRET_KEY = [YourRandomCryptographicKeyString]
    • DATABASE_URL = [YourProductionMySQLConnectionString]
  3. Database Migrations: Database tables are initialized automatically on application startup.

๐Ÿ”ฎ Future Improvements

Here is the development roadmap for future releases of StockMate:

  • ๐Ÿ” Barcode Scanner Integration โ€“ Scan item barcodes directly via browser camera.
  • ๐Ÿ“ฑ QR Codes on Invoices โ€“ Render payment QR codes on dynamic invoices.
  • โœ‰๏ธ Email Invoices โ€“ E-mail PDF invoices to customers automatically.
  • ๐Ÿ’ฌ WhatsApp Invoices โ€“ Send digital invoice receipts directly to WhatsApp.
  • ๐Ÿข Multi-Store Management โ€“ Manage inventory across multiple stores.
  • ๐Ÿšš Warehouse Transfers โ€“ Coordinate stock movements between warehouse units.
  • ๐Ÿ“ฑ Native Mobile App โ€“ Develop a companion app for inventory checks on the go.
  • ๐Ÿค– AI Demand Forecasting โ€“ Predict restocking requirements based on sales trends.

๐ŸŽฏ Why This Project

This project was built to demonstrate proficiency in core web backend concepts:

  • REST APIs: Designed using clean HTTP methods and structured JSON payloads.
  • Authentication & Authorization: Handled via HTTP-only cookie sessions and JWT parsing.
  • Database Design: Structured relational schema with database-level indexes and atomic operations.
  • Business Logic: Real-world operations like cost accounting, tax collection, and product life-cycle alerts.
  • Data Validations: Strict client/server validation using Pydantic.
  • Reporting: Programmatic file generation (PDF & CSV streams) built dynamically.

It showcases the ability to design, build, and deploy production-ready systems using the Python ecosystem.


โœ๏ธ Author

Jay Jadhav


About

StockMate is a modern, high-performance, transaction-safe Inventory and Sales Management System built to streamline daily business operations.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages