cardinal

App layout

The folders of an app and the keys of its app.exs manifest.

cardinal app new NAME writes the skeleton. The folders below it are read by name, so keep them where the table puts them.

cardinal app new library --with-frontend --requires erp

--with-frontend adds a desk plugin in frontend/. CLI commands lists every file it writes. Each --requires APP names an app already in apps/. It goes into the manifest's requires and into mix.exs as a path dependency, so that app compiles first.

Folders

PathHolds
app.exsThe manifest
mix.exsThe Mix project. It depends on cardinal_core and cardinal_jobs
lib/<app>.exThe module that calls use Cardinal.App
lib/controllers/Lifecycle hooks, one module per RecType
lib/rpc/@rpc functions, served at /api/rpc/...
lib/workers/Background job workers
rectypes/One YAML file per RecType
permissions/Rules the app adds to other apps' RecTypes
fixtures/Records the app ships, one file per RecType
patches/<version>/One-off data migrations
www/, templates/Public web pages and Jinja templates
locale/Translation catalogs (.pot, .po)
frontend/The desk plugin and the app's own frontend
test/ExUnit tests
as_system_allowlist.txtReviewed as_system call sites

use Cardinal.App reads the manifest and every YAML file at compile time and embeds them in the module. A release reads no app files.

lib/library.ex
defmodule Library do
  use Cardinal.App
end

The manifest

app.exs is a keyword list. A misspelt key fails the build.

app.exs
[
  name: :library,
  version: "0.1.0",
  requires: [cardinal: "~> 0.1"],
  modules: ["Library"],
  roles: ["Librarian"],
  fixtures: []
]
KeyMeaning
nameThe app's name, an atom
versionA semantic version. Installs record it, and a downgrade is refused
requiresCardinal's version range and each app this one needs
modulesThe module names its RecTypes may use
rolesThe roles the app declares
fixturesRecTypes whose records the app ships, in install order

A required app can carry where to fetch it:

requires: [
  cardinal: "~> 0.6",
  erp: [version: "~> 1.2", git: "https://github.com/acme/erp", tag: "v1.2.0", commit: "3f2a9c1"]
]

Optional keys

The common ones are below. Manifest reference lists every key.

KeyExample from a real app
scheduler[{:daily, Crm.Workers.InvitationExpiryWorker}]
rec_events[{"Purchase Invoice", GstCompliance.Controllers.PurchaseInvoiceEvents}], hooks on another app's RecType
apps_screen[%{name: "crm", title: "CRM", logo: "handshake", route: "/desk/frappe-crm"}]
sidebarsA module's panel rows, %{link_to: "CRM Lead", label: "Leads"}
folded_modules%{"Lead Syncing" => "FCRM"}
route_rules[%{from_route: "/crm-form/<route>", to_route: "crm-form"}]
redirects[%{source: "/old-hello/(.*)", target: "/hello?n=\\1"}]
createEntries in a form's Create menu, each %{from, to, rpc}
connectionsGroups on a record's Connections panel
global_searchRecType names in search priority order
pages[[name: "Gate Board", module: "Gate", roles: ["Gate Manager"]]], desk pages a plugin renders
widgetsWorkspace widgets, each %{name, label, sizes}
cli[{"repost-stock", Erp.CLI.RepostStock}], run as cardinal erp:repost-stock
envEnvironment variables the app reads. Install adds missing ones to .env
frontend%{mount: "hrms", entry: "app/index.html"}, a single-page app at /hrms/
priorityAn integer that orders apps no requirement orders, lower first

Module callbacks

The use Cardinal.App module may also define these functions.

FunctionRuns
after_install(ctx)Once, in the install transaction, after the fixtures
after_migrate(ctx)On every install and migrate. It must change nothing when there is nothing to do
boot(ctx)On every desk boot. Its map reaches the desk under apps.<name>
setup_wizard(ctx, args)During the first-run setup, with the wizard's fields and the app's own slides under args["app"]. An app installed after setup is marked complete and never runs it

Check the build

cardinal app check   # requires, versions and cycles; prints the hook order
cardinal meta check  # every app's RecType, permission and website files

Hooks run in requires order, then by priority, then by app name. That order is the same on every node.

On this page