Team and roles, with the rules in code
The team page lists the people with their roles, invites a new one and opens only for administrators. What each role may do lives in code, one permission table per module: the buttons ask it before they show, and the green coffee and wholesale apis ask it again before they change anything.
By Bohuslav PoláčekChecked
What the page shows
Settings has the same four pages in every app built on Meadowstack: General, Team and roles, Connected apps, and MCP and AI (the settings pattern). The last three are for administrators, and at the roastery that is the owner.
Team and roles lists the six people with their e-mails, each role a neutral badge. Its one action is Invite: an e-mail and a role, then a row that appears at once marked "Invited, waiting to accept", and a link that stays valid for 7 days. An invitation can be taken back after a confirmation. The roles to pick from are the company's own: Owner, Roaster, Quality and cupping, Operations and e-shop, Wholesale and Accountant.
Where the rules live
Each module keeps its rules in one file, domain/permissions.ts: a table from an action to the roles that may take it, plus rules that need the record, such as an invoice's state. The workspace joins the modules' tables into the one can that the kit's <Can> and useCan ask, so a component never compares roles itself (permissions).
Opening the settings beyond General asks settings.read, which only an administrator has. The green coffee and wholesale apis ask the same table before they change anything, and a real backend does the same in Postgres row-level security (Supabase).
A role decides what the data shows
- The roaster sees the cafés' standing orders, because he roasts for them, and nothing else of wholesale: no prices and no balances.
- The margin is for the owner and the accountant only.
- Four eyes: an invoice is sent by the owner or the accountant, and never by the person who prepared it.
- No access shows the page's header and a quiet note instead of the content. On Team and roles it says "Only administrators see the team.", and the demo adds a hint to switch role in its bar at the bottom.
Buttons for actions a role may not take are not drawn at all, so nobody presses a button that the save then refuses.
What AI coding tools get wrong here
- Role checks inline:
if (user.role === "admin")in a component, with a different list in each file. Here a component askscan("wholesale.invoice.send", invoice), and the answer comes from one table. - A hidden button with an open api: the button disappears and the endpoint still takes the request. Here the green coffee and wholesale apis ask the same table and refuse.
- A grid of checkboxes the code never reads: a roles matrix on the settings page, saved to a table the app does not consult. Here the rules are code, reviewed and tested with the app, and the page shows who has which role.
- Roles that only hide menu items: the sidebar loses an entry while widgets, search results and notifications still carry prices and margins. The framework's rule asks the role with the record wherever the data appears.
Who may do what at the roastery
| Permission | What it allows | Who may |
|---|---|---|
| roast.plan | Plan the roast batches | Owner, Roaster |
| roast.cupping | Record a cupping | Owner, Quality and cupping |
| green.request | Request green coffee from a supplier | Owner, Roaster, Operations and e-shop |
| green.eudr | Write a lot's EUDR reference | Owner, Accountant |
| shop.order.pack | Pack an online shop order | Owner, Operations and e-shop |
| shop.order.pay | Mark an order paid | Owner, Accountant |
| wholesale.price.read | See the cafés' prices | Owner, Wholesale, Accountant |
| wholesale.margin.read | See what each coffee costs and earns | Owner, Accountant |
| wholesale.invoice.send | Send an invoice, never one they prepared | Owner, Accountant |
| scenario.toggle | Switch a scenario on or off | Owner, Operations and e-shop |
| scenario.run | Run a test of a scenario | Owner, Operations and e-shop, Wholesale |
| settings.read | Open Team and roles, Connected apps, MCP and AI | Administrators (the owner) |
Rules that read the invoice itself
/** Without a subject the answer is "could, for some record" (a button in a list); with one, for that invoice. */
export function canWholesale(person: Who, action: string, subject?: unknown) {
if (!(rules[action as WholesaleAction] ?? []).includes(person.role)) return false;
const invoice = subject as InvoiceSubject | undefined;
if (!invoice || !action.startsWith("wholesale.invoice.")) return true;
switch (action) {
case "wholesale.invoice.send":
// Four eyes: nobody sends an invoice they prepared themselves.
return invoice.status === "draft" && invoice.createdBy !== person.id;
case "wholesale.invoice.pay":
return invoice.status === "sent";
case "wholesale.invoice.remind":
return invoice.state === "overdue" && invoice.reminders < MAX_REMINDERS;
case "wholesale.invoice.delete":
return invoice.status === "draft" && (person.role === "owner" || invoice.createdBy === person.id);Questions
Where are the permissions defined?
In code, one table per module (domain/permissions.ts): each action names the roles that may take it, and some rules also read the record, such as an invoice's state. The screens ask the table through the kit's Can and useCan, and in the demo the green coffee and wholesale apis ask it again before a change.
Can an administrator change what a role may do on the settings page?
No. The page assigns people to roles and invites new ones. What a role may do is a change to the module's permission table in code, so it is reviewed and tested with the rest of the app.
What is the four-eyes rule in the demo?
Nobody sends an invoice they prepared themselves. The owner, the accountant and the person in wholesale prepare invoices as drafts, and the owner or the accountant sends one, never their own draft.
What does a person without access see?
The page's header and a quiet note saying who may open it, such as "Only administrators see the team." Buttons for actions their role may not take are not shown at all.
Do the rules hold in the database too?
A real backend enforces the same rules, for example with Postgres row-level security on Supabase. The demo simulates its api in the browser, where the green coffee and wholesale modules ask the same tables.
Two ways
Build it yourself, or have it built
Build it yourself
Build your app on the framework
Get the codebase these apps stand on and build yours with Claude Code, Cursor or Codex.
One payment, lifetime updates
Get the frameworkHave it built
Have us build your app
Tell us how your team works. We plan the app with you and build it on the same framework at a fixed price.
After launch, Care keeps it improving, from €99 a month.
from €1,990
Describe your app