In 2019 me and some friends started to build a web-based CRM and project management tool, aimed at SMEs 1 as a little start-up project. In the end we did not succeed for market reasons, but I spent quite some time building a nice little web app, and learned quite a bit in the process.
The system consisted out of a back-end written in Golang and using PostgreSQL. The front-end utilized VueJS. As the system was designed to be used as a SaaS product by multiple companies I decided that every company (every tenant) should get their own Postgres database instance. This would also ease backing up and restoring data of a company.
As a web framework I choose Beego, a very old, quite popular web framework in Go, written by a chinese developer. I already included an ORM and some other cool things like the "bee" command line tool. When looking back this framework was maybe not the best choice I could make as development was pretty slow and the ORM was quite buggy. I spent a lot of time debugging it and repairing things in hard to read code, that uses massive amounts of reflections2
.
But never the less I was able to force the ORM to create new DB instances on new registrations by copying a template table in Postgres. An additional table was used called the "user-company-map" that would hold all login data and the corresponding database. Once I recieved a JWT3
authentication token in any request I could check what database it belongs to and retrieve the connection to this DB, passing it on to other controllers in the response chain
You can find a early version of this entire system on my personal git page, feel free to check it out, if you find room for improvement of the architecture please sen me an email, that would be highly appreciated.
You can check out the entire project here: git.lbsfilm.at/lbsadmin/multitenantStack