td204

Web development, one post per year since 2002

2008 in review: writing my own framework, without calling it that

I launched nine small sites over this year and the next, and they are, to the file, the same application. Same directory layout, same entry point, same config.php, same models/, same cron/, same inc/. Different content, different design, different domain.

I had written a framework. I did not think of it that way at the time. I thought I was copying a folder.

What was in it

index.php
config.php
includes.php
main.compile.php
models/
inc/
ajax/
assets/
cron/
cache/

An entry point that routes. A config file per site. A models directory, so data access lived somewhere other than the page. An ajax directory, because 2008. A cache directory and a compile step, because shared hosting was slow and PHP had no opcode cache I could rely on.

That is a recognisable MVC-ish structure, arrived at not by reading about patterns but by being annoyed nine times in a row.

The part I got right

Separating the model from the page. Once data access lived in models/, a fix to a query was one edit rather than a hunt through templates. Everything good about the structure follows from that one decision.

The part I got wrong

Copying the folder. Nine sites shared a design, and none of them shared a line of code. A bug fixed in one stayed broken in the other eight until each one bit me separately. An improvement was nine edits, so improvements stopped happening.

I knew this was wrong while I was doing it. What I did not have was a way to share code that was cheaper than copying: no dependency manager, no autoloading standard, no packages. Copying was the technology available. Composer was four years away, and when it arrived, this is the pain it landed on.

Small sites, plural

The strategy that year was volume: many small niche sites, each cheap to produce because the ninth one costs a tenth of the first. It worked for a while, in the sense that it made money.

What it does not survive is maintenance. Nine sites is nine sets of updates, nine bills, nine inboxes, and the revenue per site does not scale with the attention each one demands. I am starting to suspect that any business model whose margin depends on never touching the thing again is not a business model.

In short

Nine small sites, one copied codebase, and a directory structure I had accidentally turned into a framework.