# api

Authorized operations and shared contracts: responsibilities, supported exports and extension points.

## Purpose [#purpose]

The server defines oRPC procedures, domain routers, the assistant/MCP catalog and scheduled jobs. Public schema subpaths validate wire data; `client` exports only the router client type.

## Public exports [#public-exports]

Canonical subpaths follow `./<feature>/<role>` (see [ADR-0011](/docs/adr/0011-backend-feature-shape)). Contracts are leaf modules that web and mobile may import; the other entries are server-only and listed in the client boundary configuration.

| Subpath | Target |
| --- | --- |
| `./client` | `./src/client.ts` |
| `./rpc-scope` | `./src/rpc-scope.ts` |
| `./request-id` | `./src/platform/rpc/request-id.ts` |
| `./push-messages` | `./src/features/notifications/notifications.push-messages.ts` |
| `./context` | `./src/platform/rpc/context.ts` |
| `./app-router` | `./src/platform/rpc/app-router.ts` |
| `./jobs/run` | `./src/platform/jobs/run.ts` |
| `./admin/contract` | `./src/features/admin/admin.contract.ts` |
| `./audit/contract` | `./src/features/audit/audit.contract.ts` |
| `./flags/contract` | `./src/features/flags/flags.contract.ts` |
| `./todo/contract` | `./src/features/todo/todo.contract.ts` |
| `./proposals/contract` | `./src/features/proposals/proposals.contract.ts` |
| `./integrations/contract` | `./src/features/integrations/integrations.contract.ts` |
| `./billing/contract` | `./src/features/billing/billing.contract.ts` |
| `./notifications/contract` | `./src/features/notifications/notifications.contract.ts` |
| `./imports/contract` | `./src/features/imports/imports.contract.ts` |
| `./assistant/contract` | `./src/features/assistant/assistant.contract.ts` |
| `./documents/contract` | `./src/features/documents/documents.contract.ts` |
| `./agent-tools/contract` | `./src/features/agent-tools/agent-tools.contract.ts` |
| `./billing/plans` | `./src/features/billing/billing.plans.ts` |
| `./billing/http` | `./src/features/billing/billing.http.ts` |
| `./billing/web-http` | `./src/features/billing/billing.web-http.ts` |
| `./mcp/server` | `./src/features/mcp/mcp.server.ts` |
| `./mcp/context` | `./src/features/mcp/mcp.context.ts` |
| `./mcp/protocol` | `./src/features/mcp/mcp.protocol.ts` |
| `./mcp/guard` | `./src/features/mcp/mcp.guard.ts` |
| `./webhooks/events` | `./src/features/webhooks/webhooks.events.ts` |
| `./uploads/service` | `./src/features/uploads/uploads.service.ts` |
| `./assistant/http` | `./src/features/assistant/assistant.http.ts` |
| `./documents/lifecycle-plugin` | `./src/features/documents/documents.lifecycle-plugin.ts` |

### Renamed subpaths [#renamed-subpaths]

These subpaths were renamed when the backend moved to one folder per feature. Import the new subpath.

| Earlier subpath | Use instead |
| --- | --- |
| `./routers/index` | `./app-router` |
| `./routers/admin.schema` | `./admin/contract` |
| `./routers/audit.schema` | `./audit/contract` |
| `./routers/flags.schema` | `./flags/contract` |
| `./routers/proposals.schema` | `./proposals/contract` |
| `./routers/imports.schema` | `./imports/contract` |
| `./routers/assistant.schema` | `./assistant/contract` |
| `./routers/todo.schema` | `./todo/contract` |
| `./routers/integrations.schema` | `./integrations/contract` |
| `./routers/billing.schema` | `./billing/contract` |
| `./routers/notifications.schema` | `./notifications/contract` |
| `./routers/documents.schema` | `./documents/contract` |
| `./billing-plans` | `./billing/plans` |
| `./uploads/workflow` | `./uploads/service` |
| `./ai/http` | `./assistant/http` |
| `./ai/catalog.schema` | `./agent-tools/contract` |

These paths come from `packages/api/package.json`. Conditional targets distinguish platform or type resolution; consumers should import the subpath, not its source file.

## How to extend [#how-to-extend]

Add the operation to the feature's procedures and service, and register new procedures in `platform/rpc/app-router.ts`. Keep authorization in the procedure and resource scope in the query. Add a `./<feature>/contract` export when another package needs the contract. The `domain-feature` skill walks through a new feature. For AI/MCP tools, extend the single catalog after reading ADR-0007.

Read the [authorized operations and shared contracts guide](/docs/features/api) for the full flow.

## Key files [#key-files]

- [`packages/api/package.json`](https://github.com/CarlosZiegler/template-cloudflare/blob/main/packages/api/package.json)

