This Blog's Flat File Engine

When it comes to running a WordPress website, there's one thing that can really give you a headache: updates and security. With WordPress being so popular, security flaws are frequently discovered in plugins and even in WordPress itself. This means that keeping up with updates is a must, and it can take up a lot of your time. Plus, updating the wrong plugin can lead to a broken website that needs to be restored from a backup.

I know this from personal experience, which is why I decided to create my own custom CMS system that's sleek, modern, and easy to use. It's a flat file blog engine that's coded in PHP using BBCode for markup. I wanted something that was fast to load, had a small footprint, mobile friendly, secure, and, most importantly, easy to maintain.

While there are alternatives out there like Jekyll in Ruby and Grav in PHP, I found that they didn't quite fit my needs. I didn't want a system with a user interface - I just wanted to be able to load up SFTP, create a new file for my post, and start typing away.

One of the great things about my flat file blog engine is that it doesn't require a database, which means that it's even easier to maintain. It's solved a lot of problems for me, and I'm happy to make it open source so that others can benefit from it too. In this post, I'll be sharing a little bit about how it works, so stay tuned!

What is a flat file blog engine?

What exactly is a 'flat file' system? Essentially, it is a type of system that relies solely on files rather than databases. This makes it much simpler to maintain and migrate, without the need for a large and complex database infrastructure. For instance, the engine powering this blog weighs in at a mere 340 KB (excluding images), which is remarkable when you consider that the average size of a WordPress installation is around 30 MB, and can easily exceed 50 MB once plugins, themes, and databases are factored in. Managing and maintaining such a system can quickly become unwieldy, and even content delivery networks like CloudFlare may struggle to handle the sheer scale of it. Although we are only discussing a blog in this instance, even a relatively small site can become a challenge to manage.

Now how is a ‘flat file’ system even possible?

The system powering this blog, which I personally coded, relies exclusively on PHP to execute its functions. Despite the fact that the URL of the current page ends with '.html,' this may seem curious, as it was done deliberately to prevent bots from identifying the file type as PHP and attempting to exploit it through brute force methods. Additionally, this approach gives the site a more refined and streamlined appearance. To accomplish this, a .htaccess file was created to append the '.html' extension to each post or page, and 'index.php' is employed to locate the appropriate content.

Indeed, you may be wondering how this is achieved. The key to this lies in the 'index.php' and 'header.php' files, both of which are located in the 'assets/inc' folder. Essentially, the 'header.php' file accepts the requested post or page, sorts through it, and then sends it on to the 'index.php' file for display. For example, when visiting a specific post, the 'header.php' file locates the corresponding file in the 'posts' folder by matching the URL, and then extracts relevant information such as the title, date, summary, and featured image. This information is then forwarded to 'index.php' for display on the site.

The Code

Now that you have a basic understanding of what a flat file system is and how it works, you can see the benefits of using it over more complex and traditional database-driven systems. The simplicity and ease of maintenance are undeniable, making it a great choice for those who want a fast, efficient, and secure website.

You can check it out on Github @ https://github.com/dudetechitout/another-flat-file-engine/ and see for yourself on how it can benefit your own website or project!