Skip to content

Making HRMR

When making my Discord Bot I was thinking of having a SQLite based database backend but I also still wanted to support JSON based databases. I did not want to make a mess of code with either inline if (config.databasetype == "json") etc or making an abstraction layer in the codebase to make things harder to deal with.

So I made a universal abstraction layer in C++ that is fully modular and can have modules hot reloaded at runtime and called it HRMR because it's a hot reloadable module router (yes very good name. im very good at names)

It runs as a TCP server and if the first bit of the TCP request matches a function in a module the module function gets called with the full request passed into it and then it returns a string that gets stent back over TCP.

Its flexible enough to implement an HTTP/1.1 server which is included as an example module in the repo.

I am going to be making a module for HRMR to act as a broker between either a JSON or a SQLite database for my discord bot so it has the same interface for talking to both and it would have no idea. I also can use this same database interface if I want many instances to share one database or if I want anything else to have access to it at the same time.

HRMR also has a thread pool for executing module functions if they do I/O and you do not want to block the main thread. All modules are loaded from .so files and act as native code if they were compiled in which means they have very little overhead besides the indirection system that comes with modules and the need to dispatch things to a thread pool sometimes and calling malloc every time.

But they can also crash the server if not made properly, and they are programmed in C++ so be careful.

This is a pretty nice piece of software I made for myself, and I’m sharing for everyone under the LGPLv3 license and I hope me and many others can use this software as part of thier system. It is fairly well bug tested besides some that I know of and won't fix due to how are they are and I don’t expect to need to change much of the core until a v2 with ABI breakage of modules and some better data structuring to speed things up.