Best practices for combining Angular frontend with PHP API

I’m working on a personal project to create a blogging platform using Angular for the frontend and PHP for the backend. I’m pretty new to this combination and want to make sure I’m following the right approach.

Here are the main things I’m wondering about:

  • Is it better to create a pure REST API in PHP that only returns JSON data for Angular to consume?
  • Since Angular handles the views, do I even need PHP templates or should everything be client-side?
  • Should I handle URL routing on the server side with PHP or let Angular take care of all the routing?
  • What’s the best way to handle caching when you have this kind of setup?
  • Where should I put validation logic for user input - in Angular, PHP, or both?

I’m trying to figure out if building the PHP backend as just an API is the right way to go, or if there’s a better pattern for this kind of architecture. Any guidance on how to structure this properly would be really helpful.

After building several Angular-PHP applications over the past few years, I can confirm that treating your PHP backend as a pure API is absolutely the correct approach. Your Angular frontend should handle all presentation logic while PHP focuses solely on data operations and business rules. Regarding validation, implementing it on both sides is non-negotiable. Client-side validation in Angular provides immediate user feedback, but server-side validation in PHP is your security layer. Never trust data coming from the client. For routing, let Angular handle all frontend routes and use PHP only for API endpoints. This separation keeps your architecture clean and allows Angular’s router to manage the user experience effectively. Caching strategy depends on your data patterns. I typically implement Redis for frequently accessed data on the PHP side and leverage Angular’s HTTP interceptors for client-side caching of static content. This dual approach significantly improves performance without adding unnecessary complexity to your initial build.

yeah the api-only approach works great but dont forget about cors issues - you’ll probaly run into that when angular tries to hit your php endpoints. also consider jwt tokens for auth instead of sessions since your dealing with seperate domains potentially

curious about your database setup - are you planning to use an orm like eloquent or going raw pdo? also whats your deployment strategy gonna look like, seperate servers or same host? these choices can really impact how you structure the api communication