I've done some research and I've noticed that in a lot of examples Symfony2/AngularJS apps the frontend and backend are combined; for example, views use Twig.
I'd always thought that it's possible (and common practice) to create the frontend and backend separately and just join them by API. In that case if I want to change a PHP framework I will can do it without any problems and it will be enough to keep API.
So what are the best practices for doing it? It would be great if you could explain it to me and even greater if you just give me a link to good example on github or something.
Some companies like to have clear separation between the frontend code and the backend code. They go to the extent of having two different repositories - one for the backend and one for the frontend code. In this architecture the backend acts like a pure API. The backend returns just JSON data.
With a separate frontend and backend, the chances of breaking the entire website are significantly low. It is also relatively easier to debug since it is clear from the start whether there is an issue in the frontend or backend. Upgrading your web applications makes them faster and reduces the risk of bounces.
If you can't come to a decision now, I would recommend that you start with separate repositories, because it is easier to merge repositories later on than it is to split them. Actually, with the right tools - e.g. git subtree , git filter-repo - both splitting and merging are pretty easy.
There are two general approaches to building web applications today: traditional web applications that perform most of the application logic on the server, and single-page applications (SPAs) that perform most of the user interface logic in a web browser, communicating with the web server primarily using web APIs.
We have been developing some projects using the same approach. Not only I think it doesn't have any "side effect", but the solution is very elegant too. We usually create the backend in Node.js, and it is just an API server (not necessarily entirely REST-compliant). We then create another, separate web application for the frontend, written entirely in HTML5/JavaScript (with or without Angular.js). The API server never returns any HTML, just JSON! Not even an index structure.
There are lots of benefits:
Some hints that I can give you based on our experience:
I asked some questions in the past you may be interested in:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With