Build and deploy
Create an app
Create an app with tifa new
tifa new writes a small working app. This page covers the files it writes and how to put the tifa command on your machine.
tifa new
tifa new <dir> [--module module-path] [--empty]
Writes a small working app into dir, which must be missing or empty: a todo list stored in SQLite that shows how a Tifa app is laid out.
| File | What it holds |
|---|---|
go.mod |
Tifa, the Tifa command as a tool, github.com/liustack/sqlite, a SQLite driver in pure Go, and ignore node_modules |
db.go |
At the root: var DB, and OpenDB with WAL, busy_timeout and foreign keys turned on. The file is app.db in the folder the app runs in, or the setting db.path (DB_PATH, --db-path). StartBackup copies every commit to S3 or R2 when db.backup is set, see Back it up |
migrations/, schema.sql, migrate_test.go |
The tables of every domain as numbered SQL files in goose's format, 001_init.sql first. OpenDB in db.go runs the new ones at every start with goose. schema.sql shows the tables they make and is written by go test -run TestSchema -update. See Change the tables |
options.go |
At the root: the options of the app, DBPath = tifa.String("db.path", "app.db", ...), DBBackup (db.backup, empty by default) and the keys of its store, see Options of the app |
sessions.go |
At the root: a session store that keeps sessions in the SQLite database, set with tifa.SetSessionStore in OnStart, so a restart signs nobody out (see Sessions) |
hooks.go |
OnStart opens the database, OnShutdown closes it. OnRequest and OnError are described in comments only, since writing an OnError replaces the default |
app/layout.tsx, app/styles.css |
The root Layout with a nav, and an ErrorBoundary that also shows the 404 of unknown URLs, and the styles it imports |
app/route.go, app/page.tsx |
/: the list, and a form whose POST takes an input with a Validate method. The page shows the messages of the tifa.Fields it returns |
app/todos/todo.go |
The todos domain, package todos: ListTodos, GetTodo, AddTodo, SetDone. It imports the root package for DB, and both pages import it |
app/todos/todo+/ |
/todos/{todo}: a Load that returns tifa.ErrNotFound for a missing todo, a POST that marks it done, and an ErrorBoundary that shows the 404 |
app/about/page.tsx |
A page without route.go |
*_test.go |
Tests next to the code they test: the todos domain, the database and its migrations, the hooks and the session store, and tifatest tests of the route code, each on a fresh database in a temporary folder |
tifa.yaml |
Every setting of Settings, commented out at its default. ssr.vms defaults to GOMAXPROCS, at most 4, so it shows an example value |
AGENTS.md, CLAUDE.md |
Notes for coding agents on how a Tifa app works, with an index of the docs of the Tifa version in use, that give go tool tifa check as the one check command, with the part Tifa manages between marker lines (see The managed block of AGENTS.md, which tifa agents refreshes). CLAUDE.md only points at AGENTS.md |
.claude/skills/tifa/ |
The Tifa skill for coding agents, SKILL.md and its references, written by the same code as tifa agents (see tifa agents) |
package.json, tsconfig.json, vite.config.ts, .gitignore, README.md |
The npm packages, the TypeScript and Vite setup, the ignored build output and database files, and the commands |
pnpm-workspace.yaml |
minimumReleaseAge: 4320, so pnpm installs no package version that is less than 3 days old (see below) |
.gitattributes |
* text=auto eol=lf: git keeps LF line ends in the files on every system. git on Windows would check them out with CRLF, and the program embeds some of them, such as the files of migrations/, so a build there would differ from one made elsewhere from the same commit |
.github/workflows/ci.yml |
A GitHub Actions workflow that runs go tool tifa check on pull requests and on pushes to main: its token can only read the repository. It installs Go from go.mod, and Node 24 and the packages with pnpm install --frozen-lockfile --ignore-scripts (npm ci for an app made without pnpm), so commit the lock file. pnpm gets version 10 from the workflow, since package.json has no packageManager. The file is yours to edit: Tifa writes it once and never changes it. In GitHub Actions, tifa check, tifa build and tifa gen print their findings as workflow commands, so the run and the pull request mark the file and line of each, errors and warnings apart. --ignore-scripts leaves the checks to tifa check: pnpm prefixes the output of the prepare script, and GitHub does not read a prefixed command. setup-go and setup-node mark what go and tsc print |
.vscode/settings.json |
Labels the editor tabs of VS Code with the folder for the file names every folder repeats, such as orders/page.tsx and orders/route.go (page.tsx, layout.tsx, route.go, route_test.go and route.gen.ts under app/), through workbench.editor.customLabels.patterns. Other editors ignore it |
--emptywrites a skeleton in place of the todo list: the same root files (go.mod,tifa.yaml,package.json, the Vite and TypeScript config,.gitignore,.gitattributes,.github/workflows/ci.yml,AGENTS.md,CLAUDE.md,hooks.go,db.go,migrate_test.go,sessions.go,options.go) with amigrations/001_init.sqland aschema.sqlthat hold only the sessions table, a rootlayout.tsxwith its error component, apage.tsxof one line andstyles.css. It has noapp/todos/, about page, route or route tests. It builds, passesgo testandgo vet, and starts. Without the flag you get the todo list.- The module path is the folder name unless
--modulegives one. The app imports the package at its root, so the path must be one the go command imports.tifa newrefuses a path with avendorelement, and one whose first element has no dot and is, in any case, the first element of a standard library package or a go command pattern (such asfmt,netorall), even when no such package exists. Pass--module example.com/fmtinstead. - The root package is named after the last element of the module path (not counting a major version suffix such as
/v2), lowercased, with only its letters and digits kept. It must be a Go identifier that is not a keyword,mainorinit(Go does not takeinitas the name of an imported package). The Go files underapp/import it by that name, so it may not be a name that means something else where they use it: a package they import, such as the domaintodosortifa, a predeclared name they use, such aserror, or a parameter or variable in whose scope they use the root package, such asdborctx.tifa newkeeps a list of these names and refuses them, sotifa new todosfails and asks for another folder name or--module, and--module example.com/todosfails and asks for another last element of--module. Other names they use, such ascorrows, are fine. The name inpackage.jsonis the same, cut to 214 characters, the npm limit. go.modrequires the version of the Tifa command that ran when the go command downloaded it:go run github.com/liustack/tifa/cmd/tifa@<version> new myapp, orgo tool tifa newin an app. A command built in a Tifa checkout, or replaced by one, writesv0.0.0and adds a step that pointsgo.modat the checkout withgo mod edit -replace.go.modpins agithub.com/liustack/sqliterelease. The SQLite driver is pure Go and needs no C compiler.tifa newwrites files only. It runs no go or npm commands and needs no network. It prints the next steps:cdinto the folder,go mod tidy,pnpm installandgo tool tifa dev, which serves the app at http://127.0.0.1:9527. It also says to open the editor after the install, which runsgo tool tifa genand writes the types of.tifa/that the editor reads.- It looks for
pnpmon PATH, without running it. When pnpm is there, the install step and the commands inREADME.mdandAGENTS.mduse pnpm (pnpm install, andpnpm typecheckinREADME.md). Otherwise they use npm (npm install, andnpm run typecheckinREADME.md).package.jsonhas nopackageManagerfield, so both work on the same app. pnpm-workspace.yamlsetsminimumReleaseAge: 4320(minutes, so 3 days) for pnpm 10.16 or later, and pnpm 11 has a day by default. Compromised npm packages are usually found and pulled within days, and the age keeps a new version, also one that a package you use depends on, out of your install until then.package.jsonpins exact versions, andpnpm installwritespnpm-lock.yaml, which you commit and install from withpnpm install --frozen-lockfile. If an install fails because a version you need is too new, wait, or list the package inminimumReleaseAgeExclude. Older pnpm and npm ignore the file. npm hasmin-release-agein.npmrc(in days) for the same purpose.
Installing the command globally
go tool tifa is the main way to run Tifa, and it needs nothing installed. If you would rather type tifa dev, install the command once:
go install github.com/liustack/tifa/cmd/tifa@latest
Inside an app, the installed tifa hands the command to the version the app pins, as if you had typed go tool tifa ..., so it never generates code for another version of Tifa than the app uses. The rule:
- The app is the folder of
--dirwhen the command has it, else the current folder, or the nearest folder above it with ago.mod. Outside an app,tifaruns the command itself. - It forwards when that
go.modrequiresgithub.com/liustack/tifaand has thetool github.com/liustack/tifa/cmd/tifaline. - It does not forward when it already is the version of the app: a release build of the same version that
go.modrequires, with noreplacefor Tifa. A binary built in a checkout, another version, or areplacealways forwards. - A
go.workfile that is in use (GOWORK, or one above the app) always forwards, since it can change which Tifa the app gets, andgo toolfollows the workspace. tifa newnever forwards. It writes a new app, so there is none to ask.- A
tifathat the go command runs,go tool tifaorgo run, never forwards: it lives in the build cache of the go command (GOCACHE) and is the versiongo.modpicks already. - A relative
--diror-omeans what it meant where you typed it:tifamakes the values of path flags absolute before it moves to the root of the app. - The forwarded command runs in the root of the app with the same input, output, exit status and signals: on Linux and macOS
go tool tifatakes the place of the process, so a signal sent totifaalone reaches it too. It prints nothing of its own, and setsTIFA_FORWARDED=1so it never forwards twice. Ifgo tool tifacannot start,tifasays what to run instead.