Skip to Content

Generated files

app/db.ts, app/api.ts and app/hooks.ts are regenerated by manh.run on every build. You import them but never write or edit them.

app/ ├── db.ts # [generated] server ├── api.ts # [generated] browser ├── hooks.ts # [generated] browser └── orders/ ├── orders.table.ts # source of db.ts └── get.ts post.ts # source of api.ts

What it does

These files are not stored in the project. manh.run builds them from your code: app/db.ts from the .table.ts files, app/api.ts from the handler files. An agent can read them with read_files to get exact names instead of guessing.

app/db.ts (server)

  • db: the app’s database client.
  • schemaOf(table): zod { insert, update } built from the table’s columns.
  • listSchema(opts) and listOf(table, query, opts): paged lists returning { data, total }.
  • insertMany(table, rows): inserts many rows at once. scopeBy(user, { role: where }): row filtering by role.
  • Table builders: sqliteTable, integer, text, real, blob, index, uniqueIndex, primaryKey, foreignKey, unique.
  • Operators: eq, ne, lt, lte, gt, gte, like, ilike, notLike, notIlike, and, or, not, isNull, isNotNull, inArray, notInArray, between, notBetween, exists, notExists, asc, desc, sql, count, countDistinct, sum, sumDistinct, avg, avgDistinct, min, max, alias.

Importing any other name from app/db is a check error, because the build would fail. Write anything not on the list with sql.

app/api.ts (browser)

useApiClient() returns a typed client with one function per handler. Each returns exactly what the handler returned; no .data.

Handler fileCall
app/orders/get.tsapi.orders.list(params)
app/orders/post.tsapi.orders.create(body)
app/orders/[id:int]/get.tsapi.orders.detail(id)
app/orders/[id:int]/patch.tsapi.orders.update(id, body)
app/orders/[id:int]/delete.tsapi.orders.remove(id)
app/orders/[id:int]/status/post.tsapi.orders.status(id, body)
app/reports/sales/get.tsapi.reports.sales(params)
app/chat-messages/get.tsapi.chatMessages.list()

app/hooks.ts (browser)

  • useRequest(fn, opts): loads data, returns { data, loading, error, run, refresh, mutate }.
  • tableRequest(api.orders.list): the request for a hand-written ProTable. Paging, sorting, filters and the search box map to listOf’s query.
  • optionsFrom(api.users.members, "name"): options for a select. submit(fn, { done, reload, form }): a form’s onFinish that shows success, reloads the table and puts errors on the right fields.
  • useAction(fn, { ok, reload }): every other button or form action, resolves true or false.
  • useApi(): raw axios, for third-party APIs only. useRoutes(): the route list.
  • useLive(channel, onMessage): receives broadcast() messages from the server to refresh a screen at once.
  • Session: signIn, signOut, useSession, getUser, signInWith("google"); low level: setAuthToken, getAuthToken.

manh/shell (browser)

Not a file in the project, but always there like the files above: AppShell (the app frame: menu by role, sign-out, Vietnamese locale, theme), ResourceList and ResourceDetail (list and detail pages built from the columns file), RecordPage, FlowActions, StatRow, ActivityLog, useStatusTabs, errorText.

Example

app/orders/page.tsx
import { useApiClient } from "app/api"; import { ResourceList } from "manh/shell"; import { OrderStatus } from "app/shared/order"; import { orderColumns } from "./orders-columns"; export default function OrdersPage() { const api = useApiClient(); // status tabs with counts, search, paging, create form, link to /orders/:id return <ResourceList api={api.orders} title="Orders" path="/orders" columns={orderColumns} status="status" statusEnum={OrderStatus} />; }

Good to know

  • Hand edits are lost on the next build. Change the schema in a .table.ts file, the API in a handler file.
  • app/db.ts doesn’t export tables. Import a table from its .table.ts file.
  • Calling a client name that doesn’t exist makes check refuse and list the real names.
  • Two handlers mapping to the same name: the later one gets a 2 suffix. Give each its own sub-path.
  • With app/auth.ts, manh.run also generates app/users/users.table.ts, app/shared/auth-roles.ts and the /api/auth/*, /api/users APIs. See auth.ts.

Next steps

Last updated