Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SPA architecture for RoR with AngularJS

I have an AngularJS app on the front end and Ruby on Rails (RoR) on the backend.

AngularJS code will call a REST API (implemented by RoR), which will respond with JSON. That JSON will be absorbed by AngularJS. 100% of the business logic, including routing, will reside on the client (AngularJS). The only thing that RoR will do is provide the data through the REST API.

I will be using Gulp for my minification, etc. on the client side, so I won't be needing the asset pipeline. I also don't plan to use turbolinks or coffee script.

I'd like to deploy my client side as part of the RoR app.

The question I have is this... Is there anything wrong with simply placing all of the client code (HTML, CSS, JS/AngularJS) into the public folder. It seems like I wouldn't be gaining much by trying to rip apart my AngularJS app into the RoR standard folders. Actually, it seems the opposite, i.e., that I will only lose as I will have the headache of having to get around some RoR things like getting around things I won't be using (i.e., asset pipeline, turbolinks...)

If there is something wrong with this approach, what is it?

As an alternative, are there any benefits of simply deploying the two sides (client and server) separately (i.e., in 2 different deployments)?

like image 762
user5645402 Avatar asked Feb 12 '26 02:02

user5645402


1 Answers

There is nothing wrong with that approach, I've recently seen it in an app a coworker have been working on for a couple of years and it had worked great, although it is ReactJs in the front-end, but it doesn't really matter.

I'd deployed them separately if I plan to have a more complex app that operates with a lot of micro-services to get the most up-time and failure tolerance. For example, Netflix would have a micro-service that gets you the list of recommended movies if the service is available but it falls back to a predefined list otherwise (another micro-service). The front-end would ask data from one side and if it fails it will use the other service.

Of course you could have multiple servers with a single deployment but that limits my ability to scale them independently. E.g. have the SPA served from a CDN and only deploy your backend.

like image 64
nbermudezs Avatar answered Feb 13 '26 18:02

nbermudezs