Full design · Apps
Inventory and stock control
Fyshwick Cycle Supply, a bike shop and workshop group in Canberra with three locations: the Fyshwick workshop and warehouse where stock is received and bikes are built and serviced, and two retail shops at Belconnen...
Live preview. Click around, it works.
About this template
Fyshwick Cycle Supply, a bike shop and workshop group in Canberra with three locations: the Fyshwick workshop and warehouse where stock is received and bikes are built and serviced, and two retail shops at Belconnen and Tuggeranong. Items holds every product as variants (frame size, colour, wheel size) with its own SKU, cost and sell price, and a stock level per location that is always the sum of its movements, never a number typed in directly. Stock levels flags anything at or under its reorder point per location, so it is easy to see what to raise a purchase order for next. Movements is the append only ledger behind every number on the site: receive, transfer between locations, sell and adjust with a reason, searchable and never editable once written. Purchase orders are raised to a supplier and received against, in part or in full, each delivery its own movement. Stocktake compares a counted quantity against what the ledger expects, location by location, and shows the variance before it is committed. Suppliers holds who is ordered from and their lead time. A typed SKU or barcode lookup finds an item and its stock across all three locations in one search. Reports cover stock valuation at cost and which items have not moved in a chosen period. Owner, Manager and Staff see the same screens with different rights: Staff can count and move stock but cannot change a cost or sell price and cannot approve a stocktake.
What the agents are asked
The first message sent when you use this template. You can edit the plan before anything is built.
Adapt this to my own stock control, keeping every screen and working rule: Items with variants and a SKU each, Stock levels per location with reorder points, Movements as an append only ledger (receive, transfer, sell, adjust with a reason) that can never be edited or deleted, Purchase orders that can be received against in part, Stocktake comparing counted to expected with a variance shown before it is committed, Suppliers, a typed SKU or barcode lookup, and Reports for stock valuation at cost and slow movers. Keep transfers atomic: stock never leaves one location without arriving at the other in the same action. Keep the Owner, Manager and Staff roles and their real limits, in particular that Staff can move and count stock but cannot change a price or cost and cannot approve a stocktake, enforced in the database as well as the screen. Replace the business, its locations, items, suppliers and sample movements with mine; keep the sample rows marked Sample and removable in one step. When I want a real shared database, wire in the tables and functions schema.sql describes as the README explains, with every secret key kept on the server.
Stock control for a fictional bike shop and workshop group in Canberra with three locations: the Fyshwick workshop, where stock is received and bikes are built and serviced, and two retail shops at Belconnen and Tuggeranong. "Fyshwick Cycle Supply" is invented for this template. It is not modelled on any real bicycle retailer. Every person, business and email address in the sample data is fictional; email addresses use the reserved .example domain.
Built on the NovaBuild template kit (docs/guardrails/TEMPLATE-KIT.md): one CONFIG block, one design token block, and a shared data layer that runs in demo mode with no backend or against a real Supabase project once one is connected, with no code change either way.
Screens
- Overview (
#/): low stock count, open purchase orders, open stocktakes, stock value at cost, a low stock shortlist and the most recent movements. - Items (
#/items): every product, searchable by name, SKU or barcode and filterable by category. - Item detail (
#/items/<id>): a product's variants, each with its own SKU, barcode, cost, price and stock per location, and the Move stock action. - Stock levels (
#/stock): every variant at every location, searchable, filterable by location and by low stock, with reorder points an owner or manager can edit inline. - Movements (
#/movements): the ledger behind every number on the site. Receive, transfer, sell and adjust with a reason. Nothing here can be edited or deleted. - Purchase orders (
#/purchase-orders,CONFIG.features.purchaseOrders): raised to a supplier; Purchase order detail (#/purchase-orders/<id>) receives a line in part or in full, and the order's own status (draft, ordered, partial, received, cancelled) follows automatically. - Stocktake (
#/stocktake,CONFIG.features.stocktake): start a count at a location; Stocktake detail (#/stocktake/<id>) records a count against what the ledger expects and shows the variance before an owner or manager approves it into the ledger. - Suppliers (
#/suppliers): who stock is ordered from and their lead time. - Lookup (
#/lookup,CONFIG.features.barcodeLookup): a typed SKU or barcode, matched to one item and its stock across every location at once; also reachable from the quick field in the top bar or the/key. - Reports (
#/reports,CONFIG.features.reports): stock valuation at cost, by location and in total, and slow movers (no sale or transfer out in at least 30 days), each exportable as CSV. - Team (
#/team): Owner, Manager or Staff, with a plain description of what each can do. - Settings (
#/settings): business profile (read fromCONFIG), locations, the negative stock policy, the backend connection, and, for an owner, removing the sample data.
Roles, and where each one is enforced
| Capability | Owner | Manager | Staff |
|---|---|---|---|
| View items, stock, movements, orders, stocktakes, suppliers, reports | Yes | Yes | Yes |
| Receive, transfer, sell or adjust stock (with a reason) | Yes | Yes | Yes |
| Count a stocktake | Yes | Yes | Yes |
| Look up a SKU or barcode | Yes | Yes | Yes |
| Create or edit an item, a variant's SKU or barcode, a supplier or a location | Yes | Yes | No |
| Change a variant's cost or sell price | Yes | Yes | No |
| Raise, edit or cancel a purchase order | Yes | Yes | No |
| Receive against a purchase order line | Yes | Yes | Yes |
| Approve a stocktake | Yes | Yes | No |
| Change the negative stock policy | Yes | Yes | No |
| Invite, edit or remove a team member, change a role | Yes | No | No |
| Remove sample data | Yes | No | No |
The demo's "Viewing as" switch (top bar) simulates signing in as each role: it decides what the interface offers, and the same rule decides what the interface refuses. On a connected backend the same rule is enforced twice more, independently of the interface:
- Row level security in
schema.sqlgrants every table toauthenticatedonly, then narrows it by the caller's own row inteam_members(current_team_role()). Two columns are never in any update grant, at any role, not even owner:variants.cost_centsandvariants.price_cents(onlyupdate_variant_pricingchanges either), andstock_levels.quantityandpurchase_order_lines.quantity_received(only the functions below change either). - SECURITY DEFINER functions (
receive_stock,transfer_stock,sell_stock,adjust_stock,receive_purchase_order_line,update_variant_pricing,record_count,approve_stocktake,change_team_role,remove_sample_data) check the caller's role themselves and refuse exactly what the table above says they should. The demo moderpchandlers inscript.jsmirror each function's checks and messages so the two never drift apart (docs/ops/LESSONS.mdL35).
Signature: a ledger that explains itself, and a transfer that cannot half happen
The three things this template is built to prove:
- Every stock level is the sum of an append only movements ledger.
stock_levels.quantityhas no update grant at all, at any role; the only place it ever changes isnova_apply_movement, the one internal function every stock writing function calls, in the same statement as themovementsrow that explains the change.movementsitself has no insert, update or delete grant to anyone: the schema'sVERIFYblock reads a variant's stock at a location and sums its own ledger rows independently, and shows they agree, on the seed data itself. - A transfer cannot half happen.
transfer_stockwrites atransfer_outrow at the source and atransfer_inrow at the destination inside one function call; Postgres runs a function body as one statement, so an exception anywhere inside it (most often the source not having enough, whensettings.allow_negative_stockis off) undoes everything the call had done, including the first write. Callingreceive_purchase_order_linetwice with the same line and a quantity larger than what remains is refused the second time with "Only 0 left to receive on this line" rather than quietly over receiving (docs/ops/LESSONS.mdL35). - A count never trusts what it is told.
record_count'sexpected_quantityis read fromstock_levelson the server, never sent by the caller: a stocktake's variance is always the true difference between what is counted and what the ledger already believed, andapprove_stocktake(owner or manager only) turns every disagreeing line into one moreadjustmovement, reasonstocktake, rather than silently overwriting the number.
Art direction
Two portraits, one shoot: owner-nadia (Team) and manager-elijah (Team), the only two sample people with a photograph; Beau Whitford and Mei-Ling Zhou, and every product, get a typeset tile instead, since a photograph of a manufactured bike or part risks fake lettering the generator cannot be told not to invent (docs/guardrails/TEMPLATES.md, Photography). Both portraits are lit with real directional daylight at camera left or right, cool 5400K, an 85mm lens at f/2.8, fine film grain and a muted true to life grade, natural skin texture, no airbrushing, shot with the workshop and shop counter softly out of focus behind them rather than a studio backdrop. No text, logos or readable signage in either frame.
Data model (schema.sql)
locations, team_members, suppliers, products, variants, stock_levels, movements (the ledger), purchase_orders, purchase_order_lines, stocktakes, stocktake_lines, settings (one row: allow_negative_stock). Every table has row level security; anon has no access to anything, because stock control is an internal tool, not a public site. See the file's own comments for the full grant and policy reasoning, and the VERIFY block at the end for how to check it after applying.
stock_levels carries its own surrogate id rather than a composite primary key on (variant_id, location_id), so the kit's data layer can update a row through PostgREST the same single column way it updates every other table; the pair stays enforced as a unique constraint underneath. No column, at any role, holds an insert or update grant on stock_levels: a row for it is created the first time it is actually needed, either inside nova_apply_movement (the first time stock moves for that variant at that location) or inside set_reorder_point (the first time an owner or manager sets one directly), both starting it at zero stock. The Stock screen shows every variant at every location whether or not a row exists yet, so a brand new item never looks broken before its first movement.
remove_sample_data() is the only way the sample rows go away: nobody, at any role, holds a delete grant on movements, stocktake_lines, purchase_order_lines, purchase_orders, variants, products, suppliers or locations (none of these are deleted otherwise; this is the one narrow, role checked path), so Settings' "Remove sample data" calls this function rather than deleting rows itself. It skips a sample row a real (non sample) write now depends on rather than letting one row stop the rest, and skips the business's last active owner. A trigger, nova_guard_last_owner, backs the same rule everywhere else too: it refuses to delete, suspend or demote the business's only active owner no matter which column or row level policy would otherwise have allowed it.
Going live
Set CONFIG.backend in script.js to { mode: 'supabase', url: 'https://<project>.supabase.co', anonKey: '<publishable key>' } once schema.sql is applied to a real Supabase project. Everything else, every screen, every role check, every write, works unchanged: the kit's data layer switches from localStorage to PostgREST with no other code change. Never put a service_role key or a sb_secret_... key here; the kit refuses to start with one and falls back to demo mode.
Turn Confirm email on in Supabase Authentication settings before anyone signs up: claim_team_invite() and start_business() both key on the caller's confirmed email (nova_confirmed_email()), never the unverified sign up address, so with confirmation off nobody could ever satisfy either check.
The first person in. No team_members row starts out linked to a real account (the sample rows keep auth_user_id null). The first person to sign up and sign in sees an "Almost there" screen: it calls claim_team_invite() automatically, and if no invite is waiting for their email and the business has no real owner yet, they can "Start your business", which calls start_business(name) to become the first owner (only ever once; a second attempt while an owner already exists is refused). Once an owner exists, adding anyone else is a normal Team screen action (name and email, auth_user_id left null until they sign in and claim_team_invite() links them), with no SQL editor step and no service role key, ever.
Sample data
Every sample row is marked is_sample. An owner can remove it in one step from Settings, through remove_sample_data() (above), which keeps anything a real visitor has added or changed themselves; a sampleVersion bump (script.js) replaces stale sample rows in a returning visitor's browser without ever touching their own data (docs/ops/LESSONS.md L21). The Undo the toast offers after removing is a demo mode convenience only: it re-inserts from a snapshot taken in the browser before the call, and on a live backend that insert would need grants nobody holds on purpose, so Undo only appears while store.mode is "demo". On a connected backend the rows the function deleted are genuinely gone, the same as they would be from a direct SQL delete.
Adapting this to a real business
Quantities are always plain integers and money is always integer cents (cost_cents, price_cents, and every purchase order line's unit_cost_cents), formatted for display through CONFIG.locale, never stored as a float. Replace the business, its locations, items, suppliers and sample movements with real ones; keep the append only shape of movements and stocktake_lines, and keep every write that decides a cost, a price, a received quantity or a stocktake's outcome behind the functions this template already uses, not a direct table write from a screen.