The Ruby on Rails directory structure is created with the terminal command rails new <projectname>.

The directory structure is the basic organisation of the software project. Its how Rails knows where to find the files.

Rails directory structure

Create project

Rails generates the project directory structure.

If you run the command rails new blog, a new project (and directory) will be created named blog.

Typing the command cd blog and ls will then show the directory structure.

app  Gemfile.lock  package.json  tmp
bin db lib public storage vendor
config Gemfile log Rakefile test

Model View Controller

Rails uses the Model View Controller model (MVC).

HTTP requests are given to a controller class app/controllers.

A controller process it, communicates with the database (model) app/models and finally returns a template (view) app/templates.

The flow is:

URL request → ControllerModelView → Web browser.


Rails creates many directories. So what’s each directory for?

appApps components: apps business logic, controllers and views.
app/controllersController classes. Rails uses the Model-View-Controller (MVC) model.
app/helpersHelper classes for models, views or controllers.
app/modelsDatabase code. Model in the MVC model.
app/viewsTemplates to display. The Views in the MVC model.
tmpRails uses this for temporary files during execution.
dbDatabase scripts.
publicThe public directory for your Rails app, similar to the public directory in a web server like Nginx or Apache.
vendorThird-party libraries
configConfig files for your app
RakefileLike a Makefile, build and packages Rails code