Foundry.Context.Introspector (foundry v0.2.0)

Copy Markdown

Core Spark DSL introspection logic for mix foundry.context and mix foundry.context.all.

Reads compiled modules via Spark.Dsl.Extension introspection and maps them to Foundry.Context.ModuleContext structs. All reads are against the live compiled beam — never against source text.

Module type detection

Detection order (first match wins):

  1. Implements AshAuthentication subject → :resource (auth)
  2. Uses Ash.Resource:resource
  3. Uses Reactor with Transfer DSL → :transfer
  4. Uses Reactor → checked for Oban worker pattern → :oban_job
  5. Uses Foundry Rule DSL → :rule
  6. Uses Foundry Blueprint DSL → :blueprint
  7. Uses Phoenix.LiveView + LiveResource → :live_page
  8. Implements provider adapter behaviour → :adapter

Caller responsibility

The caller (Mix task) is responsible for ensuring the target project is compiled and its modules are loaded before calling into this module. Introspector never calls Mix.Task.run("compile") itself.

Sensitive detection

A module is marked sensitive: true when its string name appears in manifest.sensitive_resources, or when it is an ash_authentication User/Token resource.

Summary

Functions

Build a ModuleContext for a single module.

Build ModuleContext structs for all Foundry-relevant modules in the compiled project, grouped by domain name string.

Types

opts()

@type opts() :: [manifest_path: String.t(), project_root: String.t()]

Functions

build(mod, opts \\ [])

@spec build(module(), opts()) ::
  {:ok, Foundry.Context.ModuleContext.t()} | {:error, term()}

Build a ModuleContext for a single module.

Returns {:ok, %ModuleContext{}} or {:error, reason}.

build_all(opts \\ [])

@spec build_all(opts()) :: %{
  required(String.t()) => [Foundry.Context.ModuleContext.t()]
}

Build ModuleContext structs for all Foundry-relevant modules in the compiled project, grouped by domain name string.

Returns %{domain_name => [ModuleContext.t()]}.