Typestate
Sign in

Small shop stock

Each sale and delivery moves the stock, and the owner gets one email when a product runs low.

For a shop that sells at the counter and online, and counts its own stock.

Resend logo Resend
Start it with your agentUses 5 of your 100 changes a month

Start the small shop stock blueprint on Typestate

Asked you for the address the low-stock email goes to and the address your emails come from.

Started Small shop stock: 2 record types, 5 web endpoints.

5 actions are compiling, one change each.

Deployed to Sandbox. Try it at your Sandbox address.

What your agent does when you start this blueprint

How it runs

Who does what, in order. Each step is one action of the backend.

  1. Youadd each product with its low markAdd a Product
  2. A deliverycomes in, and the stock goes upRecord a Delivery
  3. The till or web shoprecords a sale, and the stock goes downRecord a Sale
  4. Your backendemails you once when a product runs lowRecord a Sale
  5. Youcount the shelf when the numbers driftCount the Shelf

The rule you will want to change first

When a sale takes a product under its low mark, the owner gets one email. The next email about it comes only after a delivery brings it back above the mark.

It lives in the action Record a Sale. Tell your agent how you want it instead: one sentence changes, and you read the change before it goes live.

What it is made of

What it keeps, what it does, and what it reaches.

What it keepsProductname, sku, stock, lowat, low toldMovementproduct, change,reason, noteWhat it doesAdd a Productcalled by you, withyour keyRecord a Salecalled by you, withyour keyRecord a Deliverycalled by you, withyour keyCount the Shelfcalled by you, withyour keyList Stockcalled by you, withyour keyWhat it reachesResendSend email from yourown address: sign-in...Your website5 web endpointsWhat it keepsProductname, sku, stock, lowat, low toldMovementproduct, change,reason, noteWhat it doesAdd a Productcalled by you, withyour keyRecord a Salecalled by you, withyour keyRecord a Deliverycalled by you, withyour keyCount the Shelfcalled by you, withyour keyList Stockcalled by you, withyour keyWhat it reachesResendSend email from yourown address: sign-in...Your website5 web endpoints

What it keeps

Product

5 fields

One thing the shop sells, with its stock.

name
required, at most 120 characters
sku
required, never twice, at most 40 characters
stock
required, a whole number
low at
required, a whole number
low told
required, yes or no

Only the shop's key reads and changes the stock.

Movement

4 fields

Each change to the stock, and why.

product
required
change
required, a whole number
reason
required, one of sale, delivery, count
note
optional, at most 200 characters

Only the shop's key reads and writes the movements.

What it does

Every action, with its full definition in plain English.

Add a ProductThe shop adds a product with its code and its low mark.
The shop adds a product, given its name, its code, how many are on the shelf and its low mark. If another product has the same code, refuse with "Another product has this code". Otherwise save the product and answer it.
Record a SaleThe till or the web shop records a sale, and the stock goes down. A product that runs low is emailed to the owner once.
The shop records a sale, given a product code and a number sold. 1. If the number is less than 1, refuse with "Sell at least 1". 2. If no product has that code, refuse with "No product has this code". 3. If fewer are on the shelf than were sold, refuse with "Only this many are on the shelf", and say how many. 4. Take the number off the product's stock, and save a sale movement for it. 5. If the stock is now below the low mark and the product is not told, email the address in the OWNER_EMAIL setting: subject "Running low" and the product's name, with its code, its stock and its low mark. Then mark the product told. 6. Answer the stock that is left.
Record a DeliveryA delivery comes in, and the stock goes up.
The shop records a delivery, given a product code, a number and a note. 1. If the number is less than 1, refuse with "A delivery brings at least 1". 2. If no product has that code, refuse with "No product has this code". 3. Add the number to the product's stock, and save a delivery movement with the note. 4. If the stock is now at or above the low mark, mark the product not told, so the morning email names it again when it runs low. 5. Answer the new stock.
Count the ShelfSomebody counts the shelf, and the stock is set to what is really there.
The shop counts a product, given its code and the number on the shelf. 1. If no product has that code, refuse with "No product has this code". 2. Save a count movement for the difference between the count and the stock. 3. Set the stock to the count. 4. Answer the difference.
List StockThe shop sees every product, lowest first.
The shop reads its stock. Answer every product with its name, code, stock and low mark, the ones furthest under their mark first. The shop may ask for only the products that are running low.

Web endpoints

What it doesWho may callAddress
The shop adds a product.you, with your keyPOST /products
The till or the web shop records a sale.you, with your keyPOST /sales
The shop records a delivery.you, with your keyPOST /deliveries
The shop records a count.you, with your keyPOST /counts
The shop reads its stock.you, with your keyGET /stock

What it cannot do yet

  • It does not take payments. The till or the web shop records each sale here.
  • One shop. Stock in two places is one more field and one more rule.

Build the pages with your tool

Typestate is the backend. Paste this brief into Lovable, v0, Claude Code or the tool that builds your pages.

Show the brief
Build the pages for "Small shop stock". The backend runs on Typestate and answers these web endpoints: POST /products: The shop adds a product. Who may call: you, with your key. POST /sales: The till or the web shop records a sale. Who may call: you, with your key. POST /deliveries: The shop records a delivery. Who may call: you, with your key. POST /counts: The shop records a count. Who may call: you, with your key. GET /stock: The shop reads its stock. Who may call: you, with your key. People sign up at POST /auth/signup and sign in at POST /auth/login, which answers a token. Send it as Authorization: Bearer <token>. A refused call answers a sentence that can be shown to the person as it is.

Start it

  1. Tell your agent the sentence on the right.
  2. It asks you for the address the morning email goes to.
  3. It asks you for the address emails come from, on a domain you verified at Resend, such as "Riverside Physio <hello@riverside.example>".
  4. It tells you what only you can do, such as pasting your Stripe key. A key never goes through the agent.
  5. Open your Sandbox address and try it yourself.

Uses 5 of the 100 changes a month on the Free plan, which runs it on Sandbox. Taking real money on Live needs a paid plan.

Start the small shop stock blueprint on TypestateOpen an account

Related blueprints