Skip to the page

First principles

Chapter 2 of 11

The six pillars

Six architectural rules hold across every feature in Napalm. Together, those rules keep access, transactions and shard placement consistent as your app grows.

Compiling your backend from a single schema works because Napalm enforces six rules across the compiler and runtime, from your first local migration to multi-shard failover.

Try it

Remove body from Note in your starter schema and run napalm schema push. Napalm checks every deployed query first and refuses the migration before anything changes.

Your terminal
napalm schema push notes
dbschema/queries/myNotes.edgeql
InvalidReferenceError: object type 'default::Note' has no link or property 'body'
dbschema/queries/addNote.edgeql
InvalidReferenceError: object type 'default::Note' has no link or property 'body'
Nothing was applied because the new schema would break these queries. Fix the queries or the schema.
Napalm lists every saved query that references body and leaves the database untouched.

One typed graph#

Application tables, binary files (ext::files::File), vector and full-text indexes (ext::ai::index, fts::index), background jobs (ext::napalm::Job) and permission grants all live as typed objects and links in dbschema/default.gel.

dbschema/default.gel
type Note {  required owner: ext::auth::Identity;  required title: str;  required body: str;   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)  ));} type Attachment extending ext::files::File {  required owner: ext::auth::Identity;   access policy owner_has_full_access    allow all    using (.owner ?= global caller);}
Records, search indexes and file attachments live side by side in one schema.

Full-text indexes and queued jobs commit inside the write transaction, while deferred vector embeddings refresh in the background. Every search, download and job enforces the same schema access policies without external sync workers.

Caller-bound#

Every stored object type starts closed over the API. Napalm verifies each bearer credential, binds global caller or configured service globals inside PostgreSQL, and evaluates access policy expressions in the same EdgeQL language as your queries.

dbschema/default.gel
global caller := global ext::auth::ClientTokenIdentity; type Note {  access policy owner_has_full_access    allow all    using (.owner ?= global caller);}
Access policies walk links from the verified caller identity.

One policy governs HTTP queries, live streams, signed file downloads, vector search, actions, jobs and MCP tools. Time-limited rules check datetime_of_statement() on the statement clock, and org tokens (napalm_…) manage clusters without reading row values.

Closed by default

Types without a matching policy return zero rows and refuse writes.

Verified identity

Napalm binds the caller identity inside PostgreSQL before any query runs.

Compiled#

Every EdgeQL expression carries a static type and cardinality. When you push changes, the compiler checks your schema, access policies and saved .edgeql query files together before applying DDL.

Terminal
napalm generate notes --lang ts
Generate typed SDKs, CLI commands and MCP tools from checked query files.

Saved queries compose dynamic UI filters and cursors with typed optional parameters, while POST /query runs parameterized ad-hoc statements and /ask compiles plain-English questions read-only. In every path, the compiler lowers the query and its touched policies into a single SQL statement without N+1 round trips.

Commit-atomic#

Row changes, ledger updates and queued ext::napalm::Job records commit or roll back together in one PostgreSQL transaction. Live query patches, notify webhooks and file upload windows fire only after commit, so rolled-back writes and dry-run previews emit nothing.

dbschema/queries/addNoteWithReminder.edgeql
with  note := (insert Note { owner := global caller, title := <str>$title, body := <str>$body }),  job := (insert ext::napalm::Job { query := 'sendReminder', variables := <json>(note := <str>note.id) }),select note { id }
Inserting a note and queueing its reminder commit together in one statement.

Committed responses return Napalm-Bookmark, and webhook pings carry Napalm-Position. Replicas and downstream workers wait for that commit position before reading, so callers never observe stale rows after their own writes.

Distributed from links#

Conventional sharding forces you to copy a shard key across every table, foreign key and query. In Napalm, the compiler walks required single links upward to infer placement roots for any domain hierarchy (Account, Project, Organization or Site). ext::napalm::root annotations mark explicit roots, replicate lookup tables across shards or exclude secondary links from ownership. User identities (ext::auth::Identity) and multi links never claim shard ownership, so multi-org memberships and guest collaborators span roots freely.

Sharding from links

Required links group related records on one shard without shard-key columns.

Every table keeps a standard uuid primary key. Shards split and rebalance behind one project URL, bookmarks route reads to caught-up replicas and vector indexes scale past 100 million embeddings without query changes.

Checked and fault-tested#

Static checks block breaking migrations and unplaceable root links before deploy, while runtime diagnostics verify permissions and durability under load.

Terminal
napalm schema push notes --reviewnapalm explain-access notes <note-id> --as ben@example.com
Check migrations statically in CI or trace live access rules without exposing field values.

In production, napalm explain-access, napalm people reach, napalm insights and dry-run /ask inspect permissions, reachable row counts, per-policy latency and index recommendations safely. Every release also runs automated fault campaigns on the public chaos lab, where incomplete evidence is marked Inconclusive rather than Passed.

Policy diagnostics

Inspect live permissions and reachable row counts without reading field values.

Release fault tests

Every release faces crashes, network splits and full disks before rollout.

Before writing our first access policy, let’s look at how orgs, clusters, branches and credentials fit together.

Type a word or two to search every docs page.