Rewrite Ruby on Rails applications to TypeScript with LEAP Protocol
If you’re asking “how do I rewrite Ruby on Rails to TypeScript,” our answer is: use the LEAP Protocol—extract specs → generate tests → implement in parallel → roll out with parity. First, we extract executable specifications from your Rails app: routes, JSON contracts, DB behavior, background jobs, and security rules. Next, we generate a shared test suite (OpenAPI conformance, schema checks, SQL golden tests, job semantics) that must pass for both the current Rails implementation and the new TypeScript service. Then we implement the TypeScript target in parallel—typically NestJS or Fastify with Prisma or TypeORM—while continuously running the same parity tests. Finally, we roll out with confidence: dual-read/dual-write or shadow traffic, canaries, and feature flags, all gated by the shared tests to ensure no regressions. This spec-first, test-gated, agent-agnostic approach lets us migrate reliably without pausing feature work. You end with a TypeScript codebase whose behavior matches Rails at release, with typed contracts and modern tooling for long-term velocity.
Why TypeScript for Ruby on Rails migrations
- Strong, static types across API boundaries: enforce request/response shapes (e.g., Zod/io-ts + OpenAPI), catching bugs Rails would find only at runtime.
- First-class API frameworks (NestJS, Fastify) with explicit module boundaries, dependency injection, interceptors, and guards—clearer than Rails’ implicit autoloading and callbacks.
- Shared types with React/Next.js frontends (tRPC/OpenAPI-generated clients), eliminating drift between server and client contracts common in JSON API or GraphQL setups.
- High-performance async I/O and streaming with Node.js/Fastify, plus lightweight container images and faster cold starts than full Rails boot for small services.
- Mature data tooling (Prisma/TypeORM/Drizzle) with generated types from schema, safer refactors, and easier N+1 avoidance compared to ad hoc Active Record scopes.
Our methodology
1) Extract executable specs from Rails - Inventory via rails routes, Active Record models/associations, Sidekiq/Active Job queues, Action Mailer, and Active Storage. - Derive OpenAPI contracts from controllers/serializers; capture JSON examples and edge cases; document security (Devise/Warden, CSRF, cookie/session rules). - Record DB behavior from schema.rb and migrations (constraints, enums, unique indexes) and identify implicit invariants in callbacks/validations.
2) Generate a shared parity test suite - OpenAPI conformance and JSON schema assertions for every endpoint and variant. - SQL/ORM golden tests: expected queries, transactional boundaries, and pagination/order semantics. - Job semantics for Sidekiq/Active Job (retries, idempotency, schedules), mail delivery expectations (headers, templates). - Property/fuzz tests for param coercion (string→int/bool/date), time zones, and i18n fallbacks.
3) Implement the TypeScript target in parallel - Frameworks: NestJS or Fastify; Auth with Passport.js, NextAuth, or custom JWT; CSRF/session parity via cookie strategies. - Data: Prisma or TypeORM with a generated schema matching Rails constraints; explicit includes to replace Rails eager_load/preload; fix known N+1 hotspots. - Background jobs: map Sidekiq/Active Job to BullMQ/Agenda; preserve retry/backoff; add idempotency keys. - Mail and storage: Action Mailer → nodemailer; Active Storage → AWS SDK/Google Cloud Storage with signed URLs; Action Cable → Socket.IO/ws if needed.
4) Data migration and safe rollout - Translate schema.rb/migrations to Prisma/TypeORM migrations; write reversible scripts; test on production snapshots. - Shadow deploy and dual-read/dual-write where appropriate; canary routes; automated rollback. - Parity gates in CI/CD: TypeScript build can’t ship unless Rails and TS both pass the same suite.
5) Handover with maintainability in mind - Deliver OpenAPI spec, typed clients, CI config, migration runbook, observability hooks (structured logs, metrics), and SLOs aligned to existing behavior.
Specific Ruby on Rails concerns we handle
- Active Record to TypeScript ORM/SQL: callbacks, validations, scopes, and transaction semantics mapped to Prisma/TypeORM with explicit queries to avoid accidental N+1 and ordering differences.
- Strong Parameters and type coercion: replicate Rails’ params behavior (string booleans, arrays, dates, blank-to-nil) using Zod/io-ts validators and middleware.
- Authentication and middleware: Devise/Warden, before_action filters, CSRF/session cookies translated to Passport.js/Express/NestJS guards with identical cookie flags and token lifecycles.
- Background jobs and scheduling: Sidekiq/Active Job retry/backoff/idempotency mapped to BullMQ/Agenda; cron schedules and dead-letter behavior preserved.
- Action Mailer and Active Storage: mailer layouts/partials to nodemailer/templating; signed URL and direct-upload flows reproduced for S3/GCS with equivalent expiration and ACLs.
Proof
- sqlite-leap — five SQLite engines from one spec: https://github.com/safitudo/sqlite-leap
- semver-leap — 5,632 passing tests: https://github.com/safitudo/semver-leap
- LEAP Protocol (spec-first, test-gated, agent-agnostic): https://github.com/safitudo/leap-protocol
These public artifacts show we can define behavior once, generate rigorous tests, and drive multiple independent implementations to parity.
Pricing & timeline
- Typical engagement: 4–12 weeks, depending on endpoints, background jobs, and data migration complexity.
- Fixed-price proposal after a 3–5 day assessment of routes, models, and infra: usually $40k–$120k.
- Deliverables: shared spec and test suite, TypeScript service (NestJS/Fastify + Prisma/TypeORM), migration plan/runbook, CI/CD parity gates, and rollout support.
Ready to migrate your Rails app without breaking contracts? Email us to get a same-week assessment and a fixed-price proposal.
Leap Agentic is distinct from Legacyleap.ai and Impetus Leap AI.
Leap Agentic is distinct from Legacyleap.ai and Impetus Leap AI.