---
title: Split your routes.rb file into logical files
author: Daniel Schoppmann
tags: Rails
published_at: '2024-02-09T17:55:00+01:00'
updated_at: '2024-07-18T09:06:35+02:00'
canonical_url: https://www.dotruby.com/articles/split-your-routes-rb-file-into-logical-parts
---

# Split your routes.rb file into logical files

Simplify your monolithic Rails application by splitting your routes into logical namespaces using Rails' internal `draw` method. Instead of a cluttered routes.rb file, organize your routes into clear, manageable units like `admin`, `api`, etc. for improved clarity and maintainability.

If you have a typical monolithic Rails application, you have probably already divided your application into logical namespaces or modules. Did you know that you can do the same with your routes?
Typically, all routes are stored in the `routes.rb` file. But this can get pretty messy when you have hundreds of lines to scan. Fortunately, Rails allows you to split routing files using the internal `draw` method.
So instead of having one big routing file, we like to split our routes into their selective units. For example, if we have an admin area, an api, and the actual application itself, the routes.rb file can look as simple as this:

```ruby
Rails.application.routes.draw do
  draw :admin
  draw :api
  draw :app
end
```

Now each namespace is easy to understand and can be defined on its own, for example in `config/routes/admin.rb`

```ruby
namespace :admin do
  # Place your admin routes here
end
```

Of course, namespaces themselves already come with a decent structure in the routes file, but as said, in very large applications, splitting your routes into smaller files may help for better clarity.
