Integration guides
Surfaces
Choose where Features belong, what they can do, and how to evolve your integration.
A Surface is a place in your app where users can add Rough Features. Your app chooses the location, layout, and available capabilities; users choose what to build there.
A Surface can contain many Features. You do not need a new Surface for every report or widget a user builds. Features on the same Surface use the same set of capabilities.
This guide covers design decisions for your integration. For the API contract,
see defineRoughSurface().
Start with one Surface
Choose one place in your app and a few read-only capabilities. You do not need to decide everywhere Rough might fit before trying it out.
Good starting points include:
| Location | What users might build | Capabilities to start with |
|---|---|---|
| Custom reports page | Project reports or task summaries. | Read projects and tasks. |
| Section of a dashboard | A chart or a filtered list. | Read the data relevant to that dashboard. |
| Sidebar area | A compact summary of work needing attention. | Read the current user's task summary. |
Choose a location with a clear purpose and data your app already knows how to serve securely. Start with reads; add write capabilities when you understand which actions users need.
Decide what belongs on the Surface
A useful Surface has a coherent purpose. Ask:
- Where will Features appear? A full-page report and a compact sidebar summary have different space constraints.
- What data is relevant here? Expose operations that support the location's purpose rather than every operation in your application.
- What actions should Features support? A read-only reporting area may not need any mutations.
- Should this location have its own Feature list? Separate locations can use different Surface keys to avoid mixing unrelated Features.
For example, a Custom Pages Surface might expose project and task data for reports, while a sidebar Surface exposes a smaller task summary. Keeping them separate avoids showing full-page reports in a space intended for small widgets.
A Surface is not an authorization check. Its capability list determines which operations are available, but your application and backend must still check permissions for each request. See Security.
Define a stable key and capability list
Use defineRoughSurface() to describe the location. This example starts with an
empty capability list so the Surface definition is easy to see; add the
capabilities your Features will need before using it.
import { defineRoughSurface } from '@roughapp/feature'
const reportsSurface = defineRoughSurface({
key: 'project-reports',
name: 'Project reports',
description: 'Reports and custom views of projects and tasks.',
toolList: [],
})
keyidentifies the Surface. Choose a stable value based on its purpose. Do not generate a new key for each render or Feature. Changing the key selects a different Surface; it does not rename or migrate the existing one.nameanddescriptionexplain the location to Rough. Describe the kinds of Features that belong there.toolListcontains your capabilities. Despite the property name, these are the Query, Mutation, and Subscription instances your app implements.
See Capabilities for worked examples and a populated Surface.
defineRoughSurface() returns your object without validating, copying, or
freezing it. Keep the definition and capability list unchanged while in use.
Create the definition outside repeated render work, and use consistent
definitions for a given key.
Definitions themselves contain no client or Project state and can be shared across clients. If a capability implementation captures user-specific context, your app is responsible for keeping that context correct across identity changes.
Connect the Surface to your UI
Pass the same Surface definition to the operations for that location:
subscribeToRoughFeatures()provides its published Feature list.mountRoughFeature()displays a selected Feature in an element your app owns.createRoughFeature()creates a draft on the Surface.openRoughBuilder()lets the user edit that Feature.
Creating a Feature or opening its Builder registers the Surface with Rough. Subscribing to or mounting existing Features does not register it.
A Surface does not come with a fixed layout or automatically create navigation. Your app decides whether to show Features as pages, cards, sidebar items, or another arrangement. It also owns the buttons that create or reopen Features.
For a complete implementation, follow Build your first Feature, or use the React or Svelte version.
Keep identity and state separate from Surface design
The client connects to a Project, account, and signed-in user. Use that identity to determine who shares Features; do not treat a Surface key as a substitute for account scoping or backend authorization.
Feature application state has its own storage rules. The default store is not isolated by user or account, and sharing a Feature does not automatically synchronize its state across browsers. See Feature state.
Try representative Features
Before expanding the integration, build a few Features yourself. With project and task reads available, try a project list, a report grouped by status, and a summary of overdue tasks.
Check that:
- Builder previews work with your made-up capability samples.
- Published Features display the expected live data.
- Features fit the space your app gives them.
- Permission checks prevent access to another user's or account's data.
- Live subscriptions and mounted Features are cleaned up when the view closes.
Use the results to improve capability descriptions, schemas, and samples before adding more operations.
Add another Surface when the boundary changes
Add another Surface when a location needs its own Feature list or a different set of capabilities. Do not add one merely because a user wants another report on the same data in the same location.
A useful rule: reuse a Surface for more Features with the same purpose; add a Surface for a meaningfully different place or capability boundary.
Evolve without breaking existing Features
Published Features depend on the capability IDs, inputs, and outputs they were built against. Changing or removing those contracts can break them.
- Keep Surface keys stable across deployments.
- Prefer additive capabilities over changing or removing existing ones.
- Treat schema changes as compatibility changes: even adding a required input can break an existing caller.
- Check affected Features before changing an existing capability. Keep older operations available while dependent Features are updated where practical.
- Deploy an updated definition deliberately; do not mutate an in-use Surface's
toolListduring rendering.
Rough does not version Surfaces for you today. A new key creates a separate Surface rather than upgrading the existing one, so account for existing Features when deciding to introduce one.
Next, define your capabilities, or look up the exact Surface API.