Rails Application Structure
Tags: rails, railsdirectories, railsapplications
Published: 2021-04-18 16:51:13



As amazing and magical as Rails can be, it can also be challenging to understand where to start working. and to understand the directory structure of the application.
This article will explain The directory structure rails apps.

But before we get into the directory structure of rails applications first we must have a good understanding of the
[Model View Controller structure(MVC)](https://www.tutorialspoint.com/mvc_framework/mvc_framework_introduction.htm?ref=hackernoon.com).
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0i7wakosphtq3we4m91c.png)

Let's dive in.

After Creating the application `rails new my_app` 
Boom! The first Rails app ready to start working on it.
run `cd my_app` then run `code .` to open the application in the code editor.

What are those files and folders that have just been created!? 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r9t7ghl2j1x3eoijg0el.png)


Now let's explain the purpose of each one of these directories.

#app
It organizes the application components. It has subdirectories that hold the view (views and helpers), controllers, and the backend logic (models), and here where will be most of the work done.
let's go over the app subdirectories one by one.

####app/assets
Holds the files related to the front end, such as CSS stylesheets, JavaScript code,and images.

####app/channels 
Channels for ActionCable, which integrates WebSockets with the rest of the Rails application. and allows real-time features to be written in Ruby.

####app/controllers 
The C in MVC. This subdirectory is where Rails looks to find the controller classes. A middle man between the model and the view.

####app/helpers 
Utility methods used to assist the model, view, and controller. This helps to keep the code small and focused.

####app/javascript 
Holds the application's JavaScript packs.

####app/jobs 
Background jobs, The jobs can be enqueued and executed using the different queuing backend.[Active Job Basics](https://guides.rubyonrails.org/active_job_basics.html)

####app/mailboxes
Routers for incoming emails. This folder is not present on the app until we use the Action Mailbox feature of Rails.

####app/mailers 
Mailing structure for the app.

####app/models 
The M in MVC. This subdirectory holds the classes that model and wrap the data stored in our application's database.

####app/views 
The V in MVC. Usually written in embedded Ruby (erb), it can also be written in another templating language such as Slim or Haml.


#bin 
Holds the scripts to start/manage our Rails application.

#config 
Holds the configuration files, such as database configurations, routings, localizations, etc.

#db 
Holds the migration files for the tables, schema file, and database seeders. which are just files that can be executed to prepare the database with some initial data.

#lib
Rake files and independent codes, usually libraries unless they explicitly belong elsewhere (such as vendor libraries).

#log 
Holds error logs. Rails create scripts that help us to manage various error logs. there are separate logs for the server (server.log) and each Rails environment (development.log, test.log, and production.log).

#public 
Holds the static files, such as favicon, compiled assets, error pages.

#storage 
Uploaded files for disk storage.

#test 
For the test files. but since many in the community prefer to use the RSpec framework for writing test codes; in that case, this folder will be deleted.

#tmp 
Rails uses this directory to hold the temporary files.

#vendor 
Third-party front-end dependencies. (such as security libraries or database utilities beyond the basic Rails distribution).


Apart from these directories, there are some more files:

######README
This file contains a basic detail about the application and a description of the directory structure explained above.

######Rakefile
This file helps with building, packaging, and testing the Rails code.

######Gemfile
Contains a list of all the gems that we want to include in the application. It is used with bundler (also a gem) to install, update, remove and manage the used gems.


Resources:
[rubyonrails.org](https://guides.rubyonrails.org/getting_started.html).