Project Structure
Where the bootstrap, routes, and layouts live.
Updated: 2026-07-26
Typical structure
A Karui app keeps a thin bootstrap file and puts everything else in file-based pages.
text
src/
app.tsx site bootstrap
layout.tsx global shell
pages/
index.tsx -> /
about.tsx -> /about
404.tsx not-found entity
error.tsx error entity
docs/
layout.tsx nested layout for /docs/*
[slug].tsx -> /docs/:slug
server.ts node entry
index.html template with <!--app-*--> slotsThe bootstrap file
defineSite collects your pages, wires the layout as the shell, and hydrates itself in the browser. It is the only client entry point an app needs.
src/app.tsx
import { defineSite, type FileSystemModule, type RenderState } from '@rigbyhost/karui/ssr';
import Layout from './layout.js';
const pages = import.meta.glob('./pages/**/*.tsx', { eager: true }) as Record<string, FileSystemModule<RenderState>>;
export const site = defineSite({
pages,
layout: Layout,
titlePrefix: 'My App',
pagesRoot: './pages',
hydrateMode: 'full',
});Site state
Every render starts from a RenderState of url, runtime, and generatedAt. Pass createState to carry your own data, such as a session, alongside it.
tsx
import { createRenderState, type RenderState } from '@rigbyhost/karui';
interface AppState extends RenderState {
user: string | null;
}
defineSite<AppState>({
pages,
layout: Layout,
createState: (url, runtime) => ({
...createRenderState(url, runtime),
user: null,
}),
});