How to choose the right architecture for a PHP application?

There is a task to implement a local social network (for the city). In General, the feature set is the same as in most social. networks. Ie: likes, comments, user profiles, records, private messages, chat. The main backend is written in php, but working with sockets is Node.JS.
About architecture a lot of thought, but that's how most correctly to organize it, this is a problem.
Was thinking about MVC, I think for this type of task, this pattern is not very suitable. I appeal to you for advice, maybe somebody here had encountered a similar project, please help to make a good choice, in order "not to grab his head."
September 26th 19 at 11:48
7 answers
September 26th 19 at 11:50
Solution
What kind of architecture you need? at the class level in php, or at the component level of the system?
Read the article Architecture for high loads. Also see the article Architecture of high-load applications (second part) of the blog Badoo habré (by the way, they have a lot of cool articles on the topic social.networks). Don't forget the Three key principles ON.

If you are good (or at least not bad) I know Javascript (judging by the mention Node.js in question), we consider to abandon php and to do entirely in Javascript on the server Node.js on the client Angular.Js.
Consider the framework Koa and stack KOAN - ready build koa + angular.
If Koa is not liked, then take the usual Express, then you should look for MEAN.

If your choice is still php, I recommend to take Symfony2 as a framework. powerful streamlined framework with a rich set of ready-made modules (bundles) will help you quickly realize the basic things. In principle, as they say Badoo is a good option for SOC.network, they do not regret that chose him. But for such productive systems as social.network need to know php perfectly. Like any other system.

PS And can you tell me why do we need another social.network, the more local (regional)? I can understand theme new social.network, but to do the usual - strange idea. It will be difficult to compete with the current networks, people are not very willing to change the usual environment where you have a bunch of friends on something new.
it is themed for the community - Darron commented on September 26th 19 at 11:53
If highload project, Nodejs as backend is not an option, if only for some auxiliary functions. - raul_Bayer88 commented on September 26th 19 at 11:56
I understand thematic network, which added features that are not (and will not) in shared social networks. For example, Habrahabr - the social network for it people, with special functions for it specialists. - Gustave.Fay commented on September 26th 19 at 11:59
many will not agree. If you know how to cook, and it is possible to use nodejs. Besides, I understand the question, super high load, this project would not audience - the part of the population of the city. - what is the population of the city? what is the size of the target audience? - Gustave.Fay commented on September 26th 19 at 12:02
Well it does not say on the front or on the backend, javascript is still a scripting language which is quite prosidaet in performance compared to server. Well, Yes, again depends on the scale of the project. - raul_Bayer88 commented on September 26th 19 at 12:05
any task needs its own tool. For some tasks great Node.js for some it's terrible. Here was a good benchmark a variety of platforms. And here's another large-scale test platforms. Node.js it's not brilliant, but not an outsider. Also in force in the skills of programming on a particular platform.
I don't want to protect the node and foaming at the mouth to say that it is necessary to push everywhere. But for some tasks it is great. - Gustave.Fay commented on September 26th 19 at 12:08
I agree with you completely. - raul_Bayer88 commented on September 26th 19 at 12:11
September 26th 19 at 11:52
While You are doing the first version - do it on anything.
Coming traffic - hire a team of professionals and copy fine.
September 26th 19 at 11:54
The main backend is written in php, but working with sockets is Node.JS.
if you do part with NodeJS, I suggest for just it and to take, it may be easier than PHP + NodeJs

- About architecture a lot of thought, but that's how most correctly to organize it, this is a problem.
and what thoughts?

- Was thinking about MVC, I think for this type of task, this pattern is not very suitable.
why not appropriate?

Well, if MVC is not suitable, build on HMVC.

- in order "not to grab his head."
This is why you now have a good think about it, I do not think that the toaster you someone will make the architecture of the project.
But seriously, you have town portal, i.e. the ceiling - 100k active users.
Take any cms and on its base do everything if click NodeJs - you can take a keystonejs
September 26th 19 at 11:56
Since I like to write their "bicycles", for your project did the following architecture:
Split the project into entities (selected global elements of the project), I came up with only two, it links (links to sites) and users. These are the two main entities through which the system interacts and the user. Each entity has a controller, model and view (MVC) + can be configuration and functions. As there is such a major entity as the main (main) linking other entities together. From the main also has a controller, model and view. We have the following structure: {main(mvc): [link(mvc), user(mvc)]}, model, view and controller are represented as classes. In addition, there are three main file: index, routing and configuration (as the project single page, routing parses the ajax requests).
Initialization:
1. the index plug-in configuration, the main controller and routing, create a class for the controller ($main=new Main();).
2. in places where you want to output particular content is a challenge to the main controller, in the constructor, which is a DB connection and creates instances of classes from other entities (links and users), as parameters they are given the ID database and the session (logged or not).
3. In the index file where we need to get a particular content, simply call echo $main->Link->getCategoryMenu(); (chief controller->controller links->method of getting the menu).
4. The method of obtaining the menu: turn to the model, the data from the database. Refer to view - mountable data in html, and the controller gives you the answer.
For almost all methods of the controller optional get variable ajax. If ajax==true then give echo the json, otherwise return $result;

I have problems with such a structure, no, everything is fast, easily scalable.
September 26th 19 at 11:58
I think you are asking the wrong questions. For starters it would be worthwhile to formalize a subject area, to draw the domain model. To identify the key system entities and their relationships. Starting from them, and technical requirements/wishes to pick up the tools.
MVC is basically an axiom. The question is: how much architectural design can be done classically, don't know how to call it in one word, through sorcery - "start-worked-died," and like, how many event-oriented model. On this basis, be determined enough if one of php or even can not be used.
I personally dislike node.js. If a lot is tied to event-oriented models, something better would have taken GoLang.
and why is the dislike Node.js? Bad experience? Can share? - Darron commented on September 26th 19 at 12:01
first, I personally do not like the language itself, the PLO is kind of ridiculous. Second, almost all that can node.js you can repeat and ReactPHP, but then the question arises: why waste time learning another technology, which is identical in their capabilities?
Go or Java, but this is much more serious, there is a normal multithreading. Node.js - topotecan. - raul_Bayer88 commented on September 26th 19 at 12:04
I think it is not the best idea to do a php script by a demon. PHP created to die. And I agree: Node.js - not the best solution, but not the worst. Quite a tool, but not for all tasks.
PS OOP in javascript is great! :) - Gustave.Fay commented on September 26th 19 at 12:07
javascript has interfaces or traits? Of course you can do without it, but still. On account of the article is outdated. I read the newer version, which takes into account php 5.5. In principle, it is shown that using ReactPHP became more and more interesting. The main problem is just the lack of management of memory, for example, when the limit process memory catches fatal and it does not handle. Everything else is identical node.js. - Gustave.Fay commented on September 26th 19 at 12:10
found software-gunslinger.tumblr.com/post/48215406921/ph... - raul_Bayer88 commented on September 26th 19 at 12:13
read, thank you. About reakt read on Habre, but he did not use. There are comparisons of speed ReactPHP with other eventloop-AMI?
About OOP in js is just a different approach. There are traits and multiple inheritance. Just a prototype approach began to develop relatively recently, in ES6 OOP will be significantly expanded, and is now being implemented by libraries. Not everyone likes prototype-based OOP, and I like it. We will not breed holivar, huh? - Gustave.Fay commented on September 26th 19 at 12:16
indeed, there are who are accustomed to something. Me personally after the php prototype approach seems strange. And ES6 is certainly a good topic.
React compared with node.js speed - completely identical, we can assume that the same kernel, different wrapper. - raul_Bayer88 commented on September 26th 19 at 12:19
September 26th 19 at 12:00
Than willing, efficient engines not good?
September 26th 19 at 12:02
MVC will do. Multilevel.

Find more questions by tags Designing softwareNode.jsPHPSocial networks