MCPcopy Create free account
hub / github.com/ConsciousUniverse/simple-stock-management

github.com/ConsciousUniverse/simple-stock-management @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
328 symbols 968 edges 52 files ⚖ GPL-3.0 20 documented · 6% ● updated 2mo ago★ 185

Browse by type

⨍ Functions 303◇ Types & classes 25
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Simpler Stock Management (Beta)

Simpler Stock Management is a web application designed to help manage warehouse and shop stock efficiently. The application provides features for searching, sorting, updating, and transferring stock items between the warehouse and shops. Data is stored in a local SQLite3 database.

Warning: This is a beta release. Deploy to production at your own risk (see the steps in Security, below). The app MUST NOT be run without a TLS-terminating reverse proxy, such as NGINX, in front of it.

This is an entire rewrite of the earlier (pre-V5) 'Simple Stock Management' app, from scratch. Little-used functionality has been removed and the code is now simpler and more maintainable. The earlier legacy version is now unmaintained, however the code may still be accessed in the legacy_v4 branch.

~~Live demo available below.~~

Security

A focused AI security review (carried out over two passes) was undertaken for the v5.3.0-beta release. The issues it identified, including a stored cross-site scripting (XSS) flaw, a broken access-control check on item creation, an insecure direct object reference on transfer cancellation, and spreadsheet formula injection on export, have been fixed, and defence-in-depth measures added (a Content-Security-Policy, HTTPS/secure-cookie hardening, read-only stock endpoints, output escaping in the dashboard and notification emails, and non-revealing API error messages). See the release notes for the full list.

A further AI security review for the v5.4.0-beta release found two low-risk issues, both now fixed: the warehouse, shop and transfer lists could be sorted by any database field, which let a shop user work out which items other shops had requested and roughly how much stock they held; and the Pipfile named a deprecated third-party dotenv package instead of python-dotenv.

A further AI security review for the v5.5.0-beta release found no high or medium severity issues. Acting on its low-risk findings, the release removes every address, page and API action the app does not use (including the browsable API and Django's built-in password reset by email pages, which nothing in the app linked to), adds a three-strikes lockout to the change password pages, stops notification emails being written to the log file, limits the size of spreadsheet uploads, keeps every quantity within what the database and spreadsheets store exactly, names a missing environment variable at startup instead of crashing, and fixes two timing problems with cancelling and sending transfer requests. A further review of the release's own changes found no new issues.

This is not a substitute for a professional third-party audit, and the app has not undergone one. Undiscovered vulnerabilities may still exist. Please continue to deploy conservatively:

  • Deploy on a server that has no access to your primary systems, or indeed any system where compromise could reveal personally identifiable information or other sensitive data (for example, a standalone VPS machine).
  • Remember to remotely back up the sqlite database.
  • Keep the Python dependencies updated to the latest versions, to ensure patching of any discovered vulnerabilities (this may be achieved through your python package manager, such as pip, uv or pipenv).
  • The app MUST NOT be run without a TLS-terminating reverse proxy (such as NGINX) in front of it, and gunicorn must listen only on a Unix socket or on localhost, so that every request passes through the proxy. The app relies on the proxy for TLS: with DEBUG=False it sets secure cookies, HSTS and HTTPS redirection, and trusts the X-Forwarded-Proto header to tell it which requests arrived over HTTPS, so the proxy must set that header itself rather than pass on the client's (in NGINX, proxy_set_header X-Forwarded-Proto $scheme;). Protections added at the proxy, such as the admin IP restriction below, also do not apply to requests that reach gunicorn directly.
  • Limit the admin section to your own IP address at the reverse proxy, as it can change any user, password or setting. For example, with NGINX:

nginx location /admin/ { allow 203.0.113.10; # your IP address deny all; # plus the same proxy settings as your main location block, e.g. proxy_pass http://unix:/home/django/ssm-gunicorn.socket; }

If you are behind Cloudflare's proxy (highly recommended), NGINX sees Cloudflare's addresses rather than yours, so also tell it to trust Cloudflare's published ranges and read your real address from the CF-Connecting-IP header. This may be accomplished by running the following bash command:

```bash
{ for ip in $(curl -s https://www.cloudflare.com/ips-v4) $(curl -s https://www.cloudflare.com/ips-v6); do echo "set_real_ip_from $ip;"; done; echo "real_ip_header CF-Connecting-IP;"; } | sudo tee /etc/nginx/conf.d/cloudflare-realip.conf
sudo nginx -t && sudo systemctl reload nginx
```

Features & Usage

User Authentication

  • Login/Logout: Users can log in and log out of the application.
  • User Status: Displays the logged-in user's status.
  • Brute Force Protection: Manager & shop user logins protected from brute-force login attempts.
  • Change Password: Users can change their own password from the dashboard (switched on or off with ALLOW_PW_CHANGE in the .env file). A wrong current password counts as a failed login, so three in a row log the user out and lock the account, as at the login page; the admin section's change password page works the same way.

Stock Management

  • Warehouse Stock: View and manage items in the warehouse.
  • Shop Stock: View items available in the shop.
  • Transfers Pending: View and manage pending stock transfers.
  • Download Stock Data: Both warehouse and shop stock data may be downloaded as an excel spreadsheet.
  • Upload Stock Data: Both warehouse and shop stock data may be uploaded as an excel spreadsheet and ingested into the database. The spreadsheet is considered the 'source of truth'! Important note: the unique identifer for each record is the SKU.
  • If records exist in the spreadsheet but not in the database, they are added to the database.
  • If records on the spreadsheet differ, the database is updated.
  • If records already in the database are not present on the spreadsheet, they are deleted from the database (this is optional and may be configured though a checkbox on the system admin page).
  • Spreadsheets larger than the maximum upload size set on the system admin page (2 MB by default) are refused, because loading a spreadsheet takes roughly 85 times its file size in memory; keep the limit low on a server with little memory.
  • Quantities must be whole numbers from 0 to 2,147,483,647; an upload containing any other quantity is refused, with a message naming the row.
  • Excel spreadsheets may be uploaded either in the system default schema (i.e., what you get when you download the warehouse and shop inventories), or in a custom schema. If uploading a custom schema, a conversion function file may be added to translate your spreadsheet columns into the system schema (an example custom function is included).
  • Customise Pagination: Change displayed rows per table through the system admin page.

Search and Sort

  • Search: Search for items in the warehouse and shop by SKU, description, or other attributes.
  • Sort: Sort items by SKU, description, retail price, or quantity. SKU field uses a natural sort algorithm.

Warehouse Maintenance

  • Toggle Warehouse Maintenance Mode: Managers can toggle 'maintenance mode', during which transfers by shop users are paused.
  • Add, Update & Delete Stock: Managers can add new stock items, update stock item descriptions, retail prices, and quantities, and delete items (deleting an item also removes any transfer requests still pending for it). All updates occur immediately the field is edited - no need to click any additional buttons.

Transfer Items

  • Transfer Items: Shop users can request to transfer items from the warehouse to the shop by simply entering how many units they require into the input field. The item is thereby instantly added to the 'Transfers Pending' panel. Quantities may be amended, or the transfer cancelled prior to sending the request. Clicking the 'Send Transfer Request' button submits the request, after which it can no longer be amended; nor can it be cancelled, unless the 'Allow shop user cancellations' setting is switched on. The requested items remain on the shop user's 'Transfers Pending' panel in a disabled state, with a grey background, and appear on the warehouse manager's 'Transfers Pending' notification panel.
  • Email Notifications: Email notifications may be activated, which sends an email to all warehouse managers in the 'receive_mail' group once a shop user clicks the 'Send Transfer Request' button. This email contains a list of all requested items, and includes the SKU, description, unit price and requested quantity.
  • Complete Transfers: Managers can modify, dispatch, and cancel pending transfers from the warehouse to the shops. Only a request that a shop user has sent can be dispatched, and only once. Warehouse inventory is only reduced - and shop inventory increased - after managers have clicked the 'Dispatch' button. Dispatched (or Cancelled) items are then removed from the shop user's 'Transfers Pending' panel.

Developer Contact & Support

If you'd like to discuss options to have this application installed and/or maintained on your behalf, or just have comments or suggestions, feel free to get in touch github@danbright.uk.

Live demo

The live demo is currently unavailable.

If anyone genuinely wants to see this in action and cannot get it running for some reason, ping me and I'll deploy an instance.

Screenshots

Warehouse manager's view

alt text

Shop view

alt text

What changed?

The backend is still Django Rest Framework, while the frontend is now plain old jQuery, rather than relying on ReactJS with all its dependencies. The frontend is now integrated into the Django app, as opposed to the previous standalone frontend UI.

Suggested installation steps on a Linux system

  • Create a local user with minimal privileges to run the app (e.g., 'django'); make the app's root directory; and cd into that directory.
  • Clone the repo.
  • Install the python dependencies. This project uses pipenv to install them in a virtual environment.
  • Copy .env_default to .env.
  • Configure the .env file you just copied. Be sure to set debug to False if publicly accessible, and configure your allowed hosts correctly.
  • Create the log file at the location you specified in the .env file (ensure this is writeable by the 'django' user)
  • Generate a Django secret key with this one-liner: python -c 'from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())'.
  • Set up your forwarding (reverse proxy) web server, and configure 'systemd' to run gunicorn. As an example: by creating this file /etc/systemd/ssm-gunicorn.service with this content:

    Example systemd file - Terminate TLS at the reverse proxy and ensure it sets the X-Forwarded-Proto header itself, replacing any value sent by the client (see Security). With DEBUG=False the app enables secure cookies and HTTPS redirection and relies on this header (via SECURE_PROXY_SSL_HEADER) to recognise secure requests; without it you may see redirect loops or cookies that fail to set. - The app sends a Content-Security-Policy that allow-lists the jQuery and Bootstrap CDN hosts referenced by the templates. If you change those CDN URLs, update CONTENT_SECURITY_POLICY in ssm/settings.py to match. - Do the database migrations, i.e., from the project root run: python manage.py makemigrations, python manage.py makemigrations stock_manager, then python manage.py migrate. - When upgrading to a release whose notes say it changes the database (v5.4.0-beta and v5.5.0-beta do), back up the database, then run python manage.py makemigrations stock_manager and python manage.py migrate again. - Start the 'systemd' service, and enable at boot: systemctl start ssm-gunicorn and systemctl enable ssm-gunicorn. - Create the superuser, i.e., from the project root run: python manage.py createsuperuser. - Login to the admin section with your superuser (e.g., https://your-site.domain/admin) and create your superadmin user, warehouse manager user, and shop users. - Assign the 'staff status' permission to the warehouse manager user. - Still in the admin section, create the 'managers', 'shop_users' and 'receive_mail' user groups. - It's recommended to assign all 'SSM | App Configuration' permissions to the 'managers' group. - Assign the warehouse manager user to the 'managers' group, the shop users to the 'shop_users' group, and those managers who you wish to receive notification emails to the 'receive_mail' group. - Still in the admin section, head to SSM > App Configuration > Configuration Options to switch on/off uploads, upload deletions, notification emails and shop user cancellations, and to set the maximum upload size. - Shop users cannot cancel a transfer request once they have sent it, unless 'Allow shop user cancellations' is switched on. It is off by default, because managers may be emailed the request and dispatch it before they see a cancellation in the app. Managers can always cancel. - If you wish to use the notification email feature, you'd need an account with a mail provider. The installation des

Core symbols most depended-on inside this repo

browse all functions →

Shape

Function 266
Method 37
Class 25

Languages

TypeScript76%
Python24%

Modules by API surface

static/rest_framework/js/jquery-3.7.1.min.js80 symbols
static/rest_framework/js/coreapi-0.1.1.js55 symbols
stock_manager/views.py20 symbols
static/rest_framework/docs/js/highlight.pack.js19 symbols
stock_manager/models.py16 symbols
static/rest_framework/js/prettify-min.js14 symbols
stock_manager/serializers.py13 symbols
static/admin/js/admin/RelatedObjectLookups.js13 symbols
static/rest_framework/js/bootstrap.min.js12 symbols
static/admin/js/inlines.js11 symbols
stock_manager/utils.py10 symbols
static/admin/js/actions.js10 symbols

For agents

$ claude mcp add simple-stock-management \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page