The mishka_cms_core package
v0.0.3
mishka_cms_core is the engine of Mishka CMS: an Elixir library built on Ash and Phoenix LiveView that turns database rows into running websites. This page says what the package holds, what a host supplies, how a host or an extension adds it and what the core leaves to other packages.
What the core does
The package holds the resources and the runtime of the CMS:
- Sites, with their own domain, languages, settings and content. A request is matched to its site by host, and a site serves LiveView pages, the JSON:API or both.
- Pages, layouts, components, error pages, stylesheets, JS hooks, media, translations, redirects, head code and settings.
- A runtime compiler. Pages, layouts, components and error pages become modules at runtime from HEEx, EEx or Markdown. Each site gets one stylesheet built with Tailwind CSS and one script bundle.
MishkaCmsCore.Runtime.Authoring, the document layer every authored template goes through: the HEEx tree and its edit operations, the checks a template must pass before it compiles, page forms, and the fields and elements an editor offers.- Accounts on AshAuthentication, with permissions, two-step sign-in, rate limits, a captcha, notifications and an activity log.
- The admin dashboard screens, a settings registry, email delivery, SEO fields, a sitemap and robots file for each site.
- A health check at
/_healththat answers 200 only when the node is ready, and agent receipts, which record what each tracked operation did, checked stage by stage.
Autosaved drafts, version history with restore and archiving instead of deletion apply to the versioned resources. See Drafts, publishing and versions.
What a host supplies
The package has no endpoint, router or repo of its own. The host application supplies them. Mishka CMS, the application that runs the core, tells it which repo, endpoint and web module to use:
config :mishka_cms_core,
repo: MishkaCms.Repo,
endpoint: MishkaCmsWeb.Endpoint,
host_app: :mishka_cms,
web_module: MishkaCmsWeb,
core_components: MishkaCmsWeb.CoreComponentsThe same file lists the extensions the host loads and the Ash domains that hold their tables:
config :mishka_cms_core,
extensions: [MishkaCmsCoreWeb, MishkaBlogWeb, MishkaDocumentWeb, MishkaCmsBuilderWeb]
config :mishka_cms,
ash_domains: [
MishkaCmsBuilder,
MishkaDocument,
MishkaBlog,
MishkaCmsCore.Runtime,
MishkaCmsCore.Accounts,
MishkaCmsCore.Notify,
MishkaCmsCore.Mail
]The Mishka CMS repository wires all of this for you. A host of your own copies these lines from it.
What a host mounts
Three seams of the core are the host's to wire. The Mishka CMS repository already does each of them.
- The health check.
plug MishkaCmsCore.Runtime.Plugs.HealthPluggoes in the endpoint before the sockets, the site lookup and the session, soGET /_healthanswers on any host and over plain HTTP. See Deploy Mishka CMS to production. - The API routes of extensions.
extension_routes(:api)mounts each extension'sroutes(:api)in a scope of its own, before the page catch-all, behind a pipeline that finds the site from its host, keeps the install and offline gates, and has no CSRF check and no sign-in. A site that switched the extension off answers 404, and the answer never writes a session cookie. A request that changes data reads an empty session, so a route that takes one checks the request itself, as a webhook checks its signature. The router refuses to compile an API route that starts with an address the host owns (/admin,/api,/auth,/gql,/install,/_preview,/_health,/dev,/oban,/uploads,/assets,/fonts,/images,/live,/wsor/phoenix), is/or starts with a capture, repeats another route's verb and path, or is a LiveView route. - The visitor's user agent. The live socket lists
:user_agentin itsconnect_info, so an extension can leave a bot's view uncounted.
Add it
A project cloned from the Mishka CMS repository already depends on it, and Install Mishka CMS and sign in uses that project. In a host of your own, add the package from Hex:
{:mishka_cms_core, "~> 0.0.3"}Then add the config above. An extension that depends on the core lists its own web module under extensions and its domain under ash_domains. See Install an extension and Extensions and plugins.
How extensions plug in
- Every create, update and destroy action on a resource that lists the plugin-hook notifier fires a Mishka Installer event named
<app>:<resource>:after_<action>, such asblog:comment:after_create. A create or update also firesafter_save. See Plugin events. - An extension adds routes with the
MishkaCmsCore.ExtensionRouterbehaviour and sidebar entries on thesidebar:menusevent, and it appears in the install wizard by subscribing toinstaller:extension:install. - An extension adds to the admin shell with the
topbar:*events, thesidebar:statusevent and thesettings:panelsevent, and it follows a failure that an admin skips onfailure:skip:changed. See The admin console: sidebar and top bar. - An extension answers a record's old address on
runtime:page:moved, names the states of a page's preview onruntime:page:preview_states, and adds head tags onruntime:page:head. See Plugin events. - Admin permissions are plain strings such as
admin:dashboard:runtime:page, where a*as the last segment covers everything below it. See How permissions work.
What works without the builder
The visual editor is not part of the core. It is the separate package mishka_cms_builder, split out of the core in version 0.0.3. The core keeps the authoring layer and answers the editor through plugin seams, so a CMS without the builder works as before:
- The admin keeps the code editor, and a create menu opens the form.
- The dashboards show no button that opens the editor, because nothing answers the
runtime:document:editor_urlevent. - Pages, layouts, components and error pages are written, checked and compiled the same way.