School me on Javascript MVC Frameworks

Status
Not open for further replies.
So, I've seen stuff like Backbone touted as a new way to write web code, pushing the model and the controller out into JS, and it intrigues me, but I don't really understand it. it seems like this could be a serious issue anywhere that the user can modify JS code (which is everywhere), and I'm not sure how things like authentication would work, either. I've looked around some on Google, but it seems like there are about a dozen of these different frameworks showing up, all of them shouting how different they are, and I'm still trying to get a handle on just how they differ from writing the PHP that I'm used to.

Can anyone help me enlighten myself?

Thanks in advance!
 

insertinanename

Ars Legatus Legionis
10,768
Subscriptor
Just because your client side code is organized to an MVC-like architecture doesn't mean you don't do server side validation or processing. The primary benefit of MVC libs like Backbone is that it lets you easily separate your code, just like MVC on the back end. For example, you would have views that display various pieces of data. But each view could automatically rerender itself whenever the underlying data, fetching by your model, changes.

This isn't moving your server side M and C to the client side. This is organizing your client side code in a reasonable way when in complex apps, your javascript starts to grow really large.

So users modifying JS code is a nonissue, assuming you're grabbing data from proper sources and doing proper sanity checking on the backend.
 

tinyMan

Ars Tribunus Angusticlavius
6,149
Subscriptor++
Client Side MVC can mean many things.

You can just "touch up" an existing server-driven HTML side with some Ajax interactions, or you can go full monty and use something like ExtJs 4's MVC system to move a gigantic chunk of your applications code to the client.

No matter what solution you use, the standard "never trust anything from the client" rule still applies. Sure, your app's JS code might have input validation to stop people from entering incorrect data, but your web-service tier also must re-validate that input.

Lately, I have been building all my front-end apps using a model that pushes the majority of the work to the client. I started with jQuery+jQuery UI, got tired of the lack of organization, tested out BackBone and Javascript MVC and eventually settled on ExtJS for our apps due to the speed that I was able to get some amazing functionality out the door.

The awesome thing about this process was that the server side code (all web services) did not need to be changed at all. That is the big benefit that we have been getting from this development model. We write and publish a "resource" through a web service, and then consume said resource via iApps, Android Apps, web pages and procedural code.

Authentication, as you mentioned, brings up some issues. We have a "login" webservice that front-ends can use to submit credentials for validation. If the credentials are approved, the service responds with a "Permissions" resource that lists the various activities that the credentials have access too. I just tuck the Permissions into a global-scope variable and use if to turn various features and functions on or off.

If a user intentionally subverts this mechanism, say to turn the "User Management" functionality on when their credentials don't allow it, then they will get to see the User Management tab in the interface, but when they try to open it, the web service call will fail, because, duh! Never Trust Anything From The Client. The key to making this work is having the client submit credentials with every web-service request. That way the server can validate permissions for every call, but you don't need to keep any state/session on the server. Makes scaling easier too.

Now, if you are writing a game/content app where there is little server interaction, then this model might not work for you, but for the apps we have been building, which are your typical Dashboard/Content Management/Reporting tools, it has worked very, very well for us.

Technically, our web service resources are built around a MVC model, published via RESTful interfaces to a MVC client app. Does that makes it MVCMVC? MVVC? I get confused with the terminology :)
 

Faramir

Ars Legatus Legionis
36,356
Subscriptor
The notion is generally coupled with a very strong focus on stateless servers with very loose coupling to the application (e.g. REST)

The server is there to hand out data or process valid transactions if asked to by an authorized user. How that user came to send a request is not relevant to the backend. As for as it cares it could be programmatic, a client side web application, a mobile application or a full blown desktop application.
 
Status
Not open for further replies.