Architecture: private engines
This course examines Rails engines and internal gems through one Rails application. It starts with the table_name_prefix declarations in four namespaces, which 23 of 24 models override. It explains what an engine is and what isolate_namespace does and does not do, then works through what changes if Catalog becomes an engine. It compares four boundary levels (namespace, engine, versioned gem, service), covers path, git and registry gems, and ends with a decision: no engines, no gems, plus a ten-line architecture spec and an ADR.
What you'll learn
- ✓How table_name_prefix and isolate_namespace work, and what they leave unprotected
- ✓What converting a context into an engine changes and what stays the same
- ✓How namespaces, engines, versioned gems and services compare in enforcement and cost
- ✓The differences between path, pinned git ref and registry gems
- ✓How a ten-line architecture spec checks context boundaries
- ✓How to record the decision in an ADR with conditions for revisiting it
The engine convention already here
Four files in this application declare a Rails engine convention. Twenty-three models decline it. That's the whole starting point.
Read the full lesson free →Curriculum
7 lessonsThe engine convention already here
Four namespaces declare table_name_prefix, 23 models override it with self.table_name, and only Community::Comment uses it.
What an engine actually is
An engine is a Rails application inside another; isolate_namespace prevents naming collisions but leaves constant references open.
What changes if Catalog becomes an engine
Moving Catalog into an engine leaves coupling, data and deployment unchanged, adds an isolated suite, and needs a dummy app.
Four levels of boundary
Namespace, engine, versioned gem and service compared by what each enforces, what it costs, and which fits each context.
Private gems and distribution
Loading a gem by path, pinned git ref or private registry, when versioning pays off, and what it costs.
The decision for this application
The recommendation of no engines and no gems, with a prefix decision, a ten-line architecture spec and an ADR.
Putting it together: an hour and ten lines
A recap of the measurements, the hour and a half of follow-up work, the four levels and the habits.