Installation
Install khotan-data in the order that matches the package today: package first, core runtime second, schema third, then the components you actually want to use.
khotan-data is opinionated toward Vercel-style Next.js deployments. The runtime works locally in any standard Next.js app, but the default durable workflow and scheduled-flow story assumes Vercel Workflow plus a single dispatcher cron in vercel.json.
Prerequisites
- A Next.js App Router project
- TypeScript
- Drizzle ORM
- Postgres
Fresh project?
npx khotan init --full can install the base Drizzle and shadcn dependencies for you.1. Install the package
$ npm i khotan-data2. Set environment variables
| Variable | Purpose |
|---|---|
DATABASE_URL | Postgres connection string used by Drizzle |
KHOTAN_SECRET | Encrypts stored plug vars and wire vars. Generate with openssl rand -base64 32. |
KHOTAN_WEBHOOK_URL | Public origin used when the wire command builds default callback URLs |
KHOTAN_DEBUG | Enables plug debugging routes and the khotan plug CLI |
CRON_SECRET | Optional bearer secret for the built-in /api/khotan/cron dispatcher route |
Per-environment example
KHOTAN_SECRET=your-secret-here...
KHOTAN_URL=http://localhost:3000
KHOTAN_WEBHOOK_URL=https://abc123.ngrok.app # tunnel for inbound webhooksKHOTAN_SECRET=...
KHOTAN_URL=https://myapp.vercel.app
KHOTAN_WEBHOOK_URL=https://myapp.vercel.app# .env.local (dev)
DATABASE_URL=postgres://...
KHOTAN_SECRET=...
KHOTAN_WEBHOOK_URL=https://abc123.ngrok.app
KHOTAN_DEBUG=1
CRON_SECRET=...KHOTAN_WEBHOOK_URL can point at a tunnel in development while your app still runs on localhost.
3. Initialize khotan and install built-in skills
$ npx khotan init --yesThis scaffolds the core runtime and auto-accepts the prompt to install khotan's built-in agent skills.
| File | Purpose |
|---|---|
khotan.config.ts | CLI config, including outputDir |
src/khotan/khotan.ts or khotan/khotan.ts | Your khotan factory config |
app/api/khotan/[...all]/route.ts or src/app/api/khotan/[...all]/route.ts | Catch-all API route that mounts the khotan REST handler |
AGENTS.md | Root router that points agents at khotan skills |
When skills are installed, the CLI writes them into the agent directories it detects in the project.
- Cursor:
.cursor/skills/... - Claude Code:
.claude/skills/... - Codex:
.agents/skills/... - Copilot:
.github/skills/... - Kiro:
.kiro/skills/... - Roo:
.roo/rules/...
If no agent directories exist yet, khotan defaults to Cursor plus Claude Code.
4. Add the schema files
$ npx khotan add schema --yesThis writes khotan's standard Drizzle tables into your schema directory and updates your Drizzle setup so those tables are included.
khotan_plugskhotan_resourceskhotan_flowskhotan_wireskhotan_webhook_handlerskhotan_webhook_eventskhotan_runskhotan_mappings
5. Run migrations
$ npx khotan migrateUse npx khotan migrate --push if you want Drizzle push mode instead of migration files.
6. Add the first components
$ npx khotan add plug --yes
$ npx khotan add inflow --yes
$ npx khotan add wire --yes
$ npx khotan add catch --yes
$ npx khotan add hub --yes
$ npx khotan add runs --yesThese commands scaffold files into:
src/khotan/orkhotan/for runtime builderssrc/components/khotan/orcomponents/khotan/for React componentssrc/app/orapp/for ready-made page blocks
7. Add a ready-made page block
$ npx khotan add config-page-1This creates a /config page that renders the Hub.
$ npx khotan add graph
$ npx khotan add logs-page-1
$ npx khotan add debug-page-18. Add the dispatcher cron for production
Add one cron entry to vercel.json:
{
"crons": [
{ "path": "/api/khotan/cron", "schedule": "* * * * *" }
]
}This is the recommended deployment pattern. Keep per-flow schedules in khotan.ts, and let /api/khotan/cron decide which flows are due on each tick. If CRON_SECRET is set, Vercel should call the route with Authorization: Bearer <CRON_SECRET>.
9. Verify the runtime
$ curl http://localhost:3000/api/khotan/plugs
$ curl http://localhost:3000/api/khotan/flows
$ curl http://localhost:3000/api/khotan/resourcesIf KHOTAN_DEBUG=1 is set, you can also verify the debug surface:
$ npx khotan plug --list10. What agents should do next
- read the generated
AGENTS.md - use
/docs/agentsfor the built-in skill map - use the
.mdversions of docs pages for raw, crawlable content
Next
Continue to Basic Usage for a realistic plug + flow + webhook example.