1

I'm doing an MVC 4 architecture diagram for a report and since I'm relatively new to MVC,i was wondering could some one clarify with me is REST (HTTPPOST etc) between view and controller, or controller to model? also should model drawn as in the server side and view + controller on client side?

here a few of my mock ups atm

Diagram 1


Architectural overview of Job Tracking System

  • In your first diagram, the REST block should be on the server, not the client. I assume that you're using a client-side binding framework like Angular there. – Robert Harvey Apr 11 '15 at 16:20
  • yes i am using angular, so basically move all over to the server side except for the view? – Stephen Hegarty Apr 11 '15 at 16:25
  • No, just the REST block. It's in the wrong place. The REST interface will provide data to the controller on the client side. – Robert Harvey Apr 11 '15 at 16:29
  • Thank you @RobertHarvey :) i have one small question just when we are on the topic of angular.js, what is the default REST service used in a defaulf MVC4 project? – Stephen Hegarty Apr 11 '15 at 16:33
  • Actually, what you want that block to be is a Service Layer, which implements REST as its communication model. – Robert Harvey Apr 11 '15 at 16:33
2

You're almost there...

Putting the REST between the view and the controller would be the right choice. That means that your view, i.e. a javascript code, will send REST calls to your server, which process those calls in the appropriate controller (then the models and etc.). In addition this controller would be responsible for the response back to the client.

I believe you have a confusion with the controller's part in the system. Depending on your implementation and application frameworks you're using, the controller should be part of your 'server' layer, which tells which and what view to call/dispatch.

Take a look at the following (simple) diagram:

enter image description here

The controller is responsible for updating the view, and maybe showing you another view. For example, consider the following scenario:

  1. The user fills out a form and submits it
  2. Server validates the form and

    2.1. If it is valid - the controller will route you to a "thank you" view

    2.2. else the controller will route you to a "missing input" view

  3. The user gets the routed view as a response.
  • The third sentence of your answer ("The controller should be part of your 'server' layer, which tells which and what view to call/dispatch.") is the only one that adds anything new. The OP's existing diagram already correctly illustrates the MVC relationships. – Robert Harvey Apr 11 '15 at 16:17
  • Also, the controller might actually reside on the client; it depends on the architecture. If this is a SPA application, the controller resides in a client-side Javascript library like Angular, and the server will provide data to it through a REST interface. – Robert Harvey Apr 11 '15 at 16:19
  • @RobertHarvey regarding your first one, no prob i'll edit to clarify, also I see another hidden question there. Regarding your second comment, Angular more like MVVM (Model, View, ViewModel) more than MVC (even if claimed otherwise). Hence, the way you code Angular is quite "enhanced MVC" :) – Ziv Levy Apr 11 '15 at 16:24
  • Well, now that we're splitting hairs, MVC (as practiced by web developers) isn't quite the same MVC that was invented 30 years ago in Smalltalk, and MVVM is regarded as an evolution of MVC anyway. – Robert Harvey Apr 11 '15 at 16:30
  • Your edit is wrong. The OP has established that they're using Angular, and the REST block doesn't go on the client, certainly not between the controller and the view. You're still thinking the controller resides on the server; it doesn't. – Robert Harvey Apr 11 '15 at 16:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.