# Resources & the DSL

> Author your data model in TypeScript with the resource() DSL and typed field builders.

A `resource` is a named model scoped to an app. Its fields carry types, and those types are the schema — the compiler reads them directly rather than trusting a separate declaration.

```ts title="resources/airports.ts"
import { resource, s } from "rastack/define";

export const Airport = resource("airports", "airport", {
  code: s.string({ maxLength: 3, unique: true }),
  name: s.string({ maxLength: 120 }),
  elevation: s.int({ min: 0 }),
  active: s.boolean({ default: true }),
}, {
  search: ["code", "name"],
  admin: { listDisplay: ["code", "name"] },
});
```

The signature is `resource(app, model, fields, options?)`. The first two arguments become the URL segments — `/api/airports/v1/airport/` — and the field map defines the columns.

## Field builders

Every field comes from `s.*`. Scalars carry a `__rastackScalar` discriminant and their constraints come from the call arguments:

| Builder | Type | Common constraints |
| --- | --- | --- |
| `s.string()` | text | `maxLength`, `unique`, `default` |
| `s.int()` · `s.float()` | number | `min`, `max`, `unique` |
| `s.boolean()` | bool | `default` |
| `s.datetime()` | timestamp | `autoNow` |
| `s.ref(() => Model)` | foreign key | `nullable` |

## Options

The fourth argument configures behaviour across every surface:

- `search` — fields the changelist and API search over.
- `admin` — how the record renders in the admin site (`listDisplay`, etc.).
- `access` — row-level security (see [Security & Access Control](https://reactapistack.com/docs/security.md)).
- `sync` — opt into local-first replication (see [Local-First Sync](https://reactapistack.com/docs/sync.md)).

> **Tip:** Prefer no DSL at all? The compiler can infer resources straight from plain TypeScript interfaces — see [Interface-Driven Entities](https://reactapistack.com/docs/interface-entities.md).

---

_Source: [https://reactapistack.com/docs/resources](https://reactapistack.com/docs/resources) · Full docs as one file: [llms-full.txt](https://reactapistack.com/llms-full.txt)_
