> ~ biozz / Projects

cookiecutter-biozz-project 2024-02-22

A template for the #wow projects

https://github.com/biozz/cookiecutter-biozz-project

This is the one I wanted to write about for quite some time, because it has been used for my #wow projects (groceries, debt, lately and secret at the time of writing this).

First of all, it is a Cookicutter template, which allows me to kickstart new projects with minimal effort. I know some people prefer vanilla go gen templates in Go ecosystem, but because I am coming from the Python world, I am used to Cookicutter. To be honest, Cookiecutter is language agnostic and works great.

This template will generate a Go project, which is structured mostly according to golang-standards/project-layout. There is a cmd package, which uses urfave/cli. One of the commands is always server, because this template is for web-based apps. Other commands are usually created according to the specific needs of the application. It may be some kind of data import task or a bot.

server command uses environment variables for the configuration. In general, I prefer environment variables as much as possible. I was thinking about adding a smart configuration which can parse YAML, TOML, env vars and command line arguments, but that was too much of a task for me and I decided to stick to a single source approach.

Speaking of tasks, I am using Taskfile instead of Makefile, because I like how you can start a server and make Taskfile watch for changes wihtout installing additional tools. I also like running frontend and backend processes in parallel, Taskfile allows that with no problems.

I mentioned frontend, let’s talk about it. It is located in web directory, which is a Go package, which embeds generated frontend bundle. I don’t worry about commiting my bundle files to the repository and it makes my life easier when I deploy my apps.

The frontend itself is made using SolidJS with Solid Router, because I like how it is mostly pure TypeScript with a little bit of TSX. No special syntax (like in Svelte), no strange non-HTML5 standard tags (like className in React), only the basic primitives and very intuitive for backend developers like myself.

Frontend app is styled using TailwindCSS as I find it very easy to use, and again, quite intuitive. I might switch to UnoCSS at some point, because it is fully TailwindCSS compatible and uses fewer files to configure.

One of the options which I lean torwards when I try new things is HTMX. I haven’t figured out how to make my Cookiecutter to generate different structure based on some conditions, so I might create a separate one in the future.

Last, but not least, I have a basic configuration for the Centrifugo interaction. In the past I used to have my own WebSocket server based on olahol/melody, but quickly realised that I need something more robust with predefined authentication mechanisms and ways to broadcast messages using different rules. Basically, I wanted something like SocketIO, which I didn’t use for some reason, but I might as well try sometime in the future, because there is googollee/go-socket.io, which seems to do the trick.


If you managed to read till the end, I suggest you try out PocketBase before you look into my template, because they basically acheived what I was trying to do and surpassed me in some aspects (eg. beautiful admin interface).

#dev #wow #go #solidjs