TrailBase Documentation
repository·main·Indexed 26 days ago
https://github.com/trailbaseio/trailbaseAn open, sub-millisecond, single-executable Firebase alternative built with Rust, Wasmtime, and SQLite. It features type-safe REST and realtime APIs, a built-in WebAssembly runtime, authentication, geospatial capabilities, and an integrated Admin UI. TrailBase provides first-party client libraries for JavaScript/TypeScript, Dart/Flutter, Rust, C#/.Net, Swift, Kotlin, Go, and Python.
What's inside TrailBase
- TrailBase is an open, single-executable Firebase alternative designed for sub-millisecond performance. It features type-safe APIs, a built-in WebAssembly (Wasmtime) runtime, real-time capabilities, authentication, and an integrated Admin UI. It is built using Rust, SQLite, and Wasmtime.
Overview of TrailBase Auth UI WASM Component
mainThe TrailBase Auth UI is a standalone WebAssembly (WASM) component used for authentication interfaces. It has been unbundled from the core TrailBase engine to allow for easier customization, better composability via a plugin-like system, and to reduce overhead for users who do not require the default UI.
Developers can build their own custom Auth UIs either client-side or server-side.
Overview of the TrailBase Client
mainThe TrailBase Client is the first-party library used to connect web applications and headless environments (such as Node.js or Deno) to a TrailBase instance. TrailBase itself is a single-executable Firebase alternative featuring type-safe APIs, a built-in WebAssembly runtime, real-time capabilities, authentication, and an admin UI, built using Rust, SQLite, and Wasmtime.Compare TrailBase with PocketBase and Supabase
mainTrailBase is positioned as a middle ground between Supabase and PocketBase:
- Supabase: Known for versatility and principled architecture.
- PocketBase: Known for being a single-executable, SQLite-based, easy-to-use offering.
- TrailBase: Aims to combine the flexibility and architecture of Supabase with the low-overhead and ease of use found in PocketBase.
Understand TrailBase scaling and performance
mainTrailBase is built on SQLite, providing high concurrency and sub-millisecond response times.
- Scaling Strategy: It supports 'multi-reader, single-writer' horizontal scaling via read replication. For massive scale, vertical scaling is often sufficient for tens or hundreds of thousands of concurrent users.
- Write Performance: It is suitable for most workloads unless you require hundreds of thousands of latency-critical, consistent writes per second.
- Disaster Recovery: You can achieve disaster recovery and fail-over using tools like LiteStream to maintain eventually consistent copies of your data.
- Modularity: TrailBase is designed to be modular, allowing you to replace or extend components (like adding a document store or queuing system) as your scale requirements change.
License Information: Open Software License v. 3.0 (OSL-3.0)
mainTrailBase is licensed under the Open Software License version 3.0 (OSL-3.0).
Key Terms for Users and Developers:
- Permissions: You are granted a worldwide, royalty-free, non-exclusive, sublicensable license to reproduce, translate, adapt, modify, distribute, perform, and display the Original Work.
- Derivative Works: You may create derivative works, but any copies of the Original Work or Derivative Works that you distribute or communicate to the public must also be licensed under the Open Software License.
- External Deployment: If you deploy the work in a way that allows others to use it (e.g., as a network application), this is considered a distribution under the license terms.
- Attribution: You must retain all copyright, patent, or trademark notices from the original source code. You must also include a prominent notice in your derivative works stating that you have modified the original work.
- Patent License: The license includes a grant of patent rights from the licensor for patent claims embodied in the Original Work.
- No Endorsement: You cannot use the names of the Licensor, contributors, or their trademarks to endorse or promote products derived from the work without express permission.
- Disclaimer: The work is provided on an "AS IS" basis without any warranties of any kind.
Use the TrailBase Client for Flutter and Dart
mainThe TrailBase Client is the first-party library designed to connect Flutter or Dart applications to a TrailBase backend. TrailBase provides a sub-millisecond, single-executable Firebase alternative with type-safe APIs, a built-in WebAssembly runtime, real-time capabilities, authentication, and an admin UI.Compare TrailBase performance benchmarks
mainTrailBase performance is evaluated against alternatives like SupaBase, PocketBase, and vanilla SQLite. Key performance characteristics include:
- Insertion Speed: TrailBase is significantly faster than competitors for high-volume inserts (e.g., 100k records), outperforming Payload, SupaBase, and PocketBase in benchmarked scenarios.
- Resource Utilization: TrailBase maintains a low footprint, typically consuming between 90MB and 150MB of memory (RSS) and utilizing 4 to 5 CPUs, making it suitable for small VPS environments. This is significantly lower than SupaBase's multi-service architecture.
- Latency: TrailBase offers sub-millisecond read latencies, comparable to Redis, but functions as primary data rather than a cache. This can simplify stacks by eliminating the need for separate caching layers.
- Runtime Performance: While JS/TS execution via the WASM runtime is comparable to JIT-less engines (like Goja), guest languages that compile to WASM (like Rust) see massive performance gains (up to ~135x speed-up).
Protect TrailBase Configuration
mainIn production, TrailBase configuration should be read-only to prevent accidental changes. You can achieve this by locking down file permissions or mounting the configuration as read-only if running in a container.
Important: Ensure that the data directory remains writable.
Build and deploy TypeScript WASM components
mainTo turn a TypeScript endpoint into a
.wasmcomponent that TrailBase can load:- Build the JavaScript library using
npx vite build. - Componentize the output using
jco:npx jco componentize dist/index.js -w node_modules/trailbase-wasm/wit -o dist/component.wasm. - Copy the resulting
component.wasminto the<traildepot>/wasm/directory.
# Build a JavaScript library from our TypeScript endpoint: npx vite build # Build the WASM component: npx jco componentize dist/index.js -w node_modules/trailbase-wasm/wit -o dist/component.wasm # Copy it to our <traildepot>/wasm mkdir -p <traildepot>/wasm cp dist/component.wasm <traildepot>/wasm/- Build the JavaScript library using
Implement relations in TrailBase
mainTrailBase handles relations using standard SQL patterns. All relations are modeled as edges (tuples of
parent id, child id).- 1:1 and 1:M relations: These are typically denormalized by placing the foreign key directly in the child record (
primary key, foreign key). This allows for built-in SQL features likeON DELETEorON UPDATEcascading. - N:M (Many-to-Many) relations: These require a separate "bridge" table containing
(foreign key, foreign key)edge records to manage the cardinality.
While some databases (like PocketBase) use JSON arrays for relations, TrailBase follows SQL best practices by using foreign keys and bridge tables to ensure compatibility with SQLite's relational engine and referential integrity.
- 1:1 and 1:M relations: These are typically denormalized by placing the foreign key directly in the child record (
Configure Email via SMTP
mainBy default, TrailBase uses the machine'ssendmailsetup, which is prone to being flagged as spam. For production, you should configure TrailBase to use an SMTP server from a provider like Brevo, Mailchimp, or SendGrid to ensure reliable delivery from your domain.