# A roast plan worked out from the orders

The roast plan is a board with one column per roasting day, and every batch on it says who it is for. The plan is worked out backwards from the orders, the standing orders, the subscriptions and the shelf's minimum, and above the board it names what is still missing: a batch nobody planned, or green coffee that will not stretch.

Checked 2 December 2026. By Bohuslav Poláček. https://meadowstack.com/screens/roast-plan/

*The roast plan of the demo's roastery on Wednesday 2 December, rendered when the site was built from the kit's own components, with the demo's data.*

A live screen, rendered from the kit's components on the page: https://meadowstack.com/screens/roast-plan/

Open it in the live demo: https://meadowstack.com/demo/?lang=en#/fernhill/prazeni

From the example app [An app for a roastery with an online shop](https://meadowstack.com/examples/coffee-roastery-production/).

## What the screen shows

- **Four figures**: the batches planned and the green coffee they take (22 batches, 301.5 kg until Wednesday 9 December in the demo), what has been roasted today, the batches the plan still lacks and the green coffee it is short of. Colour goes only to the two names that need a person.
- **What the plan needs**: a `NoticeList` above the board. A missing batch comes with Plan it and Change, a lot the plan runs short of with the way to it. When nothing is missing, it is one quiet line with a check.
- **Batches by day**: one column per roasting day, today first, with each day's count and kilos under its title. A card names the coffee, the green kilos and the roast, then who the batch is for: the two biggest customers and how many more. A roasted batch says when it came out, how much and its batch number instead.

## How the plan is worked out

The plan is a set of pure functions of the data (the demo's `fernhill-plan.ts`), run again on every move:

1. Demand comes from five places: orders still short of coffee, the cafés' standing orders, the subscriptions, the online shop's week and the shelf's minimum.
2. Roasted coffee rests before it ships: 2 days for the Ethiopian and Kenyan filter coffees, 4 or 5 for the espressos. A missing batch goes on the latest roasting day that still lets it rest, so it leaves as fresh as it can. When no day is early enough, it goes on the first day and is marked late.
3. Green coffee is the roasted coffee divided by one minus the coffee's expected loss, and a batch is 12 to 15 kg, 80 to 100 % of the drum.
4. Planned batches take their green coffee in day order, from the oldest lot of each origin. A batch the lots cannot cover is short, in kilos: the plan needs 42 kg of the Ethiopian, the store room has 34, so the batch on Wednesday 9 December is 8 kg short.

What it leaves to a person on purpose: the order of the batches within a day (light before dark is the habit, the roaster decides), a batch under 80 % of the drum, and what to do about a late or short batch. The short lot opens as a [traceable lot record](https://meadowstack.com/screens/lot-traceability/).

## An editor, not a report

Planning views are editors in Meadowstack ([the planning editor pattern](https://meadowstack.com/patterns/planning-editor/)). The owner and the roaster, the two roles `roast.plan` allows in the roastery's `permissions.ts`, drag a batch to another day or to another place in its day through the kit's [SortableBoard](https://meadowstack.com/components/sortable-board/). The keyboard does the same: Space picks the card up, the arrows move it, Space drops it, and a screen reader hears each step. A roasted batch stays where it is, because `canMove` lets only planned batches go.

Every move is in the plan's history, and its toast has Undo. People who only read the plan (the online shop, wholesale, quality, the accountant) get the same columns as a static `Board`, so nothing pretends to move.

## What AI coding tools get wrong here

- **The plan as a report**: a table of batches nobody can move, or a calendar where each batch is typed by hand. The framework's rule is that planning views are editors: drag, a quick add under each day, live feedback, the same from the keyboard.
- **Drag and drop without the keyboard**: a drag library wired in by hand, mouse only. An app built on Meadowstack cannot import `@dnd-kit` (ESLint stops it with "Use the kit's sortable board and list."), so every drag goes through `SortableBoard` or `SortableList`, which carry the keyboard and the announcements.
- **Coloured banners and pills**: a red bar across the page for the short coffee, a green pill for each roasted batch. Here what needs a person is a [Notice](https://meadowstack.com/components/notice/) row with colour only in its glyph, and a batch's state is a `StatusGlyph` beside its name: empty while planned, filled once roasted.

## The rules the plan is worked out by

*The drum's limits, the days the plan looks at and the latest day a batch can be roasted and still rest, from the demo's plan module.*

From `apps/demo/src/shared/companies/fernhill-plan.ts` in the Meadowstack repository:

```ts
/** One load of the Giesen W15: at most 15 kg of green coffee, at least 80 % of it. */
export const DRUM_KG = 15;
export const DRUM_MIN_KG = 12;
/** How far ahead the plan looks: today and the next seven days. */
export const PLAN_DAYS = 7;

const round1 = (value: number) => Math.round(value * 10) / 10;
const EPSILON = 0.05;

/** The roasting days from `from` through `through`: Monday to Friday, Saturday too when the roastery works it. */
export function roastingDays(from: string, through: string, saturdays = false) {
  const days: string[] = [];
  for (let day = from; day <= through; day = addDays(day, 1)) {
    const weekday = weekdayOf(day);
    if (weekday <= 5 || (saturdays && weekday === 6)) days.push(day);
  }
  return days;
}

/** The days the plan shows: the roasting days from today through a week from today. */
export const planDays = (today: string, saturdays = false) => roastingDays(today, addDays(today, PLAN_DAYS), saturdays);

/** The last roasting day that lets coffee rest `restDays` before `shipOn`, or null when none of `days` is early enough. */
export function latestRoastDay(shipOn: string, restDays: number, days: readonly string[]) {
  const by = addDays(shipOn, -restDays);
  let latest: string | null = null;
  for (const day of days) if (day <= by) latest = day;
  return latest;
```

## How the board is called

*The demo hands the batches to the kit's SortableBoard: one column a day, and only a planned batch may move, to a day the plan shows.*

From `apps/demo/src/modules/roastery/components/plan-board.tsx` in the Meadowstack repository:

```tsx
if (editable) {
  return (
    <SortableBoard
      label={tx("Plán pražení po dnech", "Roast plan by day")}
      className={boardClass}
      columns={days.map((day) => ({ id: day, title: columnTitle(day, today), meta: meta(day), footer: footer(day) }))}
      items={byDay}
      getId={(batch) => batch.id}
      getLabel={label}
      canMove={(batch, _from, to) => batch.status === "planned" && days.includes(to)}
      onMove={onMove}
      onOpen={onOpen}
      showCounts={false}
      renderCard={(batch) => <CardBody batch={batch} view={view} today={today} />}
```

## Questions

### How does the roast plan decide what to roast?

It works backwards from the demand: orders still short of coffee, the cafés' standing orders, the subscriptions, the online shop's week and the shelf's minimum. Each coffee has its rest days and its expected roast loss, so a missing batch lands on the latest roasting day that still lets it rest, in green kilos the drum can take.

### Can batches be moved without a mouse?

Yes. Space picks up a card, the arrow keys move it to another place or another day, Space drops it, and a screen reader hears each step. Only planned batches move; a roasted one stays where it was.

### Who can change the roast plan?

In the demo, the owner and the roaster. Everyone else, from the online shop to the accountant, sees the same board without the drag, and the api checks the same rule before it saves a move.

### What happens when the green coffee will not stretch?

The batch that will go without gets a red line with the kilos missing, the figure at the top says how much is short, and a notice names the lot with a button to open it. In the demo the plan needs 42 kg of the Ethiopian and the store room has 34.

### Does the plan put the batches of a day in order by itself?

No. It proposes what is missing and on which day, and leaves the order within a day to the roaster: light before dark is the habit, not a rule in the code.

## Related

- [An app for a roastery with an online shop](https://meadowstack.com/examples/coffee-roastery-production/) (Example app)
- [A dispatch plan that checks driving hours on every drag](https://meadowstack.com/screens/dispatch-plan/) (Screens)
- [SortableBoard: a kanban board that works from the keyboard](https://meadowstack.com/components/sortable-board/) (Components)
- [The planning editor](https://meadowstack.com/patterns/planning-editor/) (Patterns)
- [The workspace screen](https://meadowstack.com/patterns/workspace/) (Patterns)
- [A construction schedule that reads the weather](https://meadowstack.com/screens/construction-schedule/) (Screens)
