- Elixir 92.6%
- CSS 3.9%
- JavaScript 2.7%
- Shell 0.8%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| config | ||
| dev | ||
| documentation | ||
| lib | ||
| priv/assets/js/ash_cms | ||
| test | ||
| .formatter.exs | ||
| .gitignore | ||
| AGENTS.md | ||
| dev.sh | ||
| LICENSE.md | ||
| llms.txt | ||
| llmsfull.txt | ||
| mix.exs | ||
| mix.lock | ||
| README.md | ||
AshCms
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:
- LLM Working Context - concise first-read guidance for agents.
- Full LLM Documentation Corpus - one-file searchable aggregate of the public docs, topic guides, DSL references, roadmap, and demo READMEs.
- Get Started
- Sites and Routing
- Scoped Tailwind Assets
- Ash Resources and Storage
- Lua Templates and Component Calls
- Events, Effects, and Fragments
- Observability and Telemetry
- Editor and Tenancy
- Internationalization
- Local Development
- Roadmap
See the DSL reference for the full site and resource DSL:
documentation/dsls/DSL-AshCms.Site.mddocumentation/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.