feat(clarity): Clarity content provider for state diagrams#146
Merged
Conversation
Adds a Clarity content provider that renders a live Mermaid state
diagram on any Ash resource vertex whose module uses AshStateMachine.
The provider is only compiled when `clarity` is a dependency of the
host project (guarded via `Code.ensure_loaded?(Clarity.Content)`) and
is registered via this library's `application/0` environment under
`:clarity_content_providers` — Clarity discovers it automatically.
Diagram output comes from `AshStateMachine.Charts.mermaid_state_diagram/1`,
the same function behind `mix ash_state_machine.generate_flow_charts`,
so the diagram stays in lock-step with the DSL.
Adds `{:clarity, "~> 0.3", optional: true}` to deps.
zachdaniel
approved these changes
Apr 22, 2026
Contributor
|
🚀 Thank you for your contribution! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a Clarity content provider that surfaces a live Mermaid state diagram on any Ash resource vertex whose module uses
AshStateMachine. Same Mermaid asmix ash_state_machine.generate_flow_charts, but rendered in the Clarity UI directly from the DSL — no need to regenerate.mmdfiles.Once merged, a consumer with both
ash_state_machineandclarityin their deps automatically gets a State Machine tab alongside Resource Overview, Policies, Actions, etc. — zero config.How it works
lib/clarity/state_machine_diagram.exdefinesAshStateMachine.Clarity.StateMachineDiagram, guarded bywith {:module, _} <- Code.ensure_loaded(Clarity.Content)so the module is only compiled when Clarity is present.mix.exsregisters it viaapplication/0:```elixir
env: [clarity_content_providers: [AshStateMachine.Clarity.StateMachineDiagram]]
```
Clarity's
Clarity.Config.list_content_providers/0walks every loaded app's env and picks it up automatically.{:clarity, \"~> 0.3\", optional: true}added to deps — follows the same conventionash_diagramuses.Diagram rendering delegates to
AshStateMachine.Charts.mermaid_state_diagram/1, so the visual is guaranteed to match the DSL.Rationale
Cross-cutting Ash diagrams (ER, class, C4) belong in
ash_diagram. Extension-specific diagrams like state-machine flow are owned most naturally by the extension itself — the DSL and the diagram are one code change away from each other, versions move together, and no central-library coordination is required as the Ash ecosystem grows. Module name usesAshStateMachine.Clarity.*(rather thanClarityContent.*) to leave room for future Clarity additions (vertex types, introspectors) under the same namespace.Test plan
mix compile— passesmix test— 19 existing tests still green{:clarity, ...}is added,/clarityshows a "State Machine" tab on any resource that usesAshStateMachine, rendering the correct Mermaid diagramapplies?/2correctly skips resources that don't useAshStateMachineNotes
igniterconstraint (~> 0.6.25) excludes the igniter 0.7.x currently inmix.lock.mix deps.getafter deleting the lock resolved cleanly; CI should confirm. If it doesn't, happy to pin clarity to~> 0.4or adjust the igniter constraint — whichever you prefer.documentation/topics/charts.md.