Examples you can download and run, and prompts you can hand to your agent, for the things most web apps end up needing.
Build a website with templates.
Pages are HTML files in views/. template() fills them with data from your route: {{value}} prints escaped text, {{#for}} and {{#if}} handle lists and conditions, and {{> header}} pulls in a shared partial from views/partials/. This example has a home page that lists posts, a page for each post, and a 404 page.
views/home.html
{{> header}}
<main>
<h1>Posts</h1>
<ul>
{{#for post in posts}}
<li><a href="/posts/{{post.slug}}">{{post.title}}</a>: {{post.summary}}</li>
{{#empty}}
<li>Nothing here yet.</li>
{{/for}}
</ul>
</main>
</body>
</html>
Output is escaped unless you use triple braces, so a title like <b> shows up as text instead of markup. The intent file checks the listing, the escaping, and the 404.
# Keep the same layout: views/ and views/partials/ beside server.tnt.
ntnt intent check server.tnt -vv
ntnt run server.tnt
Validate form input.
std/validate composes schemas and validators, returning cleaned data or field-level errors. This example accepts a name and email, returns 201 for valid input, and 422 for an invalid email. It does not create an account or send mail.
# Save both files in the same directory.
ntnt intent lint server.intent
ntnt intent check server.tnt -vv
ntnt run server.tnt
It’s the same code shown on the homepage. When you change it, rerun the check so both the valid and rejected cases still pass.
Add Google and GitHub login.
std/auth has built-in settings for Google, GitHub, Microsoft, Apple, Discord, and other OAuth providers, plus OpenID Connect discovery for the rest. enable_auth registers the login, callback, and logout routes, stores sessions, and serves a basic sign-in page at /auth.
server.tnt
import { html, redirect } from "std/http/server"
import { oauth, enable_auth, get_user } from "std/auth"
import { get_env } from "std/env"
let google = oauth("google", get_env("GOOGLE_CLIENT_ID") ?? "", get_env("GOOGLE_CLIENT_SECRET") ?? "")
let github = oauth("github", get_env("GITHUB_CLIENT_ID") ?? "", get_env("GITHUB_CLIENT_SECRET") ?? "")
enable_auth([google, github], map { "session_secret": get_env("SESSION_SECRET") ?? "" })
fn dashboard(req) {
let user = get_user(req) otherwise { return redirect("/auth") }
return html("<h1>Hello, </h1>")
}
get("/dashboard", dashboard)
listen(8080)
Register /auth/google/callback and /auth/github/callback as redirect URLs with each provider. Keep the client secrets and a long random SESSION_SECRET in your environment, and use a SQLite, PostgreSQL, or Redis session store in production so sign-ins survive a restart.
sse() turns a route into a Server-Sent Events stream. Create a named channel with broadcast, and every publish reaches each browser that has the stream open. This example sends the time once a second.
In the page, the browser’s built-in EventSource receives each event:
javascript
const events = new EventSource("/events")
events.addEventListener("tick", (e) => console.log(JSON.parse(e.data).at))
For messages in both directions, ws_endpoint and websocket() add a WebSocket endpoint that can share the same broadcast. Both go through your middleware before the connection opens, so your login checks cover them too. Events live in memory in one process and aren’t replayed, so a page should reload its data after it reconnects. Try them with ntnt run; ntnt test doesn’t stream.
ntnt db keeps your schema in numbered SQL files, with the database settings in ntnt.toml. Before anything touches your database, plan runs the new files on a separate scratch database and records what will change. migrate runs only when your approval matches that exact plan, and verify checks the database against your history afterward.
bash
ntnt db init --engine sqlite
# Local development: two empty SQLite files, settings read from the environment
mkdir -p data && touch data/app.sqlite data/replay.sqlite
export NTNT_ENV=development NTNT_SECRETS_PROVIDER=env
export APP_DATABASE_FILE="$(pwd -P)/data/app.sqlite"
export APP_REPLAY_FILE="$(pwd -P)/data/replay.sqlite"
ntnt db new create_messages # creates migrations/0001_create_messages.sql
# Write your CREATE TABLE in that file, then approve only a plan that passed:
if ntnt db plan --target development --out review-0001.json &&
jq -e '.outcome == "pass"' review-0001.json > /dev/null; then
export APP_MIGRATION_APPROVAL="$(jq -r .plan_digest review-0001.json)"
ntnt db migrate --target development --plan review-0001.json
fi
ntnt db verify --target development
Each later change is a new numbered file with its own plan and approval, and an approval for one plan can’t apply another. In production, the approval comes from a separately protected secrets provider instead of your shell. PostgreSQL works the same way, including over verified TLS.
As of 0.6.5, SQLite migrations can use AUTOINCREMENT and SQLite’s built-in functions, JSON functions included, and PostgreSQL schemas can use enums, domains and extensions such as citext. Extensions a superuser installs, such as pg_stat_statements, can be declared in ntnt.toml. Not supported yet: on PostgreSQL, materialized views, foreign tables, and range types, aggregates or collations you define yourself; on SQLite, virtual tables, generated columns, INSTEAD OF triggers and PRAGMAs in migrations.
Rate limiting is off until you set NTNT_RATE_LIMIT=on. Each client then gets 30 writes and 600 page or API reads a minute, and a client over the limit gets a 429 with a Retry-After header before your handler runs. Behind a proxy or tunnel, list it in NTNT_TRUSTED_PROXIES so each visitor is counted separately.
server.tnt
import { check_limit, too_many_requests } from "std/http/server"
// Give one route its own budget (applies when NTNT_RATE_LIMIT=on)
post("/subscribe", subscribe, map { "rate": "2/minute" })
// Inside a handler: limit by something the server can't see, like an email address
let r = check_limit("signup:" + email, "3/day")
if !r["allowed"] { return too_many_requests(r) }
check_limit works even when automatic limiting is off. Limits are kept in memory for each process and reset on restart, so keep your edge protection for large floods.
std/auth handles one-time magic-link tokens and sessions. Your application decides who can sign in, sends the email, and controls which routes the user can access.
Give your agent this next step:
Add passwordless sign-in using std/auth's magic_link_flow. Use an explicit SITE_URL and a durable token store. Keep eligibility and authorization in application callbacks. Deliver through std/email with NTNT_EMAIL_MODE=log for development; do not send real messages during tests. Test ineligible requests, expired links, replay rejection, and access to a protected route.
std/email has SMTP, batch delivery, and a log transport for local work. std/jobs adds scheduling, retries, dead letters, durable claims, and execution leases. Put slow delivery in a job rather than keeping a browser request open.
Add a welcome-email job using std/jobs and std/email. Keep development on NTNT_EMAIL_MODE=log. Persist a delivery identity so retries and unknown outcomes can be reconciled. Show pending, completed, failed, and outcome_unknown separately. Test a successful log-transport delivery and a forced failure; do not call a live SMTP service from verification.
Since 0.5.5, Redis-backed jobs need Redis 7.0+ or Valkey 7.2+. Upgrade every writer and worker sharing the queue together. A crash after an external send can leave an uncertain outcome; a retry is not automatically safe.
Run network checks.
NTNT has native network operations, persistent ICMP probes, and bounded SNMPv2c monitoring. Since 0.5.5, a check can carry a start deadline, and std/http.probe_fetch brings the same deadline to HTTP. A late check is rejected before it reaches the network.
Build a small NTNT network-check page using native networking APIs. Keep ICMP ping distinct from TCP reachability. Limit targets, concurrency, and time budgets; preserve actual sample times. Show target failure separately from execution failure or missed start deadline. Test with local fixtures, and require explicit authorization for any target beyond the local test setup.
A glossary term with call: and source: calls an ordinary NTNT function directly, with no server running. The slug example checks the conversion, whitespace trimming, and that the same input always gives the same result.
# Save both files in the same directory.
ntnt intent lint slug.intent
ntnt intent check slug.intent -vv
Function tests suit business rules and data transformations. Cover the expected values and the edge cases, and rerun them whenever the function changes.
Keep credentials out of the output.
std/secrets looks secrets up by name and returns values that print as redacted. Outbound calls that support secrets can use them, but logs, templates, and ordinary serialization can’t reveal them. Where the secrets come from in production is up to your deployment.