Skip to content

frogr/tinyrails

Repository files navigation

Tinyrails

A minimal Rails-like framework built from scratch to understand how Rails and other web frameworks operate under the hood.

What it does

Tinyrails implements the core pieces of a web framework:

  • Rack integration - Connects to web servers through the Rack interface
  • Routing - Maps URLs to controller actions (e.g., /tweets/show routes to TweetsController#show)
  • Controllers - Handle requests and render views with ERB templating
  • Models - Basic JSON file-based persistence with find and query methods

Installation

Add this line to your application's Gemfile:

gem 'tinyrails'

Or install it directly:

gem install tinyrails

How it works

Controllers

Controllers inherit from Tinyrails::Controller and define action methods:

class TweetsController < Tinyrails::Controller
  def show
    render :show
  end
end

The render method looks for views in app/views/{controller_name}/{action}.html.erb.

Models

FileModel provides basic database operations using JSON files:

# Find a record by ID
tweet = FileModel.find(1)

# Get all records
tweets = FileModel.all

# Access attributes
tweet["content"]
tweet["author"] = "New Author"

Records are stored as JSON files in app/db/{table_name}/{id}.json.

Routing

The router parses the URL path to determine which controller and action to call:

  • /tweets/showTweetsController#show
  • /users/indexUsersController#index

Requirements

  • Ruby >= 3.1.0

License

MIT

About

Rebuilding the Rails Framework in Ruby to better understand Rails internals

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors