Architecture – Understanding how layers are separated in an MVC application

Architectureasp.net-mvc

I am using Visual Studio 2013 MVC 5 application using Razor.

I want to understand in which order layers sit and interact with each other.

In my solution I have:

  1. UI Layer (Main Project) – comprising of Model, View and Controller
  2. Data Access Layer (Class Library) – which contains generic Stored Procedure methods and Connection Class
  3. Repository (Class Library) – which contains data access code (Create/Update/Delete)
  4. Business Layer (Class Library) – which contains business validations
  5. Separate Layer for REST

I am preparing architecture diagram and want to understand how layers talk to each other.

I assume the order is like this:

**Data Access Layer -> Model -> Repository -> Business Layer -> Controller -> View**

Where does REST sits?

Best Answer

I assume by REST you mean a Web Api of some sort?

this should be an alternative UI layer ie

DAL -> Repo -> Model/Services

-> MVC app

OR

-> Web.API

OR

-> Windows app

OR

--> Mobile App

etc

Alternatively you can expose the repository as an API layer (although you'll have to consider security)

DAL -> Repo -> RepoService API -> RepoClient -> Models/BLL(ie on a mobile app with web data)

AND/OR you if your Business logic is comprised of services you can expose these

the idea is to rewrite as little code as possible when you change the user interface