Forum: Ruby on Rails Rails & engines - best practice/architecture query

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F48be0dee9826c6757753d989e139614?d=identicon&s=25 Paul Olivers (Guest)
on 2014-05-02 14:05
(Received via mailing list)
Hi all,

I want my app to have an HTML5 front end, and a JSON API. Would it be
overkill to split these up into separate engines?

So, I'd have a core Rails app (with Devise for auth), the controllers
for
the HTML and JSON front ends as 2 separate Rails engines.
Also, would all of my models belong to the core app, or would I have
ANOTHER engine with the models in?

thanks,
Paul.
Aa082c8b00a50928e5860dcd70bf2368?d=identicon&s=25 tamouse m. (tamouse_m)
on 2014-05-02 18:45
(Received via mailing list)
On Fri, May 2, 2014 at 5:37 AM, Paul Olivers <poliphox@gmail.com> wrote:
> Hi all,
>
> I want my app to have an HTML5 front end, and a JSON API. Would it be
> overkill to split these up into separate engines?

Yes. You don't need an engine for every front end.

What could make sense is to build the core backend of your application
as a service with an API, a la rails-api
(https://github.com/rails-api/rails-api) which would take RESTful
requests and respond with JSON. A user-facing web site (delivering
HTML5++) could be built alongside, not necessarily as an engine, but
it *could* be an engine, especially if it is doing more than the
back-end RESTful app/service is doing.

But making a separate engine just to deliver JSON seems redundant to me.

>
> So, I'd have a core Rails app (with Devise for auth), the controllers for
> the HTML and JSON front ends as 2 separate Rails engines.
> Also, would all of my models belong to the core app, or would I have ANOTHER
> engine with the models in?

If you can architect your application into separate logical services,
which have little interaction with each other, that makes a good set
of engines.

If you are just starting out with this application and it is meant for
eventual deployment (as opposed to something more of a learning
exercise) then I'd suggest you forgo the engines at this point, and
see how your app develops, and how it reacts under development and
use. On the other hand, if you really understand the application's
domain and how users interact with it, go ahead and architect out the
various services as engines.
This topic is locked and can not be replied to.