RnStack: The Professional Hybrid Framework
rn_stack is a production-grade Rails Engine that bridges the gap between Ruby on Rails and the modern, high-performance architectural patterns popularized by Next.js and Angular.
It provides a unified integration layer, allowing you to build polyglot applications that seamlessly mix Rails (ERB/Stimulus), React, and TypeScript.
๐ Table of Contents
- ๐ Getting Started
- ๐ ๏ธ CLI Productivity Suite
- ๐๏ธ Core Architecture Concepts
- ๐ Usage Examples
- ๐ Production Readiness Checklist
- ๐งช Testing, Debugging & Configuration
- ๐ CI/CD & Team Conventions
๐ Getting Started
1. Installation
Add to your Gemfile:
gem "rn_stack", path: "path/to/rn_stack"
2. Initialization
Run the setup script to configure Rails, Vite, and Databases:
chmod +x bin/setup_script
bin/setup_script
3. Development
Create a Procfile.dev to manage backend and frontend services:
web: bundle exec rails s
vite: bin/vite dev
Run development:
gem install foreman
foreman start -f Procfile.dev
๐ก Learning & Examples
Generate runnable, real-world architectural blueprints:
# Scaffold a full blog system
rails generate rn_stack:example blog
# Scaffold a starter dashboard
rails generate rn_stack:example dashboard
๐ ๏ธ The CLI Productivity Suite
rn_stack provides a powerful CLI suite for rapid development.
CLI Productivity Suite
| Task | Command |
|---|---|
| Pages | rails generate rn_stack:page [name] |
| API Handlers | rails generate rn_stack:api [name] |
| Maintenance | bundle exec rake rn_stack:maintenance |
| MVC Scaffold | rails generate rn_stack:scaffold [model] [attrs] |
| UI Components | rails generate rn_stack:ui |
| Jobs | rails generate rn_stack:job [name] |
Architecture, Security & Enterprise
| Task | Command |
|---|---|
| Services/Stores | rails generate rn_stack:service [name] \ |
| Auth/RBAC | rails generate rn_stack:auth |
| Security/I18n | rails generate rn_stack:security \ |
| Media/Mailer | rails generate rn_stack:media [model] [field] \ |
| Prod/Deploy | rails generate rn_stack:production \ |
| Monitoring/Doc/Version | rails generate rn_stack:monitor \ |
๐๏ธ Core Architecture Concepts
rn_stack enforces a professional separation of concerns:
- Routing: File-system based (
app/pages,app/api). - Logic:
app/servicesfor business logic,RnStack::Actionfor data mutations. - State:
app/frontend/storesfor reactive frontend state. - Assets: Vite pipeline (Rails, React, TypeScript, Stimulus).
- Media: Professional helpers (
pro_image_tag,pro_audio_tag,pro_video_tag).
๐ Usage Examples
1. File-System Routing (Static & Dynamic)
- Static:
app/pages/about.html.erb->/about - Dynamic:
app/pages/users/[id].html.erb->/users/:idAll routes are automatically registered and wrapped in your default layout.
2. High-Performance Media
<%= pro_image_tag @user.avatar, size: [300, 300] %>
<%= pro_audio_tag "track.mp3" %>
<%= pro_video_tag "movie.mp4" %>
2. SEO & Performance
<% set_metadata(title: "My Page", description: "SEO Description") %>
<% with_isr_cache("sidebar", expires_in: 30.minutes) do %>
<%= render "sidebar" %>
<% end %>
<%= self_hosted_font_tag "my-font" %>
3. Searching & Filtering (using Ransack)
@q = Product.ransack(params[:q])
@products = @q.result(distinct: true)
๐ Production Readiness Checklist
- [ ] Infrastructure: Run
rails generate rn_stack:production. - [ ] Observability: Run
rails generate rn_stack:monitor. - [ ] Containerization: Run
rails generate rn_stack:deployment. - [ ] Security: Run
rails generate rn_stack:security. - [ ] Assets: Ensure
bin/vite buildis configured for production.
๐งช Testing, Debugging & Configuration
- Testing: Use standard
bundle exec rake testand Capybara for full-stack integration. - Debugging: Standard Rails logging (
Rails.logger) and Vite HMR console. - Configuration: Create
config/initializers/rn_stack.rbto tune framework defaults.
๐ CI/CD & Team Conventions
CI/CD Pipeline (GitHub Actions)
Example workflow for rn_stack applications (.github/workflows/ci.yml):
name: CI
on: [push]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Run Tests
run: bundle exec rake test
๐ Architecture Overview
See ARCHITECTURE.md for a deep dive into the design philosophy.
License
MIT