November 15, 2026 · 9 min read
Designing a back-office app, part 1: rules before screens
Software Design · React · TypeScript · Frontend Architecture
Most business software has the same bones. There are accounts. Each account has things attached to it: locations, subscriptions, documents, contacts, invoices. Things move through stages. Some actions are allowed only when other things are true. Someone has to be reminded, someone has to approve, and everything has to be written down for an auditor.
I've designed a few of these and the frontend side has settled into a shape. Not a framework, more a set of decisions I now make early because I've paid for making them late. This post is about those decisions. Part 2 is about the backend half, and what to do when your system has to live next to another one that already owns the money.
Decide where rules live before writing a screen
The failure mode of internal tools is not ugliness. It's that a rule like "customers with an overdue bill can't order anything new" ends up implemented four times: once in the order form, once in the upgrade dialog, once in the import, and once nowhere, in the API endpoint that a script calls directly.
So before any screen, I decide where rules go and I'm strict about it. Thresholds and schedules go in a config object. State machines go in the domain types as data. Guards that refuse an action go in one function that every write path calls. Components are allowed to read rules. They are not allowed to contain them.
export const config = {
profiling: {
strategicMonthly: 10_000,
strategicSites: 3,
smallMonthly: 2_000,
onTimeGood: 0.9,
onTimeFair: 0.7,
},
billing: {
reminders: [
{ days: -7, label: 'Payment due in 7 days', escalate: false },
{ days: 0, label: 'Payment due today', escalate: false },
{ days: 30, label: 'Payment 30 days overdue', escalate: false },
{ days: 60, label: 'Payment 60 days overdue', escalate: true },
],
},
} as constEvery number has a comment naming who has to confirm it. That turns out to matter beyond tidiness. When stakeholders review the system, they are reviewing a list of numbers with their own names beside them. The argument is about the numbers, which is the argument you want.
The stage machine for a multi-step process is the same idea. One ordered list, and a function that filters it for a given case:
export function stagesFor(o: { kind: OnboardingKind; skipsAgreement: boolean }): Stage[] {
return stages.filter(
(s) =>
!(o.skipsAgreement && (s === 'agreement_approval' || s === 'agreement_signing')) &&
!(o.kind === 'relocation' && s === 'requirements'),
)
}When someone asks "does a returning customer have to sign again?", the answer is a line of code, and the progress indicator, the next-step button and the reminder job all read the same line.
One registry that generates the app
Business systems grow modules. Fifteen, twenty, more. Each one needs a route, a sidebar entry, an icon, a permission check, and sometimes a badge count. Done by hand, these four things drift apart within a month. The route exists but the sidebar link is missing. The sidebar link exists but the permission guard was forgotten.
I now describe modules as data and generate everything else from it.
export type Module = {
id: string
label: string
icon: IconName
group: NavGroup
to: string
permission: Permission
count?: (c: NavCounts) => { n: number; urgent?: boolean; label: string }
routes: { path: string; load: () => Promise<ComponentType> }[]
}The router maps over this array and wraps each module's pages in a permission guard. The sidebar maps over it grouped by group. The badge count is a function from one shared counts object to a number, so each module decides what it cares about and whether it's urgent, and the shell has no special cases.
Adding a module becomes one array entry and one page component. You cannot forget the guard because you didn't write the guard. The sidebar order is an array position, which ends a certain kind of meeting.
The other effect is less obvious. When I later design the backend, the module list is already the module list. Permissions are already named. The frontend registry becomes the first draft of the system's decomposition, and it was cheap to get.
The fake API is the specification
Early in a project I write the API as in-memory functions over seed data, with the shape I want the real API to have. Each function awaits a small delay, mutates arrays, and throws an error with a message a person could read.
export async function suspendService(id: string, input: { from: string; reason: string }) {
await wait(400)
const sub = findSubscription(id)
if (sub.status !== 'active' || sub.endDate) throw new ApiError('Only a running service can be suspended.')
if (!input.reason.trim()) throw new ApiError('Say why it is suspended. The customer sees this.')
// ...
}People call this a mock and treat it as throwaway. I treat it as the spec, because writing it forces every rule to be decided. You cannot fake "what happens after acceptance" without deciding that the location goes live, the subscriptions attach to the account, the funnel moves, and next month's bill includes them. You cannot fake a relocation without deciding that the old subscriptions end on the day the new ones start, so billing moves with the location, and that a location with nothing left running closes.
None of that appears in a requirements list. All of it comes out of asking "what does the data look like after this button" and refusing to leave the answer vague. A JSON fixture per screen doesn't force the question. A single coherent in-memory world does, and it also makes the screens agree with each other, which fixtures never do.
The file gets big. That's fine. It's a specification, and specifications of real systems are big.
Cache invalidation, bluntly
Two things about server state in the UI that I now do by default.
First, the fake API hands out its own in-memory objects and later mutates them. A query library that does structural sharing will see a refetch that's deep-equal to what it holds and keep the old reference, so nothing re-renders after a write. The fix is to clone at the boundary so the fake behaves like a real server returning fresh JSON:
const fresh = <T>(load: () => Promise<T>) => () => load().then((d) => structuredClone(d))The comment on that line is longer than the line. Whoever replaces the fake with HTTP calls should delete it and needs to know why it existed.
Second, every mutation invalidates every query under one root key.
export function useCrmMutation<TArgs, TResult>(fn: (args: TArgs) => Promise<TResult>) {
const qc = useQueryClient()
return useMutation({
mutationFn: fn,
onSuccess: () => qc.invalidateQueries({ queryKey: ['crm'] }),
})
}This is wasteful and I'd defend it. In a business system one write touches many screens. An acceptance changes a pipeline, a portfolio summary, an account page, a billing preview and a history timeline. Enumerating the exact keys per mutation is a maintenance burden that produces stale-screen bugs when someone forgets one. Until the data size makes the broad refresh visible, correctness wins. The proper answer later is the server pushing invalidations over a stream, keyed by resource. The early answer is "refresh everything" and move on.
Theming a component library until it disappears
I use a component library for business apps because I need data tables, dialogs, autocompletes and date pickers and I'm not writing those. But the library's defaults are a look, and the look is not the client's. The theming work is mostly unlearning.
Ripples off. Floating labels replaced by a small Field component with the label above the input, wiring aria-describedby for hints and errors so accessibility doesn't depend on remembering. Buttons in sentence case with no elevation. Shadows reserved for things that actually float, like menus and dialogs. Panels on the page are flat with a border. Focus is one global :focus-visible outline so custom controls get it for free.
Colour needs measuring, not guessing. Brand colours are often chosen for print and fail contrast as text on white. The design I settle on usually has two versions of the brand colour: the real one, used as a surface with dark text on it, and a much darker "ink" version for links, focus rings and any coloured text. The tokens file documents the ratios in its header so nobody reintroduces the pale one as text in a hurry.
Status indicators are a fixed set of tones, seven or so, and every status enum in the domain maps onto them in one file. An overdue invoice, a high-risk account and an unassigned ticket are all the same critical red because of one decision, not three. Each indicator is a small shape plus a label. The label is always present, because colour alone is not a cue anyone should have to rely on.
Small things with a high return
A quick-find dialog on a keyboard shortcut that jumps to any account by name. About an hour of work. Everyone who learns it exists uses it within a minute.
A sidebar that collapses to icons and remembers the choice in local storage. Also an hour.
Dates formatted with Intl.DateTimeFormat and never by slicing ISO strings. Slicing gives you the UTC date, which is the wrong day for anything stored as local midnight in a timezone ahead of UTC. There's a helper for date inputs with a comment explaining that, written after losing time to it.
Vendor chunks split in the build so the framework and the component library cache separately from app code across deploys. Pages lazy-loaded by route so sign-in stays light.
Write down where the prototype lies
An early version of a system is a set of coherent lies. Everything resets on reload. Attachments live in memory. Mail goes nowhere. The audit trail is an array. Single sign-on skips the identity provider. The customer-facing part trusts a tenant id from the client, which is the one thing the real backend must never do.
I list every one of these in the README with what the real implementation has to do instead, and I keep a numbered list of questions I couldn't answer. Who decides to cut off a service after ninety days of debt? Can an agreed payment plan lift the block? The prototype takes a position on each so that it works, and the question is written down so nobody mistakes my position for a decision.
Make the lies small, make them consistent, and write down where they are. That's the whole method.
Part 2 is about the backend, and specifically about what to do when you discover that something else already owns the money.