/webda:webda-modelsfrom webda
Guides adding or changing Webda models: fields, validation, primary keys, and relations (BelongTo, OneToMany, ManyToMany). Run `npm run build` after changes.
Ships in webda. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Adding a model, adding or changing a field, its validation, the primary key, or a relation between models.
A model is a class in src/models/<Name>.model.ts extending UuidModel (generated uuid key) or Model (your own key). Fields are class properties; validation comes from JSDoc tags, which the compiler turns into the JSON schema. Run npm run build after changing a model: it regenerates webda.module.json and .webda/.
import { BelongTo, Model, OneToMany, UuidModel, WEBDA_PRIMARY_KEY } from "@webda/models";
/**
* A product category, identified by its slug
*/
export class Category extends Model {
[WEBDA_PRIMARY_KEY] = ["slug"] as const;
/**
* URL-friendly identifier
* @pattern ^[a-z0-9-]+$
*/
slug!: string;
/**
* @minLength 2
* @maxLength 50
*/
name!: string;
products!: OneToMany<Product, Category, "category">;
}
/**
* A product of a category
*/
export class Product extends UuidModel {
/**
* @minLength 1
*/
title!: string;
/**
* @minimum 0
*/
price!: number;
/**
* Optional fields use `?`
* @maxLength 500
*/
description?: string;
/**
* Category the product belongs to
*/
category!: BelongTo<Category>;
}
Relations:
| Type | Meaning |
|---|---|
BelongTo<Parent> | this model belongs to a parent; deleting the parent does not delete it, delete the children yourself |
RelateTo<Other> | a link to another model, no cascade |
OneToMany<Child, ThisModel, "attribute"> | the children whose attribute points to this model (read side of BelongTo/RelateTo) |
ManyToMany<Other> | many-to-many links |
A BelongTo or RelateTo field is stored as the key of the target: pass the key of the parent, parent.getUUID() for a model with a uuid key.
import { BelongTo, UuidModel } from "@webda/models";
export class Shelf extends UuidModel {
name!: string;
}
export class Book extends UuidModel {
title!: string;
shelf!: BelongTo<Shelf>;
}
export async function addBook(shelf: Shelf): Promise<Book> {
return Book.create({ title: "Dune", shelf: shelf.getUUID() });
}
The OneToMany side is queried like a model, restricted to the children of that instance:
import { BelongTo, OneToMany, UuidModel } from "@webda/models";
export class Author extends UuidModel {
name!: string;
articles!: OneToMany<Article, Author, "author">;
}
export class Article extends UuidModel {
title!: string;
author!: BelongTo<Author>;
}
export async function articleTitles(author: Author): Promise<string[]> {
const { results } = await author.articles.query("title != ? ORDER BY title LIMIT 20", [""]);
return results.map(article => article.title);
}
Read and write data through the model (see the webda-stores skill): Product.create({...}), Product.ref(uuid).get(), Product.query("price > 10").
@Model() / @Expose() decorators and CoreModel → v3 APIs: extend Model or UuidModel, no decorators
@Inject("productStore") store: Store → never use a store directly: Product.create / Product.query
Editing webda.module.json or .webda/ → generated: change the model and run npm run build
*.model.ts (the build fails on a model file without that suffix); src/models/ is the convention.import type to avoid circular imports.npm run build must succeed (it reports invalid JSDoc tags and relation targets), then npm test.
Written for Webda 4.0.0-beta.
What SKILL.md sets; muted values are Claude Code's defaults
7 skills in this plugin
/webda-configurationUse when changing webda.config.json, application parameters, the parameters of a service or the per-environment deployments of a Webda app/webda-deployUse when deploying a Webda app, adding a deployment environment or building a container image or Lambda package/webda-operationsUse when exposing behaviour to clients as an operation, or enabling REST, GraphQL, gRPC or MCP in a Webda app/webda-servicesUse when adding or changing a Webda service, its parameters, its lifecycle or when wiring it in webda.config.json/webda-storesUse when reading or writing model data, querying models, or choosing or switching the store (memory, file, MongoDB, PostgreSQL) of a Webda app/webda-testingUse when writing, running or fixing tests of a Webda app, its models, services or operationsnpx claudepluginhub loopingz/webda.io --plugin webdaOther plugins' skills for the same job