2.37 Modular Component System — 0-Violation State, New Naming, UX QA Checker — RAIA (Real estate Artificial Intelligence Agent) Documentation
The steady-state component architecture for RAIA's frontend. Every panel, card, and nav component follows a single enforced contract — no bespoke headers, no hardcoded tokens, no drift.
The steady-state component architecture for RAIA's frontend. Every panel, card, and nav component follows a single enforced contract — no bespoke headers, no hardcoded tokens, no drift.
Updated 2026-08-10 · Architecture Decision · 0-violation state achieved · 4-Level Plug & Play Sub Menu added
Imagine the right panel in RAIA (Real estate Artificial Intelligence Agent) like a set of Lego drawers. Each drawer (Sub Menu tab — Properties, Services, Contacts, Tenancies) is a self-contained module. When you open a drawer, it fetches its own data, renders its own cards, and never borrows from another drawer. You add a new drawer by dropping in one component and pointing it at its API endpoint. No rewiring, no copying, no breaking anything else.
Before building any new menu, view, or panel in RAIA, every agent must read this page. The component system below is the single source of truth for how frontend components are built. Deviating from it requires an ADR.
Context What Happened
On 2026-08-10, a three-model panel review — Gemini 3 Pro, GPT-5, and DeepSeek R1 — was convened to settle the component system strategy for RAIA's frontend before building any more menus or views. The trigger was a single day where 200,000+ tokens were burned on compact card iterations because agents had no enforced pattern to follow.
The panel reviewed the live codebase and found 51 independent panel components, 142 hardcoded padding/margin values, and design compliance violations — all unresolved at the time of the panel. The panel's mandate: decide the path forward before the next component was built.
The decisions below were then implemented fully. As of commit 3dec004b, the component library is deployed to app.estateaigents.com in a 0-violation state.
Current State Current State — Clean
The component library passed all 4 ux-qa-check.sh checks on 2026-08-10. 0 naming violations, 0 zone shell violations, 0 unregistered components, 100% story coverage. The old violation debt has been fully resolved.
The following actions were completed to reach this state:
-
1All zone shell names renamed
WorkspaceShell→Panel_Centre_Workspace·ChromeShell→Panel_Left_Navigation·OverlayShell→Panel_Overlay -
224 legacy components renamed to convention
All component names now follow the
{Nav_Section}_{Sub}_{ViewType}convention. Examples:CompactServiceCard→Inbox_Service_CompactCard·TenantHeader→Tenants_Profile_Header. See commit3dec004bfor the full rename list. -
34 orphan components deleted
StatusSection,SubjectSection,SuggestedPersonSection,TimelineSection— all had 0 importers and were removed. -
410 interior bricks workspace-exempted
WorkspaceHeader,WorkspaceToolbar,UniversalCompactCard, and 7 others are interior bricks inside a zone shell. They carry a// workspace-exemptcomment and are excluded from the Zone Shell Gate check. -
559 story files created — 100% story coverage
Every component in
component-registry.jsonnow has a.stories.tsxfile. Story coverage is enforced by Check 4 ofux-qa-check.shon every commit. -
6Old compliance checker replaced
The grep-based
check-design-compliance.shhas been deleted. It is superseded byux-qa-check.sh— 4 focused structural checks that exit 0 on a clean codebase.
Layout Law The Three Panel Zones
RAIA's UI is divided into three fixed zones. Each zone has its own component contract. Building outside that contract is a compliance violation.
| Zone | What goes here | Component pattern | NOT allowed |
|---|---|---|---|
| Left Navigation | SidebarNav.tsx rows, icons, labels |
TS type scale + LABEL_COLORS |
Cards of any kind |
| Centre Workspace | List/table rows: inbox-table, PropertiesList, LandlordListItem |
Existing list and table row patterns. Must import Panel_Centre_Workspace or carry // workspace-exempt. |
Compact cards — rows only |
| Right Hand Side Panel | Detail view sections, compact cards | UniversalCompactCard for all compact cards. PanelShell/PanelHeader for panel sections. |
Bespoke card/header implementations |
Three-Zone Layout
flowchart LR
subgraph LEFT["Left Navigation - Panel_Left_Navigation"]
A1[SidebarNav rows]
end
subgraph CENTRE["Centre Workspace - Panel_Centre_Workspace"]
B1[InboxTable rows]
B2[PropertiesList rows]
end
subgraph RIGHT["Right Hand Side Panel"]
C1[UniversalCompactCard]
C2[PanelShell sections]
end
LEFT --- CENTRE --- RIGHT
Left Navigation
SidebarNav.tsx and Panel_Left_Navigation own the left zone. Components here are rows — icon, label, optional badge count. They consume the TS type scale for font sizing and LABEL_COLORS from @/lib/ui/chip-tokens for status colours.
Centre Workspace
The centre zone is lists and tables. InboxTable, PropertiesList, and LandlordListItem are the established patterns. Every new workspace component must import Panel_Centre_Workspace or carry a // workspace-exempt comment.
Right Hand Side Panel
The RHS panel is the detail view. All compact cards in this zone MUST use UniversalCompactCard as their base. Panel sections with a title, icon, and action buttons use PanelHeader (Phase B).
Tokens The Universal Theme Layer
Five token files govern every visual value in every component across all three zones. Importing and using these files is not optional — it is the contract.
| Token / File | What it controls | Used by |
|---|---|---|
globals.css :root vars |
Colours, backgrounds, borders | All components |
design-tokens.ts |
PILL, TEXT, AVATAR, SECTION_HEADER |
All components |
@/lib/ui/type-scale (TS) |
Font sizing hierarchy | All components |
@/lib/ui/chip-tokens (LABEL_COLORS) |
Chip/pill colours | All components |
@/lib/ui/panel-tokens.ts NEW |
Panel padding/margin values | Panel components |
Never hardcode any of these values. Always import from the token file. A hardcoded padding or colour value is a compliance violation — it will be caught by ux-qa-check.sh and must be corrected before merge.
Cards UniversalCompactCard — RHS Panel Compact Cards
What It Is
UniversalCompactCard is the single base component for all compact cards displayed in the Right Hand Side panel. It provides a consistent, composable structure: optional thumbnail, header text, an icon row for metadata, pills for status labels, a themed border, and click-through behaviour.
Components That Use It
| Component | What it renders |
|---|---|
Inbox_Person_CompactCard |
Contact/person in the RHS panel — avatar, name, role pill |
PropertyCard |
Property address, status pill, icon row with rent/beds/type |
Inbox_Service_CompactCard |
Service request with category pill and assignee icon row (formerly CompactServiceCard) |
Inbox_Tenancy_CompactCard |
Tenancy record with dates, status pill, tenant count (formerly CompactTenancyCard) |
Props Interface
interface UniversalCompactCardProps {
thumbnailUrl?: string; // optional avatar/property image
headerText: string; // primary label
iconRow?: IconRowItem[]; // metadata row
pills?: PillItem[]; // status/category pills
onClick?: () => void; // click-through navigation handler
past?: boolean; // dims the card for historical records
loading?: boolean; // skeleton state
}
ALL new compact cards in the RHS panel MUST use UniversalCompactCard as their base. This is enforced by CLAUDE.md Rule 11 (commit 640a2fff) and by Check 2 (Component Registry) in ux-qa-check.sh. Full spec in COMPACT_CARD_PATTERN.md.
Panels PanelShell — Panel Sections
PanelShell was proposed as a universal wrapper for every panel section in the RHS panel. The three-model panel reviewed this and returned a MODIFY verdict.
Panel Review Verdict
The panel agreed that a universal panel component is correct in principle, but rejected the full PanelShell wrapper because approximately 80% of panels are stat/metric cards with no rich header. The correct decomposition is:
- PanelHeader — a primitive covering title, optional subtitle, optional icon, optional actions slot. For the ~15 panels with rich headers.
- PanelFrame — optional outer wrapper for border/padding.
The Decision
| Phase | What ships | Why first |
|---|---|---|
| Phase A Shipped | panel-tokens.ts — all panel padding/margin/gap values as named exports |
Highest ROI. Immediate violation reduction. Zero new components. |
| Phase B | PanelHeader primitive — title, subtitle?, icon?, actions? |
Only needed for ~15 rich-header panels. |
Pictogram Component Pictogram — The Visual Reference
This is the canonical visual reference for every component in the RAIA (Real estate Artificial Intelligence Agent) component library. When you need to add a new panel, card, or view — find the component name here, not from memory.
Full Component Hierarchy — All Four Zones (Updated Names)
flowchart TD
subgraph CHROME["Zone 1 - Chrome"]
CS["Panel_Left_Navigation"]
SN["SidebarNav"]
NI["NavItem x 5"]
CS --> SN --> NI
end
subgraph WORKSPACE["Zone 2 - Centre Workspace"]
WS["Panel_Centre_Workspace"]
WH["WorkspaceHeader"]
WT["WorkspaceToolbar"]
CONTENT["table / list / grid"]
WS --> WH
WS --> WT
WS --> CONTENT
end
subgraph RHS["Zone 3 - RHS Detail Panel"]
EBS["ErrorBoundaryShell"]
SS["SectionShell"]
IPS["Inbox_Property_Section"]
ISS["Inbox_Service_Section"]
ICS["Inbox_Contact_Section"]
ITS["Inbox_Tenancy_Section"]
UCC["UniversalCompactCard"]
CPC["Inbox_Person_CompactCard"]
CSC["Inbox_Service_CompactCard"]
CTC["Inbox_Tenancy_CompactCard"]
PC["PropertyCard"]
EBS --> SS
SS --> IPS
SS --> ISS
SS --> ICS
SS --> ITS
IPS --> UCC
ISS --> UCC
ICS --> UCC
ITS --> UCC
UCC --> CPC
UCC --> CSC
UCC --> CTC
UCC --> PC
end
subgraph OVERLAY["Zone 4 - Overlay"]
OS["Panel_Overlay"]
OH["OverlayHeader"]
OF["OverlayFooter"]
OS --> OH
OS --> OF
end
subgraph TOKENS["Token Layer"]
GT["globals.css"]
DT["design-tokens.ts"]
PT["panel-tokens.ts"]
TS["type-scale.ts"]
end
CHROME --- TOKENS
WORKSPACE --- TOKENS
RHS --- TOKENS
OVERLAY --- TOKENS
How to Use This — Every Instruction Pattern
| You say | Programmer writes | Zone |
|---|---|---|
| "Add Properties Sub Menu" | <Inbox_Property_Section personId={id} /> |
RHS |
| "Add Services Sub Menu" | <Inbox_Service_Section services={data} isLandlord={bool} /> |
RHS |
| "Add Contacts Sub Menu" | <Inbox_Contact_Section personId={id} displayName={n} ... /> |
RHS |
| "Add Tenancies Sub Menu" | <Inbox_Tenancy_Section tenancyStatus={s} ... /> |
RHS |
| "Add a section in the RHS panel" | SectionShell title="XYZ" icon={Icon} |
RHS |
| "Add a compact card under that section" | UniversalCompactCard props={data} |
RHS |
| "Add a page in centre workspace" | Panel_Centre_Workspace + WorkspaceHeader + WorkspaceToolbar |
Centre |
| "Add a modal" | Panel_Overlay variant="modal" + OverlayHeader + OverlayFooter |
Overlay |
| "Add a drawer" | Panel_Overlay variant="drawer" + OverlayHeader |
Overlay |
| "Add a new nav item" | SidebarNav NavItem |
Chrome |
Component Registry — Full Inventory
Shells — outer wrappers, one per zone
| Component | Zone | What it wraps |
|---|---|---|
Panel_Left_Navigation | Chrome | Top nav bar + left sidebar layout |
Panel_Centre_Workspace | Centre | Page padding, max-width, scroll |
SectionShell | RHS | Section header + content |
Panel_Overlay | Overlay | Backdrop, z-index, focus trap, escape key |
ErrorBoundaryShell | Cross-zone | Crash protection — wraps any section |
Bricks — smallest reusable units
| Component | Zone | What it renders |
|---|---|---|
Inbox_Property_Section | RHS | Sub Menu: fetches + renders property compact cards for a person |
Inbox_Service_Section | RHS | Sub Menu: fetches + renders service compact cards for a person |
Inbox_Contact_Section | RHS | Sub Menu: renders primary contact card + secondary contact list |
Inbox_Tenancy_Section | RHS | Sub Menu: renders tenancy compact card with dates/rent/parties |
UniversalCompactCard | RHS | Thumbnail + header + icons + pills + click — base for all compact cards |
Inbox_Person_CompactCard | RHS | Person variant of UniversalCompactCard |
Inbox_Service_CompactCard | RHS | Service variant (formerly CompactServiceCard) |
Inbox_Tenancy_CompactCard | RHS | Tenancy variant of UniversalCompactCard |
PropertyCard | RHS | Property variant of UniversalCompactCard |
Token Files — SSOT, never hardcode these values
| File | Zone | What it controls |
|---|---|---|
globals.css | All | Colours, backgrounds, borders, semantic tokens |
design-tokens.ts | All | PILL, TEXT, AVATAR, SECTION_HEADER |
workspace-tokens.ts | Centre | Page padding, table, list, stat spacing |
chrome-tokens.ts | Chrome | Nav height, sidebar width, item padding |
overlay-tokens.ts | Overlay | Z-index scale, modal sizes, motion |
panel-tokens.ts | RHS | Panel padding, margin, gap values |
type-scale.ts | All | Font sizing hierarchy |
chip-tokens.ts | All | Chip/pill colour variants |
Storybook — Live Component Catalogue
Storybook is set up and running. Every component has a live story showing all its variants — 59 story files in total. Story coverage is enforced by ux-qa-check.sh Check 4 on every commit.
cd 03_technology/11_frontend/portal npm run storybook # Opens at http://localhost:6006
Sub Menu 4-Level Plug & Play Sub Menu Architecture
Think of the RHS panel like a Swiss Army knife. Each blade (Sub Menu) pops out independently and does its own job. The Properties blade talks to the properties API. The Services blade talks to the services API. They never share a blade or trip over each other. Adding a new blade is just adding one file — zero changes to the other blades.
The 4-Level Hierarchy
Every RHS detail panel is built on exactly four levels, from outermost to innermost. Each level has a single responsibility. You can swap any level without touching the others — that is the plug-and-play guarantee.
| Level | Component | Responsibility | Rule |
|---|---|---|---|
| 1 — Error Boundary | ErrorBoundaryShell |
Crash protection. Wraps the entire panel. No UI logic inside. | Always outermost — never skip |
| 2 — Section Shell | SectionShell |
Renders the section header: title, icon, optional count badge, optional View All link. | One per Sub Menu tab — never build headers inline |
| 3 — Sub Section | Inbox_Property_SectionInbox_Service_SectionInbox_Contact_SectionInbox_Tenancy_Section |
Owns data fetching for its entity type. Renders a list of compact card children. Each Sub Section is entirely self-contained: its own API call, its own loading/error state, its own props interface. | One per Sub Menu. Never share a Sub Section across menus. Never import another Sub Section's data. |
| 4 — Compact Card | UniversalCompactCard (via entity-specific variant) |
Renders a single entity as a compact card: thumbnail, header, icon row, pills, click handler. | MUST use UniversalCompactCard as base — no inline card markup |
Sub Menu → API Endpoint → Card Component Mapping
This table is the authoritative map. Before building any new Sub Menu, check this table first. If your entity type already has a row, reuse it. If it doesn't, add a row before writing code.
| Sub Menu | Sub Section Component | API Endpoint / Data Source | Compact Card | Props Entry Point |
|---|---|---|---|---|
| Properties | Inbox_Property_Section |
GET /api/inbox/context?personId={id} → properties[] |
UniversalCompactCard via PropertyCard adapter |
personId, fullAddress, assetRef, loading |
| Services | Inbox_Service_Section |
GET /api/inbox/context?personId={id} → services[] |
Inbox_Service_CompactCard |
services, isLandlord, propertyThumbnails, loading |
| Contacts | Inbox_Contact_Section |
GET /api/inbox/context?personId={id} → person + contacts[] |
Inbox_Person_CompactCard |
personId, displayName, role, channels, contacts, loading |
| Tenancies | Inbox_Tenancy_Section |
GET /api/inbox/context?personId={id} → tenancy fields |
Inbox_Tenancy_CompactCard |
tenancyStatus, tenancyStart, tenancyEnd, landlords, tenants, loading |
The Plug & Play Contract
Each Sub Menu is a self-contained data island. It fetches its own data from its own endpoint slice, manages its own loading and error state, and exposes a clean props interface to its parent. Adding or removing a Sub Menu requires touching exactly one file — the Sub Section component. No rewiring of parent components. No shared state. No cross-section imports.
-
1Data independence
Each Sub Section calls its own API slice (or receives its data slice via props from a parent context call). It never reads data from a sibling Sub Section.
-
2Loading independence
Each Sub Section has its own
loadingprop and its own skeleton state. If Properties is loading, Services renders immediately. There is no global loading gate across Sub Menus. -
3Card independence
Each Sub Section renders exactly its own card variant.
Inbox_Property_SectionrendersPropertyCard.Inbox_Service_SectionrendersInbox_Service_CompactCard. No Sub Section renders another Sub Section's card type. All card variants delegate toUniversalCompactCard.
Usage Patterns — Drop-In Instructions
Copy-paste the pattern that matches your task. Do not write card markup by hand.
/* Add Properties Sub Menu */
<ErrorBoundaryShell>
<SectionShell title="Properties" icon={Home} count={properties.length}>
<Inbox_Property_Section
personId={personId}
fullAddress={fullAddress}
assetRef={assetRef}
loading={loading}
/>
</SectionShell>
</ErrorBoundaryShell>
/* Add Services Sub Menu */
<ErrorBoundaryShell>
<SectionShell title="Services" icon={Wrench} count={services.length}>
<Inbox_Service_Section
services={services}
isLandlord={isLandlord}
propertyThumbnails={thumbnailMap}
loading={loading}
/>
</SectionShell>
</ErrorBoundaryShell>
/* Add Contacts Sub Menu */
<ErrorBoundaryShell>
<SectionShell title="Contacts" icon={Users}>
<Inbox_Contact_Section
personId={personId}
displayName={displayName}
role={role}
channels={channels}
email={email}
phone={phone}
contacts={contacts}
loading={loading}
/>
</SectionShell>
</ErrorBoundaryShell>
/* Add Tenancies Sub Menu */
<ErrorBoundaryShell>
<SectionShell title="Tenancies" icon={FileText}>
<Inbox_Tenancy_Section
tenancyStatus={tenancyStatus}
tenancyStart={tenancyStart}
tenancyEnd={tenancyEnd}
rentPcmAgreed={rentPcmAgreed}
landlords={landlords}
tenants={tenants}
isTenant={isTenant}
hasActiveAsset={hasActiveAsset}
loading={loading}
/>
</SectionShell>
</ErrorBoundaryShell>
The SectionShell wrapper is not optional. It provides the accessible title, the count badge, and the View All affordance. Dropping it and writing your own header is a compliance violation caught by ux-qa-check.sh.
UX QA UX QA Checker — ux-qa-check.sh
The old grep-based check-design-compliance.sh has been deleted. It is superseded by ux-qa-check.sh, which runs 4 structural compliance checks and exits 0 on a clean codebase. It runs on every commit (precommit hook) and on every PR (GitHub Actions).
Location: 03_technology/11_frontend/portal/scripts/ux-qa-check.sh
The 4 Checks
-
1Zone Shell Gate
Workspace component files in
_components/properties/,_components/landlords/,_components/compliance/thatexport defaultMUST also importPanel_Centre_Workspaceor carry a// workspace-exemptcomment. -
2Component Registry
Every
.tsxfile under_components/must have a matching entry incomponent-registry.json. Test files, story files, andindex.tsxare excluded. -
3Naming Convention
Interior brick components must follow the
{Nav_Section}_{Sub_Section}_{ViewType}naming pattern. Zone shells (Panel_*prefix), story files, test files, and workspace-exempt files are excluded. -
4Story File Completeness
Every
.tsxcomponent under_components/must have a corresponding.stories.tsxin the same directory. 100% story coverage is the current state — do not break it.
cd 03_technology/11_frontend/portal bash scripts/ux-qa-check.sh # Expected output on clean codebase: # Check 1 - Zone Shell Gate... ✅ Zone shell gate passed # Check 2 - Component Registry... ✅ All components registered # Check 3 - Naming Convention... ✅ Naming conventions pass # Check 4 - Story File Completeness... ✅ All components have story files # ✅ UX QA passed
Decisions What We Explicitly Rejected
| Proposal | Verdict | Reason |
|---|---|---|
shadcn Badge |
Rejected | Conflicts with PILL.base + LABEL_COLORS. Competing badge primitive on top of the existing token system. |
| Mantine / Chakra / MUI | Rejected | Two competing theme engines on top of the existing 4-layer system. Non-starter. |
Full PanelShell wrapper |
Modified | 80% of panels are stat cards with no header. Split into PanelHeader primitive + optional PanelFrame. |
tbl_kg_constraints table |
Rejected | Fourth source of truth competing with ADRs, pattern docs, and CLAUDE.md rules. |
Keep check-design-compliance.sh |
Deleted | Grep-based broad detection. Superseded by ux-qa-check.sh with 4 targeted structural checks. |
Decisions Component Build Checklist
Run through this checklist before writing a single line of new component code. Every question maps to an enforced pattern.
-
1Does it go in the RHS panel as a compact card?
→ Use
UniversalCompactCard. Full spec inCOMPACT_CARD_PATTERN.md. CLAUDE.md Rule 11 enforces this. -
2Does it go in the centre workspace?
→ Import
Panel_Centre_Workspaceor add// workspace-exempt. Use existing row patterns:InboxTable,PropertiesList,LandlordListItem. No cards. -
3Does it use pills?
→ Use
PILL.basetoken +LABEL_COLORSfrom@/lib/ui/chip-tokens. Never hardcode. -
4Does it use padding or margin?
→ Use
PANELtokens from@/lib/ui/panel-tokens.ts. Never hardcode spacing values. -
5Is the component named correctly?
→ Interior bricks:
{Nav_Section}_{Sub_Section}_{ViewType}. Zone shells:Panel_*prefix. Runux-qa-check.shlocally before committing. -
6Is the component registered and does it have a story file?
→ Add to
component-registry.json. Create a.stories.tsxalongside it. Missing entries fail Checks 2 and 4 ofux-qa-check.sh.
Business Case What This Saves
| Scenario | Token cost per component | Why |
|---|---|---|
| Without the component system | ~53,000 tokens | Agent builds from scratch → gets it wrong → two hotfix cycles. Each cycle re-reads context, debates pattern choices, and re-implements. |
| With the component system | ~20,000 tokens | Agent reads pattern, builds once, passes compliance check on first pass. No debate, no re-implement. |
Saving per component: ~33,000 tokens. With 15 remaining components in the current build plan, that is approximately 495,000 tokens saved — roughly £150–185 at current rates.
The three-model panel was unanimous: the token cost of defining the component system once is covered by the first three components built correctly. The system has now paid for itself — 0 violations, 330+ components, 100% story coverage.
References References & External Sources
| Source | Type | Notes |
|---|---|---|
src/app/dashboard-v2/_components/inbox/COMPACT_CARD_PATTERN.md |
Pattern document | SSOT for UniversalCompactCard. CLAUDE.md Rule 11 points all agents here. |
src/component-registry.json |
Registry file | Canonical list of all registered components. Every new component must be added here. Checked by ux-qa-check.sh Check 2. |
scripts/ux-qa-check.sh |
CI script | 4-check compliance gate. Runs on every commit and PR. Exits 0 on clean codebase. |
src/app/dashboard-v2/_components/design-tokens.ts |
Token file | SSOT for PILL, TEXT, AVATAR, SECTION_HEADER tokens. |
src/app/globals.css |
CSS theme vars | All colour, background, and border CSS custom properties. The root of the visual system. |
| ADR-141 | Architecture Decision Record | Established the three-zone layout and the RHS panel pattern. |
| ADR-287 | Architecture Decision Record | Locked LABEL_COLORS from chip-tokens as the SSOT for all chip/pill colours. |
Commit 3dec004b |
Git commit | The rename commit — 24 legacy components renamed, zone shells renamed, 4 orphan components deleted. 0-violation state achieved. |
Commit 640a2fff |
Git commit | CLAUDE.md Rule 11 — concrete enforcement point for UniversalCompactCard adoption. |