Skip to content
Agentmart
Submit a tool

typebox-model-schema

Define the complete model schema using TypeBox as the single source of truth for backend validation, SQL contract documentation, and frontend form/list/picker…

Skill by IgorAIvanov

IndexedMIT★ 1
Write a review

Chalk Labs

Need help deploying typebox-model-schema?

Chalk Labs sets up agents like this inside real teams: connected to your tools, tested on your data, with a human in the loop where it matters.

Book a call

Install

Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.

npx agentmarket install skill/igoraivanov-typebox-model-schema

Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.

Get the weekly diff

The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.

We use your email only for this newsletter. Privacy

About

Define the complete model schema using TypeBox as the single source of truth for backend validation, SQL contract documentation, and frontend form/list/picker generation.

Use cases: documents, frontend, backend

No reviews yet. Installed it? Reviews come from verified installers only. How reviews work

Permissions

What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.

Tools
No tools found
Secrets
None asked for
Install scripts
None found

Network hosts it talks to 1

  • codeload.github.com · found in install command

Files it touches

  • ~/.claude/skills/typebox-model-schema

What's inside

Skill name
typebox-model-schema
Description
Define the complete model schema using TypeBox as the single source of truth for backend validation, SQL contract documentation, and frontend form/list/picker generation.
License
MIT
Metadata
audience: app
Instructions
353 lines in SKILL.md · view on GitHub

Files (1)

  • SKILL.md

SKILL.md (first lines)

# TypeBox Model Schema Skill

Use this skill when:
- creating a new model schema file
- adding fields or commands to an existing model
- replacing manual interfaces with TypeBox schemas
- designing the shape of list, form, picker, and payload data

## TypeBox

Library: [`@sinclair/typebox`](https://github.com/sinclairzx81/typebox)  
Import: `import { Type, type Static } from "@sinclair/typebox";`

TypeBox schemas are standard JSON Schema objects with TypeScript types derived via `Static<typeof Schema>`. They work at runtime (validation) and compile time (types) from a single definition.

## Core principle

One `<model>.schema.ts` file is the single source of truth for:
- TypeScript types (via `Static<>`)
- Backend payload validation
- SQL function contract documentation
- Frontend form fields, list columns, and picker display

No separate hand-written interfaces alongside TypeBox schemas. Every shape is a TypeBox schema.

## Primary key rules

- **Default**: `bigint generated by default as identity` starting at **100**.  
  Starting at 100 leaves room for seed/reference data inserted with explicit ids (1–99).
- **In JSON/TypeScript**: bigint travels as `string` to avoid JS number precision loss.  
  Use `Type.String()` for the `id` field in all schemas — annotate with `"x-db-type": "bigint"` to document the DB type.
- **UUID**: only when the entity genuinely needs a non-sequential, globally unique identifier  
  (e.g. external integrations, distributed generation, public-facing tokens).  
  Do not use UUID for ordinary catalog or document models.
- The `id` field in `ItemSchema` is always `Type.Union([Type.String(), Type.Null()])` —  
  `null` means new record, string means existing record.
- Reference fields (foreign keys) that point to another model's bigint id are `Type.String()` in TypeScript, `bigint` in SQL.

### SQL pattern for bigint identity starting at 100

The schema name in SQL comes from the `schema` field in the model's `manifest.json`.  
The table and function names use the `model` field from the same file.

```json
{ "model": "bank", "type": "catalog", "schema": "app" }
```

```sql
-- table: {schema}.{model}
create table if not exists app.bank (
  id bigint generated by default as identity (start with 100) primary key,
  ...
);

-- functions: {schema}.{model}_{command}
-- app.bank_list, app.bank_get, app.bank_save, app.bank_delete, app.bank_lookup
```

## Shared base types

Import common framework contracts from the client shared schema — do not redefine
them per model:

```ts
import { type SortDir } from "@client/shared/schema.ts";
```

What that module holds (it lives in the `@altera/client` package, not in the app —
the app depends on the framework, never the reverse):

```ts
// @client/shared/schema.ts
import { Type, type Static } from "@sinclair/typebox";

export const SortDirSchema = Type.Union([Type.Literal("asc"), Type.Literal("desc")]);
export type SortDir = Static<typeof SortDirSchema>;

// плюс Query/Totals (контракт списку) і DocumentHeader (шапка документа)
```

## Field annotations

Standard JSON Schema annotations drive both validation and UI:

| Annotation      | Purpose                                      |
|-----------------|----------------------------------------------|
| `title`         | Field label in forms and list column headers |
| `description`   | Tooltip / help text                          |
| `minLength`     | Minimum string length (also form validation) |
| `maxLength`     | Maximum string length                        |
| `minimum`       | Minimum numeric value                        |
| `maximum`       | Maximum numeric value                        |
| `format`        | `"date"`, `"date-time"`, `"email"` — drives input type |
| `default`       | Default value for new record                 |

Custom UI annotations (prefix `x-`):

| Annotation   | Values                          | Purpose                              |
|--------------|---------------------------------|--------------------------------------|
| `x-form`     | `true` or `{ order, width }`    | Include field in the generated form  |
| `x-list`     | `true` or `{ width, sortable }` | Include field as a list column       |
| `x-lookup`   | `true`                          | Include field in picker display/search |
| `x-picker`   | `{ url, displayField }`         | Field is a reference — render ui-picker |
| `x-readonly` | `true`                          | Display only, not editable           |
| `x-filter`   | `true` or `{ op, key }`         | Field can filter the list — generates the SQL (see below) |
| `x-transient`| `true`                          | Field exists in the form type but has no column — the generator ignores it entirely |
| `x-secret`   | `true`                          | A secret (bank API token, service key): no column, kept encrypted in `app.secret` by the runtime, never returned — see below |

### `x-secret` — a secret the server keeps and never returns

```ts
token:          Type.Optional(Type.Union([Type.String(), Type.Null()], { "x-secret": true })),
tokenSet:       Type.Optional(Type.Boolean({ "x-transient": true })),
tokenChangedAt: Type.Optional(Type.Union([Type.String(), Type.Null()], { "x-transient": true })),
```

- **There is no column for it** — do not write one in `db/struc.sql`. The generator skips the field; the runtime takes it out of `save` before your SQL function runs and stores it encrypted (`SECRET_KEY`) in the core table `app.secret`. Add `"@core/secret"` to `app/sql.json` — `sql:registry` refuses without it.
- **The value in the model is an intent, not the secret**: absent or `""` — keep, a string — replace, `null` — clear. `get` and `save` answer with `<field>Set` and `<field>ChangedAt` only; `list`, export, print and the agent channel never see the field at all.
- **Only a TS command of the same model reads it** — `await ctx.secret(id, "token")`. SQL has no key and cannot decrypt.

From IgorAIvanov/altera03, MIT.

More from IgorAIvanov/altera03

Signals

Stars
1
Forks
0
Open issues
0
Last commit (this folder)
Oct 7, 2026 (23 days ago)

From GitHub (fetched Oct 24, 2026).

Details

License
MIT
First seen
Oct 24, 2026
Last checked
Oct 24, 2026

More from IgorAIvanov

Done for you

Rather not set it up yourself?

Chalk Labs scopes, builds and runs agents for your team: the task audit, the eval harness, the integrations and the weekly ops report. Fixed scope, priced before we start.

See how we build AI agents →Read the case studies

Chalk Labs is a two-founder AI and growth studio. We build AI agents, CRMs and MVPs for Web3 and AI companies, and have shipped 50+ product and token launches.

launches shipped
50+
launches shipped
media placements
500+
media placements
founders on every account
2
founders on every account

Press we've placed: Forbes · CoinDesk · Decrypt · Cointelegraph · The Block

Rahil Jain, Co-founder, Chalk Labs. Ex-Goldman Sachs engineer. You talk to the person who builds it.

Get typebox-model-schema running in your business

Tell us what you want to automate. A founder replies within one working day with a plan, not a pitch deck.

Goes to the Chalk Labs founders, not the newsletter. Privacy

Need help deploying typebox-model-schema?

CallGet help
Cite this page

typebox-model-schema skill. Agent Mart. https://agentmart.dev/skills/igoraivanov-typebox-model-schema (last updated 2026-10-24)