Getting started
Install#
pnpm add asasvirtuais zod
asasvirtuais needs React 19 and Zod 4. It is designed for Next.js with the App Router, and works in any React app.
Give your coding agent the rules#
asasvirtuais ships with a guide for coding agents. Start your project's AGENTS.md (or CLAUDE.md) from it:
cp node_modules/asasvirtuais/AGENTS.example.md AGENTS.md
It explains the project structure, the build stages, the interface file, server actions, middleware, error handling and the rules, and these docs follow it section by section. See Coding agents for skills, the docs MCP server and the Claude Code plugin.
Project structure#
app/
├── schema.ts # all table schemas
├── actions.ts # 'use server': the interface
├── db.ts # the raw database interface (Prisma, Postgres, Firestore...)
├── providers.tsx # InterfaceProvider
└── [route]/
├── page.tsx # fetches its rows and provides them to its tables
└── components/ # this page's components, one directory each
packages/
└── [model]/
├── schema.ts # readable / writable
├── fields.tsx # inputs hooked to useFields()
├── forms.tsx # Create{Model}, Update{Model}, Filter{Model}s
├── components.tsx # {Model}Item, Single{Model}
├── providers.tsx # {Model}sProvider (the table), {Model}Provider (one row)
├── hooks.tsx # use{Model}s(), use{Model}()
└── middleware.ts # the table's authorization, written last
lib/ # small shared files, only once code repeats
1. Describe a table#
Each table has a readable schema (what the database returns) and a writable schema (what a user may send).
// packages/todos/schema.ts
import z from 'zod'
export const readable = z.object({ id: z.string(), title: z.string(), done: z.boolean(), author: z.string() })
export const writable = readable.pick({ title: true, done: true })
export const schema = { readable, writable }
// app/schema.ts
import { schema as todos } from '@/packages/todos/schema'
export const schema = { todos }
2. Expose the interface#
Five server actions make up the interface, the whole backend. They pass straight to your database until the table middleware is written.
// app/actions.ts
'use server'
import { db } from './db'
export const { find, list, create, update, remove } = db
3. Mount the providers#
// app/providers.tsx
'use client'
import { InterfaceProvider } from 'asasvirtuais/context'
import * as actions from './actions'
export default function AppProviders({ children }: { children: React.ReactNode }) {
return <InterfaceProvider {...actions}>{children}</InterfaceProvider>
}
4. Fetch on the server, render forms on the client#
// app/todos/page.tsx
import { TableProvider } from 'asasvirtuais/registry'
import { list } from '@/app/actions'
import { schema } from '@/packages/todos/schema'
import { Todos } from './todos'
export default async function TodosPage() {
const todos = await list({ table: 'todos', query: {} })
return (
<TableProvider table='todos' schema={schema} asAbove={Object.fromEntries(todos.map(t => [t.id, t]))}>
<Todos />
</TableProvider>
)
}
// app/todos/todos.tsx
'use client'
import { CreateForm } from 'asasvirtuais/forms'
import { useTable } from 'asasvirtuais/context'
import { schema } from '@/packages/todos/schema'
export function Todos() {
const { array } = useTable('todos', schema)
return (
<>
<CreateForm table='todos' schema={schema} defaults={{ title: '', done: false }}>
{todo => (
<form onSubmit={todo.submit}>
<input value={todo.fields.title} onChange={e => todo.setField('title', e.target.value)} />
<button disabled={todo.loading}>Add</button>
</form>
)}
</CreateForm>
<ul>{array.map(t => <li key={t.id}>{t.title}</li>)}</ul>
</>
)
}
Submit the form and the new todo appears in the list. You wrote no state, no refetch and no cache invalidation.
Prototype without a backend#
Skip the database entirely while you shape the UI:
import { dexieInterface } from 'asasvirtuais-dexie'
<InterfaceProvider {...dexieInterface(schema)}>{children}</InterfaceProvider>
Everything runs on IndexedDB in the browser. Swap in app/actions.ts when you're ready, and the UI stays the same.
See Adapters.
Commercial app? Add the credit#
If the app is commercial (sold, a paid service, earning revenue, or built for a paying client), show
"Built with asasvirtuais" linked to https://asasvirtuais.com, for example in the footer:
<a href='https://asasvirtuais.com'>Built with asasvirtuais</a>
See License and commercial use.