Website Architecture

Published on Sept. 22, 2021 | Tags: python design

This website has been under constant changes essentially since I first created it. I used it as a playground to learn different aspects of web development and web design. First, it was a simple flask application developed in flask and deployed in an rpi0 by pulling the git repo every time I wanted to do changes and using linux services to run the web server. Later on, I containerised it and deployed with docker. Then migrated it to Django. More recently I started using tailwindcss to manage CSS instead of rolling my own. This really was a gamechanger and offered a lot more flexibility in order to write new pages for this website.


So, as mentioned briefly above, this website is developed in Django. For the main static pages such as home, contact and projects (I will update this page soon), I am basically using the Template views built-in Django along with Django templates to display static content. After having my own server where I could deploy these changes using docker, I decided to move to Heroku as it offered a lot more automation out of the box without me having to develop scripts or set up ansible plus calls to the provider's API. I can just push to Heroku directly and let the rest be handled by them.


The difficult part of this new blog was the database. My first idea was to have the files in the repo and just render these, but this posed a problem in which I would have to render markdown on the fly every time thie page was requested which is not much, but sounded not great. This would not offer me possibility to implement cool things like search, filter by dates or any kind of filtering without me having to implement a bunch of stuff and I was not guaranteed success either. Then, I came across the Datasette project really loved the idea of shipping your application, which was mostly read-only, along with the container. Then, Simon itself published this article which made me decide what the architecture of the blog would be. This allowed me to write my posts in my editor and use git to version them easily and comfortably.


Then, this is it. I have my posts in the repo of the website and at build time (or startup time in the case of Heroku) I use markdown-to-sqlite tool to create a sqlite database (which is not just a toy db) and serve it along the application without having to maintain a db instance (or pay for it), not worrying about security, allowlisting, or any other infrastructure-related security worry. Finally, I decided to follow Adam's advice and write my views as simply as possible using just functions. There's not really a need for using complex classes for an application this size and scale.


Overall, I am very pelased with the result. Using a database allows me to use the Django ORM, which I love, and will allow in the future to implement all these features I mentioned above: Search by tags, date, fuill text search, and so on. I am looking forward to learning and implementing all these things. I had a lot of fun designing the frontend of the blog but also designing and investigating all thse patterns. You can check out the all the code for this website in https://gitlab.com/mrswats/fjmwebsite-2.0/.


Ferran Jovell