Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Definition of Switching point - Frontend vs Backend #4771

Closed
dynasource opened this issue Aug 20, 2014 · 42 comments
Closed

Definition of Switching point - Frontend vs Backend #4771

dynasource opened this issue Aug 20, 2014 · 42 comments
Labels
type:docs Documentation

Comments

@dynasource
Copy link
Member

Sorry to come back on it again: a subject on which already a lot has been said. There are examples of use, examples of advantages and arguments like '@samdark: that there couldnt be one single way of use'.

Either way, I am still not satisfied with the current documentation & discussions about it. Its too vague:

Now, after 2 months of development, I keep on being confronted with the same architecture design issues - over and over again.

  • whether to use module splitting in backend & frontend?
  • whether to separate actions between backend & frontend?
  • should a userend have its own tier?
  • etc etc

The same questions keep on coming back. What exactly is the real advantage for me. Is it about structure? About convention? About consistency? About making stuff easier? About easier design?
Whats the focus? Is it about users v.s. administrators? But what if users can also manager their own content. etc. etc.

Current discussions & wiki's don't give an answer on this question, apart from the example of the advantage of 'different servers'. Therefore this thread. To make it different from other discussions, I would like to focus it on one specific definition:

  • at what point should one switch to the separation of frontend and backend

This definition would be of great value for the docs and people new to this subject (and for me, because I still havent got one single definition). I dont like vague scenarios, I prefer 100% solid proof definitions. Since you have the choice to use this separation or not, it means that there must be a important criterium to switch. Which is it or which are these?

@ghost
Copy link

ghost commented Aug 20, 2014

In my opinion, separation on frontend and backend as individual application is needed in like 5% of applications. Lets me explain further.

If we talk about code organization, you can just create 2 folders : frontend and backend, and put relevant code in each. Just for better code organization, you do not need frontend and backend as different apps.

So why you need frontend and backed as different aps ? Because your clients need it that way ? Clients are on first place. If they want to have separeted frontend and backend as 2 applications that may or may not be connected, well do it... But as I said at the beginning, you will not have many clients that will need such thing. Even further, if your clients do not need this separation and you force them to do use it, you are probably doing bad thing. They will be unhappy. Who wants to visit 2 different URL's for managing his site if he does not need to ? And if you connect frontend to use everything that is in backend, you are losing the point of having backend as different app.

When is this separation needed ? It depends on the type of application. Blog apps do not need it of course. But for example you may have an aplication where super-admins need to controll in details what their clients can do. Clients will use frontend part of app, super-admins will use backend. Also, having backend part of app as different application on different URL, can be security improvenment if used properly. Basicaly, you will know do you need something like this when your clients give you their app request.

Next question is, can frontend be connected with backend. In other words, if you create some functionality for backend side of your app, can frontend use some of it? Answers are yes and no :). For systems where high security is needed, I do not recommend mixing frontend with backend. This means, that frontend should have its own administration pannels, db tables, or even separate database. If very high security is not needed, then yes, you can share backend stuff with frontend just by having RBAC to control who can use what.

@dynasource
Copy link
Member Author

@nenad-zivkovic, thanks. To summarize your argument:

  • security: you want to lower the risks on security flaws
  • orders: you follow client orders

@dynasource
Copy link
Member Author

I can remember @samdark saying, more things out of the box. @samdark, when would you switch to the advanced template? What is your turning point? @qiangxue, @cebe, and yours?

@Sammaye
Copy link

Sammaye commented Aug 21, 2014

Frankly almost evey application I have had has required a separation of admin view from front end views.

I rarely separate models, in fact never have however, separation of view/controller logic has been in 100% of all my Yii1 and Yii2 projects. It is a very common use case to have two sections to a site, one being the front end that the user sees and the other being a fully fletched backend for administrators.

whether to use module splitting in backend & frontend?

I do not. I house these, with the models/widges/assets/etc, in the common folder.

The only time I have done this kind of separation is on some widgets that are just too close to the frontend to logically be in the common folder.

Other than that the separation most commonly in views and controllers.

However, people do also separate moels sometimes when the logic ould be too much to bare in a single file.

whether to separate actions between backend & frontend?

Yes, I have commonly have an admin view action and a customer view action. In fact I commonly have fully formed controllers for both the frontend and the backend.

I have one controller Product in the backend and one in the frontend.

should a userend have its own tier?

What do you mean?

Is it about structure?

Yep, makes my structure better.

About convention?

Does make for better code convention to know where to find admin functions. It also makes much more elegant and cleaner coding.

About consistency?

The last point includes consistency as well.

About making stuff easier?

Despite it being more coding it does make maintanence easier when you know exactly where to look for things and your controller files are not cluttered with both backend and frontend crap (not only that but the code is isolated to your problem and you will not be effecting code that could be working, introducing bugs to that code).

About easier design?

Does make separation of CSS/JS specifics easier too. Also having it as a comlpetely spearate app helps external designers who don't know Yii or how a MVC framework works understand the structure of what they are looking at without training, it is logical.

Whats the focus?

Separation.

Is it about users v.s. administrators?

Yes, mostly. However, it does have other benefits, some of which are mentioned above.

at what point should one switch to the separation of frontend and backend

This is probably a question best answered by experience rather than a generic rule that applies to all projects. A developer will just know when the application merits a frontend and a backend.

I don't think I can apply a single fit for that documentation page, maybe providing a few pointers as to when to consider separation of backend and frontend but I cannot say: "In this case do this".

To go back on what others have said:

Blog apps do not need it of course.

Even a blog would need spearation between an admin end and a user end, take Wordpress for example, I would clearly separate that into a backend and frontend; in fact they have tried to, they are currently limited by the CMS' implementation.

For systems where high security is needed,

Having built many "high security" systems even wtih Yii2 I can tell you that backend and frontend can easily share functionality and should, for example I share everything except views and contollers between the two sides.

This means, that frontend should have its own administration pannels, db tables, or even separate database

Doesn't that kind of defeat the point of an admin end if it is not effecting the data it is supposed to be administrating?

Some thoughts there for you.

@dynasource
Copy link
Member Author

@Sammaye, of course, frontend & backend have different views & layout. But you don't necessarily require complex tiers separating 'frontend', 'backend' (like in the advanced app) for this.

to consider separation of backend and frontend but I cannot say: "In this case do this"

Well, thats the whole point of this discussion. Thats the main question.

@Sammaye
Copy link

Sammaye commented Aug 21, 2014

Well it might not be the answer you want, but that is the answer from someone who is experienced in this kind of separation. I can give pointers as to when to consider separation but as youyr argument points out:

But you don't necessarily require complex tiers separating 'frontend', 'backend' (like in the advanced app) for this.

Separation is subjective to the view of the (lead) developer(s). I do not personally see it as complexity, I see it as logical and clean.

I mean you could see it as complexity because you are dealing with an app which has not recieved the complexity required for you to find combining the two together difficult but it could also be just because you don't like it.

If you don't like the sound of separation it doesn't matter how much jibberish comes out of my mouth, you shouldn't use i.

@dynasource
Copy link
Member Author

@Sammaye, of course my thanx for your arguments & experience on this matter. Can I summarize your switching point as:

  • clean code organization: code is more logically structured if you use separate yii-tiers

@Sammaye
Copy link

Sammaye commented Aug 21, 2014

I would add external factors to that, I have found that designers prefer separation, they hate nothing more than having a css file that they have to strip down to get what actually effects the user, since many designers consider the frontend and backend separate as well.

So as well as the point you summarised I would add that external individuals have shown to prefer it, at least the ones I (we) have used.

@dynasource
Copy link
Member Author

@Sammaye, I am talking about 'tiers' here. Please read the first alinea https://github.com/yiisoft/yii2-app-advanced. When should multiple tiers be used.

@Sammaye
Copy link

Sammaye commented Aug 21, 2014

Yeah it is an English barrier, tiers here are thought of differently, in database and sever terms than application terms. Tiers is in fact a very vague word for me, so I call it separation.

@dynasource
Copy link
Member Author

Well, would you use multple yii separations (tiers) to solve issues with designers? I.o.w, to simplify the work of designers?

@Sammaye
Copy link

Sammaye commented Aug 21, 2014

Yeah, it allows them to have isolated design control of a specific tier, so if you want them to edit the frontend they can do it indiscriminately without effecting the backend.

Many designers don't know how to progam PHP let alone Yii, but they know what PHP code looks like and how it echos.

Having the folder separation and physical CSS/JS separation at times helps with this. Widgets can still be a problem though but we solved that by crating overrides in the frontend assets so that we we have one central point of coding but tiered designs.

@dynasource
Copy link
Member Author

alright, we're getting somewhere. Ill add this as a turning point. Thanks

@Sammaye
Copy link

Sammaye commented Aug 21, 2014

Of course this only works if you have distinct designs between the two, most applications I have built have coincidently had different design requirements for the frontend and backend. Though I think it is not a concidence afterall that a client will have different requirements between the two.

So all of this is conditional to the clients request as well. So that is something to bare in mind with this point.

@samdark
Copy link
Member

samdark commented Aug 21, 2014

I'm choosing advanced when I need any of these:

  1. Separate admin panel.
  2. Separate login for admin.
  3. API.
  4. Complex background processing.

Most of the time if any of these is required it will get more and more controllers, components etc. and I prefere to separate these right from the start.

I'm choosing basic for:

  1. No admin simple stuff.
  2. Inline admin.
  3. Installable products.

@dynasource
Copy link
Member Author

@samdark, what are the exact criteria for those 4 examples?

@samdark
Copy link
Member

samdark commented Aug 21, 2014

These are exact criteria.

@dynasource
Copy link
Member Author

in other words, the logic behind those examples.

@samdark
Copy link
Member

samdark commented Aug 21, 2014

???

@dynasource
Copy link
Member Author

ok. I will further explain. What criterium is affected by using a separate tier? Why do you want to put all the effort in using frontend/backend/common folders & namespaces, instead of using modules?

  1. Why the use of an admin tier for an admin panel and not a submodule?:
  • cleaner code?
  • safer?
  • easier customization?
  • etc (there must be a critical criterium)
  1. Why the use of a separate login?
  • is a separate tier vital for this?
  1. Why the use of a separate tier for an API?
  • speed?
  • configuration?
  1. Why the use of a separate tier for complex processing?
  • no risk of site crashes?
  • ...
  1. Why not using a separate tier for installable products (what exactly do you mean with this?)?

@dynasource
Copy link
Member Author

I'm searching for architecture & programming logic.

In example, I see the logic behind a UserController from the Admins perspective and a UserController from the User perpective. The creation proces could be in two different processes/actions. Separation would then be logical because of:

  • consistency: 2 actions (actionCreate) are split over 2 Controllers with the same name.
  • less complexity: no complex if / else are required
  • better overview: specific action can easier / more logically be found on scenario (frontend)

Therefore a 'rule of thumb' could exist:

  • If somebody has 2 different processes for i.e. a CRUD operation, one could use a Split of either a Tier or a Module, to benefit from consistency + less complexity + better overview.

@ghost
Copy link

ghost commented Aug 21, 2014

Doesn't that kind of defeat the point of an admin end if it is not effecting the data it is supposed to be > administrating?

It can be complicated... based on requirements and so forth. What I wanted to explain is this:
Let's say that you have some app, where "normal" users of that app can have backend and frontend parts, but also you have an admin ( with his admin panel ) that can control what those users can do in both backend and frontend parts of their app. You can chose either to share users backend with some parts of admins backend, or to separate them completely. That is dilemma, and it is important dilemma :D

@samdark
Copy link
Member

samdark commented Aug 21, 2014

Aha. I was thinking about no separation vs separation but you're talking about modules vs applications. OK. From this perspective it is a bit different. I'd prefer applications in the following cases:

  1. There's a need to have admin panel separated to another server. When you have multiple frontends serving website you don't need all these to handle admin stuff since it's used by a little number of users.
  2. Extra security. One can make admin panel accessible only from LAN / VPN and do it on network level, not in the code.
  3. The number of API requests could be very different to frontend requests so it could be wise to use different number of differently configured servers. Thus, separate application for API and frontend.
  4. Separating heavy processing is vital because if there's a mistake it often results in 100% CPU load and disk swapping. If it's a separate server, frontend and API will be still OK.

In case of installable product (like Wordpress, Drupal etc.) one of your primary goals is to make installation process as simple and straightforward as possible. That's why multiple webroots won't fit.

@dynasource
Copy link
Member Author

@samdark, thanks. To summarize:

  1. centralization
  2. security
  3. configuration
  4. stability

@dynasource
Copy link
Member Author

What I am noticing again in this discussion is the confusion about the gray area around the 'frontend' and the 'backend'. For instance in the following example of @nenad-zivkovic , 3 environments can be extracted.

Let's say that you have some app, where "normal" users of that app can have backend and frontend parts, but also you have an admin ( with his admin panel ) that can control what those users can do in both backend and frontend parts of their app. You can chose either to share users backend with some parts of admins backend, or to separate them completely. That is dilemma, and it is important dilemma :D

Environments :

  1. user frontend
  2. user backend
  3. admin backend

The environments are the same ones I want to realize. The definition of backend & frontend is quite ambigious as you can see. What seem logical is to use different names & to add one.

  1. visitor end
  2. user end
  3. admin end

With all the different 'advantages' mentioned in this topic & clear naming, this looks like a complete advanced app to me.

@Sammaye
Copy link

Sammaye commented Aug 21, 2014

I have never encountered an app with 3 layers, only 2 layers and a clever RBAC system.

Take my latest project in Yii2 as an example: a ecommerce site.

I have an entire backend which can deal with all the in-house cataloguing and pricing and integration into external resources like NetSuite, Parcelforce, Neilsen, whatever and then I have a frontend which takes the form of the actual website.

On the back I have functions which certain people should not access within the company if they are not of a certain pay grade, for example me as an IT administrator have access to everything, as such I am given the rbac role of god whle many others in the company are given the rbac role of admin.

Normally you have 2 sides to an application with a clever rbac in between to restrict access.

@dynasource
Copy link
Member Author

it all depends from which perspective you look at the application. If you look at it from your perspective and @samdark #4771 (comment), you will get:

  • a clear separation: admin & non-admin

From a programmers perspective it could also make sense to look at it from a presentation perspective. How records from the DB are presented:

  • visitors: published records + listview + frontend design
  • users: user records + gridview + backend design
  • admin: all records + gridview + admin design

As you can see its about designs & filtering. Separate application could make customization easier, cleaner & get other benefits mentioned in this topic.

@dynasource
Copy link
Member Author

@qiangxue, do you see a point in separation by presentation?

@Sammaye
Copy link

Sammaye commented Aug 22, 2014

This again comes down to personal preference as you have said: applications are entities and I don't class super admins and admins as different entities.

The are the same group: admins. Only difference is one is allowed to see x while the oher can only see y.

For example guests and users of an e-commerce site would not get two different apps. When you go to Amazon you don't get two different sites depending on whether you are logged in or not.

An end user, whether logged in or not is an entity and a admin, whether super or normal, is an entity.

That's how I look at it.

I have been trying to think of a time where I would make an app with three layers. I cannot, not retail, governmental, domestic, private etc etc. I cann't think of a time where I can split more than two entities.

@Sammaye
Copy link

Sammaye commented Aug 22, 2014

But that being said, if you are cataloguing on Amazon (which you can) or you are doing an Amazon admin function you do then get a new site, a backend, so to speak.

It looks old and decrepid but it is still a different app.

So yeah, that is the way I see it.

Some apps I can see I wouldn't even split out: a stock monitoring system in a finanicial institution would be all one app, all the users would be admins, the only difference is that one admin can see x while the other can only see y.

@harry-flipkod
Copy link

The backend application as I see it serves one purpose - that's the administering of the website itself. I.e. when we have global admin interface for administering the whole website. A place where we see revenues, number of registered users, charts on how many new users registered by day, how many downloads we had, we're even handling deployments from our admin interface. Honestly - I don't want my Deployment model in the "front" part of the application.I also don't want any of the Statistics models there... etc. Yes, you can put everything in basic template with two main controllers but it's not as clean as having the backend application.

@samdark samdark assigned samdark and unassigned samdark Oct 23, 2014
@jasonhai
Copy link

Please help me with back-end path issue ... I can't access to back-end module in my project :-s ....

My backend project link like this: http://calcart.axeo.net/backend

@lynicidn
Copy link
Contributor

@jasonhai use forum. U have problem with web server configure

@jasonhai
Copy link

@lynicidn : I also dont understand your mean. Please ping me via skype: pmhai90. Thanks so much

@jasonhai
Copy link

@lynicidn Thanks all for your help !!!

@BAWES
Copy link

BAWES commented Apr 1, 2015

Let's say I want to build an e-commerce with front-end for customers, backend for admin, another backend for suppliers, and one more backend for delivery companies.

So I keep the shared models in common folder, but how to create the other backends with their own user type login? Whats the correct process for each section? Modules? Extensions? Application instances (tier)?

@samdark
Copy link
Member

samdark commented Apr 1, 2015

If going with app instances, you can do it by copy-pasting backend directory. It's nothing more than separate apps with their own entry points.

@BAWES
Copy link

BAWES commented Apr 1, 2015

@samdark Thanks! Will try this out

@Sammaye
Copy link

Sammaye commented Apr 1, 2015

Make sure you make a deploy target for them else you will find you have to
constantly copy your ./init files around

On 1 April 2015 at 11:53, Khalid Al-Mutawa notifications@github.com wrote:

@samdark https://github.com/samdark Thanks! Will try this out


Reply to this email directly or view it on GitHub
#4771 (comment).

@BAWES
Copy link

BAWES commented Apr 1, 2015

@Sammaye Can you please explain or point to where I can find how to do that

@gauravparashar12
Copy link

@samdark @Sammaye @qiangxue I am using mdmsoft module (for Rbac ) in the advanced application and separated frontend for website and backend for admin panel.In this case in the mdmsoft module routes of frontend app visible in frontend app and routes of backend app visible in backend app but here superadmin wants to see all the routes at same place.
As per the current situation we need to go frontend app as well as backend app to manage the permissions. But we think that a common platform to manage permission will be more better.

As per my project requirement there will be a admin panel accessed by multiple type of admin users with different permissions needs to manage main website and a superadmin will manage the permissions of few registered users of website and admin users both.

Please suggest us a whether we use advance app or a basic one and how.

@dynasource
Copy link
Member Author

dynasource commented Oct 13, 2016

So, two years further, I can conclude that its very useful to expand an app by more tiers. However, the developer should be careful though. The more tiers, the more complexity you will add to your configuration files. This is the largest setback. Another thing that makes it more complex is the deployment. The more tiers you have, the more deployment settings can be necessary. Also, the more tiers you have, the more difficult is to optimally test your project. If you are running a multi thread testing environment, you have to allocate your CPU's to the tiers which has consequences.

With respect to the advantages. There are many. Code is better organized. Config is better organized. Theming is easier. Performance is better. Risks are lower and its even possible to deploy by tier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:docs Documentation
Projects
None yet
Development

No branches or pull requests

8 participants