An Ideal Folder Structure for .NET MVC

Nestor picture Nestor · Dec 5, 2010 · Viewed 27.7k times · Source

When I started in .NET Webforms I didn't have much trouble finding a folder structure to follow since VS offered you application folders like "App_Code" and most app examples put "BLL", "DAL" inside there and so on.

But now in MVC, every example I check uses different structure, like no standards this time and I haven't found a good solution on Google or SO.

So, maybe we can share how we organize our MVC projects, may help others to make their own mind. Here is the structure for small to medium projects I use:

App_Data
Areas
    Admin
        Controllers
        Models
        Views
    MyAccount
        Controllers
        Models
        Views
Content
    Images
    Scripts
    Styles
Controllers
    HomeController.cs
Helpers
    ExtensionMethods    // I.e. based on HtmlHelper, use "helper" suffix
        MenuHelper.cs    // to be called as html.Menu()
    Utilities.cs    // Other generic (static) libraries, no suffix used
Models
    ViewModels    // for passing models to Views
        RegisterViewModel.cs    // use "ViewModel" suffix
    Customer.cs    // to extend models like adding Model Validation
Repositories
    CustomerRepository.cs    // use "Repository" suffix
Services
    CustomerService.cs    // use "Service" suffix, to move code away from controllers
Views
    Home
        Index.cshtml
        Register.cshtml
    Shared    // Site Layouts (Master templates), also put partials here
        SiteLayout.cshtml

What about yours?

Answer

MJ Richardson picture MJ Richardson · Dec 5, 2010

I have found it simplifies deployment to have the website project contain only content (no compiled code).

Something like:

Web.Site project

   Content
      Images
      Css
   Scripts
   Views
   web.config

And move all compiled code into another project:

Web project

   Controllers
   Filters
   Models
   ...

Then, you can treat everything within the Web.Site project as needing to be deployed, and all required assemblies will be in Web.Site\bin.

Whether you are doing simple xcopy deployment, or using WiX to build an MSI package, this will make life a little easier.