Skip to content

Commit 6cfd961

Browse files
committed
refactor(app-shell)!: retire the root-entry exports nothing outside the package names (WIP)
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012zuvAzwT4oemWPhAR81wRm
1 parent fbb7599 commit 6cfd961

3 files changed

Lines changed: 175 additions & 226 deletions

File tree

‎ui/docs/app-shell-extraction-guide.md‎

Lines changed: 170 additions & 166 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,98 @@
1-
# Console Streamlining - Architecture Guide
1+
# `@object-ui/app-shell` — Architecture Guide
22

33
## Overview
44

5-
This document describes the refactored architecture that enables third-party systems to use ObjectUI components without inheriting the full console infrastructure.
6-
7-
## New Packages
8-
9-
### @object-ui/app-shell
10-
11-
**Purpose**: Minimal application rendering engine
12-
13-
**Exports**:
14-
- `AppShell` - Basic layout container
15-
- `ObjectView` - Renders object views; it reads `objectName` from the router
16-
(`useParams()`) and takes an `objects` metadata array. For a router-free embed,
17-
use `ObjectView` from `@object-ui/plugin-view` instead - see the examples below.
18-
- `DashboardView` - Renders a dashboard by name. The dashboard renderer itself,
19-
`DashboardRenderer`, is not an app-shell export - it ships from
20-
`@object-ui/plugin-dashboard`, and `DashboardView` renders through it.
21-
- `PageView` - Renders a custom page by name. No package exports a
22-
`PageRenderer`: a page body is dispatched through the component registry on
23-
the schema node's `type` (`page`, `app`, `utility`, `home`, `record`).
24-
- `RecordFormPage` - Renders a full-screen create/edit page. No package exports
25-
a `FormRenderer`; the exported form renderer is `ObjectForm` from
26-
`@object-ui/plugin-form`, which this page delegates to.
27-
28-
**Dependencies**: `@object-ui/react`, `@object-ui/components`, `@object-ui/fields`, `@object-ui/layout`
29-
30-
**Bundle Size**: ~50KB
31-
32-
### @object-ui/providers
5+
This document describes `@object-ui/app-shell` as it ships today, and the two
6+
ways a host uses it: compose the full console from its building blocks, or take
7+
only the layout container and bring your own routing, auth and backend.
8+
9+
The package started as a minimal rendering engine for third-party hosts. It has
10+
since become the home of the console itself: its routing tree, its auth and
11+
organization pages, Studio, the metadata admin engine, the marketplace and the
12+
AI chat pages all live here, and `apps/console` composes them. The sections
13+
below describe that package, not the original plan.
14+
15+
## What the package contains
16+
17+
### `@object-ui/app-shell`
18+
19+
**Entry**: one root entry, `.` (`src/index.ts`), plus `./styles.css`. There are
20+
no subpath exports.
21+
22+
**Size** (non-test TypeScript under `src/`): about 211,000 lines in about 600
23+
files, with about 1,700 test files beside them. By directory:
24+
25+
| Directory | Lines | What it holds |
26+
|:---|---:|:---|
27+
| `views/metadata-admin` | ~97,000 | The generic metadata admin engine: directory, list, edit, history and diagnostics pages, the schema form, the per-type previews and inspectors, and its own designer string table (`i18n.ts`) |
28+
| `views/studio-design` | ~22,000 | The Studio WYSIWYG design surface, its per-type canvases and the builder landing page |
29+
| `views/` (the rest) | ~27,000 | The inner-SPA views: `ObjectView`, `RecordDetailView`, `RecordFormPage`, `DashboardView`, `PageView`, `ReportView`, search, flows, approvals |
30+
| `console/` | ~22,000 | The console routing tree (`AppContent`, `ConsoleShell`) and its pages: auth, home, organizations, marketplace, AI chat |
31+
| `hooks/`, `layout/`, `utils/`, `providers/`, `chrome/`, `context/`, the rest | ~43,000 | Shell chrome (header, sidebar, command palette, toasts), the metadata, adapter and expression providers, navigation and user-state hooks, runtime configuration and observability |
32+
33+
**Exports**: the root entry publishes about 200 names (about 35 of them
34+
type-only). They fall into these groups, in the order `src/index.ts` lists
35+
them:
36+
37+
- **The minimal shell** — `AppShell` (layout container) and its
38+
`MinimalAppShellProps`.
39+
- **Providers and hooks** — `AdapterProvider`, `MetadataProvider`,
40+
`ExpressionProvider`, the settle signal (`useSettleSignal`, `whenIdle`, …),
41+
recent items, favorites, navigation pins and sync, the AI-surface signal.
42+
- **Console building blocks** — `ConsoleShell`, `ConnectedShell`,
43+
`AuthenticatedRoute`, `RequireOrganization`, `SystemRedirect`,
44+
`SetupRedirect`, and the host-app route policy (`resolveHostAppSegment`).
45+
- **Layout chrome and top-level chrome** — `ConsoleLayout`, `AppHeader`,
46+
`UnifiedSidebar`, `ConsolePageHeader`, `CommandPalette`, `ConsoleToaster`,
47+
`ErrorBoundary`, `ThemeProvider`, the unsaved-edits guard.
48+
- **Runtime configuration and observability** — `initRuntimeConfig`,
49+
`getRuntimeConfig` and the branding / stage readers; Sentry wiring.
50+
- **Inner-SPA views** — `ObjectView`, `RecordDetailView`, `RecordFormPage`,
51+
`DashboardView`, `PageView`, `ReportView`, `SearchResultsPage`,
52+
`FlowRunner`.
53+
- **Default pages** — `DefaultAppContent`, `DefaultLoginPage`,
54+
`DefaultRegisterPage`, `DefaultHomePage`, the organization pages,
55+
`MarketplacePage`, `AiChatPage`, with the sign-up decision they share
56+
(`decideSignUpOffer`).
57+
- **Registries** — the app component registry (`registerAppComponent`), the
58+
metadata resource, preview and inspector registries, and the Studio canvas
59+
registry, so a plugin can override a page without forking it.
60+
- **Metadata admin and Studio pages** — `MetadataDirectoryPage`,
61+
`MetadataResourceRouter`, `SchemaForm`, `StudioDesignSurface`,
62+
`BuilderLanding`, `PackagedAutomationPage`.
63+
- **AI assistant bus** — `assistantBus`, connecting the metadata designers to
64+
the chat.
65+
66+
The [package README](../packages/app-shell/README.md) is the API reference for
67+
these names.
68+
69+
**Load-time registrations**: importing the entry registers, as a side effect,
70+
the built-in admin components, the console's SDUI widgets (cloud connection,
71+
product blocks, diagnostics), the record blocks (`record:attachments`,
72+
`record:approvals`, `record:approval_decision`), the global search,
73+
notifications, app launcher and nav menu blocks, and the metadata admin
74+
built-ins. The built-in metadata designers load from a deferred chunk on the
75+
first read of a designer registry, not during the entry's evaluation; the
76+
console's first-load budget (`scripts/check-eager-closure-budget.mjs`) is sized
77+
on that.
78+
79+
**Dependencies**: `@object-ui/react`, `@object-ui/components`,
80+
`@object-ui/fields`, `@object-ui/layout`, `@object-ui/core`,
81+
`@object-ui/types`, `@object-ui/i18n`, `@object-ui/auth`,
82+
`@object-ui/permissions`, `@object-ui/providers`,
83+
`@object-ui/data-objectstack`, `@object-ui/collaboration`,
84+
`@object-ui/plugin-editor`, `@objectstack/spec`, `@objectstack/formula`,
85+
`@objectstack/lint`; the view plugins (`plugin-grid`, `plugin-list`,
86+
`plugin-form`, `plugin-detail`, `plugin-view`, `plugin-dashboard`,
87+
`plugin-calendar`, `plugin-kanban`, `plugin-charts`, `plugin-report`,
88+
`plugin-designer`, `plugin-chatbot`) are peer dependencies.
89+
90+
**Bundle size**: not one number. A host that imports only `AppShell` still
91+
evaluates the entry and its load-time registrations; the console's eager
92+
closure is measured and budgeted by `scripts/check-eager-closure-budget.mjs`,
93+
not by this page.
94+
95+
### `@object-ui/providers`
3396

3497
**Purpose**: The upload adapter context
3598

@@ -44,111 +107,84 @@ Its former `DataSourceProvider`, `MetadataProvider` and `ThemeProvider` retired
44107

45108
**Dependencies**: `@object-ui/types`
46109

47-
## Architecture Diagram
48-
49-
```
50-
┌─────────────────────────────────────────┐
51-
│ Third-Party Application │
52-
│ (Your Custom Console) │
53-
└────────────────┬────────────────────────┘
54-
│
55-
├── Custom Routing (React Router, Next.js, etc.)
56-
├── Custom Auth (Your implementation)
57-
├── Custom API (REST, GraphQL, etc.)
58-
│
59-
┌────────────────┴────────────────────────┐
60-
│ @object-ui/app-shell │
61-
│ - AppShell │
62-
│ - ObjectView │
63-
│ - DashboardView │
64-
│ - PageView │
65-
│ - RecordFormPage │
66-
└────────────────┬────────────────────────┘
67-
│
68-
┌────────────────┴────────────────────────┐
69-
│ @object-ui/react │
70-
│ - SchemaRenderer │
71-
│ - SchemaRendererProvider (data source) │
72-
│ - ThemeProvider │
73-
│ - useActionRunner │
74-
│ - Component Registry │
75-
└────────────────┬────────────────────────┘
76-
│
77-
├──────────────┬──────────────┬──────────────┐
78-
│ │ │ │
79-
┌────────────────┴──┐ ┌────────┴────┐ ┌──────┴────┐ ┌─────┴──────┐
80-
│ @object-ui/ │ │ @object-ui/ │ │@object-ui/│ │ Plugins │
81-
│ components │ │ fields │ │ layout │ │ (optional) │
82-
│ (Shadcn UI) │ │ (Inputs) │ │ (Layouts) │ │ │
83-
└───────────────────┘ └─────────────┘ └───────────┘ └────────────┘
84-
```
110+
## Who consumes it
85111

86-
## Comparison: Before vs After
112+
Inside this repository three workspace members depend on the package:
87113

88-
### Before (Monolithic Console)
114+
- `apps/console` — the product console. It imports about 75 names from the
115+
root entry, and composes the routing tree mostly through
116+
`DefaultAppContent`, so components such as `ObjectView` and `ConsoleLayout`
117+
reach it through that tree rather than by name.
118+
- [`examples/console-starter`](../examples/console-starter/README.md) — the
119+
minimal full console: `ConsoleShell`, `AuthenticatedRoute`, the `Default*`
120+
pages and `DefaultAppContent`.
121+
- [`examples/byo-backend-console`](../examples/byo-backend-console/README.md) —
122+
the bring-your-own-backend embed. It imports `AppShell` only and renders data
123+
through `@object-ui/plugin-view` and `@object-ui/react`.
89124

90-
```
91-
apps/console (500KB+)
92-
├── Routing (hardcoded)
93-
├── Auth (ObjectStack only)
94-
├── Data Source (ObjectStack only)
95-
├── Admin Pages (forced)
96-
├── App Management (forced)
97-
└── Object Rendering
98-
```
125+
A name the root entry exports that nothing outside the package names is retired
126+
from the entry, not kept for a caller that may come: the module that defines it
127+
stays, and in-package code imports it from there.
99128

100-
**Problems**:
101-
- Cannot use without full console
102-
- Tied to ObjectStack backend
103-
- No customization of routing/auth
104-
- Large bundle size
105-
106-
### After (Modular Architecture)
129+
## Architecture Diagram
107130

108131
```
109-
@object-ui/app-shell (50KB)
110-
├── Object Rendering
111-
├── Dashboard Rendering
112-
├── Page Rendering
113-
└── Form Rendering
114-
115-
@object-ui/react
116-
├── SchemaRendererProvider (generic DataSource)
117-
└── ThemeProvider
118-
119-
Third-Party App
120-
├── Custom Routing
121-
├── Custom Auth
122-
├── Custom API
123-
└── Cherry-picked Components
132+
┌────────────────────────────────────────────────┐
133+
│ Host │
134+
│ apps/console · examples/console-starter │
135+
│ (or your own app — see byo-backend-console) │
136+
└───────────────────────┬────────────────────────┘
137+
│
138+
┌───────────────────────┴────────────────────────┐
139+
│ @object-ui/app-shell │
140+
│ - AppShell (minimal layout container) │
141+
│ - ConsoleShell / DefaultAppContent (routing) │
142+
│ - Default pages: auth, home, orgs, AI chat │
143+
│ - Inner-SPA views: ObjectView, RecordDetail… │
144+
│ - Metadata admin engine + Studio │
145+
│ - Providers, chrome, registries │
146+
└───────────────────────┬────────────────────────┘
147+
│
148+
┌───────────────────────┴────────────────────────┐
149+
│ @object-ui/react │
150+
│ - SchemaRenderer │
151+
│ - SchemaRendererProvider (data source) │
152+
│ - ThemeProvider │
153+
│ - useActionRunner │
154+
│ - Component Registry │
155+
└───────────────────────┬────────────────────────┘
156+
│
157+
┌──────────────┬───┴──────────┬──────────────┐
158+
│ │ │ │
159+
┌────┴──────┐ ┌─────┴─────┐ ┌──────┴────┐ ┌───────┴──────┐
160+
│@object-ui/│ │@object-ui/│ │@object-ui/│ │ View plugins │
161+
│components │ │ fields │ │ layout │ │ (peer deps) │
162+
└───────────┘ └───────────┘ └───────────┘ └──────────────┘
124163
```
125164

126-
**Benefits**:
127-
- Use components independently
128-
- Bring your own backend
129-
- Full customization
130-
- Small bundle size
131-
132-
## Migration Path
165+
## Two ways to use it
133166

134-
### Phase 1: New Packages (Current)
167+
### The full console
135168

136-
1. Create `@object-ui/app-shell`
137-
2. Create `@object-ui/providers`
138-
3. Create `examples/byo-backend-console`
139-
4. No breaking changes to console
169+
Compose the console's routing tree from the building blocks, as
170+
`examples/console-starter` does: `ConsoleShell` around `AuthenticatedRoute`,
171+
the `Default*` pages, and `DefaultAppContent` for the app routes. This brings
172+
the whole package: its auth flow against the ObjectStack backend, Studio, the
173+
metadata admin pages and the marketplace.
140174

141-
### Phase 2: Extract More Components (Future)
175+
### Bring your own backend
142176

143-
1. Create `@object-ui/console-components`
144-
2. Create `@object-ui/routing`
145-
3. More examples (Next.js, Embedded)
177+
Take `AppShell` for the layout and render data with the view plugins and
178+
`@object-ui/react` against your own `DataSource`, as
179+
`examples/byo-backend-console` and the examples below do. Routing, auth and the
180+
API are yours. The view to embed is `ObjectView` from
181+
`@object-ui/plugin-view`; app-shell's own `ObjectView` reads `objectName` from
182+
the router (`useParams()`) and is meant for the console's route tree.
146183

147-
### Phase 3: Refactor Console (Future)
148-
149-
1. Console uses new packages internally
150-
2. Reduce console to ~150 lines
151-
3. Console becomes reference implementation
184+
The package's direction — what stays in a product-neutral renderer and what is
185+
console product — is recorded in
186+
[ADR-0060](./adr/0060-product-neutral-renderer.md) and held by
187+
`packages/app-shell/src/__tests__/product-neutral-renderer.ratchet.test.ts`.
152188

153189
## Usage Examples
154190

@@ -329,55 +365,23 @@ export const myDataSource: DataSource = {
329365
};
330366
```
331367

332-
## Testing Strategy
333-
334-
### Unit Tests
335-
336-
- Each package has its own test suite
337-
- No cross-package dependencies in tests
338-
- Mock data sources for testing
339-
340-
### Integration Tests
368+
## Testing
341369

342-
- Test byo-backend-console example end-to-end
343-
- Verify custom data source integration
344-
- Test routing scenarios
345-
346-
### E2E Tests
347-
348-
- Separate E2E tests for byo-backend-console
349-
- Verify it works independently of full console
370+
- Each package has its own suite: `pnpm --filter @object-ui/app-shell test`
371+
runs app-shell's, from the `ui/` root (`vitest run --root ../..`).
372+
- The code blocks on this page are type-checked by
373+
`scripts/check-doc-snippet-types.mjs`, and every symbol a published README
374+
imports is checked against the package's built types by
375+
`scripts/check-readme-exports.mjs`.
376+
- `examples/console-starter` carries its own tests under `test/`.
350377

351378
## Documentation
352379

353-
### Package READMEs
354-
355-
Each package has comprehensive documentation:
356-
- Installation
357-
- Usage examples
358-
- API reference
359-
- Migration guide
360-
361-
### Examples
362-
363-
- `examples/byo-backend-console` - Basic integration (~100 lines)
364-
- `examples/nextjs-console` - Next.js integration (TODO)
365-
- `examples/embedded-widget` - Embedded usage (TODO)
366-
367-
### Guides
368-
369-
- Architecture Guide (this document)
370-
- Integration Guide
371-
- Migration Guide for console users
372-
- Cookbook for common patterns
373-
374-
## Success Metrics
375-
376-
- ✅ Third-party developer can build console in < 1 hour
377-
- ✅ Minimal bundle size < 200KB (vs current 500KB+)
378-
- ✅ Zero ObjectStack dependencies for core rendering
379-
- ⏳ 100% test coverage for extracted packages
380-
- ✅ At least 1 working integration example
380+
- [`@object-ui/app-shell` README](../packages/app-shell/README.md) — the API
381+
reference for the root entry's names.
382+
- [`examples/README.md`](../examples/README.md) — which example to start from.
383+
- [ADR-0060](./adr/0060-product-neutral-renderer.md) — the product-neutral
384+
renderer direction.
381385

382386
## License
383387

‎ui/packages/app-shell/src/chrome/toast-helpers.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*
2323
* Usage:
2424
*
25-
* import { toastWithUndo } from '@object-ui/app-shell';
25+
* import { toastWithUndo } from './chrome/toast-helpers.js'; // from `src/`; not on the package entry
2626
*
2727
* toastWithUndo('Lead deleted', {
2828
* onUndo: () => dataSource.restore('lead', id),

0 commit comments

Comments
 (0)