Part 2 of 6 · 2 min read
Requirements
Browse, add, place, track.
Think of a restaurant with a waiter. A guest reads the menu and tells the waiter what they want. The waiter jots it on a pad. That pad can still change: add a drink, drop a starter. When the guest says "that is all", the waiter tears off the sheet and hands it to the kitchen. From then on the sheet is fixed, and only its status changes: cooking, ready, served.
The pad is the cart. The torn-off sheet is the order.
Questions and the answers assumed here:
- One restaurant per cart? Yes. Items from two restaurants would be two orders.
- Is stock limited? Yes, each menu item has a count, and an order cannot take more than is left.
- How is the total made? Items times quantity, minus a discount, plus a delivery fee.
- What are the order stages? Placed, accepted, preparing, ready, picked up, delivered. It may be cancelled early.
- Who needs to hear about changes? The customer, the restaurant and the delivery partner.
- Out of scope: payment, maps, ratings and the delivery partner's own app.
The numbered requirements:
- R1. A restaurant has a menu of items with prices and a stock count.
- R2. A cart holds items from one restaurant, and quantities may change until placed.
- R3. Placing an order takes stock for all lines, or for none.
- R4. An order records its lines and its prices at the moment it was placed.
- R5. An order moves only through legal states, in order.
- R6. Cancelling an order before cooking starts returns the stock.
- R7. Listeners are told about every state change.
- R8. The total is subtotal minus discount plus delivery fee.
Snapshot
A snapshot is a copy of data taken at one moment and never changed afterward.
Example: an order keeps the price each item had when it was placed, so a later menu price change does not alter an old order.
Check yourself: 1. What is the difference between a cart and an order? 2. Why does an order keep its own copy of prices? 3. When is stock returned?