Solution architecture - acodeguy/acebook-rails-gang-of-four GitHub Wiki

Initially our app consisted of a purely Ruby on Rails server, built in the MVC pattern. The server would provide a set of endpoints to serve the web pages, and to receive requests to create, update, and delete data.

These endpoints would route requests to the relevant controller (e.g. a request to create a post would go to the posts controller), which would in turn use the relevant model to CRUD the data (e.g. instructing the post model to create a post), before returning the right response to the client (e.g. after the post is created, redirecting to the posts page, which would then render the posts view to display all posts).

We used Devise to handle all authentication. It provided an end-to-end solution for managing authentication, including registration, login, and authenticating requests to protected endpoints.

When we switched to React, all the views were moved to a completely separate frontend app, and the backend (routes, controllers, and models) was converted to a pure api with no ability to render views.

React enables developers to use a special syntax that combines Javascript, HTML, and CSS, to create single page applications. When it is ready to deploy, you run a command to build the app, which transforms the special Javascript down to basic HTML, CSS, and Javascript. It's then ready to be deployed onto a very simple server with a single route, on Heroku. When the user visits a page, the server sends the entire frontend application to the client.

When the user accesses a page that needs data from the backend (e.g. the timeline with all the posts), the frontend calls, via an HTTP request, the backend api, which is still in Rails. The backend is hosted on a completely different server, in a different instance of Heroku. The api returns the requested data in JSON format.

Here is a diagram: https://drive.google.com/file/d/1pgB0gf7awnIFoDCF_GsRiOGcv0-j0oKL/view?usp=sharing.

In addition, we had to change how we authenticated. Previously Devise had handled this all for us, but in the updated solution we also used the 'Devise Token Auth' gem - see the Authentication wiki page for more info: https://github.com/acodeguy/acebook-rails-gang-of-four/wiki/Authentication-model.