Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
refactor(app): simplify production port composition
joshistoast296818615c56
diff --git a/invokeai/frontend/webv2/ARCHITECTURE.md b/invokeai/frontend/webv2/ARCHITECTURE.mdindex 3a3b22b3e4..75a00d95b5 100644--- a/invokeai/frontend/webv2/ARCHITECTURE.md+++ b/invokeai/frontend/webv2/ARCHITECTURE.md@@ -7,7 +7,7 @@ Webv2 uses four top-level module groups:- `workbench/` owns the atomic project aggregate, layout, shell, widget runtime, and extension runtime.- `features/<domain>/` owns domain behavior behind a small set of public top-level entry modules (`features/<domain>/index.ts` first among them).-Dependency direction is `app -> workbench/features -> platform`. Feature callers import only a feature's public entry modules — the top-level modules each feature registers in `src/architecture/featureInterfaces.ts` (`index` is implicitly public; an unregistered feature or module is private, fail-closed); everything under `core/`, `data/`, `ui/`, and runtime implementation is private. A feature may group substantial behavior under `core/`, `data/`, and `ui/`; pure cores do not import React, HTTP, or UI code. Production canvas callers use `canvas-engine/api.ts`, not the engine implementation root.+Dependency direction is `app -> workbench/features -> platform`. Feature callers import only a feature's public entry modules — the top-level modules each feature registers in `src/architecture/featureInterfaces.ts` (`index` is implicitly public; an unregistered feature or module is private, fail-closed); everything under `core/`, `data/`, `ui/`, and runtime implementation is private. A feature may group substantial behavior under `core/`, `data/`, and `ui/`; pure cores do not import transport, Data, React, or UI modules, including through type-only imports. Production canvas callers use `canvas-engine/api.ts`, not the engine implementation root.## App and Platform ownership@@ -27,7 +27,9 @@ Ownership is based on invariants, not the first caller:The root of `src/` contains declaration files only. Runtime boot files live in App, the old root entry paths do not exist, and `index.html` names `src/app/main.tsx` directly. `@theme` resolves to Platform UI theme implementation; all other Platform callers use `@platform/*`. No compatibility path exists for moved App, HTTP, socket, external-store, selector, theme, i18n, or reusable-UI modules.-Platform transport receives authentication through `app/configureDependencies.ts`: Auth owns token storage and unauthorized-session behavior, while Platform only requests a token and reports a 401. The Platform socket publishes raw events and connection transitions; Queue and other domains interpret those events. App constructs the production Queue runtime from Queue, Workbench, Gallery, and Workflow adapters.+Platform transport receives authentication through `app/main.tsx`, before React mounts: Auth owns token storage and unauthorized-session behavior, while Platform only requests a token and reports a 401. The Platform socket publishes raw events and connection transitions; Queue and other domains interpret those events. Lifecycle-specific production composition remains explicit at its natural root: the authenticated socket in `app/router.tsx`, editor runtimes in `app/WorkbenchApp.tsx`, feature UI providers in `app/workbenchPorts.tsx`, and lazy editor bridges beside their lazy entry modules. App constructs the production Queue runtime from Queue, Workbench, Gallery, and Workflow adapters.++Platform State also owns reusable projections of broad external stores into referentially stable read-only stores. App may construct those projections for a feature port, but the listener, caching, and equality mechanics remain domain-neutral Platform code.`pnpm architecture:check` is the executable source of truth for these dependency directions. It uses the TypeScript parser to classify static imports, type imports, dynamic imports, re-exports, and inline imported types after resolving aliases and relative paths. Temporary violations must be recorded in `src/architecture/migrationExceptions.ts` with an owner and a removal ticket; architecture completion requires that registry to be empty.diff --git a/invokeai/frontend/webv2/package.json b/invokeai/frontend/webv2/package.jsonindex 947a24221b..4142d199aa 100644--- a/invokeai/frontend/webv2/package.json+++ b/invokeai/frontend/webv2/package.json@@ -4,7 +4,7 @@"private": true,"type": "module","scripts": {- "architecture:check": "vitest run --config vitest.config.mts src/architecture/dependencyPolicy.test.ts src/architecture/workbenchOwnership.test.ts src/architecture/productionPortBindings.test.ts && node scripts/write-workbench-ownership-inventory.mjs && node scripts/write-contract-caller-matrix.mjs && node scripts/write-canvas-import-matrix.mjs",+ "architecture:check": "vitest run --config vitest.config.mts src/architecture/dependencyPolicy.test.ts src/architecture/workbenchOwnership.test.ts src/architecture/architectureWorkflow.test.ts && node scripts/write-workbench-ownership-inventory.mjs && node scripts/write-contract-caller-matrix.mjs && node scripts/write-canvas-import-matrix.mjs","build": "pnpm run lint && vite build","check:architecture": "pnpm run lint && pnpm run test:all && pnpm run test:performance:architecture","dev": "vite dev",diff --git a/invokeai/frontend/webv2/performance/architecture-baseline.json b/invokeai/frontend/webv2/performance/architecture-baseline.jsonindex b82cf8ba48..0c045cff53 100644--- a/invokeai/frontend/webv2/performance/architecture-baseline.json+++ b/invokeai/frontend/webv2/performance/architecture-baseline.json@@ -27,12 +27,10 @@"graph","http","identity",- "imageUrls","index","models","nodesStore","preload-helper",- "productionPortBindings","promptHistory","react","rolldown-runtime",@@ -89,11 +87,9 @@"graph","http","identity",- "imageUrls","models","nodesStore","preload-helper",- "productionPortBindings","promptAttentionHotkeys","promptHistory","promptHistoryNavigation",diff --git a/invokeai/frontend/webv2/performance/browser-baseline.json b/invokeai/frontend/webv2/performance/browser-baseline.jsonindex ae1b775aa4..6077e08af1 100644--- a/invokeai/frontend/webv2/performance/browser-baseline.json+++ b/invokeai/frontend/webv2/performance/browser-baseline.json@@ -29,12 +29,10 @@"graph","http","identity",- "imageUrls","index","models","nodesStore","preload-helper",- "productionPortBindings","promptHistory","react","rolldown-runtime",@@ -103,13 +101,11 @@"http","identity","image-actions",- "imageUrls","index","models","nodeChrome","nodesStore","preload-helper",- "productionPortBindings","promptAttentionHotkeys","promptHistory","promptHistoryNavigation",@@ -137,6 +133,7 @@"useProjectActions","useStreamingImageSource","utility",+ "utility","vendor","widget-frame","widget:autosave-status",@@ -206,13 +203,11 @@"http","identity","image-actions",- "imageUrls","index","models","nodeChrome","nodesStore","preload-helper",- "productionPortBindings","promptAttentionHotkeys","promptHistory","promptHistoryNavigation",@@ -240,6 +235,7 @@"useProjectActions","useStreamingImageSource","utility",+ "utility","vendor","widget-frame","widget:autosave-status",@@ -309,13 +305,11 @@"http","identity","image-actions",- "imageUrls","index","models","nodeChrome","nodesStore","preload-helper",- "productionPortBindings","promptAttentionHotkeys","promptHistory","promptHistoryNavigation",@@ -343,6 +337,7 @@"useProjectActions","useStreamingImageSource","utility",+ "utility","vendor","widget-frame","widget:autosave-status",@@ -410,13 +405,11 @@"http","identity","image-actions",- "imageUrls","index","models","nodeChrome","nodesStore","preload-helper",- "productionPortBindings","promptAttentionHotkeys","promptHistory","promptHistoryNavigation",@@ -444,6 +437,7 @@"useProjectActions","useStreamingImageSource","utility",+ "utility","vendor","widget-frame","widget:autosave-status",diff --git a/invokeai/frontend/webv2/src/app/GalleryImageActionsBridge.tsx b/invokeai/frontend/webv2/src/app/GalleryImageActionsBridge.tsxindex 39b3e3b56e..0196f1d4b4 100644--- a/invokeai/frontend/webv2/src/app/GalleryImageActionsBridge.tsx+++ b/invokeai/frontend/webv2/src/app/GalleryImageActionsBridge.tsx@@ -4,8 +4,6 @@ import type { ReactNode } from 'react';import { GalleryImageActionsProvider } from '@features/gallery/react';import { ImageContextMenu, useImageActions, type ImageActions } from '@workbench/image-actions';-import { bindProductionPortBinding } from './productionPortBindings';-const GalleryImageContextMenuComponent = ({ actions, ...props }: GalleryImageContextMenuProps) => (<ImageContextMenu {...props} actions={actions as ImageActions} />);@@ -23,10 +21,5 @@ const GalleryImageActionsAdapterComponent = ({return <GalleryImageActionsProvider actions={actions}>{children}</GalleryImageActionsProvider>;};-const galleryImageActionsBridge = bindProductionPortBinding('gallery.image-actions-bridge', {- ImageActionsAdapter: GalleryImageActionsAdapterComponent,- ImageContextMenu: GalleryImageContextMenuComponent,-});--export const GalleryImageActionsAdapter = galleryImageActionsBridge.ImageActionsAdapter;-export const GalleryImageContextMenu = galleryImageActionsBridge.ImageContextMenu;+export const GalleryImageActionsAdapter = GalleryImageActionsAdapterComponent;+export const GalleryImageContextMenu = GalleryImageContextMenuComponent;diff --git a/invokeai/frontend/webv2/src/app/WorkbenchApp.tsx b/invokeai/frontend/webv2/src/app/WorkbenchApp.tsxindex d84e481f3d..04a08cda88 100644--- a/invokeai/frontend/webv2/src/app/WorkbenchApp.tsx+++ b/invokeai/frontend/webv2/src/app/WorkbenchApp.tsx@@ -12,12 +12,9 @@ import { WorkbenchSessionController } from '@workbench/WorkbenchSessionControlleimport { WorkbenchWidgetRegistryProvider } from '@workbench/WorkbenchWidgetRegistryContext';import { useMemo } from 'react';-import { bindProductionPortBinding } from './productionPortBindings';import { QueueRuntimeAdapter } from './QueueRuntimeAdapter';import { WorkbenchUiPorts } from './workbenchPorts';-const WorkbenchQueueRuntime = bindProductionPortBinding('queue.workbench-runtime', QueueRuntimeAdapter);-/*** The authenticated editor: providers, editor-only runtimes, and the shell.* The shared backend socket is mounted above this route; `WorkbenchRuntime`@@ -41,7 +38,7 @@ export const WorkbenchApp = () => {<WorkbenchUiPorts><SessionExpiryGuard /><WorkbenchHotkeyRuntime />- <WorkbenchQueueRuntime />+ <QueueRuntimeAdapter /><WorkbenchRuntime /><WorkbenchSessionController search={search} /><WidgetHosts />diff --git a/invokeai/frontend/webv2/src/app/main.tsx b/invokeai/frontend/webv2/src/app/main.tsxindex bc3eb02109..9d8900c5fa 100644--- a/invokeai/frontend/webv2/src/app/main.tsx+++ b/invokeai/frontend/webv2/src/app/main.tsx@@ -6,11 +6,9 @@ import { StrictMode } from 'react';import { createRoot } from 'react-dom/client';import { App } from './App';-import { mountProductionPortBinding } from './productionPortBindings';-// The only production binding that must exist before React mounts; all other-// bindings are enumerated in `app/workbenchPorts.tsx`.-mountProductionPortBinding('platform.http-auth', () => configureHttpAuth(identityTransportAuthAdapter));+// HTTP auth must be configured before any React-owned transport consumer mounts.+configureHttpAuth(identityTransportAuthAdapter);const rootElement = document.getElementById('root');diff --git a/invokeai/frontend/webv2/src/app/productionPortBindings.ts b/invokeai/frontend/webv2/src/app/productionPortBindings.tsdeleted file mode 100644index 8c35e8f9d5..0000000000--- a/invokeai/frontend/webv2/src/app/productionPortBindings.ts+++ /dev/null@@ -1,48 +0,0 @@-export type ProductionPortBindingOwner =- | 'gallery'- | 'generation'- | 'models'- | 'platform'- | 'queue'- | 'upscale'- | 'workflow';--export type ProductionPortBindingLifetime = 'pre-react' | 'authenticated-session' | 'editor' | 'lazy-editor';--export interface ProductionPortBinding {- id: string;- lifetime: ProductionPortBindingLifetime;- owner: ProductionPortBindingOwner;-}--/** Complete, implementation-free inventory of App's production bindings. */-export const productionPortBindingManifest = [- { id: 'platform.http-auth', lifetime: 'pre-react', owner: 'platform' },- { id: 'platform.authenticated-socket', lifetime: 'authenticated-session', owner: 'platform' },- { id: 'queue.workbench-runtime', lifetime: 'editor', owner: 'queue' },- { id: 'gallery.image-actions-bridge', lifetime: 'lazy-editor', owner: 'gallery' },- { id: 'models.ui', lifetime: 'editor', owner: 'models' },- { id: 'queue.ui', lifetime: 'editor', owner: 'queue' },- { id: 'gallery.ui', lifetime: 'editor', owner: 'gallery' },- { id: 'generation.ui', lifetime: 'editor', owner: 'generation' },- { id: 'upscale.ui', lifetime: 'editor', owner: 'upscale' },- { id: 'workflow.ui', lifetime: 'editor', owner: 'workflow' },-] as const satisfies readonly ProductionPortBinding[];--export type ProductionPortBindingId = (typeof productionPortBindingManifest)[number]['id'];--const bindingIds = new Set<ProductionPortBindingId>(productionPortBindingManifest.map((binding) => binding.id));--/** Typed mount declaration used by lifecycle-specific composition modules. */-export const bindProductionPortBinding = <Mount>(id: ProductionPortBindingId, mount: Mount): Mount => {- if (!bindingIds.has(id)) {- throw new Error(`Unknown production port binding: ${id}`);- }- return mount;-};--/** Typed one-shot mount for the pre-React binding. */-export const mountProductionPortBinding = <Result>(id: ProductionPortBindingId, mount: () => Result): Result => {- bindProductionPortBinding(id, mount);- return mount();-};diff --git a/invokeai/frontend/webv2/src/app/router.tsx b/invokeai/frontend/webv2/src/app/router.tsxindex 7ddd92da73..fe1937d8bc 100644--- a/invokeai/frontend/webv2/src/app/router.tsx+++ b/invokeai/frontend/webv2/src/app/router.tsx@@ -14,11 +14,8 @@ import { Launchpad } from '@workbench/launchpad/Launchpad';import { peekOpenProjectIds, type WorkbenchSearch } from '@workbench/projects/session';import { loadWorkbenchSettings } from '@workbench/settings/store';-import { bindProductionPortBinding } from './productionPortBindings';import { SocketHubRuntime } from './SocketHubRuntime';-const AuthenticatedSocketRuntime = bindProductionPortBinding('platform.authenticated-socket', SocketHubRuntime);-/*** Code-based route tree. The authenticated layout route owns the auth guard,* which resolves the backend's multi-user status once per app load:@@ -46,7 +43,7 @@ const rootRoute = createRootRoute({ component: Outlet });*/const AuthenticatedLayout = () => (<>- <AuthenticatedSocketRuntime />+ <SocketHubRuntime /><Outlet /></>);diff --git a/invokeai/frontend/webv2/src/app/workbenchPorts.test.tsx b/invokeai/frontend/webv2/src/app/workbenchPorts.test.tsxnew file mode 100644index 0000000000..269e06d899--- /dev/null+++ b/invokeai/frontend/webv2/src/app/workbenchPorts.test.tsx@@ -0,0 +1,22 @@+import { describe, expect, it } from 'vitest';++import { GalleryUiAdapterProvider } from './GalleryUiAdapter';+import { GenerationUiAdapterProvider } from './GenerationUiAdapter';+import { ModelsUiAdapterProvider } from './ModelsUiAdapter';+import { QueueUiAdapterProvider } from './QueueUiAdapter';+import { UpscaleUiAdapterProvider } from './UpscaleUiAdapter';+import { workbenchUiPortProviders } from './workbenchPorts';+import { WorkflowUiAdapterProvider } from './WorkflowUiAdapter';++describe('workbench UI port composition', () => {+ it('composes every feature adapter once in stable provider order', () => {+ expect(workbenchUiPortProviders).toEqual([+ ModelsUiAdapterProvider,+ QueueUiAdapterProvider,+ GalleryUiAdapterProvider,+ GenerationUiAdapterProvider,+ UpscaleUiAdapterProvider,+ WorkflowUiAdapterProvider,+ ]);+ });+});diff --git a/invokeai/frontend/webv2/src/app/workbenchPorts.tsx b/invokeai/frontend/webv2/src/app/workbenchPorts.tsxindex 6373a28b54..a881fb2f2a 100644--- a/invokeai/frontend/webv2/src/app/workbenchPorts.tsx+++ b/invokeai/frontend/webv2/src/app/workbenchPorts.tsx@@ -5,18 +5,17 @@ import { composeProviders } from '@platform/react/composeProviders';import { GalleryUiAdapterProvider } from './GalleryUiAdapter';import { GenerationUiAdapterProvider } from './GenerationUiAdapter';import { ModelsUiAdapterProvider } from './ModelsUiAdapter';-import { bindProductionPortBinding } from './productionPortBindings';import { QueueUiAdapterProvider } from './QueueUiAdapter';import { UpscaleUiAdapterProvider } from './UpscaleUiAdapter';import { WorkflowUiAdapterProvider } from './WorkflowUiAdapter';export const workbenchUiPortProviders: ReadonlyArray<ProviderComponent> = [- bindProductionPortBinding('models.ui', ModelsUiAdapterProvider),- bindProductionPortBinding('queue.ui', QueueUiAdapterProvider),- bindProductionPortBinding('gallery.ui', GalleryUiAdapterProvider),- bindProductionPortBinding('generation.ui', GenerationUiAdapterProvider),- bindProductionPortBinding('upscale.ui', UpscaleUiAdapterProvider),- bindProductionPortBinding('workflow.ui', WorkflowUiAdapterProvider),+ ModelsUiAdapterProvider,+ QueueUiAdapterProvider,+ GalleryUiAdapterProvider,+ GenerationUiAdapterProvider,+ UpscaleUiAdapterProvider,+ WorkflowUiAdapterProvider,];/** All six feature UI ports, composed once at module scope (identity must be render-stable). */diff --git a/invokeai/frontend/webv2/src/architecture/architectureWorkflow.test.ts b/invokeai/frontend/webv2/src/architecture/architectureWorkflow.test.tsnew file mode 100644index 0000000000..bda23229e7--- /dev/null+++ b/invokeai/frontend/webv2/src/architecture/architectureWorkflow.test.ts@@ -0,0 +1,17 @@+import { describe, expect, it } from 'vitest';++describe('architecture workflow', () => {+ it('retains architecture inventories and performance reports in one CI artifact even on failure', () => {+ const workflows = import.meta.glob('../../../../../.github/workflows/frontend-tests.yml', {+ eager: true,+ import: 'default',+ query: '?raw',+ }) as Record<string, string>;+ const workflow = Object.values(workflows)[0] ?? '';++ expect(workflow).toContain('name: webv2-architecture-review');+ expect(workflow).toContain('invokeai/frontend/webv2/artifacts/architecture');+ expect(workflow).toContain('invokeai/frontend/webv2/artifacts/architecture-performance');+ expect(workflow).toContain('if: ${{ always()');+ });+});diff --git a/invokeai/frontend/webv2/src/architecture/productionPortBindings.test.ts b/invokeai/frontend/webv2/src/architecture/productionPortBindings.test.tsdeleted file mode 100644index f187641c9b..0000000000--- a/invokeai/frontend/webv2/src/architecture/productionPortBindings.test.ts+++ /dev/null@@ -1,53 +0,0 @@-import { productionPortBindingManifest } from '@app/productionPortBindings';-import { describe, expect, it } from 'vitest';--describe('production port binding composition', () => {- it('enumerates the complete production binding manifest', () => {- expect(productionPortBindingManifest).toEqual([- { id: 'platform.http-auth', lifetime: 'pre-react', owner: 'platform' },- { id: 'platform.authenticated-socket', lifetime: 'authenticated-session', owner: 'platform' },- { id: 'queue.workbench-runtime', lifetime: 'editor', owner: 'queue' },- { id: 'gallery.image-actions-bridge', lifetime: 'lazy-editor', owner: 'gallery' },- { id: 'models.ui', lifetime: 'editor', owner: 'models' },- { id: 'queue.ui', lifetime: 'editor', owner: 'queue' },- { id: 'gallery.ui', lifetime: 'editor', owner: 'gallery' },- { id: 'generation.ui', lifetime: 'editor', owner: 'generation' },- { id: 'upscale.ui', lifetime: 'editor', owner: 'upscale' },- { id: 'workflow.ui', lifetime: 'editor', owner: 'workflow' },- ]);- });-- it('has exactly one production mount declaration for every binding', () => {- const appModules = import.meta.glob('../app/*.{ts,tsx}', {- eager: true,- import: 'default',- query: '?raw',- }) as Record<string, string>;- const source = Object.entries(appModules)- .filter(([fileName]) => !fileName.endsWith('/productionPortBindings.ts'))- .map(([, contents]) => contents)- .join('\n');-- for (const binding of productionPortBindingManifest) {- const escapedId = binding.id.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');- const mounts = source.match(- new RegExp(`(?:bindProductionPortBinding|mountProductionPortBinding)\\(['"]${escapedId}['"]`, 'g')- );- expect(mounts, binding.id).toHaveLength(1);- }- });-- it('retains architecture inventories and performance reports in one CI artifact even on failure', () => {- const workflows = import.meta.glob('../../../../../.github/workflows/frontend-tests.yml', {- eager: true,- import: 'default',- query: '?raw',- }) as Record<string, string>;- const workflow = Object.values(workflows)[0] ?? '';-- expect(workflow).toContain('name: webv2-architecture-review');- expect(workflow).toContain('invokeai/frontend/webv2/artifacts/architecture');- expect(workflow).toContain('invokeai/frontend/webv2/artifacts/architecture-performance');- expect(workflow).toContain('if: ${{ always()');- });-});