Make a web or webapp in 2024 with Clojure and Clojurescript

Hello everyone and thanks for your time. I have had a lot of time without using Clojure. But, my company is asking me to make a small web or webapp that uses to a sqlite database. I want to make it using Clojure or Clojurescript but I don’t know which is the best tecnologies now. I don’t know if the best is to use reframe, maybe reagent too, I was thinking in luminus or similar framework, but I really don’t know. Could someone guide me on how to do this? Thanks for the answers.

As if often the case, the answer is “it depends”.

A web app that relies only on UI components that you can build yourself, doesn’t have extra pages, and uses only JSON HTTP API, uses simple static SQL queries, can be comfortably built with just Clojure, ClojureScript, next-jdbc for SQLite, and some web server (maybe Ring on top of Jetty, maybe http-kit, maybe something else). With no other dependencies. This is a good post on the topic when it comes to the CLJS part: Applying the Art of CLJS Frontend

A web app that relies on existing React components, has multiple pages, uses WebSockets/GraphQL/Protobuf/whatever else you can throw here, requires dynamic or intricate SQL queries, will require:

  • React itself that you’ll use via one of the existing wrappers (Reagent, maybe with re-frame or without, UIx, Helix, maybe something else)
  • A way to build the CLJS code with all the dependencies from NPM (shadow-cljs is best here IMO)
  • A router on both ends (I prefer reitit)
  • Some way to build SQL queries at run time (my preference here is HoneySQL)
  • Whatever you might need for the transport layer
  • And also next-jdbc and some web server

Making good informed choices requires learning about all potential problems, the existing solutions, and what dictates every particular choice. If you feel like it - awesome, you have your reading and experimenting cut out for you. :slight_smile: If you don’t feel like it - Pedestal and Luminus are both fine choices. Going this route doesn’t mean you won’t have to learn, but some of the choices will have bene made for you (and those might not be the ones that you’d yourself make). Of course there are other frameworks, but I either know very little about them or can’t recommend them to a beginner.

Some additional reading: What Web Framework Should I Use in Clojure?

1 Like

Your answer seem to me perfect. Thank you very much.

1 Like

Awesome, that you have the chance to use Clojure again :partying_face:

If you don’t need to build any super interactive UI (a visual editor or similar), then I would go with htmx, Hiccup, next-jdbc for SQLite, Ring, httpkit and TailwindCSS. This video should provide a good overview regarding htmx + Hiccup:

Htmx will help to avoid a lot of API churn and security issues down the road:

4 Likes

Thanks for the answer. I still love Clojure, but I have started a new job in a new company, and with that company I use Elisp.
But now I have a new project and I want to use Clojure for it.

3 Likes

seancorfield/usermanager-example: A little demo web app in Clojure, using Component, Ring, Compojure, Selmer (and a database) (github.com) is a small Clojure web app that uses SQLite that might be a useful template for you. The README also links to versions built with Integrant/reitit (instead of Component/Compojure), as well as a Polylith-structured version, and one that uses XTDB for the database.

1 Like

Maybe give Electric Clojure a try as well? There’s a tutorial repo meant for playing with it and get to know it:

2 Likes

If you’re considering luminus then I would look at kit-clj instead. This is the ‘new and improved’ version from the same authors. I’m far from a professional software dev., so take my words with a generous amount of salt, but I’ve found it very helpful to generate a template from that and to gradually add (inject) the extensions to see something of the ‘best practises’ of a modern clojure web app. The very ability to do this was also new to me.

Eric Normand described Luminus (forgive his spelling :slight_smile: ) as such:

Think of Luminous as the set of libraries and configurations you would build yourself over ten years of work on an application. You might not need them at first, but eventually, you will want security, logging, and internationalization, among other concerns. Luminus gives that to you with one command.

Kit-clj is the next version and so I’m guessing it will give you a good (but opinionated) answer to your question.

1 Like

In addition to the other answers, I would recommend using unpoly on the browser side. It’s comparable to htmx and makes writing a multi page application a breeze. No need to do any Clojurescript. And still you can put all your rendering logic etc. on the backend site, using Clojure. I found it easy to use, intuitive, and hazzle-free.

2 Likes

“new company” and “elisp” – something I never expected to see in the same sentence!

1 Like

See this story on a whole air controlling system running on Emacs…

That is fascinating! Thanks for the link. The comments were gold: “emacs makes a great air-traffic controller, but could use a good text editor”