ORM
TeamPlay models are Signal subclasses attached to paths in your data tree. The conventional setup is file-based: put schemas, model classes, access rules, and aggregations in models/, then initialize that model tree in both client and server entries.
For TypeScript details, see TypeScript Support. This section focuses on ORM conventions and runtime behavior.
Quick Start
StartupJS apps can skip this quick start. StartupJS configures the Babel model loader, loads file-based models, merges plugin models, and initializes TeamPlay models automatically through its registry.
Add the Babel plugin when you want file-based models:
Create a model folder:
Create a shared setup file:
Import models.setup.ts before using TeamPlay model-backed APIs. On the client, put it near the top of your app entry:
If you need to modify, merge, or filter the model object, do it in models.setup.ts so client and server initialize the same model graph.
On the server, import models.setup.ts before creating the backend:
createBackend() reuses models that were already initialized with initModels().
Folder Map
The loader maps files to TeamPlay paths:
Use [id] for wildcard path segments. Do not use * in filenames.
Private collections such as _session/ are regular model paths; _name.ts becomes an aggregation only directly inside a public top-level collection.
Read more in File-Based Models.
Schema
Create one schema.ts per collection:
When validateSchema: true is enabled on the backend, writes are validated with this schema. The generated teamplay-env.d.ts also makes the schema module's default export usable as the document type.
Schemas for private roots such as models/_session/schema.ts describe the private value itself. They are used for TypeScript and are skipped by backend collection validation.
Read more in Schemas.
Models
models/users/index.ts is the collection model:
models/users/[id].ts is the document model:
Read more in Models.
Queries
Use collection subscriptions for filtered lists:
Read more in Queries.
Aggregations
Aggregation files start with _ and live under the collection folder:
Client builds replace server aggregation implementations with safe aggregation headers.
Read more in Aggregations.
Access Control
Access rules live in access.ts:
Client builds remove access rules from the bundle automatically.
Read more in Access Control.