katzen
Generalized algebraic theories and categorical programming for Clojure.
A Clojure library that lets you declare data schemas with built-in validation rules and write migrations as mappings between schema versions, so your data moves automatically without hand-written migration scripts.
Katzen is a Clojure library that helps you describe the structure of your data and processes once, then automatically check, migrate, and relate that data without writing repetitive boilerplate code. It is a port of a Julia software stack built around category theory, a branch of mathematics concerned with how different structures relate to each other. You do not need to understand the mathematics to use it; the library handles those details and exposes ordinary Clojure code on top.
The main practical benefit is around data schemas and their rules. Instead of scattering validation checks across many places in your code, you declare constraints directly in the schema itself, such as requiring that debits equal credits or that no references point to missing records. When you need to change the shape of your data over time, you write a mapping between the old schema and the new one, and the library moves the data along that mapping without you writing a migration script by hand.
Katzen also supports relating data of different shapes, such as pattern-matching across a graph to find where a given structure appears, or joining two stores that share a common identity. A separate capability covers modeling and simulating dynamic systems: you can describe things like disease spread models or chemical reaction networks, wire subsystems together, and run numerical solvers on them. An optional integration compiles these simulations to fast JVM code.
For exploring how code works visually, the project includes a playground in the browser where you paste a Clojure function and see it rendered as a dataflow diagram. Branches in the code become forks in the diagram, and unused bindings appear as dropped wires.
Installation is a single line added to your deps.edn file. The base library has no extra dependencies. Optional add-ons, each gated behind a separate alias, unlock a persistent queryable store, fast numerical solvers, and a formal proof checker that verifies a schema mapping actually preserves all the rules you declared.
Where it fits
- Declare a financial schema with a constraint that debits must equal credits and have Katzen enforce it automatically across all records.
- Write a mapping between an old schema version and a new one to migrate database records without scripting the transformation by hand.
- Model a simulation such as a disease spread model, wire subsystems together, and run a numerical solver against it in Clojure.
- Paste a Clojure function into the browser playground and see it rendered as a dataflow diagram with branches shown as forks and unused bindings as dropped wires.