Pages and components

Your users should see your product, not a generic admin panel. Every screen of a code-first app is your own React: a file per page in routes/, components in components/, your CSS, any npm package. Pages read and write through @appbricx/ui as the signed-in user, so your access policies decide what each person sees, and public pages are rendered on the server for search engines and fast first loads.

The files

PathIs
routes/index.tsx/
routes/my-classes.tsx/my-classes
routes/experiences/[id].tsx/experiences/:id
routes/_layout.tsxWraps every page below it: header, navigation, footer
routes/signin.tsxReplaces the built-in sign-in screen (optional)
components/*.tsx, lib/*.tsYour components and helpers; import CSS from them freely
styles/*.cssApp-wide CSS, after Tailwind
icons/*.svgYour icons, as <Icon name="app:<file>" />

A page

// routes/experiences/[id].tsx
import { defineRoute, useRow } from "@appbricx/ui";

export const meta = defineRoute({
  public: true,                                   // signed-out visitors; server-rendered; in the sitemap
  row: { table: "experience" },                   // the row is found by the route's last param (by: "id")
  seo: { title: "{{title}} · Teamday", description: "{{title}} in {{city}}", sitemap: { where: { status: "published" } } },
});

export default function Experience() {
  const { row, notFound } = useRow("experience"); // the route's row, typed from db/schema
  if (notFound) return <main className="p-6">No such experience.</main>;
  if (!row) return <main className="p-6">Loading…</main>;
  return (
    <main className="mx-auto max-w-3xl p-6">
      <h1 className="text-3xl font-bold">{row.title}</h1>
      <p>{row.city}</p>
    </main>
  );
}
metaEffect
public: trueAnyone may open it, signed out included; rendered on the server with what a visitor may read; listed in the sitemap
roles: ["member"]Only those roles (default: any signed-in role). A visitor gets the sign-in form; another role gets "Not for this account"
titleThe page's title
row: { table, by?, params? }The row the page is about: by: "slug" binds a slug instead of the id; params binds the other route parameters for the sitemap. A row a visitor can't read is a 404
seotitle, description, image, jsonld as templates over the row, noindex, and sitemap.where

Reading, writing and navigating

const { rows, loading, error } = useQuery("booking", { sort: "-created_at", embed: "class_session(title)" });
const bookings = useTable("booking");            // create, update, remove; the table's reads refresh after each
const auth = useAuth();                           // status, user (id, email, name, role), signIn, signUp, signOut
const navigate = useNavigate();                   // navigate("/my-classes")
<Link to="/desk">Desk</Link>   <NavLink to="/desk">Desk</NavLink>   // NavLink hides itself from roles that can't open it
const r = await confirmBooking({ booking: id });  // an action from server/, called like a function

useParams, useSearchParams, useCanOpen(path), useConfig() (the app's public config values) and useLive(table) are the rest; every hook is in the SDK reference. The browser can't call other hosts: put that in an action.

Components and packages

Plain React components work as they are. defineComponent adds typed, defaulted props and an entry in the console's component catalog, and client: true for libraries that need the browser:

// components/WeekChart.tsx (after: packages { "action": "add", "packages": ["recharts"] })
import { Bar, BarChart, ResponsiveContainer, XAxis } from "recharts";
import { defineComponent, p } from "@appbricx/ui";

export const WeekChart = defineComponent({
  name: "WeekChart",
  props: { days: p.json<{ day: string; booked: number }[]>().default([]) },
  client: true,                                   // the server and the first paint render the skeleton
  skeleton: <div className="h-56 rounded border" aria-busy="true" />,
  render: ({ days }) => (
    <div className="h-56">
      <ResponsiveContainer width="100%" height="100%">
        <BarChart data={days}><XAxis dataKey="day" /><Bar dataKey="booked" fill="#2F7D6D" /></BarChart>
      </ResponsiveContainer>
    </div>
  ),
});
  • Packages: packages { "action": "add", "packages": ["recharts"] } (or appbricx add recharts) writes package.json and package-lock.json. Versions are at least 7 days old, each is checked against known vulnerabilities, and React is always the platform's.
  • Code that touches the browser as soon as it loads: lazyComponent(() => import("../components/Map"), { skeleton }) loads it after the first paint, in its own chunk.
  • Icons: <Icon name="lucide:calendar-check" /> takes any Iconify icon or one of your icons/*.svg. Names must be written out (the build collects them into one sprite).
  • Images, logos and fonts: assets { "action": "upload", "name": "hero.webp", "base64": "…" } serves a file at /assets/hero.webp. Fonts also come from npm (@fontsource/inter, imported from styles/).

There are no ready-made table or form components in @appbricx/ui yet: a list is a useQuery and a map, a form is a few inputs and useTable.

Layouts and full-screen pages

routes/_layout.tsx receives the page as children and draws whatever goes around it. There is no platform header: the whole screen is yours. A folder can have its own _layout.tsx for the pages in it (a desk with its own side navigation).

// routes/_layout.tsx
import type { ReactNode } from "react";
import { Link, NavLink, useAuth } from "@appbricx/ui";

export default function Layout({ children }: { children: ReactNode }) {
  const auth = useAuth();
  return (
    <div className="min-h-screen">
      <header className="flex items-center gap-4 border-b px-6 py-4">
        <Link to="/" className="font-semibold">Stillwater</Link>
        <NavLink to="/my-classes">My classes</NavLink>
        {auth.user ? <button type="button" className="ml-auto" onClick={() => void auth.signOut()}>Sign out</button>
                   : <Link to="/signin" className="ml-auto">Sign in</Link>}
      </header>
      {children}
    </div>
  );
}

Brand and styles

Tailwind v4 is on (turn it off with ui: { tailwind: false } in app.config.ts); arbitrary values work (bg-[#2F7D6D]). Your styles/*.css and any CSS a component imports come after Tailwind. brand in app.config.ts (name, tagline, color, icon, ogImage) names the app wherever the platform draws for you, such as its email layout.

Your own sign-in screen

Write routes/signin.tsx and it replaces the built-in one; add routes/signup.tsx for sign-up. The hooks and a full example are in sign-in.

Check it

code { "project_id": "…", "action": "create", "kind": "route", "name": "/desk" }   // starts from the scaffold
code { "project_id": "…", "action": "edit", "kind": "route", "name": "/desk",
       "edits": [{ "old": "…", "new": "…" }], "then": "check" }   // strict TypeScript and lint, at path:line
screenshot { "project_id": "…", "route": "/desk", "as": "instructor" }
screenshot { "project_id": "…", "route": "/", "as": "member",
             "steps": [{ "click": "Book a mat" }, { "wait": "Booked" }] }
call_app { "project_id": "…", "kind": "page", "path": "/" }   // the server-rendered HTML a visitor gets, with error_hint

Verify's browser stage then opens every page each role can reach.

Gotchas

  • Render the same on the server and in the browser. toLocaleString() with the visitor's locale, Date.now() or Math.random() in render breaks hydration (React error #418, a verify failure). Format dates with an explicit time zone and compute browser-only values after mount.
  • The lint refuses writes to location (use useNavigate or Link), eval, and fetch to other hosts; it warns on dangerouslySetInnerHTML.
  • Embedded rows aren't in the row types. Cast where you read them: q.rows as (typeof q.rows[number] & { class_session: { title: string } | null })[].
  • Bundles have budgets: 120 KB gzip at boot and 100 KB per page are warnings. Keep big libraries in one page or a lazyComponent.
  • A page that needs a role isn't server-rendered for visitors: they get the sign-in form.

Related