prism

A Ruby web framework built purely on the standard library - no external gems. A router, a controller layer, a file-backed ORM with migrations, layouts and partials.

prism
TL;DR

A web framework in Ruby built purely on the standard library. No external gems: a hand-rolled router, a controller layer, a file-backed ORM with migrations, layouts and partials. Everything you usually get from Rails, written from scratch to understand how it truly works.

Overview

Rails is great, but after years of only using it, it is easy to forget how it works underneath. prism is a deliberate step one level down: there is not a single external gem, so every piece had to be understood well enough to write yourself. Routing, dispatch to a controller, rendering a view, the data layer.

The result is a small framework that genuinely serves an app, and at the same time a map of what the competition does behind the curtain. It is not a mockup of a framework but a working whole where every layer is within reach, because you wrote it with your own hands.

A router that untangles the path itself

The heart of any web framework is the decision of which code handles a given request. In prism that decision is explicit: you declare routes and the router matches method and path to a controller plus action pair, pulling parameters out of the address segments along the way. There is no magic here, there is a table of rules read top to bottom.

When you write the dispatch yourself, it stops being a black box. You see exactly where a path turns into a method call, and that is the very knowledge you lack when the framework does it for you.

routes.rb · ruby
Prism::Router.draw do
  get "/posts", to: "posts#index"
  get "/posts/:id", to: "posts#show"
  post "/posts", to: "posts#create"
end

The data and view layers with no hidden glue

Rather than wiring in Postgres, prism keeps data in files and adds migrations plus simple queries on top. That is enough to show the whole loop: you define a model, run a migration, save a record and read it back in a controller. The database drops out of sight, and what remains on top is the shape of how an ORM maps records onto objects.

Limiting it to files is not a shortfall but a decision. Thanks to it the data layer fits in your head as a whole and hides no step behind a database driver you cannot see anyway.

Rendering a view looks trivial until you try to assemble it from layers. prism has layouts into which the action's content is injected, and partials that compose repeated pieces. Exactly the same mechanism that happens invisibly in big frameworks is here an explicit function you wrote yourself.

➜
Tip

When everything is written by hand, debugging means reading your own code, not guessing what the framework does. That is the main payoff of the exercise: the layer whose behavior you had to infer simply disappears.

A map of what Rails hides behind the curtain

The biggest gain from prism is not the framework itself but what stays in your head after writing it. Router, controllers and ORM together fit in a few hundred lines of readable Ruby, and each of those lines corresponds to some piece Rails does behind the curtain. After this exercise a big framework stops being magic and becomes a set of decisions you understand.

Where it usually comes from, and where in prism

PieceUsually off the shelfIn prism
RoutingRailsa hand-rolled router
Data layerActiveRecorda file-backed ORM with migrations
ViewsActionViewlayouts and partials by hand
Dependenciesdozens of gemszero, just stdlib

More projects

More work from the same category - see how we tackle similar challenges.

Have a similar project?

Get in touch - a quote is free and comes back within an hour.