Sidebar

Displays the mobile sidebar.

Search the docs

Search the docs

charter
charter
What charter is
See it running
Where to go
What an app made with charter looks like
Getting started
Getting started
Working on it
Before a push
Shipping it
Tools
Every command
The commands, and what each one proves
The commands, and what each one proves
What is checked, and when you find out
What no compiler checks
create
dev
add
check
test
deploy
pack
run
The rest
An app's layout
An app's layout
What the Worker is bound to
main.go
What is generated
What is never in git
Pages
Pages
With the commands
The tree
A page declares what it needs
A region that changes by itself
The page being shown
A fragment opened as a page
What a page calls
Links
A link shows the next page with no page load
Which pages search engines get
A page that is the same for every reader
The head
The API
The API
With the commands
An operation
Who may call
Limits
SDKs
MCP
The live feed
The live feed
With the commands
Writing
Three ways out, one feed
A page's stream holds no Go
Resuming
The database
The database
With the commands
Changing it
Queries
Every statement is checked
One definition
Seeding
A deployed database
Reads near the reader
By hand
Signing in, and who may do what
Signing in, and who may do what
With the commands
One caller
Saying what is needed
Roles
The first admin, and inviting people
Signing in
Another device
An address to get back in by
Testing it
The clients
What is left to you
Languages and search engines
Languages and search engines
With the commands
Languages
Search engines
Agents
Screens and themes
Screens and themes
With the commands
The interface is gsxui's
Screens
The layout
What a page is made of
Themes
The editor, in your app
A style
While developing
Light and dark
What is checked, and what is not
Docs
Docs
With the commands
Groups, and the order
What you write, and what charter writes
Links are checked
Showing them
What comes with them
What the pages have
Code taken from a real file
Tests
Tests
A page, as plain Go
The whole app, on a real Worker
A page, in a real browser
What to test, and what not to
The API, through its own SDK
Where a test runs
A test leaves the Worker as it found it
Secrets a test needs
What else charter test does
Deploying
Deploying
Two Workers
With the commands
The plan
Nothing of your account in the repository
Credentials
Secrets
Resources
Taking an app away
Your own domain
Email
After a deploy
Environments
Everything Cloudflare gives a Worker
The admin screen
The admin screen
The pages
The app's own facts
From a program
What it does not do
Watching a deployed Worker
Watching a deployed Worker
Is it well?
Three numbers
Cloudflare's limits
Under load
A first hit
Every data centre, by country
What happened?
A failure has a reference
Memory
What charter leaves to Cloudflare
Upgrading
Upgrading
0.82
0.81
0.80
0.79
0.78
0.77
0.76
0.75
0.74
0.73
0.72
0.71
0.69
0.65
0.64
A binding, a variable, a secret's name
A scope
Screens
0.63
When upgrade stops
For your coding agent
For your coding agent
The plugins
In an app made with charter
Anywhere else
One set of commands
What an agent can ask
What a language model reads
What the Worker is bound to
What the Worker is bound to

Pages

Pages are a structpages tree, rendered with gsx and built from gsxui components. The tree is the one source of routes, links, element ids and the sitemap.

With the commands

WhenCommandWhat it does for your pages
You save a .gsx or .go filedev, runninggsx writes the template's Go, the compiler checks it, and the page in your browser is the new one in about 1.5 s
You need a componentadd ui:dialoggsxui's component, copied into ui/, where it is yours
Before a pushcheckstructpages-lint holds every link, id and target to the tree; go vet runs for your machine and for the Worker's build
Before a pushtestthe pages in a real browser on a real Worker, and every link followed

Checked before the app runs: every value a template shows and every prop it passes (a template is Go); every link, element id and swap target (each takes a page's type, never a string); what a page needs of its caller (a scope is a value); every text it shows (a message is a Go name).

Not checked until it runs: that a page's Props is handed what it asks for (structpages matches it by type when the page is asked for); an htmx attribute written by hand; anything that happens in the browser. test is what finds these.

The tree

Every route is a field, with its route in the field's tag.

example/pages/pages.go
// Pages is the tree.
type Pages struct {
	home  Home         `route:"GET /{$} Home"`
	built Built        `route:"/built Built"`
	docs  screens.Docs `route:"/docs Docs"`
	// gsxui's theme editor, in the app: a reader chooses, and the app has it from then on.
	theme screens.Theme `route:"/theme Theme"`

	// The app's own people: signing in with a passkey, and what is someone's own (charter's sign-in screen).
	signIn  screens.SignIn  `route:"/sign-in SignIn"`
	account screens.Account `route:"/account Account"`

	// What an admin sees of the system (charter's admin screen): the app at a glance, its bindings, its database.
	admin screens.Admin `route:"/admin Admin"`

	// The time zone and clock dialog's form, and where it is sent.
	preferences screens.Preferences `route:"/preferences Preferences"`

	// What the pages call: routes, not pages.
	post   PostNote   `route:"POST /notes PostNote"`
	remove RemoveNote `route:"POST /notes/{note}/remove RemoveNote"`
}

A page declares what it needs

A page is a type with a Page component, and Props for its data. Props names what it needs as parameters, and structpages hands each over by its type.

example/pages/pages.go
// Props loads what the request wants, as structpages has it. A row's button asks for that row alone (its target is
// Home's Item, with the note's id as its key): then one note is read, and structpages renders Item with it. The
// list asks for itself when its stream says the notes changed (its target is Home's List): then the newest notes
// are read, and structpages renders List with them, for this reader. Anything else is the page. Each component
// takes its share of the results by their types.
func (p Home) Props(r *http.Request, store api.Store, caller charter.Caller, target structpages.RenderTarget) (HomeProps, []api.Note, charter.Caller, api.Note, Open, Removable, Kept, error) {
	if target.Is(p.Item) {
		id, err := strconv.ParseInt(structpages.KeyOf(target), 10, 64)
		if err != nil {
			return HomeProps{}, nil, caller, api.Note{}, false, false, false, app.NotFound("no such note")
		}
		note, err := store.Get(r.Context(), id)
		if err != nil {
			return HomeProps{}, nil, caller, api.Note{}, false, false, false, app.NotFound("no such note")
		}
		return HomeProps{}, nil, caller, note, r.URL.Query().Get("open") != "", Removable(api.MayRemove(caller, note)), false, nil
	}
	notes, err := store.Before(r.Context(), math.MaxInt64, shown)
	if err != nil {
		return HomeProps{}, nil, caller, api.Note{}, false, false, false, err
	}
	if target.Is(p.List) {
		return HomeProps{}, notes, caller, api.Note{}, false, false, false, nil
	}
	props := HomeProps{Notes: notes, MayWrite: caller.May(PostNote{}.Needs()...), Caller: caller}
	// One read of KV, for every reader: what it is for.
	if props.Notice, err = built.NoticeNow(r.Context()); err != nil {
		return HomeProps{}, nil, caller, api.Note{}, false, false, false, err
	}
	return props, notes, caller, api.Note{}, false, false, false, nil
}

The store comes from main.go: RequestArgs: []any{api.OpenStore}, a function from the request to the value. No page opens a database or reads a binding itself, so a test hands a page a store of its own. The target is what the request wants: the whole page, or one part of it.

A region that changes by itself

A part of a page that htmx replaces is a component of that page. Its id and its target come from the tree, so the three places that must agree cannot drift apart.

example/pages/home.gsx
// Form is the form, a region of the page that changes by itself: PostNote answers with it, and htmx puts it in place
// of the one sent (its target is this component, by the tree), empty, or with what was typed, marked as refused.
component (p Home) Form(body string, refused bool) {
	<form
		id={Home.Form |> id}
		class="flex flex-wrap gap-2"
		hx-post={PostNote{} |> url}
		hx-target={Home.Form |> target}
		hx-swap="outerHTML"
	>
		<ui.Input
			name="body"
			class="flex-1"
			value={body}
			maxlength={strconv.Itoa(maxBody)}
			required
			autofocus
			autocomplete="off"
			dir="auto"
			placeholder={locales.HomePlaceholder}
			aria-label={locales.HomeLabel}
			{ if refused {
				aria-invalid="true"
			} }
		/>
		<ui.Button type="submit">{ locales.HomePost }</ui.Button>
	</form>
}

One of many (a row, a card) has a key: id={Home.Item |> key(id)}, and its own button targets {Home.Item |> keytarget(id)}. Props then asks whether that row is what is wanted, reads which from structpages.KeyOf, and loads that note alone, as above.

The page being shown

structpages.Within(ctx, Bindings{}) says whether the page being shown is that page or one under it: how the example's header marks its links.

A fragment opened as a page

A route with Props and no Page is a fragment: markup for part of a page, such as a dialog's form. Its address opened in a browser would be that markup alone, so charter sends such a request to the page the fragment is part of (structpages' own convention), before its Props runs. Only an htmx request for part of a page gets the fragment.

What a page calls

A type with ServeHTTP that returns an error. It answers with a component, and never writes an error or a redirect itself.

example/pages/pages.go
func (PostNote) ServeHTTP(w http.ResponseWriter, r *http.Request, store api.Store, caller charter.Caller) error {
	body := strings.TrimSpace(r.PostFormValue("body"))
	if body == "" || len(body) > maxBody || strings.Contains(body, api.END) {
		// htmx 4 swaps a 422 too: the form comes back with what was typed.
		w.Header().Set("Content-Type", "text/html; charset=utf-8")
		w.WriteHeader(http.StatusUnprocessableEntity)
		return structpages.RenderComponent(Home{}.Form(body, true))
	}
	if _, err := api.Post(r.Context(), store, caller, body); err != nil {
		return err
	}
	return structpages.RenderComponent(Home{}.Form("", false))
}
To sayReturn
It is not thereapp.NotFound("no such note")
Another statusapp.Status(http.StatusForbidden, "…")
Go somewhere elseapp.Redirect{To: url}: HX-Location for htmx, a 303 otherwise
It brokethe error: a 500, logged, with nothing of it shown

A link or a form's target comes from the tree, never from a path written as a string.

<ui.Button variant={current(ctx, Built{})} size="sm" href={BuiltIndex{} |> url}>
hx-post={PostNote{} |> url}
hx-post={RemoveNote{} |> url(map[string]any{"note": note.ID})}

Those are three lines of the example: a link to a page, a form's target, and one with a value in its address.

url is structpages' own URLFor. charter mounts the tree once for each language, each told its prefix, so every address it gives is in the reader's language by itself: a page, a form's target, a stream. structpages' linter runs inside charter check, for the machine and for the Worker's build, and fails on a link to a page that is not there, a missing parameter, or a path written as a string.

<body data-layout={string(mode)} class={bodyClass} { app.Body()... }>

app.Body() on the layout's <body> is all of it. A link to another page of the app, and a form, then keeps the document: htmx asks for the next page and puts its body in place of this one's (boost). The scripts, the stylesheet and the theme stay; everything in the body is the next page's, as if it had loaded, so nothing a reader opened on one page (a menu, a dialog) is left open over the next. The page's title comes with it, a list that follows a feed opens its stream as it arrives, and Back shows the page that was there. With htmx's preload extension (web/main.js: hx-preload.js) the request starts when the link is pressed, before the click is done.

What is asked for on a press is asked for before the reader has decided, so a GET must change nothing. One that does (a link that declines an offer, or chooses a language) is not boosted.

What stays a page load, and how each says so:

WhatHow
A page whose script runs as its document loads (the sign-in screens, the theme editor)Its type has FullLoad() bool: a link to it from anywhere is a page load, with nothing on the link
A link whose following changes something, or the document itself (another language: <html lang> changes)hx-boost="false" on the link, or hx-boost:inherited="false" on what holds several (the language list has it)
A link whose answer is no page: a download, JSON, a text fileNothing: charter sends the reader there as a page load
A link to another site, one with download, one to a place on the same pageNothing: htmx does not boost them

Which pages search engines get

The tree's GET pages without parameters are in the sitemap, in every language. The pages of the docs are too.

A page that is the same for every reader

A page that shows every reader the same thing says so on its type, and Cloudflare keeps it:

func (DocsIndex) Shared() bool { return true }

Cloudflare's cache for the Worker is asked before the Worker runs. A page it has is answered from the nearest of Cloudflare's places with no Worker started and no Go, so a reader's first hit, which otherwise waits for both, is as quick as any other. It is on in wrangler.jsonc:

  "cache": { "enabled": true },

charter decides, as each answer goes, whether it may be kept, and only all of this makes it so:

The pageIts type says Shared, and it answered 200 to a GET for a page. A part of a page is never kept
The requestBrought no cookie and no Authorization. A reader who has chosen a style or a language, or signed in, is answered by the Worker
The answerGives no cookie, and read no database

Everything else the Worker answers says private: the API, a page that is not shared, an error, a stream. That matters, since with its cache on Cloudflare keeps an answer that says nothing for two hours.

  • There is one copy of a page for every reader who brings no cookie, however they ask: a page load, a link followed in the app, a crawler, any browser in any language. Cloudflare keeps a copy for each value of the request headers an answer names (Vary), compared as written, so a shared page names only Cookie and Authorization (a reader with either is answered by the Worker), HX-Target (htmx asking for a part of the page is not given the page) and X-Forwarded-Proto (a request over http is sent to https).
  • It is not drawn from the browser's languages. In an app with several, a shared page offers another language only to a reader who has chosen one; every reader has the language list.
  • A deploy starts an empty cache, so what is kept is never of older code, and that is checked on every deploy. Every answer says the build that drew it (X-Charter-Build), a kept one too. charter deploy asks for every page of the sitemap, which fills the cache of the data centre the deploy reaches, until each is answered by the build it deployed: a new version takes some seconds to reach every data centre, and until then the one before it answers there, from its own cache. A page still of another build after a minute fails the deploy. charter test --deployed asks the same of a kept page.
  • Each of Cloudflare's data centres fills its own cache, so behind it is one copy for all of them. Where a data centre has no copy, the request reaches the Worker in front (two Workers), which answers from KV, under the build's name: the Go is not loaded. Asked on 2026-11-28 from one place, requests that missed the cache were answered from KV in 68 to 190 ms at the nearest data centre and 139 to 587 ms at the next (the first read of a page in a place is KV's slowest); before, the Go Worker drew each in 1.2 to 1.5 s. Such an answer says X-Charter-Kept: kv.
  • A copy is kept a day, and for a week after that it is still given at once while the Worker draws a new one behind it.
  • A shared page shows nothing it read for the request: no row of a database, no time in the reader's zone, nothing of who asks. The docs, the theme editor and this site's front page are shared; the example's front page reads its database and is not.
  • It gives no cookie, so the language of the last page viewed is not remembered from a shared page. A language the reader chose is.
  • A reader with a cookie is answered by the Worker, as before there was a cache. charter gives a reader none until they choose something (a style, a language, a time zone), sign in, read a page in another language than the first, or read a page that reads the database (its bookmark, for five minutes). A cookie your own script sets for every reader takes every reader out of the cache.

Not checked before the app runs: that a page which says Shared really is the same for everyone. charter test asks each of charter's own; a test of yours asks yours.

The head

<html { app.HTML(ctx)... }>
	<head>
		<app.Head title={title} description={description}/>
	</head>

app.Head writes the title and description, the canonical address, every language's alternate, Open Graph, and the scripts Vite built.

Under charter dev Vite gives the stylesheet by script, so that a change to it shows without a reload, and a script comes after the page's markup: app.Head hides the page until it is styled, as gsxui's own site does, so it is never seen bare. What is built for a deploy links its stylesheet in the head, which a browser waits for by itself.

What Vite built is kept by a browser for good. Each file has its contents in its name (assets/main-uiJkX3bL.css), so charter build writes the rule for it into the built files' _headers: Cache-Control: public, max-age=31536000, immutable for /assets/*. Cloudflare serves a Worker's static assets to be asked about on every page unless told otherwise, and then the font's answer comes after the text is shown in another one: the page is seen to change. An app's own public/_headers is kept beside the rule, and one that says what /assets/* gets is left as it is.