The Rails Directory Structure
Fast recall
Quick revision
Core answer
app/; routes and environment settings live under config/; migrations and schema information live under db/; tests live under test/ or a project-selected spec/; reusable tasks often live under lib/; and generated runtime files use folders such as log/, storage/, and tmp/. The structure supports Rails naming and autoloading conventions, so files should be placed by what they do rather than by convenience.Whether you can name the key folders (app/models, app/controllers, app/views, config/routes.rb, db/migrate) and what lives in each.
Not knowing where a feature lives (model in app/models, not app/controllers), or putting logic outside the conventional folders.
app/ (models, controllers, views, jobs); config/routes.rb (entry point); db/migrate (schema changes); Gemfile (deps). Folders map to MVC; convention finds everything.
Interview-ready guide
Interview answer
Most application behaviour lives under app/: models and domain objects, controllers, views, jobs, mailers, helpers, and framework components. Putting a class under the matching responsibility and namespace lets Rails loading conventions and teammates find it predictably.
config/ holds routes, environment settings, initializers, and database configuration. db/ holds migrations plus the current schema representation. Tests live under Rails' test/ tree or the project's chosen spec/ tree. Those roots change for different reasons and should not become a miscellaneous storage area.
A product feature may use app/models/product.rb, app/controllers/products_controller.rb, app/views/products/show.html.erb, and a matching test file. The runnable map keeps those responsibilities visible together without pretending that a view template is a Ruby constant.
bin/ contains application-aware command wrappers and lib/ commonly holds tasks or supporting code. log/, storage/, and tmp/ hold generated runtime files that may be replaced between environments. Migrations are history, so change a shared database with a new migration rather than silently editing an old applied one.
The Rails Directory Structure
Direct Answer
A Rails application's directories separate code by responsibility. Most application code lives under app/; routes and environment settings live under config/; migrations and schema information live under db/; tests live under test/ or a project-selected spec/; reusable tasks often live under lib/; and generated runtime files use folders such as log/, storage/, and tmp/. The structure supports Rails naming and autoloading conventions, so files should be placed by what they do rather than by convenience.
Deep Dive & Architecture
The top-level tree separates files by how they change. Application behaviour evolves in app; deployment and environment choices live in config; database evolution is recorded in db/migrate; dependency versions are locked through the Gemfile files; and automated checks evolve alongside behaviour in the test tree.
Within app, paths normally mirror constant namespaces. app/jobs/billing/reconcile_job.rb is expected to define Billing::ReconcileJob. Views are grouped by controller or component rather than becoming Ruby constants, but their placement still drives conventional lookup.
Migrations are history, while db/schema.rb or db/structure.sql describes the current database shape for setup and inspection. Editing an old migration that has already run in shared environments can make installations disagree; a new migration records the next change.
Runtime directories should not become hidden source locations. Logs, cached files, process IDs, uploaded development files, and temporary artifacts can be replaced between environments. Code required to understand the application belongs in versioned source or explicit configuration instead.
Code Example
# app/models/product.rb
class Product < ApplicationRecord
end
# app/controllers/products_controller.rb
class ProductsController < ApplicationController
def show
@product = Product.find(params[:id])
end
end
# app/views/products/show.html.erb
# <h1><%= @product.name %></h1>
# test/controllers/products_controller_test.rb
# verifies the HTTP behaviour of ProductsController
Common Mistakes & Pitfalls
Not knowing where a feature lives (model in app/models, not app/controllers), or putting logic outside the conventional folders.
Check your understanding
Answer these without looking back at the article.
- What is the difference between a migration and the current schema file?
- How does a namespaced constant map to a path under `app/`?
- Which Rails directories contain source, and which contain runtime data?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.