Chris Walker

Agents, tokens and contracts: a design system

How Coloring Book pulled the UI out of a Laravel app so a designer, or a model, could ship it

Where it started

The security awareness training product at Huntress is a Laravel app, and for most of its life the interface lived inside it, as Blade templates and Livewire components sitting next to the PHP that fed them. I was the only designer on a team of 9+ PHP engineers. Every change I wanted to make to a screen went through the same door as everything else, and there was no way to look at a page without the whole app, a database and a logged-in user running behind it. By early this year most of my work had moved into a conversation with Claude Code, and in that codebase the model struggled for the same reason I did. The context it had to hold to change one button was enormous, and it could not see the result.

What I wanted was easy to say. A place where the interface was only the interface. Open a page with fake data, change it, see it, hand it back without anyone translating.

The Contract

Coloring Book is a separate React project that owns every screen of the product: a token-based design system, a set of components built on it, and a Contract at its edge. The Laravel app does not build the interface anymore. It renders one component from the package and hands it the Contract: a typed list of every piece of data the UI may read, every request it may make, and every live event it may listen for. Four groups, a few dozen named types, a few hundred lines, one file.

The name is the metaphor, and it stuck because it is accurate. The Contract draws the lines. Coloring Book colors inside them. The backend fills in the real data. The UI works off the Contract and nothing else, which is what makes it safe for someone who is not a backend engineer, or for a model, to work in it.

One Contract, three fillerssrc/contract.tsx
The Contractdraws the lines
learner: {
  session: LearnerSession | null;
  achievements: () => Promise<AchievementsResponse>;
}
core: {
  events: {
    "app.alert.toast": Listener<AppAlertPayload>;
  };
}
The demo persona1 / 3
session: MOCK.LEARNER_DEFAULT,
achievements: MOCK.ACHIEVEMENTS,
"app.alert.toast": MOCK.LISTEN_FOR_ALERTS
A learner named Michael Scott at a company named Dunder Mifflin. Seven of these, one per kind of person.

Inside the package the Contract travels as props. There is no global store to reach into. A page's props type is the list of Contract fields it uses and nothing more, so a story or a test can hand it exactly what it needs. There are three kinds of thing in the Contract and each has a job. A method becomes an HTTP endpoint on the other side. A session value arrives with the HTML, so a page can draw the navigation and the person's name with no loading state. An event is a subscribe function for live websocket messages that hands back its own unsubscribe. A method with no argument becomes a GET and a method with one payload becomes a POST, and that one rule decides a surprising amount.

The Contract is also the only file in the project a model is not allowed to change. It can suggest. A person edits. Every change there needs a matching change in PHP, so it is where engineering gets involved, and everything else is where it mostly does not have to.

Faking the backend

If the UI only knows the Contract, you can hand it a fake one. The demo is the whole app running on about two thousand lines of fake data: a learner named Michael Scott at a company named Dunder Mifflin, an admin, a channel partner, a manager, seven personas in all, each one a complete Contract. Two wrappers do most of the work. One holds any method for a few seconds so I can design the loading state. The other makes it fail so I can design that one. The assignments table really filters, searches and paginates a list in memory, and deleting a row really removes it and fires a toast through a fake websocket that behaves like the real one.

Simulationsthis month
Loading. A skeleton, with a label only a screen reader hears.

Every section of every page is designed in four states: loading, error, empty, populated. Each section loads its own data, so one failing endpoint puts an error in one card instead of blanking the page. Storybook shows all of it, a couple of hundred stories, with a toolbar for light, dark and system theme and another for every language the product ships in. Two of those languages are not languages. One shows the key path for every string, so you can see which key renders where. The other replaces every letter with a tilde, and anything still readable in English is a hard-coded string that missed translation. I use that one more than I expected to.

Because every persona is typed as the Contract, adding a method to the Contract breaks the demo build until every persona has a fake for it. That is not a rule anyone has to remember. It is just true.

Tokens

Underneath the components is a token-based design system, and I want to be precise about what that means, because it is the part that made everything else cheap to change. A token is a name for a decision. There are three layers. At the bottom, primitives: the raw palette, violet-700, red-600, gray-900, values with no opinion about where they are used. Above that, semantic tokens: brand, brand-light, danger-600, text, surface. Each one is a job, and each one points at a primitive. At the top, the components, and a component is only allowed to name a job. A button is brand. An overdue pill is danger. Nothing in a component ever names a color.

nav-activeSemantic token
Component
#0f766eValue
teal-700Primitive token
brandSemantic token
Start trainingComponent
interactiveSemantic token
View reportComponent
#c43d3dValue
red-600Primitive token
dangerSemantic token
OverdueComponent
danger-textSemantic token
chris@huntressEnter a valid email.Component
teal-700Primitive token, #0f766e
nav-activeSemantic token
Component
brandSemantic token
Start trainingComponent
interactiveSemantic token
View reportComponent
red-600Primitive token, #c43d3d
dangerSemantic token
OverdueComponent
danger-textSemantic token
chris@huntressEnter a valid email.Component
A value becomes a primitive, the primitive is given jobs, and a component names the job and nothing else. Dark mode changes the first two boxes; nothing on the right is touched.

That ordering is what makes the two hard problems small. Dark mode is the semantic layer pointing at different primitives: text moves from gray-900 to gray-50, surface moves the other way, and the components do not have to know. A rebrand is the same move one layer down: change what brand points at and every button, link and active nav item follows. Type, spacing, radius and shadow work the same way. All of it lives in one CSS file, which the model reads the same way I do, and which is the one file that changes when the look changes.

The file also defends itself. The first thing it does is delete Tailwind's default color scales. Set red to initial and the red classes stop producing a color. Nothing errors. It just does not render, and after a day of that everyone, including the model, reaches for the semantic name instead, and a semantic name survives a rebrand where a raw one does not. Brand color is reserved for things you can click. A pointer cursor is never implied. Those rules live in a short UX document the model reads before it starts anything.

Lines that hold

I think of the whole package as a set of lines, and the interesting question for each one is what happens when you cross it. Most of the lines are types. The English translations file is the type of every other translations file, so a misspelled key does not compile. A story must supply every prop, because the story type says so. The public surface of the package is five exports: one component, one type, three helpers. The host cannot reach in and use a random button, which means the insides can change without asking anyone.

What holds the linedozens of lines, mostly types
typesThe Contract is the only door between the UI and data

Then there are the lines that process holds. Every push to any branch runs lint and tests, then deploys the demo and Storybook to a folder named after the branch, and the pull request gets the link. Reviewers look at real UI, not a description of it. Merging needs one approval, squash only, and the branch and its preview delete themselves. A release is a person clicking a button, so nothing reaches the product by accident.

And some lines are only words. The Contract lock is a sentence in a markdown file, and the model's permission to edit files covers that file like any other. I am being plain about that because it is the point. Knowing which lines are held by a compiler, which by GitHub, and which by a request is how you know where to look when something goes wrong. The next version turns that one into a real block.

The other side

On the Laravel side, a folder called FrontendBridge implements the Contract in PHP. One class per Contract group, one public method per Contract method, one data class per Contract type. A route file walks those classes and registers every public method as an endpoint, named after the method, GET or POST by its argument count, with validation built from the PHP types. A command generates the TypeScript that satisfies the Contract, and a test regenerates it on every build and fails if someone changed the PHP and forgot.

Rollout is a middleware and a flag. When the flag is on for an account, the old Livewire page is swapped for the Coloring Book page. When it is off, nothing has changed. The learner area moved over this way, page by page, and is fully live. The admin area is following behind a flag, account by account: one real page so far, and the rest placeholders with the routes and navigation already in place, so a new page only needs its content.

What it changed

The repository was created in the spring. The Contract landed a few weeks later, and the first Claude configuration, with the lock in it, landed the same week. Translations into two dozen languages and the go-live came a month after that. I designed the package and the rules and built most of the UI. The PHP side, the generator and the rollout were engineering's, and by midsummer they were shipping their own features through my Contracts: the assignments dashboard, the account breadcrumb, impersonation. By the end of summer there were dozens of releases, and the most recent pull request was mine, a shared text input. A couple of hundred files, small enough that one person or one session can hold the whole thing in their head, which was always the test.

The part I did not predict is how much of the value came from the lines rather than the freedom. The Contract started as a boundary. It turned out to be the thing that makes the designer's work safe to merge, and the thing that lets a model work there at all. A focused React project with typed edges is a place where Claude is very good. A large, mixed Laravel application is not, and no prompt fixes that.

If I were starting again I would make the components less clever. The flexible ones, with a prop for every situation, were the ones I kept having to explain, to engineers and to Claude. A component with fifteen props is fifteen decisions handed to whoever uses it, and a model will make all fifteen confidently and get three wrong. Clear variants with names, an OverduePill rather than a Pill with a color and an icon, cost more files and save every conversation after. Flexibility is not a feature of a design system. Predictability is.

The next design system will replace the tokens, the fonts and the components. It will keep the Contract, the personas, the four states, the preview on every branch and the rules the model reads. The look is one file. The system is everything else, and the system is what took the year.