API Reference Caravela v#0.12.0

Copy Markdown View Source

Modules

Caravela — a schema-driven, composable full-stack framework for Phoenix.

Trait-based authentication support.

Translate Ecto.Changeset errors into a structured, i18n-ready shape

Compile-time hook that assembles and validates a domain IR.

Raised from Caravela DSL macros when a caller uses them incorrectly. Carries a four-part message (what went wrong, what Caravela got, a suggested fix, a docs URL). See Caravela.Errors for helpers that build one of these from a Macro.Env.

DSL entry point. use Caravela.Domain in a module to declare a domain

Uniform error shape emitted by every Caravela read / write path.

Structured compile-time errors for Caravela's DSL and generators.

Top-level entry point for the ephemeral async-workflow system.

DSL macros for declaring flows. Pulled in via use Caravela.Flow.

GenServer that executes a flow step tree one step at a time.

Step primitives that make up a flow tree.

Wait for ms of state-stability, then advance.

Iterate a collection already in state under key. For every item, invoke fun.(item, state). The fun may return

Invoke tasks_fn.(state) to build a list of zero-arity funs, run them all concurrently, and collect each one's return under the collect_as key in state.

Run every fun in tasks concurrently, take the first to return. The winner is stored under the collect_as key.

Loop step forever. Break by raising or via {:error, _} from Run.

Run fun.(state) once. The return value drives what happens next

Run steps in order.

Synchronously apply fun.(state) → new state.

Pause for ms milliseconds, then advance.

Block until fun.(state) returns truthy, then advance.

DynamicSupervisor for flow runner processes.

Generates the authentication stack for a Caravela.Schema.Domain whose authenticatable entity declares an authenticatable block.

Generates Phoenix LiveView pages that mount the auth Svelte components produced by Caravela.Gen.AuthSvelte.

Generates typed Svelte components for the authentication UI from a domain whose authenticatable entity declares an authenticatable block.

Generates a Phoenix context module for a Caravela.Schema.Domain.

Generates one Phoenix JSON controller per entity in a Caravela.Schema.Domain.

Preserves user-authored code across regenerations.

Generates one Ecto schema module per entity from a compiled Caravela.Schema.Domain.

Generates Absinthe types, queries, and mutations from a Caravela.Schema.Domain.

Renders router snippets for a Caravela domain's generated frontend routes — one block per render mode

Generates Phoenix LiveView modules that mount Svelte components via LiveSvelte.

Generates a single Ecto migration file for every entity in a Caravela.Schema.Domain.

Generates Phoenix controllers that render Svelte components via caravela_svelte's Inertia-style transport (:rest render mode).

Renders the router scope snippet a developer needs to paste into their lib/<app>_web/router.ex after generating controllers.

Generates typed Svelte components and a TypeScript interfaces file from a Caravela.Schema.Domain.

Generates a dynamic Svelte form component from a module that declares use Caravela.Live.Form. The emitted component receives field_visibility and async_errors as props and wraps visibility- gated fields in {#if field_visibility.<name>} blocks.

Raised from Caravela.Gen.* functions and mix caravela.gen.* tasks when a generator can't produce a file given the current domain shape. Shares the four-part message shape with Caravela.DSLError.

Public, JSON-serializable view of a compiled Caravela domain.

DSL for declaring a server-side state machine that a LiveView can mount via Caravela.Live.Template. Mirrors the Ballerina "domain logic" layer: state fields, named updaters that transition the state, and event handlers that run on messages pushed from the Svelte side.

Protocol implementations so Ecto/Decimal types survive the trip from the LiveView socket to a LiveSvelte Svelte component as sensible JSON values instead of struct dumps.

DSL for declaring form-visibility predicates and async-validation rules on top of Caravela.Live.Domain.

on_mount callback that assembles the per-request context map the generated Caravela contexts expect (%{current_user: ..., tenant: ...}) and assigns it to socket.assigns.context.

use macro that binds a Phoenix LiveView to a Caravela.Live.Domain module.

Composable state updater functions for LiveView assigns.

Model Context Protocol server for Caravela.

JSON-RPC 2.0 message encoding, decoding, and builders for the Caravela MCP server.

Method dispatch for the Caravela MCP server.

Stdio event loop for the Caravela MCP server.

Behaviour + registry for Caravela MCP tools.

MCP tool: return the full Caravela IR for a domain module.

MCP tool: return the IR for a single entity within a Caravela domain (fields, relations, policy, auth).

MCP tool: report the render-mode configuration for a Caravela domain's entities — which ones use :live vs :rest, and whether :rest entities opt into SSE realtime.

MCP tool: list the entity names declared by a Caravela domain.

MCP tool: compile a candidate Caravela domain DSL and report any errors as structured data.

Naming conventions translating domain declarations into Elixir module names, file paths, and Postgres table names.

Intermediate Representation for Caravela's triple-target policy system.

A policy allow :action, fn ... end rule. action is one of :create, :update, :delete. arity is 1 or 2.

The compiled IR for a single policy :entity do ... end block.

A field-level visibility rule. arity is either 1 (depends only on the actor — static per request) or 2 (depends on actor + record — evaluated per-row).

A row-level scope rule for an entity.

Router macros that register a Caravela domain's frontend routes at compile time. The router stays in sync with the domain's DSL — add an entity, regenerate, restart the server, and the routes exist.

Internal Intermediate Representation (IR) for a Caravela domain.

Authentication configuration attached to an entity via the authenticatable DSL block.

A whole domain: the top-level IR produced by compilation.

A domain entity (table).

A single field on an entity.

A lifecycle hook declared in the DSL via on_create, on_update, or on_delete.

A relation between two entities.

Row-level multi-tenancy support.

Type mapping between the Caravela DSL, Ecto, and Postgres.

Mix Tasks

One-stop validation for a Caravela-using project.

All-in-one generator. Produces

Generates one Phoenix JSON controller per entity in the domain and prints a router scope snippet the developer can paste into lib/<app>_web/router.ex.

Generates the authentication stack from a Caravela domain whose authenticatable entity declares an authenticatable block.

Generates a Phoenix context module for the given domain, with CRUD functions for every entity, authorization via can_* permissions, and lifecycle hooks via on_*.

Generates an Absinthe schema layer for the given domain: one file each for object types, queries, and mutations. All three delegate to the generated context module, so authorization, hooks, and multi-tenant scoping flow through the Absinthe resolvers for free.

Generates the frontend layer for a Caravela domain: a trio of LiveView modules (index/show/form) per entity, plus typed Svelte components and a TypeScript interfaces file.

Generates Ecto schemas and a migration file from a Caravela domain declaration.

Print a terminal-friendly summary of a compiled Caravela domain — domain-level flags, every entity's fields / relations / policy / auth config, and top-level counts.

Print the public Intermediate Representation of a Caravela domain as JSON. Intended for consumption by editors, LLMs, and external tooling that wants a structured view of the domain without parsing Elixir source.

Start the Model Context Protocol server for the current Caravela project on stdio.