trails
trails is a re-implementation of Ruby on Rails in TypeScript. Each package ports one Rails gem (or one gem Rails depends on), file for file and method for method. Class names, method names, argument order and error messages follow the Ruby source, translated by a fixed set of naming rules. Progress is measured by running Rails' own test suite, ported test for test, and by matching the Rails public API method by method.
The full Rails scaffold pipeline runs on it. trails new generates an app, generate scaffold writes the model, migration, controller, views, route and tests, db:migrate builds the table, and trails server serves working CRUD pages: Rails' scaffold views in the generated layout, forms with CSRF protection, flash notices, validation errors, and view reloading in development. The model is typed from the schema by trails-tsc, and the scaffold's functional tests, ported from Rails' templates, pass. The quickstart walks through all of it.
It is pre-release. Alpha builds are published to npm under the alpha dist-tag. Generate an app with the trails command from @blazetrails/trailties; its package.json depends on the matching ~ version of @blazetrails/trails:
<!-- #region npm-new -->
pnpm --package=@blazetrails/trailties@alpha --allow-build=esbuild dlx trails new blog
cd blog<!-- #endregion npm-new -->
The quickstart below runs from a checkout of this repository, the contributor path, so CI can verify it against main.
- Quickstart, verified end to end on 2026-10-23
- Models: the ActiveRecord surface
- Typed models with
trails-tsc - Packages
- Status and parity snapshot
- Requirements
- Development
- Contributing
Quickstart
CI runs every command in this section and compares every output block with what the run prints (scripts/quickstart/run.sh), on Linux with SQLite and with TRAILS_ENV and NODE_ENV unset. No step needs a workaround.
1. Build the framework from a checkout
Use Node 26 or later; the workspace's engines field enforces it at pnpm install.
<!-- #region quickstart-build -->
git clone https://github.com/blazetrailsdev/trails.git
cd trails
npm install -g corepack # Node 26 no longer bundles corepack
corepack enable
pnpm install
pnpm build # tsc --build over the workspace, ~10s
export TRAILS=$PWD<!-- #endregion quickstart-build -->
2. Generate an application
<!-- #region quickstart-new -->
cd ..
node $TRAILS/packages/trailties/bin/trails.js new blog --skip-install --skip-git
cd blog create package.json
create tsconfig.json
...
create config/routes.ts
create config/database.ts
create app/controllers/application-controller.ts
create app/models/application-record.ts
create app/views/layouts/application.html.tse
...The generated package.json asks for @blazetrails/* packages from the npm registry (the alpha builds above). To run against your checkout instead, point them at it with pnpm overrides, then install:
{
echo "overrides:"
for p in $TRAILS/packages/*; do
echo " \"$(node -p "require('$p/package.json').name")\": \"link:$p\""
done
echo " vitest: \"$(node -p "require('$TRAILS/node_modules/vitest/package.json').version")\""
printf 'allowBuilds:\n better-sqlite3: true\n esbuild: true\n'
} > pnpm-workspace.yaml
node -e '
const fs = require("fs"), app = JSON.parse(fs.readFileSync("package.json"));
const meta = require(process.env.TRAILS + "/packages/trails/package.json");
for (const name of Object.keys(meta.dependencies))
app.dependencies[name] = `link:${process.env.TRAILS}/packages/${name.slice(13)}`;
fs.writeFileSync("package.json", JSON.stringify(app, null, 2) + "\n");
'
pnpm install<!-- #endregion quickstart-new -->
3. Scaffold a resource and migrate
<!-- #region quickstart-scaffold -->
bin/trails generate scaffold Post title:string body:text invoke active_record
create db/migrate/20261023194933_create_posts.ts
create app/models/post.ts
invoke test_unit
create test/models/post.test.ts
create test/fixtures/posts.yml
invoke resource_route
route this.resources("posts");
invoke scaffold-controller
create app/controllers/posts-controller.ts
invoke tse
create app/views/posts
create app/views/posts/index.html.tse
create app/views/posts/edit.html.tse
create app/views/posts/show.html.tse
create app/views/posts/new.html.tse
create app/views/posts/_form.html.tse
create app/views/posts/_post.html.tse
invoke resource_route
invoke test_unit
create test/controllers/posts-controller.test.ts
create test/system/posts.test.ts
invoke helper
create app/helpers/posts-helper.ts
invoke test_unitpnpm db:migrate== 20261023194933 CreatePosts: migrating ======================================
-- createTable("posts")
-> 0.0082s
== 20261023194933 CreatePosts: migrated (0.0112s) =============================The migration subclasses Migration.get(8.0), Rails' ActiveRecord::Migration[8.0], and the migrate writes db/schema.ts from the live database, as Rails writes schema.rb:
// db/migrate/20261023194933_create_posts.ts
import { Migration } from "@blazetrails/activerecord";
export class CreatePosts extends Migration.get(8.0) {
async change(): Promise<void> {
await this.createTable("posts", (t) => {
t.string("title");
t.text("body");
t.timestamps();
});
}
}<!-- #endregion quickstart-scaffold -->
4. Query from a script
The model the generator wrote declares no attributes; they come from the table.
<!-- #region quickstart-query -->
<!-- prettier-ignore -->
// app/models/post.ts (generated)
import { ApplicationRecord } from "./application-record.ts";
export class Post extends ApplicationRecord {
}// script/hello.ts
import "../config/environment.ts";
import { Post } from "../app/models/post.ts";
const post = await Post.create({ title: "Hello", body: "First post" });
console.log(post.id, post.isPersisted());
console.log(await Post.count());
console.log((await Post.where({ title: "Hello" }).first())?.body);
console.log(Post.where({ title: "Hello" }).order("created_at").limit(10).toSql());node script/hello.ts1 true
1
First post
SELECT "posts".* FROM "posts" WHERE "posts"."title" = 'Hello' ORDER BY created_at LIMIT 10bin/trails routes Prefix Verb URI Pattern Controller#Action
posts GET /posts(.:format) posts#index
POST /posts(.:format) posts#create
new_post GET /posts/new(.:format) posts#new
edit_post GET /posts/:id/edit(.:format) posts#edit
post GET /posts/:id(.:format) posts#show
PATCH /posts/:id(.:format) posts#update
PUT /posts/:id(.:format) posts#update
DELETE /posts/:id(.:format) posts#destroy
trails_health_check GET /up(.:format) trails/health#show
trails_postmark_inbound_emails POST /trails/action_mailbox/postmark/inbound_emails(.:format) action_mailbox/ingresses/postmark/inbound_emails#create
trails_relay_inbound_emails POST /trails/action_mailbox/relay/inbound_emails(.:format) action_mailbox/ingresses/relay/inbound_emails#create
trails_sendgrid_inbound_emails POST /trails/action_mailbox/sendgrid/inbound_emails(.:format) action_mailbox/ingresses/sendgrid/inbound_emails#create
trails_mandrill_inbound_health_check GET /trails/action_mailbox/mandrill/inbound_emails(.:format) action_mailbox/ingresses/mandrill/inbound_emails#healthCheck
trails_mandrill_inbound_emails POST /trails/action_mailbox/mandrill/inbound_emails(.:format) action_mailbox/ingresses/mandrill/inbound_emails#create
trails_mailgun_inbound_emails POST /trails/action_mailbox/mailgun/inbound_emails/mime(.:format) action_mailbox/ingresses/mailgun/inbound_emails#create
trails_conductor_inbound_emails GET /trails/conductor/action_mailbox/inbound_emails(.:format) trails/conductor/action_mailbox/inbound_emails#index
POST /trails/conductor/action_mailbox/inbound_emails(.:format) trails/conductor/action_mailbox/inbound_emails#create
new_trails_conductor_inbound_email GET /trails/conductor/action_mailbox/inbound_emails/new(.:format) trails/conductor/action_mailbox/inbound_emails#new
trails_conductor_inbound_email GET /trails/conductor/action_mailbox/inbound_emails/:id(.:format) trails/conductor/action_mailbox/inbound_emails#show
new_trails_conductor_inbound_email_source GET /trails/conductor/action_mailbox/inbound_emails/sources/new(.:format) trails/conductor/action_mailbox/inbound_emails/sources#new
trails_conductor_inbound_email_sources POST /trails/conductor/action_mailbox/inbound_emails/sources(.:format) trails/conductor/action_mailbox/inbound_emails/sources#create
trails_conductor_inbound_email_reroute POST /trails/conductor/action_mailbox/:inbound_email_id/reroute(.:format) trails/conductor/action_mailbox/reroutes#create
trails_conductor_inbound_email_incinerate POST /trails/conductor/action_mailbox/:inbound_email_id/incinerate(.:format) trails/conductor/action_mailbox/incinerates#create
trails_service_blob GET /trails/active_storage/blobs/redirect/:signed_id/*filename(.:format) active_storage/blobs/redirect#show
trails_service_blob_proxy GET /trails/active_storage/blobs/proxy/:signed_id/*filename(.:format) active_storage/blobs/proxy#show
GET /trails/active_storage/blobs/:signed_id/*filename(.:format) active_storage/blobs/redirect#show
trails_blob_representation GET /trails/active_storage/representations/redirect/:signed_blob_id/:variation_key/*filename(.:format) active_storage/representations/redirect#show
trails_blob_representation_proxy GET /trails/active_storage/representations/proxy/:signed_blob_id/:variation_key/*filename(.:format) active_storage/representations/proxy#show
GET /trails/active_storage/representations/:signed_blob_id/:variation_key/*filename(.:format) active_storage/representations/redirect#show
trails_disk_service GET /trails/active_storage/disk/:encoded_key/*filename(.:format) active_storage/disk#show
update_trails_disk_service PUT /trails/active_storage/disk/:encoded_token(.:format) active_storage/disk#update
trails_direct_uploads POST /trails/active_storage/direct_uploads(.:format) active_storage/direct_uploads#createThe console loads every model before it prompts:
bin/trails consoletrails> const p = await Post.first()
undefined
trails> p.title
'Hello'
trails> await Post.where({ title: "Hello" }).count()
1<!-- #endregion quickstart-query -->
5. Serve it
The scaffold is a complete CRUD resource: a controller with index through destroy, a setPost before-action and postParams() over params.expect, and views ported from Rails' scaffold templates.
<!-- #region quickstart-controller -->
<!-- prettier-ignore -->
// app/controllers/posts-controller.ts (generated)
import { Post } from "../models/post.ts";
import { ApplicationController } from "./application-controller.ts";
export class PostsController extends ApplicationController {
static {
this.beforeAction(":_setPost", { only: ["show", "edit", "update", "destroy"] });
}
declare posts: Post[];
declare post: Post;
// GET /posts
async index(): Promise<void> {
this.posts = await Post.all();
}
// GET /posts/1
async show(): Promise<void> {}
// GET /posts/new
async new(): Promise<void> {
this.post = new Post();
}
// GET /posts/1/edit
async edit(): Promise<void> {}
// POST /posts
async create(): Promise<void> {
this.post = new Post(this._postParams());
if (await this.post.save()) {
await this.redirectTo(this.post, { notice: "Post was successfully created." });
} else {
await this.render("new", { status: ":unprocessable_entity" });
}
}
// PATCH/PUT /posts/1
async update(): Promise<void> {
if (await this.post.update(this._postParams())) {
await this.redirectTo(this.post, { notice: "Post was successfully updated.", status: ":see_other" });
} else {
await this.render("edit", { status: ":unprocessable_entity" });
}
}
// DELETE /posts/1
async destroy(): Promise<void> {
await this.post.destroyBang();
await this.redirectTo(this.postsPath(), { notice: "Post was successfully destroyed.", status: ":see_other" });
}
// Use callbacks to share common setup or constraints between actions.
private async _setPost(): Promise<void> {
this.post = await Post.find(this.params.expect("id"));
}
// Only allow a list of trusted parameters through.
private _postParams() {
return this.params.expect({ post: ["title", "body"] });
}
}<!-- #endregion quickstart-controller -->
<!-- #region quickstart-server -->
pnpm prepare # builds app/views, the scaffold's views included
bin/trails server -p 3927 # the default port is 3000; this run used 3927=> Trails application starting in development on http://localhost:3927
=> Vite dev server with HMR enabled
=> Ctrl+C to stop<!-- #endregion quickstart-server -->
Open http://localhost:3927/posts and the scaffold works as it does in Rails:
/posts,/posts/:id,/posts/newand/posts/:id/editrender Rails' scaffold views inside the generated layout, titled fromcontentFor("title").- The forms carry an authenticity token. Create redirects
302to the new post, update and destroy redirect303 See Other, and each shows itsnoticeonce. - Add
this.validates("title", { presence: true })toPost, restart the server, and an empty title re-renders the form with422, "1 error prohibited this post from being saved", andfield_with_errorsaround the field. - A non-GET request without a valid token answers
422 ActionController::InvalidAuthenticityToken. - Edits to a view show on the next request. Edits to a model need a restart: trails has no autoloader.
GET /posts, with the development-mode <!-- BEGIN … --> / <!-- END … --> template comments and blank lines stripped:
<!-- #region quickstart-page -->
<!-- prettier-ignore -->
<!DOCTYPE html>
<html>
<head>
<title>Posts</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-capable" content="yes">
<meta name="csrf-param" content="authenticity_token" />
<meta name="csrf-token" content="…" />
<link rel="icon" href="/icon.png" type="image/png">
<link rel="icon" href="/icon.svg" type="image/svg+xml">
<link rel="apple-touch-icon" href="/icon.png">
<link rel="stylesheet" href="/assets/stylesheets/application.css" />
</head>
<body>
<p style="color: green"></p>
<h1>Posts</h1>
<div id="posts">
<div id="post_1">
<p>
<strong>Title:</strong>
Hello
</p>
<p>
<strong>Body:</strong>
First post
</p>
</div>
<p>
<a href="/posts/1">Show this post</a>
</p>
</div>
<a href="/posts/new">New post</a>
</body>
</html><!-- #endregion quickstart-page -->
6. Type-check with trails-tsc
pnpm build runs trails-tsc --schema db/schema.ts, the schema-aware tsc. The model is typed from the schema with no declare lines. This file:
<!-- #region quickstart-typecheck -->
// app/models/check.ts
import { Post } from "./post.ts";
export class Check {
static async run(): Promise<void> {
const post = await Post.find(1);
const n: number = post.title;
}
}fails the build with:
app/models/check.ts(6,11): error TS2322: Type 'string | null' is not assignable to type 'number'.
Type 'null' is not assignable to type 'number'.<!-- #endregion quickstart-typecheck -->
The build also passes after generate scaffold.
7. Run the tests
pnpm testThe scaffold's controller test is a port of Rails' functional_test.rb.tt: it drives index, new, create, show, edit, update and destroy through ActionDispatch::IntegrationTest against the generated test/fixtures/posts.yml. The model test is Rails' the truth placeholder, a todo.
Test Files 1 passed | 1 skipped (2)
Tests 7 passed | 1 todo (8)Models: the ActiveRecord surface
A Rails model and its trails port, side by side. The TypeScript below ran against SQLite in the app above, with authors, comments, tags and a posts_tags join table added by migrations. The output shown is what it printed.
class Post < ApplicationRecord
belongs_to :author, optional: true
has_many :comments, dependent: :destroy
has_and_belongs_to_many :tags
validates :title, presence: true
validates :slug, uniqueness: true
scope :published, -> { where(published: true) }
scope :authored_by, ->(author) { where(author: author) }
enum :status, { draft: 0, published: 1, archived: 2 }, prefix: true
endimport { ApplicationRecord } from "./application-record.js";
import type { Author } from "./author.js";
export class Post extends ApplicationRecord {
static {
this.belongsTo("author", { optional: true });
this.hasMany("comments", { dependent: "destroy" });
this.hasAndBelongsToMany("tags");
this.validates("title", { presence: true });
this.validates("slug", { uniqueness: true });
this.scope("published", function () {
return this.where({ published: true });
});
this.scope("authoredBy", function (author: Author) {
return this.where({ author });
});
this.enum("status", { draft: 0, published: 1, archived: 2 }, { prefix: true });
}
}A scope body is a function, not an arrow function. The relation is this, as Rails instance_execs the lambda, and the arguments are the scope's own. An arrow (rel) => rel.where(...) receives no relation and throws.
The enum carries prefix: true because without it, the enum's own published scope (status = 1) replaces the published scope declared above it (published = 1). Rails does the same, with a warning in the log.
const dean = await Author.createBang({ name: "Dean" });
const ruby = await Tag.createBang({ name: "ruby" });
const post = await Post.createBang({
title: "Hello",
slug: "hello",
author: dean,
published: true,
});
await post.comments.createBang({ body: "First!", flagged: false });
await post.comments.createBang({ body: "spam", flagged: true });
await post.tags.push(ruby);
await post.statusPublishedBang(); // enum bang writer: persists
post.status; // "published"
const posts = await Post.published()
.authoredBy(dean)
.includes("comments", "tags")
.order({ created_at: "desc" })
.limit(20);
posts[0].tags.map((t) => t.name); // [ 'ruby' ]
Post.published().authoredBy(dean).order({ created_at: "desc" }).limit(20).toSql();
// SELECT "posts".* FROM "posts" WHERE "posts"."published" = 1 AND "posts"."author_id" = 1
// ORDER BY "posts"."created_at" DESC LIMIT 20
Post.statuses; // { draft: 0, published: 1, archived: 2 }
await Post.where({ status: "published" }).count(); // 1
await Post.statusArchived().count(); // 0
try {
await Post.createBang({ title: "", slug: "hello" });
} catch (e) {
// RecordInvalid: Validation failed: Title can't be blank, Slug has already been taken
}
const dup = new Post({ title: "Again", slug: "hello" });
await dup.isValid(); // false, after running the uniqueness SELECT
dup.errors.fullMessages; // [ 'Slug has already been taken' ]A model's columns are reflected from the database the first time it is queried or created, through the class or through an association. post.comments.createBang(...) above is the first thing to touch Comment in that process.
Association proxies
post.comments is chainable like a relation, awaitable to its records, and iterable once loaded:
const post = await Post.find(1);
await post.comments.where({ flagged: false }).order("created_at"); // [ Comment 'First!' ]
const all = await post.comments; // 2 records; loads the target
for (const c of post.comments) c.body; // 'First!', 'spam'
post.comments.map((c) => c.id); // [ 1, 2 ]
post.comments[0]?.body; // 'First!'
await post.comments.size(); // 2length is a method (Ruby's length), not the JS array property, so use await post.comments.size() for a count.
A singular association (belongsTo / hasOne) returns the loaded record synchronously when it is loaded or preloaded (includes("author")), and a promise that loads it otherwise, so await post.author always works.
Async, bangs and predicates
JavaScript has no synchronous database access, so every method that touches the database is async. Relations stay lazy, and you await the terminal call (first, count, toArray(), or the relation itself). The naming rules come from one generated table, docs/ruby-ts-conventions.md, which is also what parity:api matches on.
| Ruby / Rails | trails |
|---|---|
save!, create! | saveBang(), createBang() |
valid? | await isValid(): runs DB-backed validators |
changed?, persisted? | isChanged (getter), isPersisted() |
model[:title] | model.readAttribute("title") |
model[:title] = "x" | model.writeAttribute("title", "x") |
relation.to_a | await relation.toArray() |
Post.transaction { ... } | await transaction(Post, async () => { ... }) |
arel_table[:id] | table.get("id") |
Time / Date values | Temporal types from @blazetrails/date |
Date and time values are Temporal objects, not JS Date. A JS Date passed as a bind raises TypeError: quote: JS Date is not accepted — use a Temporal type. So write:
Post.where("created_at > ?", Temporal.Instant.from("2020-01-01T00:00:00Z")).toSql();
// SELECT "posts".* FROM "posts" WHERE (created_at > '2020-01-01 00:00:00')The longer guide is Trails Idioms. The places where trails diverges from Rails on purpose, and why, are catalogued per package on the package pages, generated from each package's ratified CLAUDE.md sections.
Database adapters
The adapter is picked by name in config/database.ts. Each one loads its own driver, which you install yourself:
adapter: | Driver |
|---|---|
sqlite3 | better-sqlite3 |
node-sqlite | Node's built-in node:sqlite |
expo-sqlite | expo-sqlite (React Native) |
libsql, libsql-remote, libsql-replica | libsql |
postgresql | pg |
mysql2 | mysql2 |
A URL config maps the sqlite:, postgres: and mysql: schemes onto those names (ActiveRecord.protocolAdapters). CI runs the ActiveRecord suite against SQLite, PostgreSQL and MySQL/MariaDB. The quickstart above was verified on SQLite only.
Typed models with trails-tsc
trails-tsc ships in @blazetrails/activerecord-cli. It is a tsc replacement that reads db/schema.ts and each model's static {} block, and rewrites the model file in memory at type-check time. Attribute types come from the schema, and association, scope and enum members come from the class body. So a model needs no hand-written declare lines. A generated app's build script already uses it (see step 6).
What the schema-driven typing covers today, checked against the app above:
- Attributes are typed from the column:
post.titleisstring | null, andpost.created_atis a Temporal instant/date-time. - Associations:
post.commentsis anAssociationProxy<Comment>, andpost.authorisAuthor | null | Promise<Author | null>. - Scopes are typed on the class and on
Relation<T>:Post.published()is aRelation<Post>, and so isPost.published().authoredBy(x). - Enums: the attribute is typed as its value names (
post.statusis"archived" | "draft" | "published" | null). The predicates, bang writers and scopes are typed too (isStatusDraft(),statusPublishedBang(),Post.statusArchived()), and enum scopes chain with other scopes.
The trails-tsc language-service plugin in the generated tsconfig.json covers .tse views only. Editor support for model virtualization is not built yet.
Outside a trailties app, dump the schema from a live database with ar db:schema:dump, then point trails-tsc --schema db/schema.ts at it. See packages/activerecord-cli.
Packages
Every package under packages/. "Rails source" names the upstream it ports. The parity figures are in the next section.
| Package | Rails source | What it is, and how usable it is today |
|---|---|---|
@blazetrails/activerecord | activerecord | The ORM: persistence, querying, associations, validations, callbacks, enums, migrations, schema dumping, transactions, encryption, fixtures. SQLite, PostgreSQL and MySQL adapters. The most complete package, and the one to evaluate first. |
@blazetrails/activemodel | activemodel | Attributes and type casting, validations, callbacks, dirty tracking, errors, naming, serialization, has_secure_password. Near-complete. |
@blazetrails/arel | activerecord/lib/arel | The SQL AST, managers and per-dialect visitors that ActiveRecord builds its queries with. Near-complete. Class names drive visitor dispatch, so do not minify them. |
@blazetrails/activesupport | activesupport | Inflector, core extensions, HashWithIndifferentAccess, callbacks, concerns, notifications, caching, message verifiers and encryptors, time zones, Duration, JSON, testing helpers. Broad and mostly complete. |
@blazetrails/activerecord-cli | the rails db:* tasks, standalone | The ar CLI for using ActiveRecord without trailties: ar new, generate:model / migration, db:*, console, runner, models:dump, plus the trails-tsc binary. Works. |
@blazetrails/actionpack | actionpack | ActionDispatch (routing and Journey, request/response, middleware, cookies, sessions, CSP, integration testing) and ActionController (Metal, Base, API, parameters, rendering, filters, rescue). Runs the full scaffold request cycle: routing, sessions, flash, CSRF protection and strong parameters. Coverage is in the parity snapshot below. |
@blazetrails/actionview | actionview | Template lookup and rendering, layouts, partials, and helpers (tag, URL, form, asset, text, number, date, sanitize). Templates are TSE, the trails analogue of ERB. Renders Rails' scaffold views, including formWith and its form builder. Coverage is in the parity snapshot below. |
@blazetrails/trailties | railties | The trails CLI (new, generate, server, db, routes, console, credentials), application boot and initializers, engines, generators, the Vite-backed dev server. Generates and serves a complete scaffolded app. |
@blazetrails/rack | rack gem | Rack: the request/response interface, Builder, and the standard middleware. Nearly complete. |
@blazetrails/rack-session | rack-session gem | Rack::Session::Abstract::Persisted / PersistedSecure / SessionId and the in-memory Pool store, which ActionDispatch's session stores build on. The cookie store and encryptor are not ported. |
@blazetrails/rack-test | rack-test gem | Rack::Test::Session, cookie jar, uploaded files and multipart, used by integration tests. Nearly complete. |
@blazetrails/globalid | globalid gem | GlobalID, SignedGlobalID and the locator. Nearly complete. |
@blazetrails/i18n | i18n gem | I18n config, simple and fallback backends, interpolation, pluralization and exceptions. The whole gem test suite is ported. |
@blazetrails/date | date gem | Ruby's Date / DateTime, built on Temporal (@js-temporal/polyfill). Re-exports Temporal, which is how trails represents time values. The ported date gem tests all pass. |
@blazetrails/did-you-mean | did_you_mean gem | SpellChecker with Jaro-Winkler and Levenshtein distances, for "Did you mean?" error suggestions. The parts trails uses are complete. |
@blazetrails/bcrypt | bcrypt gem | BCrypt::Password and BCrypt::Engine, behind ActiveModel's has_secure_password. |
@blazetrails/msgpack | msgpack gem | MessagePack packer, unpacker, factory and extension types, used by ActiveSupport's message serializers and ActiveRecord. |
@blazetrails/activejob | activejob | ActiveJob::Base with enqueuing, execution, callbacks, retry_on / discard_on, argument serialization, logging and instrumentation, plus the async, inline and test queue adapters. Solid Queue is a separate package. |
@blazetrails/actionmailer | actionmailer | ActionMailer::Base, mail views and layouts, delivery methods (SMTP, sendmail, file, test), previews, deliver_later through ActiveJob, and the mailer test case. |
@blazetrails/actionmailbox | actionmailbox | Inbound email: InboundEmail records, routing to mailboxes, the ingresses and their controllers, incineration, and the mailbox test helpers. |
@blazetrails/activestorage | activestorage | Attachments (has_one_attached / has_many_attached), blobs, the disk service, direct uploads, analyzers, previewers and variants through image-processing. |
@blazetrails/actiontext | actiontext | Fragments, attachments, attachables and Trix conversion. Early: no rich-text record yet, and about a fifth of its tests are ported. |
@blazetrails/solid-queue | solid_queue gem | The database-backed ActiveJob backend: job, execution and process records, queues, pauses, semaphores, workers, the dispatcher, the scheduler and recurring tasks. |
@blazetrails/solid-cable | solid_cable gem | The database-backed Action Cable subscription adapter: messages table, listener and trimming. |
@blazetrails/fugit | fugit gem | Cron, duration and natural time parsing, which Solid Queue's recurring tasks use. |
@blazetrails/et-orbi | et-orbi gem | Zoned times for fugit. |
@blazetrails/raabro | raabro gem | The parser combinator library fugit parses with. |
@blazetrails/chronic | chronic gem | Natural-language date parsing, used by fugit. |
@blazetrails/actioncable | actioncable | Action Cable's server half: channels, connections, the server and worker, the async, inline, test, PostgreSQL and Redis subscription adapters, remote connections, the helper and the channel and connection test cases. The browser client is the published @rails/actioncable. |
@blazetrails/marcel | marcel gem | MIME type detection by magic bytes, file name and declared type. |
@blazetrails/mini-mime | mini_mime gem | MIME type lookup by extension and content type, used by mail. |
@blazetrails/mail | mail gem | Email parsing and generation: messages, headers and fields, multipart bodies, encodings, and the delivery methods ActionMailer drives. |
@blazetrails/net-smtp | net-smtp gem | Ruby's SMTP client, over nodemailer's SMTPConnection. |
@blazetrails/image-processing | image_processing gem | Image transformation pipelines for ActiveStorage variants, with a libvips backend (wasm-vips) and an ImageMagick backend. |
@blazetrails/mini-magick | mini_magick gem | ImageMagick command lines, shelled out to as in Ruby. |
@blazetrails/builder | builder gem | Builder::XmlMarkup, behind ActionView's .builder templates. |
@blazetrails/tzinfo | tzinfo gem | Time zone lookups over the platform's IANA data, standing in for the parts of tzinfo ActiveSupport uses. |
@blazetrails/ruby-compat | Ruby core / stdlib | Ruby primitives that Rails calls and does not define (Range, Rational, Enumerator, String#succ, Hash#fetch semantics, Kernel#respond_to?, monitors, method_missing proxies). A leaf package; see its README. |
@blazetrails/rake | rake gem | Rake tasks, file tasks, rules, FileList, the application and DSL, behind trails tasks. |
@blazetrails/thor | thor gem | The command-line toolkit trailties' commands and generators are built on: commands, options, groups, actions and shell. |
@blazetrails/zeitwerk | zeitwerk gem | The application autoloader, run as a build step that writes the autoload tables. |
@blazetrails/rackup | rackup gem | The rackup server command and handler lookup. |
@blazetrails/vitest-matchers | none | Vitest matchers for the Minitest assertions whose meaning turns on Ruby semantics (truthiness, nil). |
@blazetrails/tse-compiler | erubi gem | The TSE (Trails Server Embedded) template compiler: lexer, parser and JS emitter with source maps. Used by actionview and the view build. |
@blazetrails/trails-tsc | none | A TypeScript 5.9 compiler wrapper with a plugin host. Today it builds and type-checks .tse views (trails-tsc-views) and provides the views language-service plugin. The model trails-tsc binary lives in activerecord-cli. |
@blazetrails/html-sanitizer | rails-html-sanitizer gem | FullSanitizer, LinkSanitizer and SafeListSanitizer, over sanitize-html. Small, and nothing in the workspace depends on it yet. |
@blazetrails/nokogiri | nokogiri gem (XML SAX only) | The slice of Nokogiri's XML SAX parser that ActiveSupport's XmlMini needs, over libxml2-wasm. Small. |
@blazetrails/website | none | Private. The project website and docs site (SvelteKit + VitePress), including the guides linked above. Not a library. |
Status and parity snapshot
As of 2026-11-11, main at 784200d33b, the day of trails' 10,000th pull request. To regenerate from a checkout:
pnpm parity:api --public-only # "Public API" column: Rails public methods with a TS counterpart
pnpm parity:api # "All methods" column: public + protected + private
pnpm parity:test # "Rails tests" column: Rails test cases matched by a ported testparity:api matches each Ruby method in the vendored Rails source (vendor/rails/v8.0.5.2, plus the vendored gems) to a TypeScript method by name, under the rules in docs/ruby-ts-conventions.md. parity:test matches each Rails test case to a ported test of the same name. A matched test passes in CI or is counted as skipped.
| Package (parity row) | Public API | All methods | Rails tests |
|---|---|---|---|
| activerecord | 5008 / 5126 (97.7%) | 6987 / 6991 (99.9%) | 8940 / 8965 (99.7%) |
| activemodel | 624 / 627 (99.5%) | 820 / 821 (99.9%) | 1037 / 1037 (100%) |
| arel | 783 / 784 (99.9%) | 1052 / 1052 (100%) | 739 / 739 (100%) |
| activesupport | 1715 / 1868 (91.8%) | 2110 / 2266 (93.1%) | 3065 / 3379 (90.7%) |
| actionpack: ActionDispatch | 1292 / 1384 (93.4%) | 1801 / 1809 (99.6%) | 1627 / 1670 (97.4%) |
| actionpack: ActionController | 593 / 655 (90.5%) | 852 / 854 (99.8%) | 1921 / 1949 (98.6%) |
| actionpack: AbstractController | 146 / 160 (91.2%) | 178 / 178 (100%) | 52 / 52 (100%) |
| actionview | 2349 / 2419 (97.1%) | 3057 / 3057 (100%) | 2524 / 2562 (98.5%) |
| actioncable | 358 / 390 (91.8%) | 496 / 496 (100%) | 213 / 215 (99.1%) |
| activejob | 267 / 269 (99.3%) | 369 / 369 (100%) | 395 / 395 (100%) |
| actionmailer | 175 / 189 (92.6%) | 230 / 230 (100%) | 251 / 255 (98.4%) |
| activestorage | 408 / 455 (89.7%) | 631 / 631 (100%) | 427 / 451 (94.7%) |
| actionmailbox | 125 / 137 (91.2%) | 148 / 167 (88.6%) | 82 / 87 (94.3%) |
| actiontext | 94 / 201 (46.8%) | 133 / 253 (52.6%) | 23 / 116 (19.8%) |
| trailties (railties) | 1100 / 1254 (87.7%) | 1661 / 1787 (92.9%) | 679 / 2419 (28.1%) |
| rack | 519 / 524 (99.0%) | 600 / 600 (100%) | 939 / 960 (97.8%) |
| rack-session | 60 / 60 (100%) | 98 / 98 (100%) | 123 / 124 (99.2%) |
| rack-test | 62 / 87 (71.3%) | 108 / 108 (100%) | 233 / 234 (99.6%) |
| rackup | 38 / 38 (100%) | 51 / 51 (100%) | 56 / 64 (87.5%) |
| rake | 349 / 389 (89.7%) | 464 / 465 (99.8%) | 589 / 599 (98.3%) |
| thor | 325 / 354 (91.8%) | 504 / 504 (100%) | 790 / 791 (99.9%) |
| zeitwerk | 104 / 104 (100%) | 147 / 147 (100%) | 381 / 418 (91.1%) |
| globalid | 64 / 64 (100%) | 93 / 93 (100%) | 148 / 148 (100%) |
| i18n | 235 / 236 (99.6%) | 329 / 329 (100%) | 307 / 307 (100%) |
| 973 / 996 (97.7%) | 1257 / 1278 (98.4%) | 1377 / 1639 (84.0%) | |
| net-smtp | 91 / 91 (100%) | 106 / 106 (100%) | 73 / 95 (76.8%) |
| mini-mime | 23 / 23 (100%) | 23 / 23 (100%) | 9 / 9 (100%) |
| solid-queue | 375 / 378 (99.2%) | 693 / 696 (99.6%) | 157 / 172 (91.3%) |
| solid-cable | 15 / 15 (100%) | 19 / 19 (100%) | 21 / 21 (100%) |
| fugit | 326 / 326 (100%) | 349 / 349 (100%) | 419 / 420 (99.8%) |
| et-orbi | 84 / 84 (100%) | 110 / 110 (100%) | 145 / 145 (100%) |
| raabro | 101 / 101 (100%) | 101 / 101 (100%) | 89 / 89 (100%) |
| chronic | 249 / 249 (100%) | 268 / 268 (100%) | 163 / 163 (100%) |
| builder | 19 / 21 (90.5%) | 34 / 34 (100%) | 98 / 98 (100%) |
| mini-magick | 122 / 122 (100%) | 125 / 125 (100%) | 145 / 145 (100%) |
| image-processing | 92 / 92 (100%) | 105 / 105 (100%) | 177 / 178 (99.4%) |
| marcel | 25 / 25 (100%) | 32 / 32 (100%) | 19 / 20 (95.0%) |
| did-you-mean | 14 / 14 (100%) | 16 / 16 (100%) | 7 / 7 (100%) |
| bcrypt | 16 / 16 (100%) | 18 / 18 (100%) | 39 / 39 (100%) |
| msgpack | 32 / 34 (94.1%) | 35 / 35 (100%) | 165 / 374 (44.1%) |
| erubi | 7 / 8 (87.5%) | 21 / 23 (91.3%) | 38 / 39 (97.4%) |
| crass | 61 / 70 (87.1%) | 61 / 70 (87.1%) | 10 / 15 (66.7%) |
| rails-dom-testing | 34 / 36 (94.4%) | 66 / 69 (95.7%) | 48 / 55 (87.3%) |
| nokogiri | 200 / 548 (36.5%) | 230 / 599 (38.4%) | 96 / 351 (27.4%) |
| tzinfo | 56 / 284 (19.7%) | 62 / 372 (16.7%) | 50 / 961 (5.2%) |
| date | n/a (C extension) | n/a | 137 / 137 (100%) |
| ruby-compat | n/a (not a gem) | n/a | 64 / 563 (11.4%) |
| Data layer (activerecord + activemodel + arel) | 6415 / 6537 (98.1%) | 8859 / 8864 (99.9%) | 10716 / 10741 (99.8%) |
| Overall | 20035 / 22226 (90.1%) | 26987 / 28857 (93.5%) | 29100 / 33891 (85.9%) |
The Overall row also counts the partial pg, mysql2, sqlite3, racc, loofah and rails-html-sanitizer rows, the actionpackversion row, and test support (activerecord-test-support, 41 / 56 public), which are left out of the table. The activerecord row also counts the ported sqlite3 gem internals the SQLite adapter uses (229 / 298 public).
Read the columns this way. API coverage says a method with the Rails name exists. The fidelity gates in CONTRIBUTING.md (call sets, call arguments, parameter names, arity) say how closely its body follows the Rails body. Test coverage is the better signal of what works. By that measure the data layer, ActionPack, ActionView, ActionCable, ActiveJob, ActionMailer, Rack, Rake, Thor, i18n, globalid, date and the Solid Queue scheduling stack (fugit, et-orbi, raabro, chronic) are close to done. ActiveStorage, ActionMailbox, Zeitwerk and mail are most of the way there. trailties, ActionText and the gems that are ported only as far as Rails needs them (tzinfo, nokogiri, msgpack) are where most of the remaining work is.
What the prose above means in practice:
- ActiveRecord / ActiveModel / Arel. Use them. Querying, associations (including
has_many :through, HABTM, polymorphic and composite keys), validations, callbacks, enums, migrations, schema dump/load, transactions, encryption and fixtures are ported, with Rails' test suite as the specification. The deliberate differences are that everything touching the database is async, and that time values are Temporal. - Standalone ActiveRecord (
ar, no web stack) works for create / migrate / status / schema dump / runner / console / models dump. - Full stack (
trails new): generates an app that type-checks, then boots, migrates, routes, runs a console, renders TSE views with layouts, and serves from Vite in development.generate scaffoldproduces a working CRUD resource with passing tests, as the quickstart shows. A real app is most likely to hit unported ActionView helpers.
Versioning and releases
Every public package is published at one version, as Rails versions its framework gems together from RAILS_VERSION. @blazetrails/trails is the rails meta-gem's counterpart: it depends on the frameworks at that version. A port of a third-party gem rides the trails version; the gem and version it ports are its package.json mirrors field. Internal dependencies are workspace:*, which pnpm publishes as an exact pin, so one install never holds two copies of ruby-compat or activesupport.
Before 1.0, a minor bump may break; a patch does not.
The first official release is 0.1.0-alpha1. Until then the packages sit at 0.1.0-alpha0, and alpha releases go out as 0.1.0-alpha0.1, 0.1.0-alpha0.2, … under the npm dist-tag alpha, so semver sorts every one of them below 0.1.0-alpha1 and latest never points at one.
To release, run pnpm release:version <version>, merge it, and push the tag v<version>. .github/workflows/release.yml builds and publishes every public package with npm provenance; a rerun skips versions already on the registry. Pull requests that touch release config run it as a dry run. After the publish, its registry job runs scripts/release/registry-check.sh on Node 26 against the version just published: the npm-new block above, and an install of @blazetrails/activerecord and @blazetrails/actionpack that must hold exactly one copy each of @blazetrails/ruby-compat and @blazetrails/activesupport. Before promoting a prerelease to latest, check that job and trailmap's canary workflow, which builds, tests and smoke-tests trailmap against the newest alpha.
No real publish runs until RFC 0100's publish-shape stories land: exclude-compiled-tests-from-published-dist, stop-publishing-sourcemaps, files-field-for-leaf-packages, unpublish-activerecord-test-harness, globalid-notice-file and package-size-budget-ci-gate.
Requirements
- Node >= 26, enforced by
engines. The repo and a generated app pin26.13.0in.node-version. - pnpm, through
corepack enable(Node 26 dropped the bundled corepack:npm install -g corepackfirst). The repo pinspnpm@12.3.4. - TypeScript 7.1 for the workspace, pinned to the exact nightly
7.1.0-dev.20260920.1that CI builds with. The pin moves to 7.1 stable when it ships (scheduled 2026-11-24). The packages that touch the compiler API usetypescript/unstable/*, which carries no semver guarantee, so their ranges are the exact build they were verified against:
| package | typescript | why |
|---|---|---|
@blazetrails/trailties | optional peer, 7.1.0-dev.20260920.1 | ./template-builder/testing's parseTs() uses API#transpileModule. |
@blazetrails/activerecord-cli | dependency, 7.1.0-dev.20260920.1 | the trails-tsc typecheck bin runs on the 7.1 API. |
@blazetrails/trails-tsc | dependency, typescript-5@npm:typescript@5.9.3 | it drives a programmatic --build and hosts a language-service plugin, neither of which TypeScript 7 offers yet. |
For trailties the peer is optional. Its runtime does not need the compiler, only the subpath named above does. trails-tsc's 5.9.3 is an alias, so it never collides with a project's own typescript. Both retire when TypeScript 7 ships a programmatic build API (RFC 0125-typescript-7-ground-floor in the tasks repo).
Development
npm install -g corepack # Node 26 no longer bundles corepack
corepack enable
pnpm install
pnpm build # tsc --build, ~10s cold
pnpm vitest run path/to/file.test.ts # run the files you touchedDo not run the whole suite locally. CI runs it on every push, across all three databases.
Database backends
ARCONN picks the backend, naming a connection exactly as Rails' test/config.yml does. Connection details come from separate environment variables.
| Backend | How to run locally | Connection settings |
|---|---|---|
| SQLite (default) | pnpm vitest run <file> | (none) |
| PostgreSQL | ARCONN=postgresql pnpm vitest run <file> | PGHOST PGPORT PGUSER PGPASSWORD |
| MySQL/MariaDB | ARCONN=mysql2 pnpm vitest run <file> | MYSQL_HOST MYSQL_PORT MYSQL_SOCK |
These are the keys Rails interpolates (vendor/rails/v8.0.5.2/activerecord/test/config.example.yml:12-20), plus the PG* set its postgresql: entries leave to libpq (config.example.yml:74-81). Each has a working default (localhost and the stock port), so a local server on default ports needs only ARCONN. ARCONN=sqlite3_mem selects the pure :memory: lane.
The credential and database name are fixed, as in Rails: the harness connects as username: rails with no password (config.example.yml:4,24) to activerecord_unittest (test/support/config.rb:28-34). docker compose up provisions that user for both PostgreSQL and MySQL, on tmpfs like the CI service containers. The one addition with no Rails counterpart is AR_DB_SLOT: trails runs parallel vitest workers and gives each an _N-suffixed copy of the database.
Contributing
trails is a port, and the bar is "would a Rails developer recognize this as the same method", not "do the tests pass". The rules, the naming table and the gates that enforce them are in:
- CONTRIBUTING.md: working principles, the
@internalconvention, and how progress is measured. - CLAUDE.md: the full rulebook (fidelity, deviation registers, the pre-PR gate sequence, and the language-shortcoming decisions ratified repo-wide).
- docs/ruby-ts-conventions.md: the generated Ruby → TypeScript naming rules.
Work is tracked as RFCs and stories in the separate tasks repository. Pick work with pnpm tasks ready, not from docs. The Rails source every port is checked against is vendored at vendor/rails/v8.0.5.2/ by pnpm vendor:fetch.
Disclaimer
Trails is not affiliated with, endorsed by, or connected to Ruby on Rails or the Rails Core team. Rails is an inspiration and a guiding light for this project's API design, but Rails and its trademarks belong to their respective owners.
License
- Source code is licensed under the MIT License.
- Hand-written documentation prose under
packages/website/docs/guides/is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0). Code examples embedded in documentation remain MIT.
See LICENSES.md for the full split and rationale.