Skip to the page

Guides · Start building

Your first app

napalm new scaffolds a notes app with sign-in, a live list, file uploads and search, and five commands take it live.

In the schema
—

What you’ll build#

You will build a browser-direct notes app with no custom server. People sign up with an email and password, keep notes synchronized across open tabs, attach files and search notes by both meaning and keywords. One command scaffolds the app, and five commands configure the project.

FeatureBuilt withFile
Sign-inThe project’s own sign-inFilesrc/SignInForm.tsx
Note ownershipOne access rule per typeFiledbschema/default.gel
A list that stays currentA live queryFilesrc/Notes.tsx
FilesA record, then the bytes to the bucketFilesrc/Files.tsx
SearchA vector index and a text indexFilesrc/Search.tsx

The other Apps guides start from this project. Next.js & React moves it onto a server, and Realtime & collaboration shares notes between people.

Declarative schema & policies

dbschema/default.gel defines Note, file attachments, vector and keyword indexes, and per-owner access rules in one file.

Named deployed queries

Each .edgeql file in dbschema/queries deploys by name and compiles into typed calls and React hooks via napalm generate.

Cross-tab live subscriptions

useLiveQuery streams commit patches over one shared SSE connection so open tabs stay current with zero manual refetches.

Before you start#

The CLI, signed in
The quickstart installs the CLI and runs napalm login.
A project
napalm projects lists your projects. This page uses a new project named notes. On a project that already has a schema, read the plan first with napalm schema push notes --plan.
Node.js 18 or later
For the dev server.

Make the app#

Terminal
napalm new notes-app notescd notes-app

napalm new scaffolds a Vite and React app in a new folder. Passing the project name writes its address to .env.local and prints tailored setup commands. The folder also includes AGENTS.md and CLAUDE.md describing how the project uses Napalm, plus .mcp.json registering the project’s MCP server.

Set the project up#

Run five commands from the app’s folder. The commands napalm new printed include your cluster’s name.

Terminal
# The schema, and the queries in dbschema/queries, deployed by namenapalm schema push notes # The API, for this app's dev servernapalm endpoint notes --enable --passthrough all --allow-origin http://localhost:5173 # Sign-in with an email and a passwordnapalm sign-in set notes --app-name Notes --email-password --no-require-verification # Buckets for the files, on the project's clusternapalm storage enable <cluster> files # What's on, what's missing, and the command for eachnapalm status notes
--allow-origin
A project’s API answers a browser only from listed origins, including the port. The dev server therefore stays on port 5173.
--passthrough all
Lets a session send a custom statement. The app needs custom statements only for the search box and calls deployed queries for everything else. --passthrough keys restricts sessions to deployed queries, and the search must then be a deployed query too.
--no-require-verification
Address confirmation needs a mail server (napalm sign-in email), so this setup turns confirmation off. Turn confirmation on before real people sign up.

Run the app#

Terminal
npm installnpm run dev

Open http://localhost:5173, sign up and add a note.

Look inside the app#

  1. One rule sets note ownership

    The schema declares one access policy per type, limiting each note or file to its owner. The app never checks access in client code: every query, live query and search runs under the rule, so unreadable notes are omitted inside PostgreSQL.

    dbschema/default.gel
    # Napalm's extension brings auth and ai. This schema declares them too, for the types the schema uses.using extension auth;using extension ai;using extension files;using extension napalm;using future simple_scoping; module default {  # Whoever is asking: the identity of the session a call came with. Nobody, for a call with no session.  global caller := global ext::auth::ClientTokenIdentity;   # Napalm's own embedding provider: there's no key to set, and what it embeds is on your bill.  abstract type NapalmEmbedding extending ext::ai::EmbeddingModel {    annotation ext::ai::model_name := 'openai/text-embedding-3-small';    annotation ext::ai::model_provider := 'napalm';    annotation ext::ai::embedding_model_max_input_tokens := '8191';    annotation ext::ai::embedding_model_max_batch_tokens := '8191';    annotation ext::ai::embedding_model_max_output_dimensions := '1536';    annotation ext::ai::embedding_model_supports_shortening := 'true';  }   type Note {    required owner: ext::auth::Identity;    required title: str;    required body: str;     # A search reads both: the first finds a note by its meaning, the second by its words.    deferred index ext::ai::index(embedding_model := 'openai/text-embedding-3-small')      on (.title ++ '\n\n' ++ .body);    index fts::index on ((      fts::with_options(.title, language := fts::Language.eng, weight_category := fts::Weight.A),      fts::with_options(.body, language := fts::Language.eng, weight_category := fts::Weight.B)    ));     # The one rule: a note is its owner's. Every query, live query and search runs under it.    access policy owner_has_full_access      allow all      using (.owner ?= global caller);  }   # A file is a record: its bytes are in the project's bucket, and the same kind of rule says who may have them.  type Attachment extending ext::files::File {    required owner: ext::auth::Identity;     access policy owner_has_full_access      allow all      using (.owner ?= global caller);  }}
  2. One client carries the session

    SignIn holds the signed-in session, and the client attaches it to every call. When someone signs in or out, the client clears active results and reruns live queries as the new caller.

    src/napalm.ts
    // src/napalm.tsimport { NapalmClient, SignIn, webStore } from 'napalm-client' /** The project's address, from .env.local: `napalm endpoint <project>` prints it. */export const address = import.meta.env.VITE_NAPALM_URL as string /** Who is signed in, kept in this browser. */export const signIn = new SignIn(address, { store: webStore() }) /** One client for everything: it sends the session, and starts its live queries again when the person changes. */export const napalm = new NapalmClient(address, { signIn }) /** * Calls a deployed query by its name, as whoever is signed in, and gives its rows. `npm run generate` writes a typed * call for each query in dbschema/queries, which is what an app that grows should use. */export async function call<Row>(name: string, variables: Record<string, unknown> = {}): Promise<Row[]> {  const response = await napalm.fetch(`${address}/query/${name}`, {    method: 'POST',    headers: { 'Content-Type': 'application/json' },    body: JSON.stringify({ variables }),  })  const answer = await response.json()  if (!response.ok) throw new Error(answer.error?.message ?? answer.error?.code ?? response.statusText)  return answer.data}
  3. The list is a live query

    The query carries no owner filter because the access rule restricts rows to the caller’s notes automatically.

    dbschema/queries/myNotes.edgeql
    # The caller's notes. The rule decides whose they are: the query doesn't say.select Note { id, title, body }order by .title

    useLiveQuery returns the query’s rows and keeps them current. Adding a note takes only the insert, with no manual refetch.

    src/Notes.tsx
    // src/Notes.tsximport { deployed } from 'napalm-client'import { useLiveQuery } from 'napalm-client/react'import { useState, type FormEvent } from 'react'import { call } from './napalm' type Note = { id: string; title: string; body: string } /** dbschema/queries/myNotes.edgeql, by its name. */const myNotes = deployed<Note, Record<string, never>>('myNotes') export function Notes() {  // Kept current: a note added here, in another tab or by an agent shows up without asking again. The access rule  // runs inside it, so these are only ever the notes of whoever is signed in.  const { rows, error, isLoading } = useLiveQuery(myNotes, {})  const [title, setTitle] = useState('')  const [body, setBody] = useState('')   const add = async (event: FormEvent) => {    event.preventDefault()    await call('addNote', { title, body })    setTitle('')    setBody('')  }   return (    <section>      <h2>Your notes</h2>      <form onSubmit={add}>        <input placeholder="Title" value={title} onChange={(event) => setTitle(event.target.value)} required />        <input placeholder="Body" value={body} onChange={(event) => setBody(event.target.value)} required />        <button type="submit">Add</button>      </form>      {error && <p role="alert">{error.message}</p>}      {isLoading ? (        <p>Loading…</p>      ) : (        <ul>          {rows?.map((note) => (            <li key={note.id}>              <strong>{note.title}</strong> {note.body}            </li>          ))}        </ul>      )}    </section>  )}
  4. A file is a record plus bytes

    The query that sets a file’s size receives the upload plan. napalm.upload then streams bytes straight to the bucket, splitting large files into parallel parts. The same access rule governs downloads.

    dbschema/queries/addFile.edgeql
    # The query that sets a file's size is the one given its upload.select (insert Attachment {  owner := global caller,  file_name := <str>$name,  file_size := <int64>$size,}) { id, file_upload }
  5. Search reads two indexes

    The Note type declares an ext::ai::index for semantic search and an fts::index for keyword search. napalm.search('Note', query) fuses both indexes under the same access rule, so only the caller’s own notes can match.

Add your own query#

Each query lives in dbschema/queries, and its file name becomes the call name. Save the query below as titlesStarting.edgeql.

dbschema/queries/titlesStarting.edgeql
# The caller's notes whose title starts with what was typed.select Note { id, title }filter .title ilike (<str>$start ++ '%')order by .title
Terminal
napalm schema push notesnpm run generate

Pushing deploys the query and refuses any schema change that would break a deployed query. npm run generate writes a typed call and a live hook for each query into src/generated so your components use generated types instead of untyped call.

src/Titles.tsx
// src/Titles.tsximport { useTitlesStarting } from './generated/hooks' export function Titles({ start }: { start: string }) {  // Typed from the query: start is a string, and each row has an id and a title.  const { rows } = useTitlesStarting({ start })  return (    <ul>      {rows?.map((note) => (        <li key={note.id}>{note.title}</li>      ))}    </ul>  )}

Check the app#

  1. Open a second tab

    Add a note in one tab. The note appears in the other tab without a reload.

  2. Sign up as someone else in a private window

    The new person’s list is empty, and a search for a word from the first person’s note finds nothing. No app code enforces the separation.

  3. Check the project status

    napalm status notes shows each layer as on, and napalm people reach counts the rows one person can read and change, type by type.

Next steps#

Sign-in for your app
Magic links, Google and GitHub, passkeys, address confirmation and session storage.
Realtime & collaboration
Shared notes, drag-and-drop ordering and active viewers.
React, Vite & single-page apps
Cross-tab PKCE sessions, generated live hooks, direct browser uploads and deployed-query lockdown.
Next.js & React
The same app with a server: sign-in in a cookie, pages rendered as the person, lists still live.
Files, media & document search
Multipart file progress, background PDF passage extraction and cited hybrid search.
Testing & verification
Caller-matrix access tests, dry-run write previews and pull-request CI gates.
Environments & going live
A development branch and the settings to lock down before launch.
Schema
Types, links and access policies for your own app.

Type a word or two to search every docs page.