Skip to content
@pyreon/feature
fundamentals · CRUD

You have built this CRUD screen before. Declare it this time.

Give defineFeature a name, a Zod schema and a REST path. You get the list, detail and search queries, create, update and delete mutations that refresh the list, a validated form that saves itself, a table with columns from the schema, and a store, all wired to Pyreon's query, form, table and store packages.

bun add @pyreon/feature
Documentation
you write
name · schema · apidefineFeature({ name: 'posts', schema, api: '/api/posts' }).
you get
9 hooks, 2 componentsuseList … useStore, plus <Posts.Field> and <Posts.Table>.
REST shape
GET · POST · PUT /:id · DELETE /:idEvery mutation refreshes the list.
schemas
Zod, or any Standard SchemaValibot, ArkType, @pyreon/validate validate; fields and columns are read from Zod.
One schema becomes the list, form, table and store Schematic: defineFeature with the name posts, a three-field schema and the path /api/posts fans out to generated members: useList, useForm, useTable and useStore. Submitting the form sends POST /api/posts and the list refetches with the new row; deleting it sends DELETE /api/posts/:id and the list refetches again. DEFINEFEATURE · NAME · SCHEMA · API defineFeature({ name: 'posts', api: '/api/posts', schema: z.object({ title, body, published }), }) useForm()POST /api/postsuseList()GET /api/postsuseTable()columns from schemauseStore()shared, signal-backed posts Hello world Release notes Signals 101 POST /api/posts→ list refetches DELETE …/posts/:id→ list refetches 9 hooks and 2 components · Zod or any Standard Schema
  • 1 declaration for list, detail, search, create, update, delete, form, table and storepackages/fundamentals/feature/src/types.ts, Feature interface
  • 3 requests for a create, and the list on screen is current: GET, POST, GET.scratch/app/feat.ts, mock fetcher log

synthetic · author-run · M3 Max · record of 2026-11-05

Every result, including where we lose →
why teams pick it

The resource boilerplate, generated from the schema you already wrote.

  1. One declaration, the whole resource

    Posts.useList(), useById(id), useSearch(term), useCreate(), useUpdate(), useDelete(), useForm(), useTable(), useStore(), typed from z.infer of your schema.

  2. The list never goes stale

    Create, update and delete invalidate the ['posts'] query on success. Add a post and every useList() on screen refetches: GET, POST, GET.

  3. A form that knows where to send itself

    Posts.useForm() starts from the schema's defaults, validates with it, and POSTs on submit. useForm({ mode: 'edit', id }) loads the record first and PUTs instead.

  4. Generated, not hidden

    Each hook is the real @pyreon/query, @pyreon/form, @pyreon/table or @pyreon/store object. Take one generated piece and hand-write the next; <Posts.Field> renders one field, so your layout stays yours.

the difference

The same screen, before and after.

React + TanStack Query + react-hook-form + Zod

Query keys, fetchers, invalidation and a resolver, per resource. Then update and delete, the same again.

const PostSchema = z.object({
  title: z.string().min(1), body: z.string(), published: z.boolean(),
})

export const usePosts = () =>
  useQuery({ queryKey: ['posts'], queryFn: () => fetch('/api/posts').then(json) })

export function useCreatePost() {
  const qc = useQueryClient()
  return useMutation({
    mutationFn: (data: z.infer<typeof PostSchema>) =>
      fetch('/api/posts', { method: 'POST', body: JSON.stringify(data) }).then(json),
    onSuccess: () => qc.invalidateQueries({ queryKey: ['posts'] }),
  })
}
// …usePost, useUpdatePost, useDeletePost

function NewPost() {
  const create = useCreatePost()
  const { register, handleSubmit, formState: { errors } } = useForm({
    resolver: zodResolver(PostSchema),
    defaultValues: { title: '', body: '', published: false },
  })
  return (
    <form onSubmit={handleSubmit((v) => create.mutate(v))}>
      <input {...register('title')} />
      {errors.title && <p>{errors.title.message}</p>}
      <textarea {...register('body')} />
      <input type="checkbox" {...register('published')} />
      <button disabled={create.isPending}>Create</button>
    </form>
  )
}
with @pyreon/feature

One declaration. The form validates, posts and refreshes the list on its own.

import { defineFeature } from '@pyreon/feature'
import { z } from 'zod'

export const Posts = defineFeature({
  name: 'posts',
  api: '/api/posts',
  schema: z.object({
    title: z.string().min(1), body: z.string(), published: z.boolean(),
  }),
})

const NewPost = () => {
  const form = Posts.useForm()   // POST /api/posts, then the list refetches
  return (
    <form onSubmit={form.handleSubmit}>
      <Posts.Field form={form} name="title" />
      <Posts.Field form={form} name="body" />
      <Posts.Field form={form} name="published" />
      <button disabled={() => form.isSubmitting()}>Create</button>
    </form>
  )
}
try it

What one declaration gives you.

Click a generated member to see what it does. The table on the right uses useList, useCreate and useDelete: add a row and the list refetches.

posts = defineFeature(…)

posts.useCreate · Create mutation (POST /api/posts); invalidates the list on success.

  • GET /api/posts0
  • POST /api/posts0
  • DELETE /api/posts/:id0

useList(): loading…
titlepublished

Try an empty title, or one that exists: the schema and the server answer.

what's included

What one defineFeature returns.

  • useList({ page, pageSize, params }) A @pyreon/query list query; page can be a signal.
  • useById(id) One record from GET /api/posts/:id.
  • useSearch(term) Pass a signal; it refetches with ?q= when the term changes and waits while it is empty.
  • useCreate / useUpdate / useDelete Mutations that invalidate the feature's queries on success.
  • useForm({ mode, id }) A @pyreon/form state with schema validation; create posts, edit loads the record and puts.
  • useTable(data, { columns }) A TanStack Table v9 instance from @pyreon/table, columns from the schema.
  • useStore() A @pyreon/store with cached items, selection and loading.
  • <Posts.Field> / <Posts.Table> Label, typed control and error for one field; a sortable table with per-column cell overrides.
  • reference(Users) Mark a foreign key to another feature.
  • fields, extractFields, defaultInitialValues The schema introspection, for building your own UI.
recipes

Things to build with it.

An admin list with search and delete

The generated table, a search box bound to useSearch, and a delete button that refreshes the list when it succeeds.

const PostsAdmin = () => {
  const term = signal('')
  const all = Posts.useList()
  const found = Posts.useSearch(term)
  const remove = Posts.useDelete()
  const rows = () => (term() ? found.data() : all.data()) ?? []
  const view = Posts.useTable(rows, { columns: ['title', 'published'] })
  return (
    <>
      <input placeholder="Search" onInput={(e) => term.set(e.currentTarget.value)} />
      <Posts.Table
        of={view}
        cell={{
          title: (ctx) => (
            <>
              {ctx.row.title}
              <button onClick={() => remove.mutate((ctx.row as typeof ctx.row & { id: number }).id)}>Delete</button>
            </>
          ),
        }}
        empty="No posts yet"
      />
    </>
  )
}
An edit page

Edit mode loads the record, refuses to submit until it has arrived (so blank defaults never overwrite it), and sends PUT /api/posts/:id on save.

const EditPost = (props: { id: number }) => {
  const form = Posts.useForm({
    mode: 'edit',
    id: props.id,
    onSuccess: () => toast.success('Saved'),
  })
  return (
    <Show when={() => !form.isLoading()} fallback={<p>Loading…</p>}>
      <form onSubmit={form.handleSubmit}>
        <Posts.Field form={form} name="title" />
        <Posts.Field form={form} name="body" />
        <button disabled={() => form.isSubmitting()}>Save</button>
      </form>
    </Show>
  )
}
api

A small surface that generates a large one.

Every export has a reference page with its signature, an example and the mistakes people make with it.

define · 3
  • defineFeature
  • reference
  • isReference
generated hooks · 10
  • useList
  • useById
  • useSearch
  • useCreate
  • useUpdate
  • useDelete
  • useForm
  • useTable
  • useStore
  • queryKey
generated components · 2
  • Field
  • Table
introspection and building blocks · 5
  • extractFields
  • defaultInitialValues
  • createFieldComponent
  • createTableComponent
  • featureTableFeatures
types · 11
  • Feature
  • FeatureConfig
  • FeatureFormOptions
  • FeatureFormState
  • FeatureStore
  • FeatureTableOptions
  • FeatureTableResult
  • InferSchemaValues
  • ListOptions
  • FieldInfo
  • FieldType
good to know

Good to know before you start.

Conventional REST under one path

The routes are derived from api: GET /, GET /:id, POST /, PUT /:id, DELETE /:id. Other shapes need a custom fetcher, or the underlying @pyreon/query hooks directly.

Fields and columns come from Zod

Valibot, ArkType and @pyreon/validate schemas validate, but auto form fields, columns and create defaults are read from Zod only. With another schema, pass initialValues and columns; a one-time dev warning says so.

Needs a QueryClientProvider

The generated queries and mutations are @pyreon/query hooks, so mount a QueryClient above them.

On native, the declaration crosses

With a literal field map, iOS and Android get a Codable struct and initialValues. An inline z.object of scalars, with on-device safeParse, follows in the next release. The generated hooks stay web. Native targets are experimental.

questions

What people ask first.

Is this a code generator?

No files are written. defineFeature runs at import time and returns an object whose members are the real query, form, table and store hooks, typed from your schema.

Can I customise one piece?

Yes. Use Posts.useForm() with your own markup, replace one <Posts.Field> with a hand-written input, or skip the generated table and call @pyreon/table with the data from Posts.useList(). Nothing is all-or-nothing.

What about auth headers or a different backend?

Pass fetcher, any function with the fetch signature, to add headers, a base URL or a different transport.

Does it work with Valibot or ArkType?

For validation, yes, through the Standard Schema bridge in @pyreon/validation. For auto fields and columns, use Zod or pass them yourself.

Fifty lines per resource, times every resource. Or one call each.

bun add @pyreon/feature
Read the feature guide