This is the story of how I said “Goodbye! 👋” to my 14-year-old codebase.
I co-founded arı24, the online student newsletter for Istanbul Technical University in 2009. At that time, I had no idea that I was creating something that would exist for longer than a decade and something that would be widely recognized and respected by every member of the university.
In 2009, the codebase started as a CakePHP project, uploaded to shared hosting with FTP. It had a very basic URL routing scheme based on object IDs. I wanted to host the codebase in an SVN repository because I wasn’t comfortable enough with Git back then. Unfortunately, it is hard to get this habit if you are the only one working on a project.
Around 2012, I was pretty occupied with contributing to open-source projects and my internships. An outside collaborator started to work on arı24. It was a complete rewrite with more features and more complex URL routing schemes. At the same time, it was the exact opposite of best practices.
My consistent attempts to host the codebase in an SVN repository were denied. We rendered HTML tags inside PHP code. The classes were not what you expected them to be. Instead of creating new instances for different objects, we had a
select() method that modifies the existing reference.
$post = new Post(); $post->select($postId); // ¯\_(ツ)_/¯
Even though I am grateful for this outside collaborator to step in when I was focused on different things, for a lot of things in the codebase I still wonder “Why?” 🤔
In the 5th year of arı24, in 2014, we were popular enough to have a dedicated software development team of volunteer students. It was a great opportunity to set things straight.
We migrated from shared hosting to our own VPS. We started using Git for version control. We even had continuous deployment pipelines, deploying each commit to the production.
First, we started using Vagrant for our development environments to make sure anyone can set up a local workspace in one step and it was the replica of our VPS setup.
Second, I focused on some best practices and improvements to increase the developer experience. The two most important changes were implementing a router and leveraging a template engine. These two changes helped us to apply the MVC pattern once again, although model implementation had never been finished. The team released multiple features during this period, and it was one of the most active times for the project. I am proud of this team.
Over the next few years, we lost focus on the project again. We graduated from university and had full-time jobs. I was the only developer once again, and it was a maintenance-only time for arı24. I upgraded PHP and MySQL versions to keep the site alive after the operating system upgrade in the VPS. Things were mostly stable, but the project didn’t scale well as some of the tables in the database reached millions of rows.
Especially in the admin panel, some pages started to take forever to generate and even timed out randomly. The project needed a plan to move forward…
Even though we modernized the public-facing pages with views and controllers, we still didn’t have a proper model implementation and our admin pages were a huge pile of spaghetti and our main pain points. The year was 2019, few months before the COVID-19 pandemic, and it felt like the right time to migrate to the Django Framework because of the following reasons:
- PHP was not more popular than Python anymore and Python offered more readability with better tooling and more opportunity to attract volunteer students.
- Django has a great implementation for models, database migrations, and ORM which makes developing new features easier.
- Django generates admin pages automatically and they are very easy to customize and maintain.
I started a new codebase and a Django project and created the models for our database tables. It wasn’t a hard task but took a lot of time because of the tiny details. At the end of a couple of weeks of work, I completely replaced the old admin panel with Django.
We had one goal, the old codebase with PHP would only be used for public-facing pages with read-only connection to the database. All database write operations and all file uploads would go through Django. For this reason, in addition to the admin panel, we implemented a couple of forms and API endpoints in Django. Until today, the old and new codebases lived and served together.
I knew migrating all public pages to Django and making a huge switch won’t be an easy task, so I decided to migrate controllers one by one. To achieve this, I had to move static assets from the old codebase to Django and create the same base template for pages. Again, this wasn’t a hard task but took a lot of time because I also had to make sure the PHP codebase can serve pages with references to assets in Django.
I needed to configure path-based routing between Django and PHP applications. Most importantly, since the Django application requires a restart for each release, I needed to find a way for near-zero downtime releases. At this point, I decided to containerize the application and use the docker rollout plugin. With the proper tools to support my development, I migrated more than 20 controllers in the last 3 months. And, as of today, our 14-year-old PHP codebase is now officially dead.
The development of arı24 always had a theme of the Portal series. Hostname of our VPS is “GLaDOS“. There are a lot of references in commit messages. In my last commit to the codebase, I couldn’t miss the chance to give one last reference to the Portal 2 ending song “Want You Gone”:
commit e1bb9fa783ca4c2b5d4865e07514da48c2db4ea8 (HEAD -> master, origin/master, origin/HEAD) Author: Onur Güzel firstname.lastname@example.org Date: Sun Jul 16 21:29:05 2023 +0200 Terminate project I used to want you dead But now I only want you gone