VulCode

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

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 big frameworks do 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.

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 compact, readable Ruby, and each part of it corresponds to some piece Rails does behind the curtain. After writing it, 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

Questions about prism

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.