Currently I am working on a REST API for a mobile app. I use rails-api and have some third party dependencies. Lately, one of my client asked to have admin panel, so that he could take a look at some data or edit them. I add activeadmin to the project, it works great, but I feel not right because originally I want my REST API project to be very slim and have less dependencies, but after I added activeadmin it has many dependencies. My app becomes big and it also takes more memory to run the app. We want to scale API part easily, and we donât care much about admin panel because itâs only for one or two people who use it less often as well. Thatâs why I thought it would be nice to split into two projects and connect to the same DB, but I have no any experiences on sharing models that have some third parties dependency. For example: User model depends on devise, elasticsearch, and etcâŚ
Have you had any experiences on splitting rails projects?
Yes. Very early into the lifetime of a public-facing Rails site, I realized I wanted the admin functionality to be different, so I made a new admin app.
I figured the models would be the same on both - so I symlinked the model directory of the admin app to the model directory of the public app.
This turned out to be a mistake, and one Iâm still working on fixing. Eventually I realized that, by having the same file used in multiple apps, adding functionality in one would complicate things in the other.
(Another error in my thinking resulted from seeing all sorts of books and sites saying âthin controller, fat modelâ, which is terrible advice)
âUserâ was the perfect example. In my public-facing app I used the âauthlogicâ gem for user authentication. Unfortunately this gem adds callbacks and validation rules to your user - things that make sense ONLY in the event that youâre creating / updating a user from a public page (password_confirmation, for example).
It meant that in the admin app I had to put workarounds in place to disable all the unwanted features that this gem added to my user, so that admins could edit and create users without any session-management silliness that simply wasnât relevant.
So, to undo this mistake, I began by simply getting rid of the symlink and making two separate copies of the models directory, with the same files. When I have occasion to revisit one of those files Iâll read through at and figure out whatâs irrelevant for the given app, and remove it.
Itâs a slow process, and a year or so later thereâs still plenty of unreachable code in both apps, that exist only because the other app wants it.
I will consider using the existing REST API for admin app. One interesting to think about is some action to be used only from admin, but not from mobile client app.