The pages are React
Unmodified React, one toolchain. Drop a file in pages/ and it is a route, with loaders, layouts, form actions and client navigation. No fork, no compiler magic, no bundler config to own.
Open source · MIT · Self-hosted
File-based React pages rendered on Bun. API routes written in Go. Types that cross from one to the other on their own. All of it on one box you control, with no platform underneath.
Three ideas
Unmodified React, one toolchain. Drop a file in pages/ and it is a route, with loaders, layouts, form actions and client navigation. No fork, no compiler magic, no bundler config to own.
A static binary on net/http answers the port: your API, your static files, your event streams. Bun renders the pages behind it. The process that pages you at 3 a.m. is the boring one.
borgogen reads your handlers and writes the TypeScript: routes, responses, request bodies, WebSocket payloads. No OpenAPI spec to keep honest, because the code is the spec.
The typed bridge
Take the three steps yourself. Hover a field to see where it lands on the other side.
A Go handler answers with a Note. borgogen reads it and writes the TypeScript type; the page's loader is typed without declaring anything.
type Note struct {
ID int `json:"id"`
Title string `json:"title"`
Done bool `json:"done"`
}
//borgo:route GET /api/notes/{id}
func GetNote(w http.ResponseWriter, r *http.Request) {
note := find(r.PathValue("id"))
borgo.JSON(w, http.StatusOK, note)
}export async function loader(ctx: LoaderContext) {
const note = await ctx.api("GET /api/notes/{id}", {
params: ctx.params,
});
// note: { id: number; title: string; done: boolean }
return { heading: note.title, done: note.done };
}Rendering
Here rendering strategy is one export, per page, and every mode keeps the same loaders, layouts and typed API client.
nothingRendered on every request, streamed through Suspense.the page's JavaScriptexport const revalidate = 300Rendered once, cached and shared; rendered again when the clock runs out, or, with tags, the moment Go says the data changed.the page's JavaScriptexport const hydrate = "visible"Hydration waits until the marked part of the page scrolls into view.the page's JavaScript<Island name="Counter" />Only that component's JavaScript, inside an otherwise static page. This page is built that way.one component's JavaScriptexport const hydrate = falseServer HTML only. Not one byte of JavaScript shipped.no JavaScriptexport const prerender = trueBaked to plain HTML by borgo export, for nginx or any CDN. No borgo process at all.no JavaScriptTry it, on this server
This form posts to a Go handler running on the machine that served you this page. Get it wrong: the answer is a 422 with a map of fields, and the page shows, beside each field, what Go said about it.
// what the Go handler answers
// will appear here// asked by borgo.BindValid, after the body is decoded
func (a Arrival) Validate() error {
bad := borgo.Invalid{}
if strings.TrimSpace(a.Name) == "" {
bad["name"] = "the gatekeeper needs a name"
}
if strings.EqualFold(a.From, "vercel") {
bad["from"] = "you can stay, but you host yourself here"
}
return bad.OrNil()
}
//borgo:route POST /api/greet
func Greet(w http.ResponseWriter, r *http.Request) {
a, err := borgo.BindValid[Arrival](r)
if err != nil {
borgo.BindError(w, err) // 422 {error, fields}
return
}
borgo.JSON(w, http.StatusOK, welcome(a))
}In the box
A file is a route, a folder's _layout wraps it, and a slow part of a page streams in behind a Suspense boundary.
A form posts to the page that drew it and works with JavaScript off. With it on, the same form answers without a reload.
An event stream is a hub and a goroutine. A WebSocket topic carries payloads typed from the Go call that pushed them.
Signed cookies, password hashing, login, logout and register handlers, CSRF on every action. The user store stays yours.
A guard in Go in front of the API and the pages, and one in TypeScript in front of loaders, props and actions.
Security headers and a strict Content-Security-Policy are on from the first request, with a nonce per response.
Variables declared once, validated before the server binds, typed at every read, and the same contract on the Go side.
/healthz, /readyz with your own checks, a stop that drains, a request id on everything and metrics you can alert on.
A Dockerfile in every scaffold, and borgo deploy init for Caddy, nginx, systemd or Compose.
borgotest for handlers in Go, and loaderContext and actionContext for loaders and actions in TypeScript.
FanOut and Deliver put the realtime relay on a bus of your choosing, so Push reaches every instance.
A manifest and a service worker from one command, served with the headers they need.
Quickstart
You need Bun 1.4 or later and Go 1.27 or later. Three templates: base is a tour of loaders, actions, islands and SSE; minimal is one page and one route; full is notes on SQLite with auth, middleware, a cached page and typed WebSockets.
bunx create-borgo@latest my-app
cd my-app
bun install
go mod tidy
bun run dev
Built with borgo
Workspaces, rooms, threads, files, search, realtime, a second step at sign-in, sign-in through an identity provider, bots and webhooks, in nine languages. It is the largest thing built with borgo, and its stress test: what was hard to build there changed the framework.
Measured, with the biases first
One laptop, a harness written by borgo's own author, and 11 of 27 comparisons that drifted between two sweeps by more than their own noise. The three documents are not the same size either. Read it for what it is, then run it yourself.
Said plainly
Everything here is a deliberate choice, with its reason and its bill attached.
Loaders returning serialized props are the model, with a runtime small enough to read.
One box, two processes, a reverse proxy. borgo will not deploy you to someone else's runtime.
The framework is small enough that the extension mechanism is reading the source and changing it.
Cookies, hashing, handlers and CSRF are provided. The user store, OAuth and everything beyond stay in your hands.
You can read the whole thing: roughly thirty thousand lines of TypeScript and Go, comments included, with the reasoning threaded through them.
Built by Luigi Micca. The case study, why borgo exists and what building it taught him, is on his site.