The goal of this project is to provide a FHIR® Server with an internal CQL Evaluation Engine which is able to answer population wide aggregate queries in a timely manner to enable interactive, online queries over millions of patients.
- Language: Main language is Clojure with some parts written in Java.
- Build System: Clojure
tools.deps. All build steps are available viaMakefiles. - Modules: Most code is located in
modules/. Each module is structured similarly.- Frontend: A special module
modules/frontendwritten in Svelte.
- Frontend: A special module
- Server: The FHIR Server is built via the top-level
Makefile.
Rigorous adherence to these patterns is required:
- Functional Core: Blaze is primarily implemented using pure functions.
- Avoid Bang Functions: Don't introduce functions with side effects (
!suffix) if you can avoid it. Instead of a function wrappingswap!orreset!, extract only the pure state transition and apply it at the call site (e.g.(swap! running-jobs mark-running id)with a puremark-running), so the effect stays visible where it happens. Likewise, pass the dereferenced value instead of the atom to functions that only read state.
- Avoid Bang Functions: Don't introduce functions with side effects (
- Error Handling: Use Cognitect Anomalies for error handling. Do not use Exceptions for control flow.
- Component System:
- Use Integrant for wiring components.
- Implement
ig/init-keyandig/halt-key!multimethods. - Define
m/pre-init-specfor dependency validation.
- Specs:
- Every public function must have a spec. Exception: functions in namespaces whose last segment is
impl(e.g.blaze.luid.impl, but notblaze.db.impl.index) don't need specs. - Return Values: Every
s/fdefmust have a:retspec.st/instrumentchecks only:args, so a wrong or missing:retnever fails a test run — that's the reason to be deliberate about it, not a reason to leave it out. For a function returning either a value or an anomaly, use(s/or :value <pred> :anomaly ::anom/anomaly). - Location: Specs must never be defined inline in the implementation namespace. There are two distinct spec namespace conventions:
s/def(data/attribute specs) → dot-separated*.specnamespace (e.g.,blaze.db.node.specforblaze.db.node), in aspec.cljfile nested under the namespace directory.s/fdef(function specs) → hyphen-separated*-specnamespace (e.g.,blaze.db.node-specforblaze.db.node), as a sibling file to the implementation.
- Classpath: Public module-level specs go in
src, but inner-module public function specs should be intestto keep the production classpath small.
- Every public function must have a spec. Exception: functions in namespaces whose last segment is
- Java Interop:
- Avoid reflection.
- Mandatory: Add
(set! *warn-on-reflection* true)to any namespace performing Java interop.
- Null Checks in Java: Guard every argument of a public constructor or method of a Java class that must not be
nullwithrequireNonNull, statically imported fromjava.util.Objects(e.g.this.snapshot = requireNonNull(snapshot);). So anullfails at the call passing it, not later where it is used, possibly on another thread. Arguments of non-public constructors and methods don't need a guard, because their callers are in the same package. - Async Composition:
- Prefer the
blaze.async.comp/do-syncmacro overblaze.async.comp/then-applywhere feasible, also for a single step. Binding the result to a name reads better than an anonymous function like#(into [] (take 2) %). If thethen-applyis followed by other steps likeblaze.async.comp/exceptionally, put thedo-syncform first in the threading macro. - Always use
blaze.async.comp/then-apply,blaze.async.comp/then-composeand similar in conjunction with the threading macro (->), never as a standalone call.
- Prefer the
- Macros:
- Macros must always be
:refered directly so they can be used without a namespace alias prefix (e.g.,[blaze.async.comp :refer [do-sync]]).
- Macros must always be
- Reuse:
- Avoid code duplication.
- Use existing functions if possible.
- Create a function if code is used more than two times.
- Forms over Strings: Analyse and transform FHIRPath expressions as forms, never as source strings (no splitting, regex replacement or assembling of strings).
blaze.fhir-path/parseturns a string into a form,blaze.fhir-path/compilecompiles a form, andblaze.fhir-path/formreturns the form of an already compiled expression. Derive new expressions by transforming forms with plain Clojure (e.g.clojure.walk) and compile the result directly. Useblaze.fhir-path/unparseonly to show a form as FHIRPath, e.g. in messages or as a lookup key, never to parse it again. Likewise, analyse CQL on its ELM or on the forms of compiled expressions (blaze.elm.compiler/form). - Named Functions over Explaining Comments: If a piece of code needs a comment to explain what it does or why, especially an anonymous function whose intent isn't obvious (e.g.
#(or % false)in aswap!), extract it into a function with a name stating its intent and put the explanation into its docstring, instead of writing an inline comment. - Docstrings Name Visible Arguments: If a docstring refers to an argument that the parameter vector destructures, so that its name doesn't appear in the signature (e.g.
{node-id :id}while the docstring talks aboutnode), add:arglistsmetadata with the names the docstring uses (e.g.{:arglists '([db graph node state resource-handle])}). This applies to public and private functions alike. - No no-op nil calls: Don't deliberately call a function with a
nilargument just so it does nothing and returns its input unchanged (e.g. a nil-tolerant pass-through wrapper for an optional dependency). This is an antipattern — it hides the optionality at the call site. Make the call conditional instead (e.g. withcond->), so the absence of the dependency is visible where it matters. - Testing:
- Test-Driven Development (mandatory): Never change production code without first writing a failing test that captures the new behaviour. Write the test, see it fail, then make it pass. This applies to bug fixes (regression test first), new features, and contract changes (e.g. allowing an anomaly return value).
- Spec Instrumentation: Always enable spec instrumentation in tests to catch spec violations early.
- Require
[clojure.spec.test.alpha :as st]. - Call
(st/instrument)at the top level of the test namespace.
- Require
- Java Interop: Enable reflection warnings (
(set! *warn-on-reflection* true)) ONLY if the test namespace performs Java interop. - Fixtures: Use the standard test fixture in all test namespaces.
- Require
[blaze.test-util :as tu]. - Call
(test/use-fixtures :each tu/fixture).
- Require
- Locale: When a test asserts on locale-sensitive formatting (e.g. the thousands separator in
10,000), call(tu/set-default-locale-english!)at the top level of the test namespace. Do not make the production code locale-independent for this — set the locale in the test instead. For this to work the production code must build such strings at call time, not in a top-leveldef(adefis evaluated at namespace load, before the test sets the locale). - Assertions: Use the
givenmacro fromjuxt.iotafor asserting map values (e.g. anomalies).- Require
[juxt.iota :refer [given]]. - Example:
(given (my-fn ...) ::anom/category := ::anom/fault ::anom/message := "...") - Use
isonly for simple scalar equality checks that don't involve maps.
- Require
- Async Testing:
- To assert that a
CompletableFuturecompletes exceptionally with an anomaly, usegiven-failed-futurefromblaze.test-util— not the(given (ba/try-anomaly (ac/join ...)))pattern. - To obtain the value of a successfully-completed future inside a test, use
@future(Clojure'sderef).
- To assert that a
- Private Functions: Do not call private functions (via
#') from tests. If a function needs to be tested, move it to animplnamespace where it becomes part of the public API of that namespace.
- Downloading search results: In integration test scripts (
.github/scripts,.github/integration-test-*), useblazectl downloadto fetch all resources matching a FHIR search — blazectl performs paging. Do not usecurlwith a large_countvalue, which silently truncates the result at one page.
- Dashboard: Every new metric must be charted in the Grafana dashboard. Add a panel to the row of the component exporting the metric in
modules/monitoring/dashboard.edn(not the generated JSON), with a description stating what the metric means and which values are expected, and update the panel and id counts inmodules/monitoring/test/blaze/monitoring/dashboard_test.clj. A metric with labels exports no samples until its first use. If the integration test doesn't exercise it, add it with a comment to the allowlist in.github/scripts/check-dashboard-metrics.sh, so that the dashboard metrics check doesn't fail.
- Environment Variables: Every new environment variable introduced via
#blaze/cfginresources/blaze.ednmust be documented indocs/deployment/environment-variables.md, following the existing format (heading, description, default value, since badge). - API Behaviour: Before finishing, state whether the change alters what a client can observe on an existing interaction or operation (accepted header, parameter, status code, response media type). If it does, update the corresponding page under
docs/api/, including the sibling pages sharing that behaviour, and badge new sections with the version of the issue's GitHub milestone (gh issue view <issue-number> --json milestone). If it's unclear whether a behaviour change is user-facing, ask rather than guess.
- Before implementing a feature that involves real design decisions (competing approaches, non-obvious rules, migrations), write a design document and get it approved. Bug fixes and small enhancements need none; the GitHub issue is enough.
- Design documents follow the structure described in
specs/README.md. Start fromspecs/0000-template.mdand put the document inspecs/YYYY-MM-DD-<topic>-design.md, never underdocs/, which is published. - Set its status to
Acceptedonce it's approved, and commit it together with the change. Don't commit implementation plans: they are build instructions and go stale once the code exists. - Don't rewrite an accepted design document when a later change alters the design. Write a new one and mark the old one as superseded, as described in
specs/README.md. - Link the design document from the issues it was written for and from later issues building on it.
When generating a CHANGELOG.md entry for a new version:
- Fetch issues from the GitHub milestone matching the version name:
gh issue list --milestone <version> --state all --limit 200 --json number,title,labels,state,url - Fetch the milestone number for the "full changelog" link:
gh api repos/samply/blaze/milestones --jq '.[] | select(.title == "<version>") | .number' - Categorize issues by their labels into sections — in this order if present:
Notes,Survey,Security,Enhancements,Performance,Bugfixes,Documentation,Maintenance. Omit issues labeledciand dependency updates. - Use issue titles verbatim (1:1) as the changelog entry text. Do not rewrite, title-case, shorten, or normalize them to the imperative mood — even when an issue title does not follow the usual title conventions. Fixing the issue title is out of scope at release time.
- Insert the new entry at the top of
CHANGELOG.md, directly below the# Changelogheading, following the format of existing entries. - End the entry with:
The full changelog can be found [here](https://github.com/samply/blaze/milestone/<number>?closed=1).
When starting to work on an issue, you can use the GitHub CLI to fetch the issue details: gh issue view <issue-number>
When creating an issue, classify it via GitHub's native issue type (e.g. Bug, Feature), not via a bug/feature label. The gh issue create flag for this is --type (e.g. gh issue create --type Bug ...). Only labels that aren't covered by a type (e.g. module:db) should be passed via --label. The deciding question between Bug and Task is whether something is actually broken, not whether production code is touched. Two cases that are therefore Task, not Bug: bugs in test code that can be fixed purely by changing only test code (e.g. a flaky test), because the production code is unaffected; and hardening production code against a failure mode that no current code path can reach (a latent invariant gap, defence in depth), because nothing is broken yet.
Always run make build-ig first on a freshly created git worktree. Some modules (e.g. job-async-interaction and anything depending on it, like interaction) need the generated IG resources, which are absent in a new worktree and would otherwise make prep fail.
Before finishing a task, ensure the following commands pass:
- Format:
make fmt - Lint:
make lint(Usesclj-kondo) - Test: Run tests only for the modules you changed:
make -C modules/<module> test(e.g.make -C modules/db test). Usemake testonly when changes span multiple modules or the root.- To run a single test or a single namespace, use the
test-focustarget with aFOCUSvariable holding a kaocha test id — either a whole namespace or anamespace/var:make -C modules/<module> test-focus FOCUS=blaze.db.api-testormake -C modules/db test-focus FOCUS=blaze.db.api-test/pull-fn-test. - Changed Java classes: Call
make -C modules/<module> clean test(orclean test-focus) whenever Java classes of a module changed. Theprepstep compiles Java classes only once (guarded bytarget/prep-done), so withoutcleanthe tests silently run against the stale classes.
- To run a single test or a single namespace, use the
- Coverage:
make test-coverage(Checks for adequate test coverage — must be ≥ 95% forms)- Reflection warnings printed during
make test-coverageare normal: cloverage instruments the code in a way that disables type hints, so reflection warnings appear there even for correctly hinted code. Do not try to fix them based on the coverage run — only reflection warnings frommake lint/normal compilation matter.
- Reflection warnings printed during
When adding a new module under modules/, also add it to the module matrix in .github/workflows/build.yml (the test job, sorted alphabetically) so CI picks it up.
Every change requires a GitHub issue. If no issue exists for the work, create one first (see above) before writing any code. All work must be tracked by an issue.
After verification, when working on an issue:
- Commit the changes:
git add .andgit commit- The commit title should be the issue title. Both use the imperative mood, are written in title case, and fit within about 50 characters (e.g.
Fix Error Combining Composite Token-Token Params). - The commit body should just contain:
Closes: #<issue-number> - Do not add a
Co-Authored-Bytrailer (or any other AI/tool attribution). The changes are authored by the human, who appears as the commit's author and uses AI merely as a tool; the AI assistant may appear only as the commit's committer.
- The commit title should be the issue title. Both use the imperative mood, are written in title case, and fit within about 50 characters (e.g.
- There should be exactly one commit per issue. Multiple changes have to be ammended to the first commit.