Monthly Archives: March 2011

ChopShop: A MVC.NET E-Commerce project

I decided to start a little open source project recently.  The idea was that it would allow me to flex some programming muscle, play around with some technologies I wouldn’t be allowed to use at work now and generally make my karma better by giving back (to whoever decided to pick it up) – who knows, it may be the next Magento (yeah right!).  Over the course of this coming year I’m hoping to carry on working on this project and documenting some of the decisions I’ll be making around the codebase.

High Level Architecture Decisions

Although I have a features list in mind that’s about a mile long, my intention, with regards to code architecture, is to keep things as simple as possible.  The application will be split into two websites – one for the front end (the Shop) and an administrative back end.  Keeping scalability and performance in mind, the idea would be to allow the front end to be customised/expanded independently of the admin site – the only thing linking the two would be the database.

My web application of choice will of course be ASP.NET MVC 3 using C# 4.  Database persistence will be handled by NHibernate 3 and the entire thing will be glued together with Castle Windsor 2.5 and jQuery.  I’ve opted for a fairly typical (I think) n-tier logical architecture liberally using Interfaces to keep the layers separate.

The general pattern to get data from the database to the browser would be for the Controller (in the Web project) to request some data for a View Model from a Service. I’ve opted for a very simple Repository pattern allowing Windsor to inject dependencies for me based on the “WithFirstInterface” convention. The service would then request data from the repository, pass it to the Controller, which then gives it to the ViewModel to mash together into whatever the View requires.  There is some implementation leakage from the Repository layer into the Service layer, but that is acceptable due to the dependency on NHibernate in the first place.  I felt that keeping things DRY and SOLID far outweighed any perceived need to change out the ORM at any future stage (thus also sticking to YAGNI).

So far, so very simple, but then again I’ve been mainly working on putting the framework together for the Admin site.  The architecture for the Shop could look different (but only very slightly).  One of the most fundamental architectural decisions in this project is that each component must be swappable (with the exception of the data access layer).  One of my aims is to have multiple payment providers, so being able to have a plug and play architecture will be vital.  Designing the application this way should also allow for each component to be tested without affecting any other components.

The TL;DR architectural summary then would be:

  • Take a dependency on NHibernate
  • Take a dependency on ASP.NET MVC 3
  • Separate layers/components intelligently with Interfaces
  • Glue the layers/components together with Castle Windsor
  • Create a series of unit tests around each component

 

Project Management

The biggest problem I’ve traditionally had with doing little projects like these in the past has been the lack of focus around what it is exactly I want to achieve.  To combat this, I’ve taken to using agilezen.com to record all the different user stories that I want around the creation of this application.  To date there’s around 52 stories and so far I’ve only managed to complete 1(!).  The downside to User Stories is that they don’t take frameworks and infrastructure into account.  The User may only care about adding a Product to their Catalog, but without a supporting framework in place very little can be done.  I’m still not sure how I could approach that kind of “start up” problem better – I’m sure it’ll come to me the more projects I start up.

 

Mac: MacBook Pro hard disk upgrade

It didn’t take long before my requirements for my laptop exceeded the capabilities of the thing.  The bottom of the range specification of a 250GB hard disk with 4GB of RAM is very quickly overcome when trying to run Windows 7 and Visual Studio 2010 through Parallels.  The latest refresh of the MacBook Pro didn’t take my fancy either – it just doesn’t seem worth the money and I may as well wait out another year.  So what’s a geek to do when the laptop’s hard disk is straining due to my having carelessly thrown two operating systems at it as well as a couple of development environments (that’s XCode rather than TextMate) and my whole music collection?

Well I could have upgraded the entire laptop but where’s the fun in that.  A quick look on scan.co.uk brings up a a very reasonably priced Western Digital Scorpio Black 500GB.  Under £50 for a hdd that’s twice the capacity and much faster than my current one – yes please.  Might as well upgrade the RAM at the same time (because modern OS’s need more than 2GB each to run smoothly), but sadly Scan was out of stock.

So the problem becomes very simple: What steps are required to migrate hard disks without losing any data or settings when you run Windows 7 on a BootCamp partition with Parallels (although I imagine the same process applies to VMWare Fusion)?

I needed:

  1. An external hard disk of some description (I bought another 3.5″ SATA, which I was going to re-use after in my desktop, together with an external HDD enclosure that I am already using for my media center). This will preferably be bigger than your existing laptop’s HDD.
  2. A MacBook Pro (mid-2010 vintage although I don’t see why it wouldn’t work with something older).
  3. A tiny tiny phillips screwdriver and a size 0 Torx screwdriver.
  4. TimeMachine (comes with Mac).
  5. WinClone (free download).
  6. The original OSX install CD that comes with the MacBook
  7. Lots and lots of Time…

The first thing I did after connecting the new external hdd to the laptop (via USB) was to partition it into 2.  One partition would be for the OSX backup and the other for the BootCamp image.

Next, run TimeMachine to take a full backup of your OSX installation.  Set the destination to the external disk and wait for a few hours.  TimeMachine will back absolutely everything up… EXCEPT the BootCamp partition.  Which is where WinClone comes in.  After TimeMachine has finished, run WinClone and take an image of the BootCamp partition.  I placed this image directly on the partition of the external HDD reserved for it.

Once both of these processes have finished, power down and swap the hard disks round.  The actual assembly/disassembly time was in the region of 15 minutes – less if you have a Torx screwdriver, but a small set of pliers will do the trick too.  Rather than describe the process there’s a very succinct video on YouTube showing the process.

With that out the way, power up the laptop and pop the OSX CD in.  When the bootstrapping process has completed, OSX will ask whether you want to restore from a backup.  It wasn’t entirely intuitive and in your face like most of Apple’s prompts, but you’ll need to look for a menu item at the top for the utility to restore.  Before you do that though you will need to create a partition on the new hard disk (otherwise there’s nowhere for the OS to install to) and this can be found in the Disk Utility.  You can then set TimeMachine to restore to the new partition you’ve created on your brand new hard disk.  After waiting for what seemed like a long time (overnight) your laptop will be ready to go… almost.

What’s still missing is the Windows installation that’s still sitting as an image on the external hard disk.  Fire up BootCamp again and recreate a BootCamp partition.  As I now have a larger hard disk I can afford a larger Windows partition, so I created it twice as big as my last one.  Once that’s been created (don’t go through the whole process, just create the partition), I used WinClone to restore the image onto the new BootCamp partition.  However, because I increased the partition space and want to take advantage of that exra space, I needed to do one more thing.  The Tools menu on WinClone has a menu option to Expand NTFS Filesystem, use this on the new BootCamp partition and you’re pretty much all set.

At this point, Parallels still complains that it can’t find the Virtual Machine you’ve just lovingly restored into the new BootCamp partition.  That’s because it’s still looking for it on the old hard disk.  Power down the Virtual Machine and look in the Config menu.  Switch the hard disk in the dropdown to point to your new disk and then restart the VM.  Windows will go through a process of checking the disks but after that everything should be back to normal.

And so ends (part of) my laptop upgrade journey.  It was a lot easier than I thought it would be (this being an Apple product and all).  Next up is a RAM upgrade but that should be a lot easier now I’ve opened it up once already.