Getting started
Quick start: inside a React Router app
Requirements: Node 22.12 or later (React Router 8 needs 22.22), React 19, React Router 7 or 8, Postgres 14 or later.
npm i genga @genga-cms/react-router @genga-cms/reactGenga accepts React Router 7.18 and React Router 8.5 or later.
1. Define a block and a collection. The config holds the fields of a block. The site gives its component.
import type { BlockProps } from '@genga-cms/react';import { defineBlock, text, textarea } from 'genga';
export const heroBlock = defineBlock({ type: 'hero', label: 'Hero', fields: { title: text({ label: 'Title', required: true, maxLength: 120 }), text: textarea({ label: 'Text', rows: 2 }), },});
export function Hero({ title, text: body }: BlockProps<typeof heroBlock>) { return ( <section className="hero"> <h2>{title}</h2> {body && <p>{body}</p>} </section> );}import { blocks, defineConfig, slug, text, type FieldValues } from 'genga';import { heroBlock } from './blocks/hero';
const pageFields = { title: text({ label: 'Title', required: true }), slug: slug({ label: 'Slug', from: 'title', required: true }), body: blocks({ label: 'Content' }),};export type PageData = FieldValues<typeof pageFields>;
export const gengaConfig = defineConfig({ collections: { pages: { label: 'Pages', labelSingular: 'Page', titleField: 'title', path: (value) => `/${value}`, fields: pageFields, }, }, blocks: [heroBlock],});
// app/blocks/index.tsimport { defineBlockComponents } from '@genga-cms/react';export const blocks = defineBlockComponents(gengaConfig, { hero: Hero });2. Create one instance per process.
import { createGenga } from 'genga/server';import { gengaConfig } from '../genga.config';
export const genga = createGenga(gengaConfig, { databaseUrl: process.env.DATABASE_URL!, siteUrl: process.env.SITE_URL ?? 'http://localhost:5173',});3. Mount the Genga paths. One resource route calls genga.handle for the admin, its API
and the media. The admin is a prebuilt single-page app inside the genga package: the site needs
no admin route, no admin stylesheet and no change to root.tsx.
import { type RouteConfig, route } from '@react-router/dev/routes';
export default [ route('/admin/*', 'routes/genga.ts', { id: 'genga-admin' }), route('/media/*', 'routes/genga.ts', { id: 'genga-media' }), route('/:slug', 'routes/page.tsx'),] satisfies RouteConfig;import { gengaResourceRoute } from '@genga-cms/react-router';import { genga } from '../.server/genga';
const route = gengaResourceRoute(genga);// React Router removes `loader` and `action` from the browser build: do not destructure them.export const loader = route.loader;export const action = route.action;4. Render a page, with live preview.
import { Blocks, usePreviewData } from '@genga-cms/react';import { loadPage } from '@genga-cms/react-router';import { genga } from '../.server/genga';import { blocks } from '../blocks';import type { PageData } from '../genga.config';import type { Route } from './+types/page';
// The document, a 301 for a renamed slug, or a 404, with the cache headers.export const loader = ({ request, params }: Route.LoaderArgs) => loadPage<PageData>(genga, request, 'pages', params.slug);export const headers = ({ loaderHeaders, errorHeaders }: Route.HeadersArgs) => errorHeaders ?? loaderHeaders;
export default function Page({ loaderData }: Route.ComponentProps) { const { data: page } = usePreviewData(loaderData.doc, loaderData.preview); return ( <article> <h1>{page.title}</h1> <Blocks blocks={page.body} registry={blocks} preview={loaderData.preview} /> </article> );}Start the app with DATABASE_URL set. At the first start, the server logs a one-time link
/admin/setup?token=… that creates the first admin.
A site on Genga 0.3 with the admin route modules keeps working: read the migration guide to move to the admin app.
The example app has the Genga routes, MCP, the cache headers and a blog collection. Copy from it. Read configuration and blocks for the details.
Quick start: headless with Docker
curl -O https://raw.githubusercontent.com/sakuga-software/genga/main/apps/server/docker-compose.example.ymlcurl -O https://raw.githubusercontent.com/sakuga-software/genga/main/apps/server/config.example.jsonexport GENGA_SECRET="$(openssl rand -base64 48)"docker compose -f docker-compose.example.yml up- Open the one-time setup link that the server logs, and create the first admin.
- Write and publish a post at http://localhost:3000/admin.
- Read it:
curl http://localhost:3000/api/v1/collections/posts/documents.
The collections and blocks come from config.example.json (a JSON or .mjs file). The
blocks are schemas only: your site renders them. Read headless server
for the settings, the reverse proxy and the backups.