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

The commands, and what each one proves

You build a charter app by running a handful of commands while you, or your coding agent, add code. This page goes through them in the order you meet them, and says for each one what it does and what it proves about your code.

That second part is the reason for the stack. Each tool in it was picked because it lets a mistake be found by a machine before a reader finds it: gsx turns templates into Go, structpages turns routes into Go types, sqlc checks SQL against the schema, Huma writes the API's spec from Go types, Fern writes clients from that spec. charter's job is to run them at the right moment so you never have to remember to.

Not everything is checked by a compiler. Where it is not, this page says so, and says what catches the mistake instead.

What is checked, and when you find out

What you writeWritten once, inWho checks itYou find a mistake
A page or a componenta .gsx filegsx writes Go from it; the Go compiler checks every value, prop and callon save, under dev
A link, an element's id, a swap's targetthe page tree (Go structs)structpages: url, id, target take a page's type, never a string; structpages-lint checks each against the treeon save for a type that is gone; in check for the rest
A tabledb/schema.sqlcharter writes the migration from iton save, under dev
A statement on the databasedb/queries.sqlsqlc checks its columns and types against the schema; charter writes it as a Go functionon save, under dev
Who may do whata scope, declared once as a Go value (var Write = charter.NewScope("write"))the compiler: a page's Needs, an operation's Security and caller.May take the value, never a wordon save, under dev
A binding, a variable, a secret's namewrangler.jsonc (a secret's name: .dev.vars.example, fnox.toml)charter writes each as a Go value of its kind (env.DB, env.KV, env.APP_NAME); the compiler refuses one that is not declared, or of another kindon save, under dev
The APIGo types (api/contract.go)Huma writes the OpenAPI spec from the types; check compares it with the committed onein check
A client of the API, in any languagenothing: it is generatedFern writes it from the spec; it is proven by calling the Workerin test and pack --prove
Text, in every languagelocales/*.tomlcharter writes each message as a Go name, so a page that uses one that is gone does not compileon save; check for a language that is incomplete
A live feedlive.Feed[Note]the Go compiler: a feed is of one type, for pages, API and SDKon save

The same holds for what Cloudflare gives the Worker. Take a bucket out of wrangler.jsonc and every line that used it stops compiling, because env.BUCKET is gone. Hand a KV namespace to something that takes a database and it does not compile either.

So one change, a column renamed in db/schema.sql, is followed through by machines: the migration is written, every query that used the column fails, the Go that used the row no longer compiles, the API's spec changes and check says the committed one is stale, and the generated clients change with it.

What no compiler checks

These are strings or behaviour, and a wrong one compiles. Each is found by charter test, which runs the app on a real Worker, and not before.

WhatWhy it is not checkedWhat finds a mistake
That a binding is there on the deployed Worker, and a secret has a valueThe name is checked; what Cloudflare has under it is not Go's to knowdeploy makes what wrangler.jsonc names; charter run resources and charter run secrets say what the Worker has; test --deployed
That a role grants what you meant it toA scope is checked; whether a moderator should have it is your decisiontest, signed in as each role
What a page's Props asks forstructpages hands it over by its type when the page is asked fortest: the page answers with an error
A link in a page of the docs, or in any page's textIt is text. A link in a template is from the page tree and checked by check; one written in Markdown is nottest: the audit follows every link to the site itself and fails on one that leads nowhere
An htmx attribute written by hand: hx-swap="innerMorph"It is text for htmx. What charter gives for the hard cases (live.Follows(), app.Body()) is Gotest, in a real browser
JavaScript: web/, and the glue that runs Gocharter has no TypeScript. It is kept small and free of logictest, in a real browser and on the Worker
Go calling Cloudflare inside charter's cloud packageGo on Workers calls JavaScript by namecharter's own tests, on a Worker
Three statements of the admin screenThey ask a database what tables it has, which is no table of a schemacharter's own tests

If you can express something as a Go type or a query, do: it moves from this table to the one above.

create

mise exec go@latest -- go run github.com/joeblew999/charter/cmd/charter@latest create my-app

Copies the example, the one app that uses all of charter, under your name. It pins the tools in the app's own mise.toml, installs them and writes the specs.

What it proves: nothing yet, but what it gives you passes check and test as it stands. You start from an app in which every layer above is already wired, and change it.

dev

go tool charter dev

The loop you work in. It runs the app on the real runtime (workers-go on wrangler dev, with the bindings of wrangler.jsonc) and stays running; every other command works beside it.

Each save runs the generator that owns the file, then the Go compiler:

You saveWhat is written for youWhat is then checked
A .gsx fileits Gothe compiler: every value and prop in the template
A .go filethe compiler
db/schema.sqlthe migration, and the local database followsevery query, again, against the new schema
db/queries.sqldb/queries.gen.go: a function and a row type for each querysqlc: columns and types; then the compiler, on every caller
locales/*.tomlthe messages as Go namesthe compiler, on every page that uses one
The API's spec, db/*.sql, wrangler.jsoncthe docs' pages of the API, the database and what the Worker is bound to (what charter writes)nothing to check: they are read from the source
wrangler.jsonc, .dev.vars.example, fnox.tomlenv/env.built.go: each binding, variable and secret's name as a typed valuethe compiler, on every line that uses one

A mistake shows in the browser in gsx's overlay within a second or two, and the last page that worked stays up.

What it proves: that the app compiles, with its templates, queries and messages. That is most type mistakes, at the moment you make them.

What it does not: it runs no linter and no tests, and it does not compare the API's spec. A link to a page that was removed can still be there. That is check.

add

go tool charter add screen:sign-in
go tool charter add ui:dialog
go tool charter add locale:de
go tool charter add d1:DB

Brings something more into the app: a screen of charter's, a gsxui component, a language, a Cloudflare resource with its binding, a Go module or an npm package.

What it proves: what it adds arrives in the checked form. A screen is a .gsx file in your app, built from your own components, so it is compiled as your pages are. screen:sign-in writes its tables into your db/schema.sql, and from then on check holds your schema to the statements charter runs on them. d1:DB writes the binding into wrangler.jsonc, and with that env.DB exists for your Go to use.

check

go tool charter check          # says
go tool charter check --fix    # writes what can be written

Everything that can be said without running the app. It starts nothing, so it is safe beside dev. Run it before a push; CI runs it too.

PartWhat it checks
toolsGo, Node and fnox are the versions mise.toml pins, so what you build is what CI builds
generatethe messages, the components' Go and the browser's files are written again, so everything after reads what is true now
fmtGo and gsx files are formatted
lintgo vet, twice: for your machine and for the Worker's build. Then structpages-lint: every link, id and target against the page tree, and any internal address written as a string
statementsno statement on the database is written in Go: each is a query in db/queries.sql, checked by sqlc (the database). And your schema still has the sign-in screen's tables as charter uses them
bindingsno binding, variable or secret is named as text (kv.NewNamespace("KV"), cloudflare.Getenv("X")): each is its value in env, which only exists for what is declared
scopesa scope is made only where it is declared, as a package's variable: never from a word where it is used
contractthe committed OpenAPI and AsyncAPI specs and the queries' Go are what the code gives now, and each rate limit the contract declares is bound
languagesevery language is complete, plural forms are right, no message is unused
screenscharter's screens that you have not changed are charter's current ones

What it proves: the whole first table on this page, for the whole app at once, and that nothing generated is stale. dev checks what you touched; check checks everything, including what a change somewhere else broke.

What it does not: it never runs your code. Everything in "What no compiler checks" is still open after a green check.

check --json gives the same as one JSON document, each part with what it said, for a script or a coding agent.

test

go tool charter test
go tool charter test --deployed

Runs go test for plain logic, then starts the Worker on wrangler dev with a new database filled by the seed, and tests it from outside: the pages in a real browser, the API through its own generated SDK, and the site as a search engine reads it, which includes following every link to the site itself.

What it proves: what types cannot. That the bindings answer, that a signed-in member may do what a member may and no more, that a page asks for what it is given, that a list updates in a second tab, that the JavaScript and Go meet. And it proves the generated clients against a running Worker, not only that they compile.

The tests use the types too: a test names a page by its type and an element by its id from the tree, never by an address or a selector, so a renamed page fails the test at compile time and not by timing out.

It also fails when a Go runtime of the Worker ended itself while the tests ran (Go's own fatal error:). The Worker starts another and every request is still answered, so nothing else would say. What Cloudflare refuses while a Worker starts, a local Worker allows: that shows only in test --deployed, which is why you run it after a deploy.

What it does not: what only shows at scale or far away: memory under many readers, a first hit on another continent. Those are run load and run cold, before a release.

--deployed runs the same tests against the deployed Worker, and leaves it as it found it.

deploy

go tool charter deploy

Applies the migrations that have not run, then deploys with wrangler. The first time, it makes the database, the KV namespace, the bucket and the queue that wrangler.jsonc names, and writes their ids there.

What it proves: that the deployed database has the schema the deployed code was checked against. The migrations are the ones written from db/schema.sql, and they are applied before the code that needs them. It stops rather than guess when a bucket or a queue was renamed, since that would make a new, empty one.

What it does not: that the app works there. Run test --deployed after it. A deploy does not wait on tests or on health; it says how the Worker did in the day before.

pack

go tool charter pack --prove

What others consume: SDKs written by Fern from the API's spec.

What it proves: that a client in each language, written from the same contract the Worker serves, calls the running Worker and gets what the types say. The spec comes from your Go types, so a client is typed all the way from your table: db/schema.sql gives the row, the row is what the API serves, the spec says so, and the SDK's type is that.

run

go tool charter run            # lists the tasks
go tool charter run db:seed
go tool charter run health

Everything that is no verb: tasks for languages (intl:), search engines (seo:), the database (db:), components (ui:), people, secrets, and watching a deployed Worker.

What they prove is about the running system, which no type describes: health says how requests ended on Cloudflare, load what happens under many readers, cold what a first reader waits. They take seconds or minutes, so none is part of check, test or deploy.

The rest

CommandFor
installeverything the app pins, and gsx's language server for your editor
fmt, lintthe parts of check, alone
build, previewwhat dev and deploy build, by hand
execone of the app's tools as it pins it: charter exec wrangler …
update, outdated, upgradethe pins, and charter itself
stagedcheck for what is staged, as a pre-commit hook
envwhat this machine has of what an app needs, and where dev is running

go tool charter <command> -h says a command's flags.