Declarative, typed, ADT-backed config resolution for Clojure.
Part of the hive-agi ecosystem.
Config resolution across addon systems is ad-hoc: string replacement, manual type parsing, scattered defaults. hive-di replaces all of that with a single defconfig macro that generates typed config, validation, and tests.
;; deps.edn
io.github.hive-agi/hive-di {:git/tag "v0.1.0" :git/sha "..."}
(ns my-app.config
(:require [hive-di.core :refer [defconfig env literal]]))
(defconfig MilvusConfig
:host (env "MILVUS_HOST" :default "localhost" :type :string)
:port (env "MILVUS_PORT" :default 19530 :type :int)
:secure (env "MILVUS_SECURE" :default false :type :bool)
:collection-name (literal "hive-mcp-memory"))
;; From environment + defaults
(resolve-MilvusConfig)
;; => {:ok {:host "localhost" :port 19530 :secure false :collection-name "hive-mcp-memory"}}
;; With overrides (e.g., from addon manifest)
(resolve-MilvusConfig {:host "milvus.svc" :port "9091"})
;; => {:ok {:host "milvus.svc" :port 9091 :secure false :collection-name "hive-mcp-memory"}}
;; With mock env (testing)
(resolve-MilvusConfig {} {:env-fn {"MILVUS_HOST" "prod.host"}})
defconfig generates| Artifact | Description |
|---|---|
MilvusConfig | ADT with :config/resolved, :config/unresolved, :config/invalid variants |
MilvusConfig-fields | Field registry map (source of truth for resolution) |
MilvusConfig-schema | Malli schema (closed map, derived from field types) |
resolve-MilvusConfig | Resolver fn (0/1/2 arity) returning Result |
(ns my-app.config-test
(:require [hive-di.testing :refer [defconfig-tests]]
[my-app.config :refer [MilvusConfig MilvusConfig-fields]]))
(defconfig-tests MilvusConfig MilvusConfig-fields :num-tests 100)
;; Generates:
;; MilvusConfig-totality — resolver never throws for any input
;; MilvusConfig-defaults-only — defaults alone produce valid config
;; MilvusConfig-roundtrip — resolved config survives EDN serialization
;; MilvusConfig-field-mutations — removing each default is handled gracefully
blank->nil: VAR="" triggers default, not silent empty string19530 stays int, no string round-tripenv-fn: Zero mocking frameworks needed for testshive-dsl. Schema validation is opt-inAGPL-3.0-or-later
Can you improve this documentation?Edit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |