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.tsWhat 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)andlistOf(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 file | Call |
|---|---|
app/orders/get.ts | api.orders.list(params) |
app/orders/post.ts | api.orders.create(body) |
app/orders/[id:int]/get.ts | api.orders.detail(id) |
app/orders/[id:int]/patch.ts | api.orders.update(id, body) |
app/orders/[id:int]/delete.ts | api.orders.remove(id) |
app/orders/[id:int]/status/post.ts | api.orders.status(id, body) |
app/reports/sales/get.ts | api.reports.sales(params) |
app/chat-messages/get.ts | api.chatMessages.list() |
app/hooks.ts (browser)
useRequest(fn, opts): loads data, returns{ data, loading, error, run, refresh, mutate }.tableRequest(api.orders.list): therequestfor a hand-writtenProTable. Paging, sorting, filters and the search box map tolistOf’s query.optionsFrom(api.users.members, "name"): options for a select.submit(fn, { done, reload, form }): a form’sonFinishthat shows success, reloads the table and puts errors on the right fields.useAction(fn, { ok, reload }): every other button or form action, resolvestrueorfalse.useApi(): raw axios, for third-party APIs only.useRoutes(): the route list.useLive(channel, onMessage): receivesbroadcast()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
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.tsfile, the API in a handler file. app/db.tsdoesn’t export tables. Import a table from its.table.tsfile.- Calling a client name that doesn’t exist makes
checkrefuse and list the real names. - Two handlers mapping to the same name: the later one gets a
2suffix. Give each its own sub-path. - With
app/auth.ts, manh.run also generatesapp/users/users.table.ts,app/shared/auth-roles.tsand the/api/auth/*,/api/usersAPIs. See auth.ts.
Next steps
- Data fetching — use
useApiClient()and these hooks in a page. <resource>.table.ts— declare the tablesapp/dbreads.- auth.ts — turn on sign-in to get the users table and sign-in API.