Show HN: Hyvor Blogs – Multi-language blogging platform
Here are some enjoyable technical experiences we had &#x2F; decisions we made while developing Hyvor Blogs...<p>Tech Stack<p>Our other product, Hyvor Talk [<a href="http:&#x2F;&#x2F;talk.hyvor.com" rel="nofollow">http:&#x2F;&#x2F;talk.hyvor.com</a>], handles more than 30 million users and 500 million requests each month for a considerably low hosting cost using monolith architecture. So, it was a no-brainer to use the same technologies:<p>PHP and Laravel for the backend
MYSQL for the primary database
Meilisearch [<a href="https:&#x2F;&#x2F;meilisearch.com" rel="nofollow">https:&#x2F;&#x2F;meilisearch.com</a>] for the search index
Redis for cache<p>PHP isn’t dead. It definitely has some weirdness introduced in older versions that cannot be removed due to backward compatibility promises. However, recent versions of PHP have improved performance and developer experience significantly. Also, we use strict types and PHPStan [<a href="https:&#x2F;&#x2F;phpstan.org" rel="nofollow">https:&#x2F;&#x2F;phpstan.org</a>] (max level) to ensure type safety. And, we try to have 95%+ coverage using Pest PHP [<a href="https:&#x2F;&#x2F;pestphp.com" rel="nofollow">https:&#x2F;&#x2F;pestphp.com</a>]. With those tools, writing PHP is fun. Laravel saves a lot of time by abstracting away many HTTP, queue, and CLI-related tasks. MYSQL is the single source of truth. We sync data to Meilisearch for search. Laravel Scout makes syncing effortless. Redis is used for caching and queues.<p>More details on the open-source software we use are available here: [<a href="https:&#x2F;&#x2F;blogs.hyvor.com&#x2F;docs&#x2F;oss" rel="nofollow">https:&#x2F;&#x2F;blogs.hyvor.com&#x2F;docs&#x2F;oss</a>]<p>Theme Development:<p>In Hyvor Blogs, all themes are fully customizable. We wanted to make the theme development process as friendly as possible for developers. Being a hosted software, this is quite hard. Developers aren’t fond of (including me) editing a file on the browser to make something work. Providing an online web editor to create themes wasn’t an option. So, we created a simple CLI tool [<a href="https:&#x2F;&#x2F;github.com&#x2F;hyvor&#x2F;hyvor-blogs-cli">https:&#x2F;&#x2F;github.com&#x2F;hyvor&#x2F;hyvor-blogs-cli</a>] that developers can install locally via NPM. This CLI tool listens for file changes and syncs all theme files to a development blog in our production system. So, developers can make changes in their local editor and see changes with almost no delay. This has worked pretty well so far!<p>Theme Structure:<p>We wanted to keep the theme structure simple. No Javascript frameworks - just plain old-school HTML because it works the best with search engines, minimizes the data transfer required between the server and the browser, and even provides a better experience for end users.<p>We obviously needed a templating language to render HTML from data. There were many options like Handlebars, Liquid, and Twig. All do the job. We went with Twig because its original package is written in PHP and managed by the Symfony team so we could trust it and easily integrate it into our system.<p>Another thing we cared about a lot is creating standardized theme guidelines. For example, if you take WordPress themes, most themes have their own structure and are very different from each other. This adds a learning curve to each theme. To prevent that, we created standardized theme guidelines for all published themes to follow. We also standardized how common things in blogs like color theme switching, searching, language switching, etc. work. This helps users switch between and customize their themes effortlessly.<p>Then, there is one important thing we realized. “The structure of a blog is very simple”. First, you might think you need several stylesheets, jQuery, bootstrap, etc. NO! Just one stylesheet and barely some vanilla javascript for interactive elements like search. Realizing this helped us further improve theme performance. In our themes, the developer writes several SCSS files inside the &#x2F;styles directory. This makes it easier for them to manage styles in chunks. Then, we convert all SCSS files into a single styles.css when loading it in the blog. That way, only 1 HTTP request is needed for styles - it’s super fast!<p>You can see more about theme development here: [<a href="https:&#x2F;&#x2F;blogs.hyvor.com&#x2F;docs&#x2F;themes-overview" rel="nofollow">https:&#x2F;&#x2F;blogs.hyvor.com&#x2F;docs&#x2F;themes-overview</a>]<p>All official themes are free and open-source. [<a href="https:&#x2F;&#x2F;github.com&#x2F;hyvor&#x2F;hyvor-blogs-themes">https:&#x2F;&#x2F;github.com&#x2F;hyvor&#x2F;hyvor-blogs-themes</a>]<p>We have ported multiple open-source themes, and now working on a couple of original themes as well.<p>Caching:<p>We incrementally cache content using “first-request caching”. If you visit a post in the blog, the response is dynamically created and cached. Subsequent responses are served from the cache until the blogger updates the post.<p>This is highly efficient and scalable. Also, there is no building step involved as in Netlify or similar static hosting platforms. You can immediately see changes but also benefit from caching.<p>The cache is saved on a Redis server in our data centers, but we may try CDN edge caching in the future.<p>Multi-language support:<p>Multi-language support is probably the most unique selling point of Hyvor Blogs. The first version of Hyvor Blogs did not have a multi-language feature. Adding that feature took a lot of careful thought and effort, but it was totally worth it. I can safely say there’s no other hosted blogging platform that makes managing multiple languages as easy as Hyvor Blogs does.<p>First, we had to figure out what data was translatable. For example, post content, description, etc. Then instead of saving that data in the `posts` table, we created a new `post_variants` table to save them linked to a specific `language_id`. The blogger can create multiple languages and each entity (`post` , `tag` , `user`) can have variants for each language.<p>Additionally, we integrated DeepL [<a href="https:&#x2F;&#x2F;deep.com" rel="nofollow">https:&#x2F;&#x2F;deep.com</a>] to let bloggers automatically translate posts into many languages.<p>Data API filtering:<p>Our Data API [<a href="https:&#x2F;&#x2F;blogs.hyvor.com&#x2F;docs&#x2F;api-data" rel="nofollow">https:&#x2F;&#x2F;blogs.hyvor.com&#x2F;docs&#x2F;api-data</a>] returns public data of the blog. This is also internally used in themes to fetch additional data. If you think about filtering data (ex: posts), one may want to filter `published_at &lt; {time}`  while another wants `published_at &gt; {time}`. If we went with the normal API approach, we’d need many query parameters like `published_at_greater_than`, `published_at_less_than`, etc. That’s ineffective. So, we wrote a little query language called FilterQ to take a single `filter` input parameter and safely convert it to the `WHERE` part of the SQL query. With it, you can call the API with `filter=published_at&gt;{time}` param. And, it’s even possible to use `and` &#x2F; `or`  and grouping for complex filtering.<p>Library (implemented in Laravel): <a href="https:&#x2F;&#x2F;github.com&#x2F;hyvor&#x2F;laravel-filterq">https:&#x2F;&#x2F;github.com&#x2F;hyvor&#x2F;laravel-filterq</a><p>Sub-directory hosting:<p>We designed a new way to host a blog in a subdirectory of a web application. Let’s say you have a Laravel application at example.com. We created Delivery API [<a href="https:&#x2F;&#x2F;blogs.hyvor.com&#x2F;docs&#x2F;api-delivery" rel="nofollow">https:&#x2F;&#x2F;blogs.hyvor.com&#x2F;docs&#x2F;api-delivery</a>] to help you host your blog at example.com&#x2F;blog.<p>This API tells you how to deliver a response for a request (hence “Delivery” API). For example, when your Laravel app receives a request to &#x2F;blog&#x2F;hello-world, your app calls the Delivery API to learn how to respond to “&#x2F;hello-world”. The Delivery API returns a JSON with all the data needed. Your app will then use that JSON response to create an HTTP response and send back the response to the client. It will also save the response in the cache so that it doesn’t have to call the Delivery API next time for the same path.<p>This is quite similar to a reverse proxy with caching, but the JSON API makes it easier to use it in web applications as we do not need HTTP parsing logic.<p>This is also similar to how our “first-request” caching works, but this time this caching happens inside your web application. To clear the cache, we use webhooks.<p>For now, we have developed libraries for Laravel and Symfony for sub-directory hosting, with plans to cover more frameworks in the future.<p>Rich Editor<p>This was probably the hardest part of all. We spent months testing many frameworks like Draft.js, Prosemirror, and even pre-built rich editors like TinyMCE. We wanted customizability and also ease-of-use. No framework checked all boxes.<p>We decided to go with ProseMirror [<a href="https:&#x2F;&#x2F;prosemirror.net" rel="nofollow">https:&#x2F;&#x2F;prosemirror.net</a>]. It was complex but eventually, we came to understand the power of it. It has a steep learning curve, but it’s totally worth it. We actually enjoy writing Prosemirror plugins now to add some functionality to the Rich Editor. Also, recently the author added typescript support, which incredibly improved the experience. We created many nodes like Blockquotes, Callouts (with emoji), Images with captions, Embeds, and Bookmarks pretty easily after that. ProseMirror has quite good browser support as well.<p>Flashload<p>I’ve been a fan of InstantClick [<a href="http:&#x2F;&#x2F;instantclick.io&#x2F;" rel="nofollow">http:&#x2F;&#x2F;instantclick.io&#x2F;</a>]. We wanted to add something similar to all blogs to add a “fake-fast” effect. If you haven’t used InstantClick before, it is a simple library that turns separate HTML pages into a single-page app. It starts loading content on the mouseoever event of a link and replaces the &lt;body&gt; when clicked on it. This makes navigation super fast. We created an almost copy of Instantclick named Flashload [<a href="https:&#x2F;&#x2F;github.com&#x2F;hyvor&#x2F;flashload">https:&#x2F;&#x2F;github.com&#x2F;hyvor&#x2F;flashload</a>] with additional configurations and optimized caching. Feel free to use it in your projects :)<p>Overall, it’s been a great learning experience working on Hyvor Blogs. We’d love to know what HN thinks about our project. I am happy to answer any questions you might have.