A quick walk through of Sitecore helix on how to setup a Sitecore website based on Helix Architecture from scratch/blank solution
There is two solution to start with Helix:
- First to download the habitat demo site, cleanup and rename the project as per the requirement of the Project, and start working on the top up of the habitat.
- Second, create the solution from scratch means from blank solution.
I always preferred the second approach, because we can have full control of the solution and no need to understand the existing site logic and complexity.
So with the consideration of approach 2, here we are going to setup the site from scratch using Helix principle.
Hope you already have gone through the Sitecore helix principles, habitat documents, and training.
There was a lot of confusion regarding the Helix and Habitat terms, is it architecture? Principle? , design? Sitecore accelerator, what exactly is it?? It was a big question mark in the Sitecore community when Sitecore introduced this in the September 2016.
Helix is a set of overall design principles and conventions for Sitecore development.
Habitat is a real Sitecore project implemented on the Sitecore Experience Platform using Helix. It is an example that allows developers to see how Helix is applied and lets developers experience a project based on these principles.
I am not going to explaining in detail what is helix and habitat?
Refer the below Sitecore helix documentary link for more details:
Helix is all about the structure, structure, and structure, Helix says to split your solution into the logical and physical structure. Everything thing is a component here.
“A Visual Studio solution can host a number of different project types, such as Web Application projects, unit test projects, Team Development for Sitecore (TDS) projects, behavioural testing projects, Xamarin projects, etc., but modules are always grouped by their logical connection to a module – and never by type.”
On the very high level, implementation point of view, I divided the solution into 2 Main categories as below:
- Physical Structure: Create file system structure (physical structure)
- Logical/Virtual Structure: Create Visual Studio Solution structure (logical Structure)
Logical structure- Visual Studio Solution file Structure
For maximum discoverability, the structure of the Visual Studio solution must represent the layer and module structure, i.e. have solution folders for Project, Feature and Foundation layers and separate solution folders for each module. If there are any additional grouping of modules, these can have their own solution folders.
Then I set up the folder structure inside Visual Studio, adding the Project, Feature and Foundation folders. Solution folders are virtual, not physical.
NOTE: it is very important to sync your visual studio folder structure with file system structure, Need to follow some discipline to maintain the structure.
Helix solution has a fixed folder structure on disk.
The first thing is to set up the folder structure on disk. Helix recommend having everything in the folder named src. Habitat places the solution file outside this src folder. We will also follow the Habitats example
Folder structure will looks like:
Here I am starting with visual studio solution, I am taking one project reference let’s start with an Example called: DubaiRTX
Let’s do some workshop:
Create the file system folder called DubaiRTX anywhere in your filesystem, I created under C:/Websites/DubaiRTX
Create the blank solution named DubaiRTX and placed under folder named DubaiRTX
Then create the folder named src under DubaiRTX folder, we will place everything in this folder like below:
Create three folder under src, named Project, feature, Foundation.
Now open the visual studio solution, and create the feature, Foundation, and project solution Folder in the solution.
NOTE: important point to sync the both structure (file system and visual studio solution)
Now, we have three folder in the visual studio and same folder structure in the file system.
So, we have mapped the logical structure with physical structure as below:
Now create the multiple modules under: Foundation, Feature, and Project layer.
First we need to create the subfolder under each layer to categories in to modular format, means we should not create the project directly into the Project, feature, and Foundation layer as per the Helix principles.
Helix Principle based solution
So below is my requirement, I need to create some feature, foundation and main project website:
Feature: Category, navigation, RightTheme
Foundation: Bucket, Security
Let’s add projects into the solution
Add project into the Solution
- Go to visual studio solution
- Navigate to feature > Add solution folder named Navigation > Add new project under Navigation
- Select location of the project > click on Browse > select physical project feature path>
- Create folder named > navigation > and select that path to store the newly created project
- Named the project as Code.
Note: it’s very important to sync your project with proper file structure, that’s why we created folder named navigation in the feature folder and created the project by name called code, because we need to maintain all the project file under the code folder, and it will create the folder directory into the >DubaiRTX>src>feature>Navigation>Code>project files.
Rename Project Name
- Rename the Project name from Code to DubaiRTX.Feature.Navigation as per Helix naming principles.
- Select Project > Right Click>Property>
- Also, rename the Assembly name and default namespace name as highlighted to DubaiRTX.Feature.Navigation and save the solution
Change the Webconfig setting
We need to make sure the Web.config file doesn’t get published, set the build action to ‘None’:
Go to the project > select the webconfig > right click > property > change build action to none
Do the same steps for all project you want to include in the solution:
I have done the same exercise using the above-mentioned steps for 6 projects.
As per the Helix principle
Projects are grouped together in a solution by the layer and module to which they belong.
Project Naming convention in Helix
A project, and assembly should be named in a namespace-like fashion with:
- The overall customer, partner or solution name
- The layer (optional for project layer modules)
- The logical module grouping (optionally)
- The module name
The logical Grouping of the project in the solution:
Feature Name: DubaiRTX.Feature.Navigation
This name is the combination of Company Name, layer module and logical module group as below:
Company Name: DubaiRTX
Logical Module: Navigation
Now check the Physical File Structure as well,
As per the Best practice, all code should be in src folder, then there are 3 layers named feature, Foundation, project.
In each layer, there is a module name, under module name, there is Code folder named where the actual code file is placed.
Below is the snapshot of the Physical structure of the helix based Sitecore project
Done!! oops Also need to add Test Project as well,
Let’s add test project in the solution as well,
Add test project in the Sitecore Helix solution
Add new project
Rename from Tests to DubaiRTX.Feature.Category.Tests
Change the property and assembly name:
Check the file structure of the Tests Project, everything should be under Tests folder
Now build the solution:
Yuppy, Build Successfully!!
What Next? Automation, Automation, Automation, all this step should be done by some script or other tools??? Yes, this is the wish of every developer 🙂
The very first thing came into my Mind for automation is PowerShell, yes I am the big fan of powershell, it is really very powerfull by its name as well.
Good news guys, Sitecore MVP, and the Most Active member of our Sitecore Community Akshay Sura already provided some solution for setting up helix from scratch using Powershell, here is the link:
I hope this article will help you to understand the basic concept’s to setup the Sitecore helix project from scratch.
If you have any questions or concerns, please get in touch with me on twitter @sitecore_ashish or on Slack).
Happy Sitecoring and Helix