Saturday, July 28, 2012

Things To Think About Before Building My Own CMS

If you're considering developing a content management system of any magnitude from scratch, it's probably a good idea to sit down with a scratch pad and think through how you will approach the project. What languages will you use? How are you going to store files? Will this be for a single developer (for just personal use) or will you have levels of access (for use in development teams, or for developer-client use)? My assumption is, for your first time, you probably want to start with basic functionality and options. However, from a professional developer's viewpoint, you should always consider scalability with any project you might put to code. Let's look at some examples.

Dirt Simple CMS - the humble beginnings

When I started doing freelance Web building as a teenager, the clients were quite happy to let me do all the work, including updating content and managing resources like photos, etc. The projects were simply promotional sites and didn't need to be updated more than once a month. As I got older and more skilled, clients became more demanding, and I had less time on my hands. Time to look into investing in a self-sustained content management system and let go of control of content. So I sampled a few simple CMS's out there, having been fully disenchanted with the full-service systems available, and ultimately decided to build my own.

My first attempt at a simple CMS used mostly Javascript and a tiny scrap of PHP for updating data. I pulled out Ben Alman's .hashchange() jQuery plugin, and then played with that using a little AJAX and a single JSON file to store the entire site content -- only about six pages. Eh, it serving its purpose. So what if the site can't be crawled by Google. It took me all of a single afternoon to code it. (I'll post about that project later.) Also, you know that scalability thing we talked about earlier? Using a NoSQL database system like JSON or XML won't really scale well when it comes time to store and manage large sites using more complex queries. So play with NoSQL, if you must, but when you're ready to get down to business, go ahead and pull out a SQL database.

A Better (Yet Still Simple) CMS

The next iteration of our homemade management system should, as I mentioned, include a full-service SQL like MySQL or MSSQL. And since we're saving data to a server, you will need, of course, a familiar server-side language, like PHP or ASP. Put down that Javascript reference, because we're going to do this properly, which means progressive enhancement comes after we've made a functional, SEO-friendly CMS. And it wouldn't hurt to brush up on Regular Expressions to do some data parsing as well. I would have considered suggesting a little mod_rewrite using .htaccess for this iteration, but you can still create a fully functional yet simple CMS without needing to manipulate URL requests just yet. Later we'll get into virtual file systems, which is ultimately what I'm going to use. For our simple CMS we just need a way to create templates and to query and display the appropriate content for the pages. We're still creating the pages manually, just like we did back in high school Web Design class, and adding in the template with server-side code. (I'll also post some examples, and maybe a tutorial, for this concept later.)

Automated All The Way

There are probably more subtle iterations we could discuss before setting loose on a full-service CMS, but I'm getting impatient. Lets jump right into a fully automated CMS, which, for large projects and/or a team of more than one, is going to be necessary from the word go. We don't want to create pages manually. Heck, we don't really even need pages to exist until they're requested by the user. I'm a strong proponent for never writing duplicate code if it is unnecessary; and truthfully, when is it every really necessary? But automation proposes new challenges. How will you create virtual file systems? How will your content editors create and manage the files? How will end-users request them? One approach is to store new pages in a database table and use mod_rewrite to redirect page requests, which I plan to do. These, I'll admit, are not simple concepts, and there are many common and disputed schools of thought on how best to create and manage tables for a virtual file system; and there is more than one way to use .htaccess for URL redirects (if .htaccess is even the route you would like to take). My boss commonly reminds me to "do the simplest thing that works". So I'm going the route that makes the most sense and is easiest to implement for me. (These topics will probably be posted about the most on this blog.)

Wrapping up

I know this post was not exactly instructional, but hopefully it's brought up some things to consider before tackling this kind of project. If you think of anything I may have missed (and of course, I've skipped over a plethora of topics that might be appropriate to discuss at the 10,000 foot view) please comment.

Friday, July 27, 2012

What's the deal? Why write your own CMS?

I've set out to build my very own content management system (CMS). "And why am I doing this?" You ask. "That wheel's been reinvented ad nauseum." Well here's my anti-climactic, if not extremely predictable response: I'm just looking for a new challenge. I mean, who doesn't pipe-dream about writing their own game of Chess or Solitaire during their next beach vacation? And who hasn't tried to design their own RSS feed reader over Christmas break? Anyone? Bueller?

Okay, so it's not the most exciting project in the bucket. Sure I have other, more achievable project ideas that I could probably be putting to code; a laundry list of side projects for clients I could be spending a little more time on. Not to mention the actual laundry that has been piling up and that I've been promising my wife I'd wash before it sprouts legs and walks out of our apartment in disgust. My point is...well I've kind of lost the point. Henceforth, my point shall be I want to do it and there's nothing you can do to stop me, so stop complaining and read on.

The inspiration

Back in May I started working on front-end Web development with a largish company in the Knoxville area. On my first day I was tasked with training myself on the company's CMS software of choice: an ASP.NET-based behemoth with a lot of little-use controls and clunky file system design. Sure, it has good documentation, but the modules are fairly non-intuitive. It has a steep learning curve for those not familiar with CMS templating and filesystem, and it forces an incongruous separation of back-end and front-end development. I also have principle issues with using the closed-source ideology of Microsoft-based systems when creating such a globally distributed and innately open-sourced resource as a Web site. I might be a little melodramatic, but there it is. That is what has inspired me to create my own CMS. Well, that and a few other things I won't delve into in this post.

Approaching the giant

Endeavoring to build your own content management system from scratch is all about the process, not the product. Like Ralph Waldo Emerson so eloquently stated, "Program development is a journey, not a destination."...or was that Steve Jobs? Every Web development project I've ever picked up has started out half-baked and ended up only one third finished. This project is really no different and I have roughly the same expectations. I'll put that out there right now, just so we're starting off on the right foot. However, I've never embarked on a project with which I didn't gain exponentially more knowledge.

I've been stewing this idea of a ground-breaking CMS in my head for the past several months. I've only recently decided it would be a brilliant idea to blog about it. Writing brief and interesting prose has never been my strong suit, and I just thought there should be some documentation of that out on the interwebs somewhere, hence this blog is born today. Let's see where it goes.