Skip to content

CrateStackOne schema in, three role-specific macros out

Build typed services from one schema — server-side Postgres, embedded SQLite (mobile, desktop, browser-via-OPFS), or HTTP client — with generated delegates, routes, policy checks, and clients.

The CrateStack mark, three stacked isometric crates

CrateStack is a schema-first Rust framework that turns one .cstack file into typed runtimes for three deployment shapes: a Postgres-backed server, an embedded SQLite ORM that works on mobile, desktop, and browsers via OPFS, and a HTTP client. One schema in, three role-specific macros out — each emits only what its target needs, no transitive sqlx in mobile builds, no rusqlite in server builds.

INFO

Define your service once in .cstack, then pick a macro: include_server_schema! for sqlx-backed Postgres servers, include_embedded_schema! for offline-capable apps (native sync, browser async via OPFS), or include_client_schema! for the generated Rust client. Each emits a cratestack_schema module shaped for that one role — Dart, TypeScript, and gRPC clients are generated separately via CLI subcommands.

Why CrateStack ​

CrateStack is built for teams that want framework leverage without giving up Rust ownership. You define the data model and policy surface once, and the framework handles the repetitive service plumbing around it.

  • What you author. You write a .cstack schema that defines models, procedures, auth shape, mixins, and policy rules.
  • What gets generated. CrateStack can generate SQLx-backed delegates, Axum CRUD and procedure routes, policy-aware runtime surfaces, and typed Rust or Dart clients.
  • Where it fits best. The current slice is strongest for internal Rust services that want typed CRUD, generated contracts, and host-owned auth without building a custom framework from scratch.

From Schema To Service ​

  1. Define the contract. Model your auth principal, shared mixins, models, and policies in a .cstack file.
  2. Pick your macro. Use include_server_schema!("…", db = Postgres) for the server, include_embedded_schema! for embedded ORM, or include_client_schema! for HTTP-only clients. Each validates the schema at compile time and emits a cratestack_schema module shaped for that role.
  3. Wire your runtime. Server: build with a sqlx::PgPool and bind your application auth through the host-owned provider boundary. Embedded: open a RusqliteRuntime (native) or install OPFS first inside a Worker (browser). Client: construct a CratestackClient against the server's URL.
  4. Choose your surface area. Use the generated delegates directly, mount generated Axum routers (server only), or do both depending on how much API surface you want exposed.

What You Get Today ​

  1. compile-time schema validation, split into three role-specific macros (include_server_schema! / include_embedded_schema! / include_client_schema!)
  2. generated SQLx-backed model delegates (server) and rusqlite-backed delegates (embedded)
  3. generated Axum CRUD and procedure routes (server)
  4. generated policy enforcement for the supported subset (server only — embedded runtime is unauthenticated by design; clients are untrusted)
  5. generated Rust, Dart, and TypeScript client surfaces
  6. reusable schema mixins for shared field sets
  7. banking-grade primitives: idempotency, optimistic locking, transactional audit, explicit transaction isolation (run_in_isolated_tx; the @isolation procedure attribute is ignored through 0.14.0 and enforced since 0.14.1, see Transaction isolation), soft delete, rate limiting, validators, Decimal scalar, forward-only migrations
  8. embedded SQLite backend (cratestack-rusqlite) — sync API, bundled SQLite, exact-precision Decimal round-trip; works on native (mobile, desktop) and wasm32-unknown-unknown (browser, OPFS-backed) from the same source

WARNING

CrateStack is usable today, but the public v0 track is narrower than the broader target architecture. COSE transport, parts of the client runtime, richer schema coverage, and some policy features are still deferred. Use Current State as the source of truth for adoption decisions.

Explore By Goal ​

Repository Note ​

This documentation tree is a standalone VitePress project. The framework code itself lives in a separate CrateStack repository.

Rust API Docs ​

Generated Rust API documentation is published at https://rust-doc.cratestack.dev/.

Released under the MIT License.