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

An app's layout

charter finds everything by where it is. There is nothing to configure for any of this.

pages/         the page tree and its components
pages/screens/ charter's screens: the docs' pages, the languages, the theme switch
api/           contract.go: the API
db/            schema.sql, queries.sql; the migrations charter writes from them
env/           what the Worker is bound to, as Go: written by charter from wrangler.jsonc, never by hand
seed.go        what a new database starts with, and what the tests know is there
fnox.toml      the deployed Worker's secrets: their names and who keeps them, never a value
docs/          the app's docs, as Markdown
locales/       <language>.toml: the languages are the files here
web/  public/  what the browser loads
ui/            gsxui's components
test/          tests of the pages and of the API
sdk/go/        the app's own Go client
wrangler.jsonc the Worker and its bindings, without ids
charter.toml   only url, and what Fern should generate
main.go

What the Worker is bound to

A binding is declared once, in wrangler.jsonc. charter writes each as a Go value in the app's env package, under the name it has there, with the type of its kind:

Declared in wrangler.jsonc asIn GoWhat you do with it
d1_databases: DBenv.DBenv.DB.Open(): the database, for the queries
kv_namespaces: KVenv.KVenv.KV.Open(): workers-go's *kv.Namespace
r2_buckets: BUCKETenv.BUCKETenv.BUCKET.Open(): workers-go's *r2.Bucket
queues.producers: QUEUEenv.QUEUEenv.QUEUE.Open(): workers-go's *queues.Producer
durable_objects.bindings: HUBenv.HUBlive.Feed[Note]{Binding: env.HUB, …}
ratelimits: WRITE_LIMITenv.WRITE_LIMITenv.WRITE_LIMIT.Allow(key); api.Limit{Binding: env.WRITE_LIMIT}. It carries the calls and the seconds wrangler.jsonc says, so they are said once
send_email: MAILenv.MAILenv.MAIL.Send(from, to, raw)
vars: APP_NAMEenv.APP_NAMEenv.APP_NAME.Value()
a secret named in .dev.vars.example or fnox.tomlenv.ADMIN_TOKENenv.ADMIN_TOKEN.Value(); api.Token{Secret: env.ADMIN_TOKEN}

Why it is this way: a name written as text (kv.NewNamespace("KV")) compiles whatever it says, and fails on a Worker when nothing is bound there or something of another kind is. A value cannot be wrong like that:

  • What is not declared does not exist. Take a bucket out of wrangler.jsonc and every line that used env.BUCKET stops compiling.
  • A kind is a type. api.D1Accounts(env.KV) does not compile: it takes a database.
  • No value can be written by hand. api.D1Accounts("DB") does not compile either.

The file is env/env.built.go. dev writes it again when wrangler.jsonc, .dev.vars.example or fnox.toml is saved, and build, check and test write it too; it is not committed. charter check fails an app that names a binding the old way, with the file and the line.

A binding's name must be one Go can have, starting with a capital letter (DB, WRITE_LIMIT), since it is its name in Go too. What workers-go gives that has no name of the Worker's (the Cache API, fetch, Cron Triggers) is used as workers-go's docs say.

What this does not tell you: whether the deployed Worker has the thing. charter deploy makes what wrangler.jsonc names; charter run resources and charter run secrets say what is there.

main.go

example/main.go
func main() {
	// What the Worker does that is no request: a queue's consumer, a Cron Trigger's task, email (package built).
	built.Background()
	(&app.App{
		Name:  "charter-example",
		Dist:  dist,
		Pages: pages.Mount,
		// The app's own docs (docs/*.md), shown by charter's docs pages, which the tree mounts at /docs.
		Docs: &app.Docs{
			Name:    "charter-example",
			Summary: "charter's example: notes that are live on every open page, an API from a contract, and a card for everything Cloudflare gives a Worker.",
			Pages:   docs.Pages,
			Repo:    "https://github.com/joeblew999/charter",
			Dir:     "example",
			Agents:  "A coding agent working on this app uses the Claude Code plugins of the marketplace joeblew999/charter: charter, gsx, gsxui and structpages. The app's .claude/settings.json enables them.",
		},
		// Who may do what, for the pages as for the API (api.Auth): a page or a group says what it needs with a Needs
		// method, and whoever is not signed in is sent to the sign-in screen.
		Auth:   api.Auth,
		SignIn: screens.SignInPage{},
		// The app's own lines on the admin screen's overview: asked when that page is.
		Facts: []app.Fact{
			{Label: locales.FactsNotes, Value: func(ctx context.Context) (any, error) {
				report, err := api.Report(ctx)
				return report.Notes, err
			}},
			{Label: locales.FactsWriters, Value: func(ctx context.Context) (any, error) {
				report, err := api.Report(ctx)
				return report.Authors, err
			}},
		},
		Args: []any{api.Auth},
		// What a page asks for by type, made from the request: the notes' store (D1), and who is asking.
		RequestArgs: []any{api.OpenStore, api.Auth.Caller},
		API:         api.Handler(api.Env{Var: charter.Var}),
	}).Run()
}

That one value is the pages, the API, the docs, Vite's files, a URL per language, robots.txt, the sitemap and /llms.txt.

What is generated

Two kinds, told apart by name.

KindFilesIn git
Built from your sources each time*.x.go, *.built.go, .charter/, build/, dist/no
Read from the repository by something*.gen.go, db/migrations/, fern/, sdk/go/yes, and check holds each to its source

dev, build and check write the first kind, so a fresh clone needs only go tool charter check. check --fix writes the second.

What is never in git

.dev.vars, the local secrets wrangler dev reads. charter makes it from .dev.vars.example.