Skip to content
RefPieSign in
Search documentation
Knowledge sections

Effect v4 backbone

Shared Effect services, schemas, errors, and HTTP contracts.

effectcapabilities
On this page

packages/capabilities owns application behavior as Effect v4 services, schemas, and tagged errors. The web, API, and background Workers compose these services instead of implementing separate use cases.

Services and adapters

Services use Context.Service. Live adapters read and write Postgres; Seed adapters implement the same contracts in memory for tests and fixture-backed execution. Tests can provide a Seed layer without starting a Worker.

WorkspaceContext carries the resolved workspace and caller into capability calls:

export class WorkspaceContext extends Context.Service<
  WorkspaceContext,
  WorkspaceContextInterface
>()('@refpie/capabilities/WorkspaceContext') {}

Source: packages/capabilities/src/workspace-context.ts, lines 99–102

Contracts and errors

Effect Schema defines capability values and HTTP payloads. packages/api composes those schemas into HttpApi groups, which drive server routing, OpenAPI, and the typed client.

Tagged errors distinguish expected refusals from unexpected failures. HTTP annotations assign statuses such as WorkspaceNotFound 404, AuthorizationDenied 403, and RateLimited 429. MCP handlers return expected operation refusals as tool errors. Web handlers translate allowlisted errors into safe UI messages.

For example, the workspace lookup error declares its HTTP status alongside its schema:

export class WorkspaceNotFound extends Schema.TaggedError<WorkspaceNotFound>()(
  'WorkspaceNotFound',
  { slug: Schema.String },
  { httpApiStatus: 404 }
) {}

Source: packages/capabilities/src/errors.ts, lines 13–17

The web app loads server state through TanStack Start loaders and server functions. Browser modules must not import server adapters or their runtime dependencies.

Follow First business feature to add a workspace-owned resource through Postgres, Effect adapters, permissions, UI, and REST.