In my shop, I have shelves mounted between the studs, including a couple for holding my chargers and batteries. In order to hold them, as they are wider than the studs are deep; I made the shelves extend past the studs. As it turned out, this made building the compartment very simple. Most likely, your application will be different than mine. No problem, as with most Instructables, it is the original idea that counts. Just modify my idea to fit your need.
In order to make my existing shelves into a cabinet, I simply cut plywood pieces for each end. After that, all I had to do to finish the construction was to build a pair of doors.