Juan Pablo Gallegos Work Clara

Clara

Making illegal states unrepresentable when the interface is the legal record.

Frontend Engineer 2024 React XState Module Federation Legaltech
Role
Frontend Engineer
Duration
~10 months
Stack
React · XState · TypeScript
Context
Cap-table & data-room legaltech
Proof summary

What changed before the long read

The case is about removing ambiguity from high-stakes legal flows while letting product teams keep moving.

Correctness
Ambiguous legal screens became named states and declared transitions.
Reviewability
The heaviest flows became diagrams the team could reason about and test.
Autonomy
Cap-table, data-room, and admin surfaces could ship on separate clocks.
01

Context

Clara is a legaltech platform for managing cap tables, share issuances, and investor data rooms. The interface is the record that companies and investors act on.

That changes the stakes of an interface. A misread screen here is not a UX nit-pick — it is legal exposure.

02

Problem

The decision-heavy flows — issue shares, grant options, open a data room to a counterparty — had grown into tangles of conditional rendering and boolean flags.

The UI could drift into states nobody had designed: a half-submitted issuance, an ambiguous "is this actually signed?" Meanwhile multiple teams were trying to ship into the same codebase, and every change risked stepping on another.

03

Constraints

Correctness was non-negotiable. An undesigned state was not a glitch; it was a defect with legal weight.

Several teams shipped into one application and could not all coordinate around a single release.

This was a mature React codebase. The work had to be a rewrite-in-place of the worst flows, not a greenfield restart.

04

Role

I worked on the platform core as a frontend engineer. I owned the modeling of the highest-stakes flows and the architecture that let separate teams ship without blocking each other.

05

System shape

The critical flows are modeled as explicit state machines. An issuance, for example, moves through named states and nothing else:

Draft
Pending Signature
Executed
Recorded

Every state is named, every transition is declared, and the UI renders as a pure function of the current state — components read the machine, they cannot invent a transition that was never designed.

The application is split into micro-frontends via Module Federation, so the cap-table, data-room, and admin surfaces build and deploy on their own cadence.

State contract
Legal flow guardrails
State
Name every legal condition. Draft, pending, executed, and recorded are explicit UI states, not boolean combinations.
Transition
Only declared events move the flow. Components dispatch events instead of inventing their own paths.
Surface
Split team ownership without splitting the domain. Module Federation separates delivery while the state contract stays shared.
06

Key decisions

Decision 01
State machines over boolean flags

An issuance has named states, not a soup of isDraft / isSigned / isRecorded flags that combine into dozens of invalid screens. The machine makes illegal transitions impossible by construction.

Decision 02
UI as a function of state

Components render from the machine's current state and dispatch declared events. They have no way to reach a state the designer never drew.

Decision 03
Micro-frontends over a monolith

Module Federation lets separate teams ship their surface independently, instead of queueing behind a single shared release train.

07

Trade-offs

Gained

  • Undesigned, ambiguous screens are impossible by construction
  • Flows are inspectable and testable as diagrams
  • Teams deploy their surfaces independently
  • Every transition has a focused, isolated test

Cost

  • XState has a real learning curve for the team
  • Module Federation adds build and runtime complexity
  • More moving parts to operate and observe
08

Outcome

The heaviest flows became diagrams the team could reason about, review, and test directly. Ambiguous screens stopped reaching production, and separate teams shipped on their own clocks without colliding in a shared release.

09

Lessons

1
A state machine is documentation that cannot go stale, because it is the code that runs.
2
"Make illegal states unrepresentable" stops being a slogan the first day a wrong click costs someone equity.
3
Module Federation buys team autonomy at the price of operational complexity. It is worth it only when teams genuinely need to move independently.