← Foundations

Foundation 01

Start with an object and its collection

Write a TypeScript class for something your app needs to keep. Its collection handles finding, listing, counting, and creating those records.

Your class
DatabaseManifestRESTMCPCLI
One object description supports the rest of the application.

Define the thing your app is about

Name the class after the thing people recognize: Item, Article, Place, Invoice, or Agent. Fields and useful behavior stay together.

  • Field defaults tell s-m-r-t what to store.
  • Decorators add relationships, tenant scope, and public interfaces.
  • The collection provides list, get, count, create, and related queries.
src/lib/objects/Item.ts
typescript
import { ObjectRegistry, SmrtCollection, SmrtObject, smrt }
  from '@happyvertical/smrt-core';

@smrt({ api: true, mcp: true, cli: true })
export class Item extends SmrtObject {
  title = '';
  status = 'draft';
}

export class ItemCollection extends SmrtCollection<Item> {
  static readonly _itemClass = Item;
}

ObjectRegistry.registerCollection('Item', ItemCollection);

Let the manifest carry the description

The scanner records the fields, relationships, methods, permissions, and package identity. Migrations and public interfaces all read that shared description.

  • Change the TypeScript object, regenerate the manifest, then migrate.
  • Normal lists return objects; list({ select }) returns smaller plain rows.
  • Use include for named relationships when you need full objects without N+1 queries.