Learn NTNT

From install to verified app in four prompts.

Pre-1.0. NTNT runs production apps, including this site, but minor versions can still include breaking changes. Release notes call them out.

Step 1: Your First App

Pick your tool and copy the prompt. Your agent handles the install, the syntax, and the demo.

Install NTNT (curl -sSf https://raw.githubusercontent.com/ntntlang/ntnt/main/install.sh | bash), then run `ntnt learn claude-code` and read the generated rules before writing any code.

Build a web app in server.tnt: a GET / that returns a greeting and a GET /api/status that returns JSON. Add a requires contract on one handler. Make the app look good. Write a server.intent file with scenarios for both routes. Run `ntnt intent check server.tnt` until all pass, then `ntnt run server.tnt`. Respond with the URL of the running app.
Install NTNT (curl -sSf https://raw.githubusercontent.com/ntntlang/ntnt/main/install.sh | bash), then run `ntnt learn codex` and read the generated rules before writing any code.

Build a web app in server.tnt: a GET / that returns a greeting and a GET /api/status that returns JSON. Add a requires contract on one handler. Make the app look good. Write a server.intent file with scenarios for both routes. Run `ntnt intent check server.tnt` until all pass, then `ntnt run server.tnt`. Respond with the URL of the running app.
Install NTNT (curl -sSf https://raw.githubusercontent.com/ntntlang/ntnt/main/install.sh | bash), then run `ntnt learn cursor` and read the generated rules before writing any code.

Build a web app in server.tnt: a GET / that returns a greeting and a GET /api/status that returns JSON. Add a requires contract on one handler. Make the app look good. Write a server.intent file with scenarios for both routes. Run `ntnt intent check server.tnt` until all pass, then `ntnt run server.tnt`. Respond with the URL of the running app.
Install NTNT (curl -sSf https://raw.githubusercontent.com/ntntlang/ntnt/main/install.sh | bash), then run `ntnt learn` and read the generated rules before writing any code.

Build a web app in server.tnt: a GET / that returns a greeting and a GET /api/status that returns JSON. Add a requires contract on one handler. Make the app look good. Write a server.intent file with scenarios for both routes. Run `ntnt intent check server.tnt` until all pass, then `ntnt run server.tnt`. Respond with the URL of the running app.

ntnt learn generates platform-native config files so your agent loads the rules every session. One command, permanent knowledge.

Step 2: Add a Database

Once your demo is running, add persistence.

Add a SQLite database to the app. Create a messages table, add POST /messages to save a message and GET /messages to list them. Update server.intent with scenarios for both endpoints. Run `ntnt intent check server.tnt` until all pass. Add a link to the homepage to /messages and a form that posts a new message.
Add a SQLite database to the app. Create a messages table, add POST /messages to save a message and GET /messages to list them. Update server.intent with scenarios for both endpoints. Run `ntnt intent check server.tnt` until all pass. Add a link to the homepage to /messages and a form that posts a new message.
Add a SQLite database to the app. Create a messages table, add POST /messages to save a message and GET /messages to list them. Update server.intent with scenarios for both endpoints. Run `ntnt intent check server.tnt` until all pass. Add a link to the homepage to /messages and a form that posts a new message.
Add a SQLite database to the app. Create a messages table, add POST /messages to save a message and GET /messages to list them. Update server.intent with scenarios for both endpoints. Run `ntnt intent check server.tnt` until all pass. Add a link to the homepage to /messages and a form that posts a new message.

Step 3: Add Authentication

Lock it down so only logged-in users can access the site.

Add session-based authentication using cookies and SQLite. Create a login page, protect the homepage and /messages so only logged-in users can access the site, and redirect unauthenticated users to /login. Add a logout link to the app. Add contracts on the protected handlers. Update server.intent to test login page renders, unauthenticated access redirects and POSTS and run `ntnt intent check server.tnt` until all pass.
Add session-based authentication using cookies and SQLite. Create a login page, protect the homepage and /messages so only logged-in users can access the site, and redirect unauthenticated users to /login. Add a logout link to the app. Add contracts on the protected handlers. Update server.intent to test login page renders, unauthenticated access redirects and POSTS and run `ntnt intent check server.tnt` until all pass.
Add session-based authentication using cookies and SQLite. Create a login page, protect the homepage and /messages so only logged-in users can access the site, and redirect unauthenticated users to /login. Add a logout link to the app. Add contracts on the protected handlers. Update server.intent to test login page renders, unauthenticated access redirects and POSTS and run `ntnt intent check server.tnt` until all pass.
Add session-based authentication using cookies and SQLite. Create a login page, protect the homepage and /messages so only logged-in users can access the site, and redirect unauthenticated users to /login. Add a logout link to the app. Add contracts on the protected handlers. Update server.intent to test login page renders, unauthenticated access redirects and POSTS and run `ntnt intent check server.tnt` until all pass.

Step 4: Refactor

Production structure: middleware, routing, templates, and shared code.

Refactor the app to use middleware, file-based routing, external HTML templates in a views/ directory for all pages, partials for nav and footer and add a static CSS file. Move functions to lib folder. Make sure it still looks decent. Verify `ntnt intent check server.tnt` still passes.

Four prompts. You’ve got a full-stack web app with a database, auth, templates, middleware, and file-based routing. You didn’t write any NTNT. Your agent did, and ntnt intent check checked the scenarios at every step.

Advanced Demo Prompts

Step 5: PostgreSQL & Docker requires Docker

Real database, containerized.

Migrate from SQLite to PostgreSQL. Create a Dockerfile and docker-compose.yml with the ntnt app and a postgres container. Use environment variables for the connection string. Verify `ntnt intent check server.tnt` still passes. Leave the app running when you're done.

Step 6: Background Jobs

Scheduled jobs, on-demand triggers, and a job log.

Add a background job that fetches a new random cat fact from an API every 10 minutes and stores it in the database. Display the latest cat fact on the homepage with a button that schedules an immediate job to fetch a new one. Add a job log page that shows a record of all jobs run with their status and timestamps. Verify `ntnt intent check server.tnt` still passes.

Installation

macOS / Linux:

bash
curl -sSf https://raw.githubusercontent.com/ntntlang/ntnt/main/install.sh | bash

Windows (PowerShell):

powershell
irm https://raw.githubusercontent.com/ntntlang/ntnt/main/install.ps1 | iex

Hello World

bash
echo 'print("Hello, World!")' > hello.tnt
ntnt run hello.tnt

A Web API

ntnt
// api.tnt
import { json } from "std/http/server"

fn home(req) {
    return json(map { "message": "Hello!" })
}

fn get_user(req) {
    return json(map { "id": req.params["id"] })
}

get("/", home)
get("/users/{id}", get_user)

listen(3000)
bash
ntnt run api.tnt
# Visit http://localhost:3000

Hot-reload: HTTP servers automatically reload when you edit the source file.

Intent-Driven Development

Write .intent files describing features, link code with @implements, and verify everything matches.

1Write an intent file
intent
# server.intent

## Glossary

| Term | Means |
|------|-------|
| a user visits {path} | GET {path} |
| the home page | / |
| the page loads | status 200 |
| they see {text} | body contains {text} |

---

Feature: User Greeting
  id: feature.greeting

  Scenario: Greet by name
    When a user visits /?name=Alice
    → the page loads
    → they see "Hello, Alice"

  Scenario: Default greeting
    When a user visits the home page
    → the page loads
    → they see "Hello, World"
2Annotate your implementation
ntnt
// server.tnt
import { html } from "std/http/server"

// @implements: feature.greeting
fn home(req) {
    let name = req.query_params["name"] ?? "World"
    return html("<h1>Hello, #{name}!</h1>")
}

get("/", home)
listen(8080)
3Lint the spec, then verify

ntnt intent lint server.intent catches unresolved phrases before anything runs. Then:

bash
$ ntnt intent check server.tnt

✓ User Greeting  2 scenarios

=== Summary ===
Features:   1 total, 1 passed, 0 failed
Scenarios:  2 passed, 0 failed, 0 skipped
Assertions: 4 passed, 0 failed

Design by Contract

ntnt
fn withdraw(balance: Int, amount: Int) -> Int
    requires amount > 0
    requires amount <= balance
    ensures result >= 0
{
    return balance - amount
}

// In HTTP handlers:
// requires fails → 400 Bad Request
// ensures fails  → 500 Internal Server Error

A failed contract reports the expression and the runtime values that broke it, so an agent can fix the cause instead of guessing.

Put it to work

Once your first app runs, the recipes cover building a website with templates, form validation, passwordless sign-in, sending email from a background job, and testing a function without a server. Browse the recipes →

Standard Library

Everything ships in the binary: 554 documented functions across 28 modules. No package manager.

Webstd/http/server, std/http, std/urlRouting, middleware, static files, response builders; fetch with SSRF protection and safe redirects
Auth & securitystd/auth, std/crypto, std/secretsOAuth/OIDC, sessions, CSRF, TOTP, magic links; SHA-256, AES-GCM, Argon2, UUIDs; redacted secret values
Input & mailstd/validate, std/emailDeclarative schemas for forms and APIs; SMTP with batches and a dev log transport
Datastd/postgres, std/sqlite, std/kvPooled PostgreSQL and SQLite with transactions; KV over Redis, Valkey, SQLite, or memory
Formatsstd/json, std/csv, std/markdownParse and serialize; markdown rendering and source-mapped block parsing
Jobsstd/jobsLanguage-native job DSL: priority queues, cron, unique jobs, retries, dead letters, crash-safe leases. Memory, PostgreSQL, and Redis backends
Concurrencystd/concurrent, std/processTasks, channels, select, parallel, race; supervised child processes (off by default)
Networkstd/net, std/netmonCIDR math, TCP, DNS; ping, persistent probes, SNMP
Files & envstd/fs, std/path, std/envFile and binary I/O, atomic writes, paths, environment
Utilitiesstd/string, std/collections, std/time, std/math, std/logText and collection helpers; dates and durations; math; structured logging

CLI Commands

ntnt run app.tntRun a program; HTTP servers hot-reload on save
ntnt lint app.tntLint for errors and style issues (JSON output)
ntnt validate app.tntValidate with machine-readable errors, several per pass
ntnt inspect app.tntEvery route, function, and contract as JSON
ntnt check app.tntQuick syntax check
ntnt test app.tnt --get /healthStart the server, make requests, stop
ntnt intent check app.tntVerify code matches its intent file
ntnt intent lint app.intentStatically validate glossary and scenarios
ntnt intent coverage app.tntFeature coverage report
ntnt intent init app.intentGenerate scaffolding from an intent file
ntnt intent studio app.intentVisual workspace with live results
ntnt learn <platform>Agent config for claude-code, codex, cursor, or copilot
ntnt docs std/stringLook up module and function docs
ntnt worker app.tntStart background workers for jobs in a file
ntnt jobs status | list | inspect | retryInspect and manage the job queue
ntnt workers status | scaleLive worker status and runtime scaling
ntnt migrate .Migrate old {expr} interpolation to #{expr}
ntnt completionsShell completions for bash, zsh, and fish
ntnt replInteractive REPL

Documentation