Skip to content
Trilha
Chapters

Cookbook

Cookbook

The parts every app needs and no framework decides for you — database, session, upload, pagination, e-mail, scheduled task, Docker — with code that compiles.

"Learn" teaches the framework and "Reference" describes each symbol. This section answers a third kind of question, the one that shows up on the second day: how do I do the thing every app does? Open a database, keep someone logged in, receive a file, paginate a list, send an e-mail, run a task every hour, put the whole thing in a container.

None of that is the framework's decision. Trilha has no ORM, no session store and no mailer — what it has is a place for yours, and this is where the placing is written down.

PageWhat it answersRecipe
The management appwhat trilha new --template app writes, and the afternoon from the command to productioneight of them
Databasepool, queries, transaction, migrations, sqlcstore
Sessionslogin, signed cookie, current user, flashlogin
Uploadsreceive a file, validate it, store it, hand it backblob
CSVexport a spreadsheet Excel opens, import one with the error per cell—
A form in stepswhere step one lives while somebody is on step two—
A public linka form filled in with no login, and a code that verifies a document—
Fileswhere an upload lives, how it comes back, and the orphan sweepblob
Paginationpage and cursor, and the footer that goes with them—
E-mailSMTP in production, the log in dev, a body from a templatemail
Background tasksqueue, dedupe, retry with a name, the progress screentasks
Webhookssigned delivery, retry with backoff, the record of every attemptwebhooks
Billingplans, subscriptions on a closed state machine, the signed provider webhook, dunningbilling
Notificationsthe person's channel, quiet hours, daily digest, per-channel limit, the outboxnotify
Backofficeapp/admin/ denied by default: users, audit, approvals, searchadmin
Scheduled tasksa ticker that starts with the app and stops with it—
Installable app (PWA)manifest, icons and an install invitation that adapts to each browserpwa
Dockera small image, the variables, the health probe—
Production checklistwhat to check before publishing, in order—
AI chatthe key, the page's context, the history, the test with no key—
An AI agenttools over your data, a write that waits for a person, the steps, the trail—
Migrationplain net/http to Trilha, and between minor versions—
From Next.jsthe React pattern you know, and what replaces it here—

Where the code comes from#

Every Go block on these pages is copied from a file in examples/cookbook, which is part of the repository's module: go vet ./... compiles it on every run, and a site test checks that each block still appears, character for character, in the file it came from. A recipe that stops compiling breaks the build before it can mislead anyone.

That has a price worth knowing about: the package uses the standard library only, like the rest of the repository. So there is no database driver, no password hash and no metrics client in it. Where one is needed, the page says which line to add and why it is not here.