Safsaf – A Web Framework for Guile

DASD1 pts0 comments

Safsaf - A web framework for Guile

Christopher Baines

Personal website.

Home<br>Posts<br>Projects<br>About<br>Contact

cbaines.net/

posts/

Safsaf - A web framework for Guile

Programming for the web with Guile Knots resource pools

Posts

ZimaBoard 2 Setup

Background

Over the past week or two I've been working on a new web framework for<br>Guile. This is based on the knowledge I've accumulated over the past 7<br>years working on things like the Guix Data<br>Service, Guix Build<br>Coordinator and Nar<br>Herder, but also based on their<br>code, as I've used Claude Code running Claude Opus 4.6 to build this<br>(a large language model).

I've been hesitant to try coding with LLMs so far, I still think<br>there's plenty of reasons to be, and others have done much more<br>thinking about LLMs and the ethical and legal implications of using<br>them to write software.

This blog post definitely isn't an argument for using these tools, but<br>my "excuse" if you call it that, is that I wanted a Guile web<br>framework to both use for existing and new projects, and this was an<br>approach to get there faster and with the limited amount of motivation<br>I have at the moment.

Introducing Safsaf

Safsaf, or Guile Safsaf<br>if you prefer, is a web framework for Guile, built around using<br>Guile Fibers and the Guile<br>Knots web<br>server.

It's only ~1800 lines of code, and the largest part is the router,<br>deciding which handler should respond to requests. The Guix Data<br>Service handled routing using match on the method and path<br>components, and this works pretty well, but for a long while I've<br>wanted a more declarative approach to routing. One where the code<br>could introspect the routes and generate links or even API<br>specifications.

Another important property of having routes as data is that it allows<br>applying handler wrappers to the routes and the handlers that they<br>reference. This is the model that Safsaf uses for middleware or<br>functionality that you want to apply across some or all of the web<br>service. Safsaf comes with a number of useful handler wrappers and<br>functionality like logging and exception handling is implemented as<br>handler wrappers.

I think it's also important what's not included. In comparison to<br>GNU Artanis (which I did try using for the<br>Guix Data Service many years ago), there's no inbuilt support for<br>talking to databases, database migrations, a Model View Controller<br>design or file based templates, and for all these things, I don't<br>currently see a good reason to include support for them.

I would like to look at what can be included for internationalization<br>support, as I think that's important. I'd also like to look at what's<br>required for Server Sent Events (SSE) and WebSocket support,<br>particularly as the Build Farm Front-end (BFFE) uses Server Sent<br>Events.

The Safsaf Git repository includes a couple of example apps which you<br>can run, a<br>paste-bin<br>and a blog<br>site.

There's inevitably some issues with the code, and there's probably<br>some issues with the design as well, but my hope is that this is a<br>good starting point.

If you have any comments or questions, please reach out to me via<br>email at mail@cbaines.net, raise an issue<br>on Forgejo, or contact me<br>on the Fediverse.

Tags:

Fibers

Guile

Guix

Knots

LLMs

Safsaf

guile safsaf framework guix code using

Related Articles