Splitting up app with different users/features?

I’m trying to rebuild an old, unfinished rails app (that I wrote years ago) from scratch and build a lot of new functionality on top of it. It’s basically a tool for administrative tasks within the company I work for, mostly managing our employees and making their jobs easier, and we have very different kinds of employees.

At the moment we have four different user types (employees) that want to do different things with the application, so the app is divided into more or less isolated sections but with very similar UI. We have one user type/section that manages invoices, payments and customers (among other things), and another section with schools, teachers and schedules. Admins need to be able to see and change almost everything, preferably without logging in to different places. Some features are shared between all employees, like managing their profile, receipts and salaries. Salaries are common to all employees, but are different for different employees. Certain employees within the “schools”-section need to create/view/change certain other employees, too, depending on permissions.

So for the last 2 months I’ve been trying to mash all of this into the same codebase, but it’s getting out of hand. I have already three different controllers for dealing with (different) salaries, which seems really wrong to me. There’s too much logic in the views since I wanna show different things to different users, so I have a lot of partials and if-statements. The forms are a pain too, I’m never quite sure when/what to separate with the views and controllers. The models look okay to me, though. I’ve put all common logic for the employees in a module and put each user type in its own class which includes that module. Then I have roles within each class that determines permissions (with Pundit). This part of the code seems to work pretty well. So far.

My guess is that I need to split things up, but I’m not sure how. Do I split by purpose/functionality or user type? Separate apps with shared code in gems? Engines within the same codebase (seems too complicated)? Make a base app that talks to the smaller apps? What are my options and what are the pros and cons of each? Is rails even the best framework for this?

We don’t have a huge user base right now but we’re gonna be needing more features and quite possibly more users with different needs and requirements in the future, so I really don’t wanna make the wrong decision here. Any ideas?

I’ve found that splitting an app into pieces (using engines, gems, or entirely separate apps) generally incurs a lot of overhead.

Because of this, I tend to prefer putting everything in one app, at least at first.

If you’re having trouble writing clean code when everything is in one app, I don’t think it’s likely that splitting stuff out will help much.

There’s some good discussion of this on one of our podcasts: The Bike Shed: 9: Monorails, For the Kids.

You might also benefit from having an experienced dev spend some time with you on this. Second sets of eyes are helpful. If you don’t know anyone, you might want to look into our coaching: Learn Ruby on Rails | Ruby on Rails Tutorials | Online Classes.

1 Like