import { Acryl } from 'acrylblends'
const app = new Acryl()
app.get('/', (c) => c.text('Acryl!'))
export default app
Contents
- Requirements
- Start an app in five minutes
- Run it in a browser or in a desktop window
- Start from the registry
- Publish your app, or your own starter
- Keep the framework current
- Use it as a library
- A first API
- Middleware
- Validation
- Typed client
- Testing
- Serving on Node.js
- What is in the package
- Upgrading from an older version
- The acrylblends command
- Links
- License
Requirements
- Node.js 22.19 or newer. Node.js is the verified runtime, and it runs
.ts files directly, so there is no build step.
- Bun runs the same app (
export default app) and is experimental.
acrylblends has no dependencies. Its types need only Node's types (@types/node), not the DOM library.
Start an app in five minutes
npm create @acryldev/blends@latest my-app
cd my-app
npm install
npm run dev
The starter asks which template you want; naming one skips the question (npm create @acryldev/blends@latest my-app notes).
| Template |
What you get |
blank |
the router, the Node server and one route: the smallest app |
nodejs |
a page rendered with JSX and a client component, without a bundler |
notes |
a multi-user notes app on the db port: sign-up, sessions, migrations, search, a typed client |
chat |
an answer streamed over server-sent events from an OpenAI-compatible API, history in SQLite |
todo |
a to-do list on the router and live state |
agent |
the blank app with an agent that writes and installs plugins into the running app |
Every template is a Cordis app: blend.yaml lists its plugins, plugins/ holds them as code you own, and the starter also writes
docs/framework (the pages this README links to), AGENTS.md, CLAUDE.md, one skill for a coding agent, and its own tests. npm run dev
serves it and prints the URL, npm test runs the tests, npm run check type-checks.
Adding a capability is one command: npx acrylblends add <plugin> copies a library plugin and what it needs into plugins/, prints the row to
add to blend.yaml, and records what it copied so acrylblends upgrade can move it forward later. npx acrylblends plugins lists the library.
Run it in a browser or in a desktop window
The same app runs both ways; the routes, the plugins and the data are the ones you already wrote.
- Browser: what you get.
npm run dev (or npm start) serves it on a loopback port and prints the URL.
- Desktop: add the shell and run it as a window on the app's own server.
npx acrylblends init my-app --desktop # create an app with the shell (--template picks the template)
# or, in an app you already have:
npx acrylblends add desktop
npm install # the shell needs electron
npm run desktop # an Electron window on the app's own server
Every Electron call lives in plugins/desktop-shell, so the app's own code never imports it. See
Desktop.
Start from the registry
The registry is a set of starting points people published, browsable at acrylblends.github.io/blends
and readable by any tool as plain JSON at https://acrylblends.github.io/registry/index.json. Each entry says which runtime it is for. An
acrylblends starter is a whole app, and one command makes it from npm alone:
npm create @acryldev/blends@latest my-notes -- --from acrylblends.notes-desktop # npm needs the -- before the options
cd my-notes
npm install
npm run dev
The other starters in the registry (acryl.gtd, acryl.blank, ...) are for the ACRYL app: @acryldev/create-blends refuses them with a line that
says so. A repository with an acryl.template.json works the same way (-- --from github:you/starter), and a team's own registry is the same
layout in its own repository (-- --from you.thing --registry github:you/registry).
Publish your app, or your own starter
Your app belongs to you and lives in your repository: npm run save commits it and pushes to its remote. It refuses a file that looks like
a secret, and refuses to push a private app to a public remote.
Before an app goes on a server: with NODE_ENV=production the door, the agent panel and the PTY driver start nothing, the agent template leaves its agent, builder and extensions rows out
(ACRYL_PRODUCTION_KEEP names the ones to keep, with a warning), and the chat template is closed until it has a CHAT_ACCESS_TOKEN
A starter other people can pull is a pull request to the registry repository: add registry/blends/<id>/ with your app as it stands (without node_modules/
and dist/), its blend.yaml made public (id, a licence, a category and a one-line description) and an acryl.template.json, which is what marks it as an
app for acrylblends. CI validates every entry, makes the app with @acryldev/create-blends, and fails when index.json is stale, so what the site lists is what
passed. The layout, and how to keep a starter private without a registry at all, is in
the registry README.
Keep the framework current
An app carries its framework plugins as source, so a new release moves them in place and leaves your own code alone:
npx @acryldev/blends@latest upgrade --dry-run # the plan: what would be replaced
npx @acryldev/blends@latest upgrade # an edited file stops it with the diff, unless --force
Write @latest: a bare npx acrylblends upgrade runs the copy the app has installed, and an app made before 1.0 has an old one with no upgrade verb (it prints its help and exits 0, so it looks as if it worked, or answers "unknown command" and exits 2).
Use it as a library
An Acryl app is also a plain function from Request to Response, which needs no scaffold. Create a folder and install the package:
mkdir my-app && cd my-app
npm init -y
npm pkg set type=module
npm install @acryldev/blends
Write the app in index.ts:
import { Acryl } from 'acrylblends'
const app = new Acryl()
app.get('/', (c) => c.text('Acryl!'))
export default app
Serve it on Node.js with the adapter in server.ts:
import { serve } from '@acryldev/blends/node-server'
import app from './index.ts'
serve({ fetch: app.fetch, port: 3000 }, (info) => {
console.log(`Listening on http://localhost:${info.port}`)
})
Run it and open http://localhost:3000:
node server.ts
For Bun, bun run index.ts serves the same export default app. The same app mounts inside a Cordis plugin with
ctx.router.route(prefix, app), which is how a generated app is put together: see
Acryl in a Cordis app.
A first API
import { Acryl } from 'acrylblends'
import { HTTPException } from '@acryldev/blends/http-exception'
type Book = { id: string, title: string }
const books = new Map<string, Book>()
const app = new Acryl()
app.get('/api/books', (c) => c.json([...books.values()]))
app.get('/api/books/:id', (c) => {
const book = books.get(c.req.param('id'))
if (book === undefined) throw new HTTPException(404, { message: 'no such book' })
return c.json(book)
})
app.post('/api/books', async (c) => {
const { title } = await c.req.json<{ title: string }>()
const book = { id: crypto.randomUUID(), title }
books.set(book.id, book)
return c.json(book, 201)
})
app.notFound((c) => c.json({ error: 'not found' }, 404))
app.onError((error, c) => error instanceof HTTPException ? error.getResponse() : c.json({ error: 'internal error' }, 500))
export default app
Read more: Routing,
Context,
Request,
Exceptions.
Middleware
Each built-in middleware has its own subpath:
import { Acryl } from 'acrylblends'
import { cors } from '@acryldev/blends/cors'
import { logger } from '@acryldev/blends/logger'
import { secureHeaders } from '@acryldev/blends/secure-headers'
import { bearerAuth } from '@acryldev/blends/bearer-auth'
const app = new Acryl()
app.use(logger())
app.use(secureHeaders())
app.use('/api/*', cors())
app.use('/admin/*', bearerAuth({ token: process.env.ADMIN_TOKEN ?? '' }))
Built in: basic-auth, bearer-auth, body-limit, combine, compress, context-storage, cors, csrf, etag, ip-restriction,
jwk, jwt, language, logger, method-not-allowed, method-override, powered-by, pretty-json, request-id, secure-headers,
serve-static, timeout, timing, trailing-slash, plus ACRYL's loopback-only. Each one is documented under
Middleware. To write your own, see the
middleware guide.
Validation
acrylblends/validator validates any part of a request: json, form, query, param, header, cookie. The validated value is typed
in the handler:
import { Acryl } from 'acrylblends'
import { validator } from '@acryldev/blends/validator'
const app = new Acryl()
app.post(
'/api/books',
validator('json', (value, c) => {
const title = (value as { title?: unknown }).title
if (typeof title !== 'string' || title === '') return c.json({ error: 'title is required' }, 400)
return { title }
}),
(c) => c.json({ title: c.req.valid('json').title }, 201),
)
acrylblends/schema-validator drives the same validator with any Standard Schema library (Zod, Valibot,
ArkType and others). See the validation guide.
Typed client
Export the app's type, and acrylblends/client calls its routes with typed paths, inputs and answers:
// api.ts
import { Acryl } from 'acrylblends'
const app = new Acryl().get('/api/hello', (c) => c.json({ message: 'Acryl!' }))
export type AppType = typeof app
export default app
// client.ts
import { hc } from '@acryldev/blends/client'
import type { AppType } from './api.ts'
const client = hc<AppType>('http://localhost:3000')
const answer = await client.api.hello.$get()
console.log((await answer.json()).message)
See RPC.
Testing
app.request() answers a request in process, with no server and no port, so tests need nothing else running:
import assert from 'node:assert/strict'
import { test } from 'node:test'
import app from './index.ts'
test('GET / says hello', async () => {
const response = await app.request('/')
assert.equal(response.status, 200)
assert.equal(await response.text(), 'Acryl!')
})
Run it with node --test. acrylblends/testing adds testClient, the typed client over app.request(). See the
testing guide.
Serving on Node.js
acrylblends/node-server serves any Acryl app on Node's http module (or http2 and https with createServer), streams bodies, aborts
c.req.raw.signal when the client goes away, and serves files:
import { Acryl } from 'acrylblends'
import { serve } from '@acryldev/blends/node-server'
import { serveStatic } from '@acryldev/blends/node-server/serve-static'
import { getConnInfo } from '@acryldev/blends/node-server/conninfo'
const app = new Acryl()
app.use('/static/*', serveStatic({ root: './' }))
app.get('/ip', (c) => c.text(getConnInfo(c).remote.address ?? 'unknown'))
const server = serve({ fetch: app.fetch, port: 3000, hostname: '127.0.0.1' })
process.on('SIGTERM', () => { server.close() })
See Node.js.
What is in the package