We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Best practices to use SOA (Service Oriented Architecture) in Phalcon

I'm concerning to use an architecture for serving the core data / core data API to multiple "client apps" such as main website, mobile website and the mobile apps. After doing some research, I know that the architecture which I want to apply is called SOA. Is there any pros or cons to apply SOA in PHP or Phalcon? I wonder how to create a service in Phalcon in a right way, or I can do other things which is more simple?

Thank you.


I think that Phalcon is a good choice for this. You can create a directory( ie: common) where you can store the files you are sure that all your apps need, for example some validation functions a vendor and some models. For each of your applications, you can create it's own loader and dependency injection. I'am working on a website special for searching articles and a cms and a frontend website. all of them have it owns MVC patterns and library, but they share the models and validations in a commen library.


I found this in MVC repo of Phalcon: https://github.com/phalcon/mvc/tree/master/multiple-service-layer-model/apps/models But I don't catch up these terms: repositories and services What is the different of them?




Honestly, I am not familiar with the sample you give, The Phalcon team has build many samples, and you are free the choose the one you like. The services is an importand, feature you will find in many Phalcon applications. It's a dependicy injection container, and allows you to 'inject' objects from your library, With this, you can use for example Incubator functionality (https://github.com/phalcon/incubator) to your application. Or check https://docs.phalcon.io/en/latest/reference/di.html to read more about dependicy injection. This sample https://github.com/phalcon/mvc/tree/master/multiple is also one that gives you a good view how it works in practice.

Good, luck.



Hi! Sorry for digging upt the topic but I am concernig myself too about how to design my app architecture and found this post. I am going to develop some quite complex app and thinking what will be the best architecture to deploy. I am researching now for some solutions and best practices.

I was inspired by a post of one of Phalconee here https://github.com/phalcon/cphalcon/issues/2686 - first post of @rushmorem user. I think his practice is similiar to this SOA concept and Phalcon repo https://github.com/phalcon/mvc/tree/master/multiple-service-layer-model/apps/models.

Did you found aby interesting resources about SOA or other architecture issues and can share some? I mean some interesting tutorials, posts on forum, github reps to analize.

Thanks in advance!

edited Aug '14


Sorry to make you dissapointed, but I 've already decided to keep our app's architecture as simple as it can to focus on our main app logic. The core architecture of Phalcon was written with SOA in mind. I started my app by using the simple preset of Phalcon. Until now, I didn't see any issue with that, if It's happen in the future, I will refactor later.

At this moment, I prefer the KISS principle than any other approach.

Good luck!