Build a web app
You will create a React web app with Putnami, explore its structure, and add a new page with server-side data loading.
Steps
1) Create the app
Start in an empty directory after installing Putnami:
putnami init webappThis scaffolds a full React SSR application from the typescript-web template, with file-based routing, a plain-HTML layout and home page, and example pages built with @putnami/ui. For an app with a table, putnami init webapp --template web-database starts from typescript-web-database instead: one Postgres table, the page that lists and adds its rows, and its test, without the examples.
2) Run it
putnami serve webappputnami serve prints the app's URL, http://webapp.localhost:3000/ when port 3000 is free at your first run. Open it. You see the welcome page. The example pages answer at /about and /guestbook.
3) Explore the project structure
The scaffolded project lives in webapp/:
webapp/
├── src/
│ ├── main.ts # Application entrypoint
│ ├── serve.ts # Server bootstrap
│ ├── app/
│ │ ├── layout.tsx # Root layout, plain HTML
│ │ ├── page.tsx # Home page
│ │ ├── error.tsx # Error boundary
│ │ ├── not-found.tsx # 404 page
│ │ └── (examples)/ # Example pages, the only users of @putnami/ui
│ │ ├── examples-shell.tsx # Their shell (nav, theme toggle)
│ │ ├── counter.tsx # Client-side interactive component
│ │ ├── about/page.tsx # About page, at /about
│ │ └── guestbook/ # Guestbook, at /guestbook
│ │ ├── page.tsx # Guestbook page
│ │ ├── loader.ts # Server-side data loader
│ │ └── action.ts # Form action handler
└── test/
├── app.test.ts
└── examples.test.tsThe parentheses make (examples) a route group: it groups files without
adding a URL segment. The project's README gives the one step that removes the
examples, their test and @putnami/ui together, for an app built on plain HTML
or another component kit.
4) Add a new page
Create webapp/src/app/hello/page.tsx:
import { page } from '@putnami/web';
export default page().render(function HelloPage() {
return (
<>
<h1>Hello</h1>
<p>This is a new page.</p>
</>
);
});Navigate to /hello on the same URL. File-based routing picks it up automatically.
5) Load data from the server
Create webapp/src/app/hello/loader.ts:
import { loader } from '@putnami/web';
export default loader(async () => {
return { message: 'Hello from the server', timestamp: new Date().toISOString() };
});Update webapp/src/app/hello/page.tsx to use the loaded data:
import { page, useLoaderData } from '@putnami/web';
export default page().render(function HelloPage() {
const { message, timestamp } = useLoaderData<{ message: string; timestamp: string }>();
return (
<>
<h1>{message}</h1>
<p>Loaded at {timestamp}</p>
</>
);
});The loader runs on the server before rendering. The data is typed and available via useLoaderData.
6) Choose a render mode
Routes are SSR by default. Declare other modes explicitly per route — the mode is never inferred:
// Static (SSG): pre-rendered at build, ships zero client JS
export default page().static().render(HelloPage);
// Incremental Static Regeneration: revalidate every 60s
export default page().static({ revalidate: 60 }).render(HelloPage);Add interactivity to a static page with an island — a component in a
*.island.tsx file that hydrates on its own:
// src/app/hello/Counter.island.tsx
import { island } from '@putnami/web';
export default island().load('visible').render(Counter);Each build writes a diffable .gen/putnami-web-manifest.json (route · mode ·
hydration · client-JS budget). A .static() route that reads request data fails
the build — static means static. See the framework's
doc/rendering-modes.md for the full guide.
The build also commits schema/http-routes.json, with a build copy under
.gen/schema/. Its file-route entries with GET and HEAD identify pages;
a POST entry at the same path identifies the page's action. Count distinct
evidencePath values when counting page files, because static expansion can
produce several URLs from one file. Commit the generated inventory with your
route changes: the build reports drift when the committed contract changes.
Result
You have a React SSR app with layout, file-based routing, and server-side data loading. The template gave you a working starting point — you extended it with a new page and a loader.
Next steps
- Check the existing
(examples)/guestbook/page for an example of form actions withaction.ts - See
(examples)/counter.tsxfor a client-side interactive component - Add persistence for database-backed data
- Add authentication to protect routes
Companion sample:
typescript/samples/03-web— a runnable project covering pages, layouts, loaders, actions, and forms. Runputnami serve @example/webfrom the workspace root.