Startrek
A very simple demonstration of coding a reasonably simple API and UI using Clojure, Donut System, i18n support, error handling, HTMX and tests!
Install / Use
/learn @dharrigan/StartrekREADME
= Star Trek Clojure Project :author: David Harrigan :email: dharrigan@gmail.com :docinfo: true :doctype: book :icons: font :numbered: :sectlinks: :sectnums: :setanchors: :source-highlighter: highlightjs :toc: :toclevels: 5
ifdef::env-github[] :tip-caption: :bulb: :note-caption: :information_source: :important-caption: :heavy_exclamation_mark: :caution-caption: :fire: :warning-caption: :warning: endif::[]
== Introduction
This is a very small, yet surprisingly complete, example of using Clojure to serve up a RESTful API and to provide a user interface using Thymeleaf and HTMX. It uses a variety of technologies to demonstrate how this is possible. The project offers a full API CRUD (Create, Read, Update and Delete) experience over some Star Trek starships!
== Features
- API CRUD Functionality
- Login and view for the UI (Delete and Create/Update not implemented yet!)
- Exception Handling (both RESTful and for the UI)
- Internationalisation (i18n)
- Swagger API
- Input Validation (using https://github.com/metosin/malli[Malli])
- https://www.thymeleaf.org[Thymeleaf] to render webpages
- https://htmx.org[HTMX] to provide user interaction via the UI.
=== Star Trek
This backend is written in Clojure and uses a PostgreSQL database to store a list of starships. The technologies in play include:
- https://github.com/metosin/reitit[reitit]
- https://github.com/seancorfield/next-jdbc[next-jdbc]
- https://github.com/seancorfield/honeysql[honeysql]
- https://github.com/donut-power/system[donut.system]
- https://github.com/juxt/aero[juxt aero]
- https://github.com/flyway/flyway[flyway database migration]
- https://babashka.org/[babashka (for some gentle scripting)]
The frontend is rendered using:
- https://www.thymeleaf.org/[thymeleaf]
- https://www.htmx.org[htmx]
Additionally:
- https://cljdoc.org/d/metosin/reitit/0.7.2/doc/advanced/dev-workflow[Uses a dynamic (repl-friendly) reitit dev workflow]
- Also includes tests (including transactional rollbacks per test)!
A full list of the technologies that are used can be found in the deps.edn
file.
This service also exposes https://prometheus.io/docs/introduction/overview/[Prometheus] metrics AND a JMX endpoint for your enjoyment!
=== Engage!
[IMPORTANT]
If you want to use the supplied Justfile, you'll need to have
https://github.com/casey/just/blob/master/justfile[just] installed.
There are at least 3 ways to launch this project:
[IMPORTANT]
You need to have the database and cache services running first (in
a separate terminal). The command to do this, if you have just installed is
just up, or if you don't have just installed, you can do
docker compose -f scripts/docker/docker-compose-services.yml up====
Now, then for the first option:
==== Option 1
[IMPORTANT]
You need to copy the resources/config/config-example.edn to
resources/config/config-local.edn and modify, for example, if you are
connecting to your own PostgreSQL instance.
Fire up your repl using:
clj -M:dev
to load up the dev alias defined in the deps.edn then
(require 'dev)(dev/go)
to start the system.
==== Option 2
[IMPORTANT]
You need to copy the resources/config/config-example.edn to
resources/config/config-local.edn and modify, for example, if you are
connecting to your own PostgreSQL instance.
just run-local
or
bin/buildbin/run-local
==== Option 3
[IMPORTANT]
You don't need to copy any config file, as the docker container is configured
to use config/config-example.edn, and thus this is the one by the
application.
just run-docker
or
bin/buildbin/imagifybin/run-docker
== Interrogating the API
Once the service is up and running (and listening by default on port 8080),
there are a few examples of interrogating the API to pull back some data. The
scripts can be found in scripts/bb.
[IMPORTANT]
You will need https://babashka.org/[Babashka] installed.
To run a script just execute them on the command line, i.e.,
./find-all-starships.clj
If you have https://github.com/borkdude/jet[jet] installed, you can convert the EDN response to JSON like so:
./find-all-starships.clj | jet -o json
== Logging in via the UI
Open up a browser and visit http://localhost:8080/ From that page, click on
the login link. The username and password has been pre-filled in for you.
== License
Find the full https://unlicense.org/[unlicense] in the UNLICENSE (and
LICENSE) file, but here's a snippet:
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
== Feedback
I welcome feedback. I can usually be found hanging out in the #clojure-uk or
#clojure-europe channels on https://clojurians.slack.com[Clojurians] Slack.
You can also email me if you wish :-)
== Finally!
Live Long and Prosper!
Related Skills
openhue
346.8kControl Philips Hue lights and scenes via the OpenHue CLI.
sag
346.8kElevenLabs text-to-speech with mac-style say UX.
weather
346.8kGet current weather and forecasts via wttr.in or Open-Meteo
tweakcc
1.6kCustomize Claude Code's system prompts, create custom toolsets, input pattern highlighters, themes/thinking verbs/spinners, customize input box & user message styling, support AGENTS.md, unlock private/unreleased features, and much more. Supports both native/npm installs on all platforms.
