# @xemahq/xema-decorators

> Declarative NestJS decorators for routes and capabilities.

## Overview

NestJS decorators that declare a service's resources, routes and capabilities on its controllers. Actions, operation ids and permissions are inferred from naming conventions, and `XemaRuntimeModule` scans the app at boot to emit the route, capability and service manifests, so none are written by hand.

## When to use it

- Use it to declare a NestJS service's route and capability surface as annotations.
- Use `@BffController` for a browser-facing composition surface.
- Use the inference functions standalone in tests or codemods.

## Installation

```bash
pnpm add @xemahq/xema-decorators
```

## Usage

```ts
import { XemaResource, XemaRoute, XemaPublicRoute } from '@xemahq/xema-decorators';

@XemaResource('invoice')
@Controller('invoices')
export class InvoiceController {
  @XemaPublicRoute()
  @Get()
  list() { /* ... */ }

  @XemaRoute()
  @Post()
  create() { /* ... */ }
}
```

For a browser-facing surface, `@BffController` declares the whole contract at once. `orgRole` is required and `path` must start with `bff/`.

```ts
import { OrgRole } from '@xemahq/contracts/tenant';
import { BffController } from '@xemahq/xema-decorators';

@BffController({ resource: 'invoice', path: 'bff/invoices', orgRole: OrgRole.Member })
export class InvoiceBffController {
  @Get()
  summary() { /* ... */ }
}
```

## Peer requirements

- `@nestjs/common`, `@nestjs/core` — host framework.
- `@xemahq/platform-common` — request context, token classes and org roles;
  `@BffController` composes its guards.
- `reflect-metadata` — decorator metadata runtime.

## License

Apache-2.0 &copy; Xema — [xema.dev](https://xema.dev)
