Skip to main content
Connect your host product to Patchsmith, define the capabilities apps can use, and render installed apps in React. You need an existing React frontend, a backend that handles standard Request and Response objects, and a Patchsmith account. Get your project key from Patchsmith and make it available to your server as PATCHSMITH_PROJECT_KEY. Keep it out of client bundles. The examples use @/ for your source directory; adjust imports to match your project.
1

Install Patchsmith

Choose a validation library to use with Patchsmith. If you’re unsure, use Zod. Then add Patchsmith and your chosen library to your project:
2

Define the shared contract

Create src/lib/patchsmith.ts to define the contract between installed apps and your platform. It declares components, views, slots, and scopes that identify an installation’s owner. Both your server and frontend import this file, so keep server credentials and logic elsewhere.
Breaking contract changes, like removing a component or requiring a field, can break existing apps.
src/lib/patchsmith.ts
A slot’s optional description gives app authors and agents layout and sizing guidance. Your host controls the actual dimensions. See Slots for a side panel example.
3

Implement the server

Create src/lib/patchsmith-server.ts to connect your contract to Patchsmith using your project key. Set baseUrl to your host’s Patchsmith handler URL in each environment, including production.
src/lib/patchsmith-server.ts
4

Create the client

Create src/lib/patchsmith-client.tsx to connect your frontend to the Patchsmith API. Map each contract component to its React implementation. The example assumes your Button and Input components accept the props shown below.
src/lib/patchsmith-client.tsx
5

Add the API handler

Mount the handler at your Patchsmith base path. If you use a path other than /api/patchsmith, update baseUrl in both patchsmith-server.ts and patchsmith-client.tsx to match.Choose your framework below. Replace auth with your authentication implementation and return a stable subjectId and verified scope values from the session.
app/api/patchsmith/[...patchsmith]/route.ts
6

Add the provider

Wrap pages that use Patchsmith hooks or render apps in PatchsmithProvider. Choose the root layout for your framework:
app/layout.tsx
7

Render a view

Use useViewContext to share page data with apps and useViews to find apps available in the page slot. Render the selected app with RenderSlot.
app/app-views/page.tsx
8

Verify the integration

Start your host app, then check these endpoints at your configured host origin:
The schema and metadata endpoints describe your public app contract. The apps endpoint requires a valid host session and returns the apps installed for the authenticated scopes. Each scope is named by the schema key, such as user.While signed in to your host, open /app-views. You should see either an app view or “No views available yet.” An unauthenticated request to /api/patchsmith/apps should be rejected.If the routes return 404, check the catch-all route and handler path. If the schema works but apps fail to load, check that authenticate returns a valid session and that the client points to the same origin as your host.

Create your first app

Follow Create an app to scaffold an app against your host contract. Then write a view for one of its slots.