A Lua backed CMS built for the Ash ecosystem
  • Elixir 92.6%
  • CSS 3.9%
  • JavaScript 2.7%
  • Shell 0.8%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-07-08 09:09:38 +02:00
config Initial rc 2026-07-01 13:10:48 +02:00
dev Add Postgres-backed scoped CSS materialization 2026-07-04 19:10:36 +02:00
documentation Add AshCMS telemetry spans 2026-07-08 09:08:37 +02:00
lib Optimize Lua rendering hot paths 2026-07-08 09:09:08 +02:00
priv/assets/js/ash_cms Handle explicit click RPC submit controls 2026-07-01 13:48:43 +02:00
test Add rendering performance coverage 2026-07-08 09:09:38 +02:00
.formatter.exs Add i18n maintenance checks 2026-07-07 15:41:00 +02:00
.gitignore Initial rc 2026-07-01 13:10:48 +02:00
AGENTS.md Initial rc 2026-07-01 13:10:48 +02:00
dev.sh Initial rc 2026-07-01 13:10:48 +02:00
LICENSE.md Initial rc 2026-07-01 13:10:48 +02:00
llms.txt Add AshCMS telemetry spans 2026-07-08 09:08:37 +02:00
llmsfull.txt Add AshCMS telemetry spans 2026-07-08 09:08:37 +02:00
mix.exs Add AshCMS telemetry spans 2026-07-08 09:08:37 +02:00
mix.lock Add Postgres-backed scoped CSS materialization 2026-07-04 19:10:36 +02:00
README.md Add AshCMS telemetry spans 2026-07-08 09:08:37 +02:00

AshCms

Hex version badge Hexdocs badge

AshCms is an Ash-native CMS runtime for Phoenix applications that render full HTML documents through Lua, store editable page/component/layout source in Ash resources, and expose a Hologram editor for managing those records.

The host application owns its data model, Ash resources, policies, tenancy, and persistence. AshCms supplies the site DSL, Phoenix runtime endpoints, Lua renderer, browser runtime, editor surface, and storage contract around those host-owned resources.

What It Provides

  • Spark DSLs for declaring AshCms sites and marking Ash resources with CMS roles.
  • Full-page Lua rendering backed by ash_lua.
  • Source-backed pages, components, layouts, and optional translations through host-owned Ash resources, including i18n orphan and missing-locale checks.
  • Built-in layout primitives for sections, containers, stacks, and responsive grids without seeded component records.
  • Built-in form primitives with Ash-shaped validation errors and inline field error rendering.
  • Route bindings that call AshLua namespaces or host-derived callbacks.
  • Progressive browser updates through RPC, effects, and Lua-rendered fragments.
  • Telemetry spans for page, Lua, component, asset, and CSS timing.
  • A Hologram editor for page, component, and layout authoring.
  • Demo Phoenix apps under dev/ for full-site Lua rendering and mixed Phoenix/Lua routing.

Installation

Add ash_cms and ash_postgres to the host application:

def deps do
  [
    {:ash_cms, "~> 0.1.0"},
    {:ash_postgres, "~> 2.0"}
  ]
end

AshCms is Postgres-first. The editable CMS state is expected to live in host-owned AshPostgres resources so migrations, constraints, policies, and future granular editor operations use normal Ash tooling.

Documentation

Start with the getting-started guide, then move into topic guides:

See the DSL reference for the full site and resource DSL:

  • documentation/dsls/DSL-AshCms.Site.md
  • documentation/dsls/DSL-AshCms.Resource.md

Minimal Site Shape

defmodule AppWeb.PublicSite do
  use AshCms.Site,
    otp_app: :app,
    authority: AppWeb.PublicAuthority,
    cms_domain: App.Cms,
    renderer: AshCms.Renderer.Lua,
    template_resolver: AppWeb.PublicTemplates

  lua_surface do
    otp_app :app
    labels [:cms]
  end

  browser_assets do
    serve_from "/_ash_cms/assets"
    rpc_path "/_ash_cms/rpc"
    sse_path "/_ash_cms/events"
  end

  tailwind do
    source_dir "priv/ash_cms/tailwind"
    public_path "/assets/ash_cms"
    asset_path "css"
  end

  site_bindings do
    bind :site, call: "site.current", output: :site do
      input input: %{host: request(:host)}
    end
  end

  routes do
    page "/", name: "catalog.products" do
      resolve_page do
        input route_name: "catalog.products",
              site_id: binding(:site, "id")
      end

      bind :products, call: "catalog.products", output: :product_list do
        input input: %{category: query("category")}
      end

      render "public.products"
    end

    page "/products/:slug", name: "catalog.product" do
      bind :product, call: "catalog.product", output: :product do
        input input: %{slug: param(:slug)}
      end

      render "public.product"
    end
  end

  fragments do
    fragment :product_grid do
      target "product-grid"
      render "fragments.product_grid"
    end
  end
end

AshCms does not define a tenant-field DSL. If CMS records are tenant-owned, model that in the host resources with normal Ash attributes, relationships, actions, and policies. AshCms only passes optional editor scope inputs such as ash_cms_tenant_id to host actions that declare them.

For editor routing, keep host selectors explicit. Tenant-owned copies should be selected by tenant_id only. If global admins can edit multiple global base sets, put whatever selector the host app owns in the URL, such as /cms/global/:base_id, and pass it as trusted action_input to host actions that declare the matching argument. The selector key is not built into AshCms; examples often use base_package_id, but a host may use any declared action argument.

Tenant scopes may also show inherited global fallback records without copying the whole base set. Host list actions can mark rows with owner_scope, artifact_key, and source_id; AshCms exposes inherited?/override? metadata. The Hologram editor shows inherited rows as read-only until the user explicitly chooses Customize, which calls a host create :create_override action and switches editing to the tenant-owned override. AshCms does not autosave editor changes; Save, Publish, and Customize are explicit actions.

If no custom layout is configured, AshCms wraps rendered page content in a built-in Lua layout that emits the scoped stylesheet link and AshCms browser runtime. Add a layout block only when the site needs a custom document shell. Prefer layout do name "public.layout" end for a CMS-stored layout record; layout do template "public.layout" end is the code-backed escape hatch.

Preview pages can render the real CMS/Lua templates against static fixture data by passing trusted action_overrides from host code. If the preview runtime is mounted under a separate path, pass matching per-request browser_assets overrides (serve_from/base_path, rpc_path, sse_path) to page, asset, RPC, SSE, and progressive endpoints.

AshCms resolves scoped CSS when a page renders render.assets.stylesheet_link. The compiled stylesheet is materialized through the Ash resource marked cms role :css and exposed at content-tagged URLs such as /assets/ash_cms/css/global.<etag>.css and /assets/ash_cms/css/tenant_aurora.<etag>.css. Tagged responses include an ETag and cache-control: public, max-age=31536000, immutable; untagged scope URLs redirect to the current tagged URL.

Theme/plugin CSS belongs in the site tailwind block so every materialization path sees the same compiler inputs:

tailwind do
  plugin_css {AppWeb.StorefrontSite.TailwindTheme, :plugin_css, []}
  custom_css ".cms-custom-token{color:var(--color-popover)}"
end

Public rendering only reads materialized CSS and can serve the newest old tag while AshOban rebuilds dirty rows. Editor, preview, or publish save paths can request immediate CSS with tailwind: [ensure?: true, scope: tenant_id].

You can still run mix ash_cms.tailwind --site AppWeb.PublicSite --scope global or another explicit scope in the host app after CMS records are seeded or published. The task reads aggregate page, component, layout, built-in layout primitive, and template source for that scope, extracts Tailwind candidates, and compiles scoped CSS through AshCms' bundled runtime compiler into the materialized CSS resource. It does not write stylesheet files to disk.

Minimal Resource Shape

defmodule App.Cms.Page do
  use Ash.Resource,
    otp_app: :app,
    domain: App.Cms,
    data_layer: AshPostgres.DataLayer,
    extensions: [AshCms.Resource]

  cms do
    role :page
  end
end

For scoped CSS, add one host-owned resource to the CMS domain:

defmodule App.Cms.Css do
  use Ash.Resource,
    otp_app: :app,
    domain: App.Cms,
    data_layer: AshPostgres.DataLayer,
    extensions: [AshCms.Resource]

  cms do
    role :css
  end

  postgres do
    table "cms_css"
    repo App.Repo
  end

  attributes do
    uuid_primary_key :id

    attribute :site, :string, public?: true, allow_nil?: false
    attribute :scope_id, :string, public?: true, allow_nil?: false
    attribute :href, :string, public?: true, allow_nil?: false
    attribute :etag, :string, public?: true, allow_nil?: false
    attribute :source_hash, :string, public?: true
    attribute :content_hash, :string, public?: true, allow_nil?: false
    attribute :css, :string, public?: true, allow_nil?: false
    attribute :byte_size, :integer, public?: true, allow_nil?: false
  end
end

Pages, components, layouts, and subscriptions are host-owned Ash resources that store Lua template_source or handler source. Translations are optional host-owned resources. cms role :css stores materialized scoped stylesheet content and tags. AshCms injects the conventional CSS read/create/update/destroy actions, dirty-marking actions, metadata attributes, and the AshOban trigger for Postgres-backed CSS resources; the host owns the table, migrations, and Oban runtime. Layouts use cms role :layout and can point at a code template or store their own Lua source; page subscriptions use cms role :subscription and run server-side from PubSub-backed SSE events.

Each storage role is documented in Ash Resources and Storage and in the generated AshCms.Resource DSL reference.

Local Development

The repo ships committed demo/example apps under dev/, but they are not part of the root compilation or package artifacts.

./dev.sh setup-dev
./dev.sh start storefront
./dev.sh urls

dev/demo_storefront is the main full-site Lua storefront demo. dev/demo_mixed_articles shows a normal Phoenix app that forwards only an article subtree to AshCms.