Skip to content

In developmentLinux builds today

One language from the UI to the server.

Weft is a typed language with its own app platform. A page, its state and the server functions it calls are one program, and every value is a copy, so the compiler knows exactly what each change touches.

curl -fsSL https://weft-lang.dev/install.sh | sh

Installs weft into ~/.weft. Linux x86_64 and aarch64; macOS and Windows are coming.

routes/page.weft
weft
import { uuid } from "std/random"
import { plural } from "std/format"

type Note = { id: string, text: string }

let mut notes: Note[] = []
let mut draft = ""
derived count = plural(notes.length, "note")

// Runs on the server; the page calls it like any async fn.
action fn save(text: string): Note {
  return Note { id: uuid(), text: text.trim() }
}

async fn add() {
  if draft.trim() == "" { return }
  let note, err = try await save(draft)
  if err != null { return }   // offline: keep the draft
  notes.push(note)
  draft = ""
}
---
<Card className="w-80 px-4">
  <Box class="flex gap-2">
    <Input bind:value={draft} onsubmit={add} placeholder="A note" />
    <Button onpress={add}>Add</Button>
  </Box>
  @for note of notes key note.id {
    <Text>{note.text}</Text>
  }
  <Text class="text-muted-foreground">{count}</Text>
</Card>
The notes page running in a browser: a field, an Add button and three notesThe notes page running in a browser: a field, an Add button and three notes

One language

From the UI to the server, one typed program.

Pages, components, server functions, endpoints and backends are all Weft. Calling the server is a typed function call: the compiler writes the request, and the server checks the arguments again when they arrive.

  • A validating type, like Title, is checked on both sides.
  • The page may import a server module's server functions and types, nothing else.
The server
routes/page.weft
weft
import { listTodos, addTodo } from "lib/server/todos"
import type { Todo, Title } from "lib/server/todos"

let mut todos: Todo[] = []
let mut draft = ""
let mut problem = ""

async fn add() {
  let title, bad = try draft as Title
  if bad != null {
    problem = "A title is 1 to 200 characters."
    return
  }
  let next, err = try await addTodo(title)
  if err != null {
    problem = err.message
    return
  }
  todos = next
  draft = ""
  problem = ""
}

todos = try await listTodos() else []
---
<Box class="flex flex-col gap-2">
  <TextField bind:value={draft} onsubmit={add} placeholder="What next?" />
  <Text>{problem}</Text>
  @for t of todos key t.id {
    <Checkbox checked={t.done} label={t.title} />
  }
</Box>
lib/server/todos.weft
weft
import { uuid } from "std/random"

export type Todo = { id: string, title: string, done: boolean }
export type Title = string where it.trim() != "" && it.length <= 200

let mut todos: Todo[] = []

export action fn listTodos(): Todo[] {
  return todos
}

export action fn addTodo(title: Title): Todo[] {
  todos.push(Todo { id: uuid(), title: title.trim(), done: false })
  return todos
}

Values, not references

Nothing changes your data unless you hand it over.

let b = a makes a copy, and changing b leaves a alone. A function changes a value only when it's passed with &, so what a call can touch is written at the call.

Copies cost nothing until one side writes, and memory is freed by reference counting, with no garbage collector.

Values and borrows
main.weft
main.weft
weft
import { log } from "std/log"

type Note = { title: string, tags: string[] }

fn rename(mut note: Note, title: string) {
  note.title = title
}

let mut a = Note { title: "Draft", tags: [] }
let mut b = a
b.title = "Final"
rename(&a, "Kept")
log(a.title, b.title)
$ weft run main.weft
Kept Final

Reactivity the compiler proves

An update runs exactly the code that depends on it.

There are no signals or wrappers. Because values are copies, the compiler can list what every piece of markup reads and what every handler writes, and the runtime updates only those.

Here typing writes only draft, so the list is left alone. Checking a box writes one done, so only left and that box update.

Components and reactivity
Todos.weft
Todos.weft
weft
import { uuid } from "std/random"
import { plural } from "std/format"

type Todo = { id: string, title: string, done: boolean }

let mut todos: Todo[] = []
let mut draft = ""
derived left = todos.count(t => !t.done)

fn add() {
  let title = draft.trim()
  if title == "" { return }
  todos.push(Todo { id: uuid(), title, done: false })
  draft = ""
}
---
<Box class="flex flex-col gap-2">
  <TextField bind:value={draft} onsubmit={add} placeholder="What next?" />
  @for mut todo of todos key todo.id {
    <Checkbox bind:checked={todo.done} label={todo.title} />
  }
  <Text>{plural(left, "item")} left</Text>
</Box>
$ weft hir Todos.weft (its units, shortened)
derived left               reads [todos]
fn add                     reads [todos, draft]  writes [todos, draft]
bind:value={draft}         writes [draft]
bind:checked={todo.done}   writes [todos[*].done]
label={todo.title}         reads [todos[*].title]
{plural(left, "item")}     reads [left]

Every platform

The web, a desktop app and server rendering, from the same files.

On the web, Weft compiles to JavaScript and the DOM. Everywhere else it runs as bytecode on a Rust VM: on the server, which renders each page before the browser takes it over, and in the desktop app, which draws with its own GPU renderer.

Mobile comes later, through native views.

The desktop app
sh
weft new hello              # an app: a page, server functions, a test
weft dev hello              # http://localhost:3000, rendered on the server
weft dev hello --window     # the same pages in a native window
The app weft new writes, in a browserThe app weft new writes, in a browser
The same app in Weft's desktop windowThe same app in Weft's desktop window

The app weft new writes, in Chromium and in the desktop app.

A framework, and apps users can edit

Pages from the file tree. Users' own pages over them.

A project with routes/ is an app: pages, layouts, errors and endpoints come from where files sit, and links to them are typed. Without it, Weft is a plain language.

An app can let its users, or an AI working for them, write their own pages. Each one is checked and compiled when it's saved, and runs in its own VM through std/sandbox, reaching only what the app hands it.

User-editable apps
main.weft
weft
import { app } from "std/app"
import { session } from "std/http"
import type { Request } from "std/http"
import { trees } from "lib/server/pages"

try await app.serve(async (req: Request) => {
  let user = try await session(req).user()
  // the signed-in user's own pages first, then the app's
  return [user != null ? trees.tree(user.id) : null, "./routes"]
}, {
  // all a user's page can reach: its `caps` prop (and what it `imports` of the app)
  sandbox: async (req: Request) => ({ caps: { user: (try await session(req).user())?.name ?? "" } }),
})
lib/server/pages.weft
weft
import { request } from "std/http"
import { requireUser } from "std/auth"
import { dir } from "std/sandbox"
import type { Problem, TreeError } from "std/sandbox"

export let trees = dir("trees")

/// Saves the signed-in user's home page, checked and compiled first.
export action fn publish(source: string): Problem[] {
  let user = try await requireUser(request())   // signed out: a 401
  let _, err = try await trees.save(user.id, { files: [{ id: "home", source }], routes: [{ path: "/", file: "home" }] })
  return match err {
    null => [],
    Problems { problems } => problems,   // it doesn't check: show why
    Storage => fail err,
  }
}

Data

The schema is Weft. Queries go through its policies, and go live.

std/db runs on SQLite, Postgres and MySQL behind one API. Tables are record types; policies say who may read and write each row, and apply to every query a user's handle makes, raw SQL included, which is checked against the schema when the program compiles.

A page can read a query live: when a committed write changes its result, the server sends the rows that changed. A test writes who can do what as a file, so a policy change shows as a diff.

Data
db/schema.weft
weft
import { table, schema, primary, references, index, immutable, default, owned, flag, public } from "std/db"
import type { Principal } from "std/http"

export type User = { @primary id: string, name: string }
export type Todo = {
  @primary @default(uuid) id: string,
  @references(users.id) @index @immutable owner: string,
  title: string,
  @index @default(false) done: boolean,
  @index @default(false) public: boolean,
}

export let users = table<User, Principal>("users", { read: public(), update: owned("id") })
export let todos = table<Todo, Principal>("todos", {
  read: owned("owner").or(flag("public")),
  write: owned("owner"),
})
export let app = schema({ tables: { users, todos } })
lib/server/todos.weft
weft
import { request } from "std/http"
import { principal } from "std/auth"
import { sqlite, identify } from "std/db"
import { app, todos } from "db/schema"
import type { Todo } from "db/schema"

let db = try await sqlite(app, "todos.db")
identify(db, async () => try await principal(request()) else null)

/// Open todos the caller may see: theirs and the public ones.
export query fn openTodos(q: string): Todo[] {
  return try await db.query.todos().filter(t => !t.done && t.title.startsWith(q))
}

export query fn openCounts(): { name: string, open: number }[] {
  return try await db.sql"select u.name, count(t.id) as open from users u left join todos t on t.owner = u.id and t.done = {false} group by u.name"
}
routes/page.weft
weft
import { openTodos } from "lib/server/todos"

let mut q = ""
derived found = await openTodos(q)
---
<TextField bind:value={q} placeholder="Search" />
@for t of found.value ?? [] key t.id {
  <Text>{t.title}</Text>
}
db/access/todos.txt (written by a test: r read, u update, d delete, i insert)
rowanyoneannabob
a-open----rudi----
b-private--------rudi
b-publicr---r---rudi

Components

shadcn's components, in Weft, in your project.

Weft's primitives are headless: behaviour, focus, keyboard and accessibility, but no look. weft component copies styled components from the registry into components/ui/, where they're your code to change, with a theme for light and dark.

UI components
sh
weft component card input label button
A profile card built from the registry's Card, Label, Input and ButtonA profile card built from the registry's Card, Label, Input and Button
routes/settings/page.weft
weft
let mut name = "Ada Lovelace"
let mut email = "ada@example.com"
---
<Card footer className="w-96">
  <CardHeader>
    <CardTitle>Profile</CardTitle>
    <CardDescription>How others see you.</CardDescription>
  </CardHeader>
  <CardContent className="flex flex-col gap-4">
    <Box class="flex flex-col gap-2">
      <Label>Name</Label>
      <Input bind:value={name} />
    </Box>
    <Box class="flex flex-col gap-2">
      <Label>Email</Label>
      <Input bind:value={email} />
    </Box>
  </CardContent>
  <CardFooter className="flex justify-end gap-2">
    <Button variant="ghost">Cancel</Button>
    <Button>Save</Button>
  </CardFooter>
</Card>

Status

What works today, and what doesn't yet.

Weft is in development, and built in steps. Everything on this site is checked by the compiler when the site is built; what's listed as working has its tests in the repository.

The reference
  • WorksThe language and its tools. The checker, formatter and diagnostics; weft new, check, fmt, test.
  • WorksThe web. Weft compiled to JavaScript and the DOM, styles to static CSS; pages rendered on the server and taken over by the browser.
  • WorksThe server. Server functions, std/http, std/auth (passwords, passkeys, OAuth), std/app, std/s3, std/time, and user code through std/sandbox.
  • WorksThe desktop app on the Rust VM, drawn by its own GPU renderer; 26 registry components.
  • WorksData. std/db on SQLite, Postgres and MySQL: the schema in Weft, typed queries and SQL, policies and migrations.
  • WorksLive data. std/live: channels over WebTransport or WebSocket, and live queries that send the pages reading them what changed.
  • In progressPrimitives in Weft. On the web, the headless primitives are still Svelte components under the compiled code; they move to Weft one by one.
  • NextSpeed and reach. The VM runs Weft 2.4× as fast as QuickJS runs the same JavaScript; the target is 3×. Release builds for macOS and Windows.
  • NextThe editor and the MCP server, designed: one tool overlaid on any running app, both editing it through one checked edit API.
  • LaterMobile through native views; machine code if the benchmarks call for it.

Start in a minute.

Install the weft command, make an app and open it.

curl -fsSL https://weft-lang.dev/install.sh | sh
sh
weft new hello && weft dev hello

Weft is in development. The reference is the spec as it stands today.